Package org.jpox.metadata

Examples of org.jpox.metadata.MapMetaData


            if (valueType == null)
            {
                valueType = ClassUtils.getMapValueType(field.getType(),field.getGenericType());
            }
            // No annotation for maps so cant specify the key/value type, dependent, embedded, serialized
            contmd = new MapMetaData(fmd, keyType, null, null, null, valueType, null, null, null);
        }
        if (contmd != null)
        {
            fmd.setContainer(contmd);           
        }
View Full Code Here


                                mapValueType = ((Class)paramtype.getActualTypeArguments()[1]);
                            }
                        }
                    }

                    contmd = new MapMetaData(mmd,
                        (mapKeyType != null ? mapKeyType.getName() : null), embeddedKey, dependentKey, serializedKey,
                        (mapValueType != null ? mapValueType.getName() : null), embeddedValue, dependentValue, serializedValue);

                    if (embeddedKeyMembers != null)
                    {
View Full Code Here

            }
            // New map container for this field
            else if (localName.equals("map"))
            {
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                MapMetaData map = new MapMetaData(fmd,
                                getAttr(attrs,"key-type"),
                                getAttr(attrs,"embedded-key"),
                                getAttr(attrs,"dependent-key"),
                                getAttr(attrs,"serialized-key"),
                                getAttr(attrs,"value-type"),
View Full Code Here

                {
                    element_class = clr.classForName(fmd.getCollection().getElementType());
                }
                else if (fmd.hasMap())
                {
                    MapMetaData mmd = (MapMetaData)fmd.getContainer();
                    if (fmd.getValueMetaData() != null && fmd.getValueMetaData().getMappedBy() != null)
                    {
                        // value stored in the key table
                        element_class = clr.classForName(mmd.getKeyType());
                    }
                    else if (fmd.getKeyMetaData() != null && fmd.getKeyMetaData().getMappedBy() != null)
                    {
                        // key stored in the value table
                        element_class = clr.classForName(mmd.getValueType());
                    }
                    else
                    {
                        // No information given for what is stored in what, so throw it back to the user to fix the input :-)
                        throw new JPOXUserException(LOCALISER_RDBMS.msg("050050", fmd.getFullFieldName()));
View Full Code Here

            {
                throw new JPOXDataStoreException(LOCALISER.msg("056016", exists ? updateStmt : putStmt),e);
            }
        }

        MapMetaData mapmd = ownerMemberMetaData.getMap();
        if (mapmd.isDependentValue() && !mapmd.isEmbeddedValue() && oldValue != null)
        {
            // Delete the old value if it is no longer contained and is dependent
            if (!containsValue(sm, oldValue))
            {
                sm.getObjectManager().deleteObjectInternal(oldValue);
View Full Code Here

            {
                throw new JPOXDataStoreException(LOCALISER.msg("056012",removeStmt),e);
            }
        }

        MapMetaData mapmd = ownerMemberMetaData.getMap();
        ApiAdapter api = om.getApiAdapter();
        if (mapmd.isDependentKey() && !mapmd.isEmbeddedKey() && api.isPersistable(key))
        {
            // Delete the key if it is dependent
            om.deleteObjectInternal(key);
        }

        if (mapmd.isDependentValue() && !mapmd.isEmbeddedValue() && api.isPersistable(oldValue))
        {
            if (!containsValue(sm, oldValue))
            {
                // Delete the value if it is dependent and is not keyed by another key
                om.deleteObjectInternal(oldValue);
View Full Code Here

            ApiAdapter api = ownerSM.getObjectManager().getApiAdapter();
            Iterator iter = entrySetStore().iterator(ownerSM);
            while (iter.hasNext())
            {
                Map.Entry entry = (Map.Entry)iter.next();
                MapMetaData mapmd = ownerMemberMetaData.getMap();
                if (api.isPersistable(entry.getKey()) && mapmd.isDependentKey() && !mapmd.isEmbeddedKey())
                {
                    dependentElements.add(entry.getKey());
                }
                if (api.isPersistable(entry.getValue()) && mapmd.isDependentValue() && !mapmd.isEmbeddedValue())
                {
                    dependentElements.add(entry.getValue());
                }
            }
        }
View Full Code Here

     **/
    public void initialize(ClassLoaderResolver clr)
    {
        assertIsUninitialized();

        MapMetaData mmd = fmd.getMap();
        if (mmd == null)
        {
            throw new JPOXUserException(LOCALISER.msg("057017",fmd));
        }

        PrimaryKeyMetaData pkmd = (fmd.getJoinMetaData() != null ? fmd.getJoinMetaData().getPrimaryKeyMetaData() : null);
        boolean pkColsSpecified = (pkmd != null && pkmd.getColumnMetaData() != null);
        boolean pkRequired = requiresPrimaryKey();

        // Add owner mapping
        ColumnMetaData[] ownerColmd = null;
        if (fmd.getJoinMetaData() != null &&
            fmd.getJoinMetaData().getColumnMetaData() != null &&
            fmd.getJoinMetaData().getColumnMetaData().length > 0)
        {
            // Column mappings defined at this side (1-N, M-N)
            // When specified at this side they use the <join> tag
            ownerColmd = fmd.getJoinMetaData().getColumnMetaData();
        }
        ownerMapping = ColumnCreator.createColumnsForJoinTables(clr.classForName(ownerType), fmd, ownerColmd,
            storeMgr, this, pkRequired, false, false, false, FieldRole.ROLE_OWNER, clr);
        if (JPOXLogger.DATASTORE.isDebugEnabled())
        {
            debugMapping(ownerMapping);
        }

        // Add key mapping
        boolean keyPC = (fmd.hasMap() && fmd.getMap().getKeyClassMetaData() != null);
        if (isSerialisedKey() || isEmbeddedKeyPC() || (isEmbeddedKey() && !keyPC))
        {
            // Key = PC(embedded), PC(serialised), Non-PC(serialised), Non-PC(embedded)
            keyMapping = dba.getMappingManager().getMapping(this, fmd, dba, clr, JavaTypeMapping.MAPPING_MAP_KEY);
            if (JPOXLogger.DATASTORE.isDebugEnabled())
            {
                debugMapping(keyMapping);
            }
        }
        else
        {
            // Key = PC
            ColumnMetaData[] keyColmd = null;
            KeyMetaData keymd = fmd.getKeyMetaData();
            if (keymd != null && keymd.getColumnMetaData() != null && keymd.getColumnMetaData().length > 0)
            {
                // Column mappings defined at this side (1-N, M-N)
                keyColmd = keymd.getColumnMetaData();
            }
            keyMapping = ColumnCreator.createColumnsForJoinTables(clr.classForName(mmd.getKeyType()), fmd,
                keyColmd, storeMgr, this,  false, false, fmd.getMap().isSerializedKey(), false,
                FieldRole.ROLE_MAP_KEY, clr);
            if (JPOXLogger.DATASTORE.isDebugEnabled())
            {
                debugMapping(keyMapping);
            }
        }

        // Add value mapping
        boolean valuePC = (fmd.hasMap() && fmd.getMap().getValueClassMetaData() != null);
        if (isSerialisedValue() || isEmbeddedValuePC() || (isEmbeddedValue() && !valuePC))
        {
            // Value = PC(embedded), PC(serialised), Non-PC(serialised), Non-PC(embedded)
            // Add field(s) for value
            valueMapping = dba.getMappingManager().getMapping(this, fmd, dba, clr, JavaTypeMapping.MAPPING_MAP_VALUE);
            if (JPOXLogger.DATASTORE.isDebugEnabled())
            {
                debugMapping(valueMapping);
            }
        }
        else
        {
            // Value = PC
            ColumnMetaData[] valueColmd = null;
            ValueMetaData valuemd = fmd.getValueMetaData();
            if (valuemd != null && valuemd.getColumnMetaData() != null && valuemd.getColumnMetaData().length > 0)
            {
                // Column mappings defined at this side (1-N, M-N)
                valueColmd = valuemd.getColumnMetaData();
            }
            valueMapping = ColumnCreator.createColumnsForJoinTables(clr.classForName(mmd.getValueType()), fmd,
                valueColmd, storeMgr, this, false, true, fmd.getMap().isSerializedValue(), false,
                FieldRole.ROLE_MAP_VALUE, clr);
            if (JPOXLogger.DATASTORE.isDebugEnabled())
            {
                debugMapping(valueMapping);
View Full Code Here

    {
        super(storeMgr);

        setOwnerMemberMetaData(fmd);
        String ownerFieldName = fmd.getMappedBy();
        MapMetaData mmd = (MapMetaData)fmd.getContainer();
        if (mmd == null)
        {
            // No <map> specified for this field!
            throw new JPOXUserException(LOCALISER.msg("056002", fmd.getFullFieldName()));
        }

        // Check whether we store the key in the value, or the value in the key
        boolean keyStoredInValue = false;
        if (fmd.getKeyMetaData() != null && fmd.getKeyMetaData().getMappedBy() != null)
        {
            keyStoredInValue = true;
        }
        else if (fmd.getValueMetaData() != null && fmd.getValueMetaData().getMappedBy() == null)
        {
            // No mapped-by specified on either key or value so we dont know what to do with this relation!
            throw new JPOXUserException(LOCALISER.msg("056071", fmd.getFullFieldName()));
        }
        else
        {
            // Should throw an exception since must store key in value or value in key
        }

        // Load the key and value classes
        keyType = mmd.getKeyType();
        valueType = mmd.getValueType();
        Class keyClass = clr.classForName(keyType);
        Class valueClass = clr.classForName(valueType);

        ApiAdapter api = getStoreManager().getApiAdapter();
        if (keyStoredInValue && !api.isPersistable(valueClass))
View Full Code Here

TOP

Related Classes of org.jpox.metadata.MapMetaData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.