Package org.datanucleus.metadata

Examples of org.datanucleus.metadata.ValueMetaData


                        ArrayList<JoinColumn> elementColumns = new ArrayList<JoinColumn>();
                        elementColumns.addAll(Arrays.asList((JoinColumn[])annotationValues.get("inverseJoinColumns")));
                        AbstractElementMetaData aemd = null;
                        if (Map.class.isAssignableFrom(member.getType()))
                        {
                            aemd = new ValueMetaData();
                            mmd.setValueMetaData((ValueMetaData)aemd);
                        }
                        else
                        {
                            aemd = new ElementMetaData();
                            mmd.setElementMetaData((ElementMetaData)aemd);
                        }
                        for (int j = 0; j < elementColumns.size(); j++)
                        {
                            ColumnMetaData colmd = new ColumnMetaData();
                            colmd.setName(elementColumns.get(j).name());
                            colmd.setTarget(elementColumns.get(j).referencedColumnName());
                            colmd.setAllowsNull(elementColumns.get(j).nullable());
                            aemd.addColumn(colmd);
                        }
                    }
                    UniqueConstraint[] joinUniqueConstraints = (UniqueConstraint[])annotationValues.get("uniqueConstraints");
                    if (joinUniqueConstraints != null && joinUniqueConstraints.length > 0)
                    {
                        // Unique constraints on the join table
                        for (int j=0;j<joinUniqueConstraints.length;j++)
                        {
                            UniqueMetaData unimd = new UniqueMetaData();
                            for (int k=0;k<joinUniqueConstraints[j].columnNames().length;k++)
                            {
                                ColumnMetaData colmd = new ColumnMetaData();
                                colmd.setName(joinUniqueConstraints[j].columnNames()[k]);
                                unimd.addColumn(colmd);
                            }
                            joinmd.setUniqueMetaData(unimd); // JDO only supports a single unique constraint on a join table
                        }
                    }
                }
                else if (annName.equals(JPAAnnotationUtils.COLLECTION_TABLE))
                {
                    // Process @CollectionTable to generate JoinMetaData
                    String tableName = (String)annotationValues.get("name");
                    if (!StringUtils.isWhitespace(tableName))
                    {
                        mmd.setTable(tableName);
                    }
                    String catalogName = (String)annotationValues.get("catalog");
                    if (!StringUtils.isWhitespace(catalogName))
                    {
                        mmd.setCatalog(catalogName);
                    }
                    String schemaName = (String)annotationValues.get("schema");
                    if (!StringUtils.isWhitespace(schemaName))
                    {
                        mmd.setSchema(schemaName);
                    }

                    joinmd = mmd.getJoinMetaData();
                    if (joinmd == null)
                    {
                        // Should always be set by @ElementCollection but add just in case
                        joinmd = new JoinMetaData();
                        mmd.setJoinMetaData(joinmd);
                    }

                    if (annotationValues.get("joinColumns") != null)
                    {
                        ArrayList<JoinColumn> joinColumns = new ArrayList<JoinColumn>();
                        joinColumns.addAll(Arrays.asList((JoinColumn[])annotationValues.get("joinColumns")));
                        for (int j = 0; j < joinColumns.size(); j++)
                        {
                            ColumnMetaData colmd = new ColumnMetaData();
                            colmd.setName(joinColumns.get(j).name());
                            colmd.setTarget(joinColumns.get(j).referencedColumnName());
                            colmd.setAllowsNull(joinColumns.get(j).nullable());
                            joinmd.addColumn(colmd);
                        }
                    }
                    UniqueConstraint[] joinUniqueConstraints = (UniqueConstraint[])annotationValues.get("uniqueConstraints");
                    if (joinUniqueConstraints != null && joinUniqueConstraints.length > 0)
                    {
                        // Unique constraints on the join table
                        for (int j=0;j<joinUniqueConstraints.length;j++)
                        {
                            UniqueMetaData unimd = new UniqueMetaData();
                            for (int k=0;k<joinUniqueConstraints[j].columnNames().length;k++)
                            {
                                ColumnMetaData colmd = new ColumnMetaData();
                                colmd.setName(joinUniqueConstraints[j].columnNames()[k]);
                                unimd.addColumn(colmd);
                            }
                            joinmd.setUniqueMetaData(unimd); // JDO only supports a single unique constraint on a join table
                        }
                    }
                }
                else if (annName.equals(JPAAnnotationUtils.MAP_KEY_COLUMN))
                {
                    if (keymd == null)
                    {
                        keymd = new KeyMetaData();
                        mmd.setKeyMetaData(keymd);
                    }
                    String name = (String)annotationValues.get("name");
                    if (name != null)
                    {
                        keymd.setMappedBy(name);
                    }
                    Class keyType = mmd.getMap() != null && mmd.getMap().getKeyType() != null ? clr.classForName(mmd.getMap().getKeyType()) : Object.class;
                    keymd.addColumn(newColumnMetaData(keymd, keyType, annotations));
                }
                else if (annName.equals(JPAAnnotationUtils.MAP_KEY))
                {
                    String keyMappedBy = (String)annotationValues.get("name");
                    if (keyMappedBy != null)
                    {
                        if (keymd == null)
                        {
                            keymd = new KeyMetaData();
                            mmd.setKeyMetaData(keymd);
                        }
                        keymd.setMappedBy(keyMappedBy);
                        if (mmd.getMap() != null &&
                                (mmd.getMap().getKeyType() == null || mmd.getMap().getKeyType().equals(Object.class.getName())))
                        {
                            // Set keyType based on mapped-by field of value class
                            String valueType = mmd.getMap().getValueType();
                            try
                            {
                                Class cls = clr.classForName(valueType);
                                try
                                {
                                    Field fld = cls.getDeclaredField(keyMappedBy);
                                    mmd.getMap().setKeyType(fld.getType().getName());
                                }
                                catch (NoSuchFieldException nsfe)
                                {
                                    try
                                    {
                                        String getterName = ClassUtils.getJavaBeanGetterName(keyMappedBy, false);
                                        Method mthd = cls.getDeclaredMethod(getterName, (Class[])null);
                                        mmd.getMap().setKeyType(mthd.getReturnType().getName());
                                    }
                                    catch (NoSuchMethodException nsme)
                                    {
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                            }
                        }
                    }
                }
                else if (annName.equals(JPAAnnotationUtils.MAP_KEY_ENUMERATED))
                {
                    EnumType type = (EnumType)annotationValues.get("value");
                    if (keymd == null)
                    {
                        keymd = new KeyMetaData();
                        mmd.setKeyMetaData(keymd);
                    }
                    // TODO Merge with any @MapKey specification of the column
                    ColumnMetaData colmd = keymd.newColumnMetaData();
                    colmd.setJdbcType(type == EnumType.STRING ? "VARCHAR" : "INTEGER");
                }
                else if (annName.equals(JPAAnnotationUtils.ORDER_BY))
                {
                    if (mmd.getOrderMetaData() != null)
                    {
                        throw new NucleusException("@OrderBy found yet field=" +
                            cmd.getFullClassName() + "." + member.getName() +
                            " already has ordering information!");
                    }

                    String orderBy = (String)annotationValues.get("value");
                    if (orderBy != null)
                    {
                        // "Ordered List"
                        OrderMetaData ordmd = new OrderMetaData();
                        ordmd.setOrdering(orderBy);
                        mmd.setOrderMetaData(ordmd);
                    }
                }
                else if (annName.equals(JPAAnnotationUtils.ORDER_COLUMN))
                {
                    if (mmd.getOrderMetaData() != null)
                    {
                        throw new NucleusException("@OrderColumn found yet field=" +
                            cmd.getFullClassName() + "." + member.getName() +
                        " already has ordering information!");
                    }

                    String columnName = (String)annotationValues.get("name");
                    OrderMetaData ordermd = new OrderMetaData();
                    ordermd.setColumnName(columnName);

                    String colNullable = null;
                    String colInsertable = null;
                    String colUpdateable = null;
                    if (annotationValues.get("nullable") != null)
                    {
                        colNullable = annotationValues.get("nullable").toString();
                    }
                    if (annotationValues.get("insertable") != null)
                    {
                        colInsertable = annotationValues.get("insertable").toString();
                    }
                    if (annotationValues.get("updatable") != null)
                    {
                        // Note : "updatable" is spelt incorrectly in the JPA spec.
                        colUpdateable = annotationValues.get("updatable").toString();
                    }
                    ColumnMetaData colmd = new ColumnMetaData();
                    colmd.setName(columnName);
                    colmd.setAllowsNull(colNullable);
                    colmd.setInsertable(colInsertable);
                    colmd.setUpdateable(colUpdateable);
                    String tmp = (String)annotationValues.get("columnDefinition");
                    if (!StringUtils.isWhitespace(tmp))
                    {
                        colmd.setColumnDdl(tmp);
                    }
                    ordermd.addColumn(colmd);
                    mmd.setOrderMetaData(ordermd);
                }
                else if (annName.equals(JPAAnnotationUtils.ONE_TO_MANY))
                {
                    // 1-N relation
                    oneToMany = true;
                }
                else if (annName.equals(JPAAnnotationUtils.MANY_TO_MANY))
                {
                    // M-N relation
                    manyToMany = true;
                }
            }

            // Post-processing to apply JPA rules for field relationships etc
            if (oneToMany && mmd.getJoinMetaData() == null && mmd.getMappedBy() == null &&
                jpaLevel.equalsIgnoreCase("JPA1"))
            {
                // 1-N with no join specified and unidirectional so JPA says it has to be via join (no 1-N uni FKs)
                mmd.setJoinMetaData(new JoinMetaData());
            }
            if (manyToMany && mmd.getJoinMetaData() == null && mmd.getMappedBy() == null)
            {
                // M-N with no join specified and unidir so add the join for them
                mmd.setJoinMetaData(new JoinMetaData());
            }

            if (mmd.getOrderMetaData() == null && Collection.class.isAssignableFrom(member.getType()))
            {
                // @OrderBy not specified but is a Collection so use ordering of element using PK field(s)
                OrderMetaData ordmd = new OrderMetaData();
                ordmd.setOrdering("#PK"); // Special value recognised by OrderMetaData
                mmd.setOrderMetaData(ordmd);
            }

            if (columnMetaData == null)
            {
                // Column specified (at least in part) via @Column/@Lob/@Enumerated/@Temporal
                ColumnMetaData colmd = newColumnMetaData(mmd, member.getType(), annotations);
                if (colmd != null)
                {
                    columnMetaData = new ColumnMetaData[1];
                    columnMetaData[0] = colmd;
                }
            }

            if (columnMetaData != null)
            {
                // Column definition provided so apply to the respective place
                if ((mmd.hasCollection() || mmd.hasArray()) && joinmd == null)
                {
                    // Column is for the FK of the element of the collection/array
                    ElementMetaData elemmd = mmd.getElementMetaData();
                    if (elemmd == null)
                    {
                        elemmd = new ElementMetaData();
                        mmd.setElementMetaData(elemmd);
                    }
                    for (int i=0;i<columnMetaData.length;i++)
                    {
                        elemmd.addColumn(columnMetaData[i]);
                    }
                }
                else if (mmd.hasMap() && joinmd == null)
                {
                    // Column is for the FK value of the map
                    ValueMetaData valmd = mmd.getValueMetaData();
                    if (valmd == null)
                    {
                        valmd = new ValueMetaData();
                        mmd.setValueMetaData(valmd);
                    }
                    for (int i=0;i<columnMetaData.length;i++)
                    {
                        valmd.addColumn(columnMetaData[i]);
                    }
                }
                else if (elementCollection)
                {
                    // Column is for element/value column(s) of join table of 1-N of non-PCs
                    if (mmd.hasCollection() || mmd.hasArray())
                    {
                        ElementMetaData elemmd = mmd.getElementMetaData();
                        if (elemmd == null)
                        {
                            elemmd = new ElementMetaData();
                            mmd.setElementMetaData(elemmd);
                        }
                        for (int i=0;i<columnMetaData.length;i++)
                        {
                            elemmd.addColumn(columnMetaData[i]);
                        }
                    }
                    else if (mmd.hasMap())
                    {
                        ValueMetaData valmd = mmd.getValueMetaData();
                        if (valmd == null)
                        {
                            valmd = new ValueMetaData();
                            mmd.setValueMetaData(valmd);
                        }
                        for (int i=0;i<columnMetaData.length;i++)
                        {
                            valmd.addColumn(columnMetaData[i]);
                        }
                    }
                }
                else
                {
View Full Code Here


        }
        else
        {
            // Value = PC
            ColumnMetaData[] valueColmd = null;
            ValueMetaData valuemd = mmd.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(mapmd.getValueType()), mmd,
                valueColmd, storeMgr, this, false, true, FieldRole.ROLE_MAP_VALUE, clr);
            if (mmd.getContainer().allowNulls() == Boolean.TRUE)
            {
View Full Code Here

                    jdbcType = keymd.getColumnMetaData()[0].getJdbcType();
                }
            }
            else if (fieldRole == FieldRole.ROLE_MAP_VALUE)
            {
                ValueMetaData valmd = (mmd != null ? mmd.getValueMetaData() : null);
                if (valmd != null && valmd.getColumnMetaData() != null && valmd.getColumnMetaData().length > 0)
                {
                    jdbcType = valmd.getColumnMetaData()[0].getJdbcType();
                }
            }
            else
            {
                if (mmd != null && mmd.getColumnMetaData() != null && mmd.getColumnMetaData().length > 0)
View Full Code Here

            }
        }
        else if (role == FieldRole.ROLE_MAP_VALUE && mmd.hasMap())
        {
            // Value of a map
            ValueMetaData valuemd = mmd.getValueMetaData();
            if (valuemd != null && valuemd.hasExtension("name"))
            {
                // Use "name" extension for element
                return valuemd.getValueForExtension("name");
            }
            else
            {
                ColumnMetaData[] colmds = (valuemd != null ? valuemd.getColumnMetaData() : null);
                if (colmds != null && colmds.length > 0 && colmds[0].getName() != null)
                {
                    // Use column name for value
                    return colmds[0].getName();
                }
View Full Code Here

            }
            else if (roleForMember == FieldRole.ROLE_MAP_VALUE)
            {
                // Creation of columns in join table for map of references as values
                ColumnMetaData[] colmds = null;
                ValueMetaData valuemd = mmd.getValueMetaData();
                if (valuemd != null && valuemd.getColumnMetaData() != null && valuemd.getColumnMetaData().length > 0)
                {
                    // Column mappings defined at this side (1-N, M-N)
                    colmds = valuemd.getColumnMetaData();
                }
                createPerImplementationColumnsForReferenceField(false, false, false, false,
                    roleForMember, colmds, clr);
            }
            else
View Full Code Here

            }
            // New value
            else if (localName.equals("value"))
            {
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                ValueMetaData valuemd = new ValueMetaData();
                valuemd.setColumnName(getAttr(attrs, "column"));
                valuemd.setDeleteAction(getAttr(attrs, "delete-action"));
                valuemd.setUpdateAction(getAttr(attrs, "update-action"));
                valuemd.setIndexed(IndexedValue.getIndexedValue(getAttr(attrs, "indexed")));
                valuemd.setUnique(getAttr(attrs, "unique"));
                valuemd.setMappedBy(getAttr(attrs, "mapped-by"));
                fmd.setValueMetaData(valuemd);
                pushStack(valuemd);
            }
            // New fetch-group
            else if (localName.equals("fetch-group"))
            {
                MetaData md = getStack();
                FetchGroupMetaData fgmd = new FetchGroupMetaData(getAttr(attrs,"name"));
                fgmd.setPostLoad(getAttr(attrs,"post-load"));
                if (md instanceof FetchGroupMetaData)
                {
                    FetchGroupMetaData fgmdParent = (FetchGroupMetaData)md;
                    fgmdParent.addFetchGroup(fgmd);
                }
                else if (md instanceof AbstractClassMetaData)
                {
                    AbstractClassMetaData cmd = (AbstractClassMetaData)md;
                    cmd.addFetchGroup(fgmd);
                }
                else if (md instanceof FetchPlanMetaData)
                {
                    FetchPlanMetaData fpmd = (FetchPlanMetaData)md;
                    fpmd.addFetchGroup(fgmd);
                }
                pushStack(fgmd);
            }
            else if (localName.equals("extension"))
            {
                MetaData md = getStack();
                md.addExtension(getAttr(attrs,"vendor-name"), getAttr(attrs,"key"), getAttr(attrs,"value"));
            }
            else if (localName.equals("version"))
            {
                AbstractClassMetaData cmd = (AbstractClassMetaData)getStack();
                VersionMetaData vermd = cmd.newVersionMetadata();
                vermd.setStrategy(getAttr(attrs,"strategy")).setColumnName(getAttr(attrs,"column"));
                vermd.setIndexed(IndexedValue.getIndexedValue(getAttr(attrs,"indexed")));
                pushStack(vermd);
            }
            else if (localName.equals("index"))
            {
                MetaData md = getStack();
                IndexMetaData idxmd = new IndexMetaData();
                idxmd.setName(getAttr(attrs,"name"));
                idxmd.setTable(getAttr(attrs,"table"));
                idxmd.setUnique(getAttr(attrs,"unique"));
                if (md instanceof AbstractClassMetaData)
                {
                    AbstractClassMetaData cmd = (AbstractClassMetaData)md;
                    cmd.addIndex(idxmd);
                }
                else if (md instanceof AbstractMemberMetaData)
                {
                    AbstractMemberMetaData fmd = (AbstractMemberMetaData)md;
                    fmd.setIndexMetaData(idxmd);
                }
                else if (md instanceof JoinMetaData)
                {
                    JoinMetaData jmd = (JoinMetaData)md;
                    jmd.setIndexMetaData(idxmd);
                }
                else if (md instanceof AbstractElementMetaData)
                {
                    AbstractElementMetaData elmd = (AbstractElementMetaData)md;
                    elmd.setIndexMetaData(idxmd);
                }
                else if (md instanceof OrderMetaData)
                {
                    OrderMetaData omd = (OrderMetaData)md;
                    omd.setIndexMetaData(idxmd);
                }
                else if (md instanceof VersionMetaData)
                {
                    VersionMetaData vermd = (VersionMetaData)md;
                    vermd.setIndexMetaData(idxmd);
                }
                else if (md instanceof DiscriminatorMetaData)
                {
                    DiscriminatorMetaData dismd = (DiscriminatorMetaData)md;
                    dismd.setIndexMetaData(idxmd);
                }
                pushStack(idxmd);
            }
            else if (localName.equals("unique"))
            {
                MetaData md = getStack();
                UniqueMetaData unimd = new UniqueMetaData();
                unimd.setName(getAttr(attrs,"name"));
                unimd.setTable(getAttr(attrs,"table"));
                unimd.setDeferred(getAttr(attrs,"deferred"));
                if (md instanceof AbstractClassMetaData)
                {
                    AbstractClassMetaData cmd = (AbstractClassMetaData)md;
                    cmd.addUniqueConstraint(unimd);
                }
                else if (md instanceof AbstractMemberMetaData)
                {
                    AbstractMemberMetaData fmd = (AbstractMemberMetaData)md;
                    fmd.setUniqueMetaData(unimd);
                }
                else if (md instanceof JoinMetaData)
                {
                    JoinMetaData jmd = (JoinMetaData)md;
                    jmd.setUniqueMetaData(unimd);
                }
                else if (md instanceof AbstractElementMetaData)
                {
                    AbstractElementMetaData elmd = (AbstractElementMetaData)md;
                    elmd.setUniqueMetaData(unimd);
                }
                pushStack(unimd);
            }
            else if (localName.equals("foreign-key"))
            {
                MetaData md = getStack();
                ForeignKeyMetaData fkmd = new ForeignKeyMetaData();
                fkmd.setName(getAttr(attrs,"name"));
                fkmd.setTable(getAttr(attrs,"table"));
                fkmd.setUnique(getAttr(attrs,"unique"));
                fkmd.setDeferred(getAttr(attrs,"deferred"));
                fkmd.setDeleteAction(ForeignKeyAction.getForeignKeyAction(getAttr(attrs,"delete-action")));
                fkmd.setUpdateAction(ForeignKeyAction.getForeignKeyAction(getAttr(attrs,"update-action")));
                if (md instanceof AbstractClassMetaData)
                {
                    AbstractClassMetaData cmd = (AbstractClassMetaData)md;
                    cmd.addForeignKey(fkmd);
                }
                else if (md instanceof AbstractMemberMetaData)
                {
                    AbstractMemberMetaData fmd = (AbstractMemberMetaData)md;
                    fmd.setForeignKeyMetaData(fkmd);
                }
                else if (md instanceof JoinMetaData)
                {
                    JoinMetaData jmd = (JoinMetaData)md;
                    jmd.setForeignKeyMetaData(fkmd);
                }
                else if (md instanceof AbstractElementMetaData)
                {
                    AbstractElementMetaData elmd = (AbstractElementMetaData)md;
                    elmd.setForeignKeyMetaData(fkmd);
                }
                pushStack(fkmd);
            }
            else if (localName.equals("order"))
            {
                OrderMetaData ordmd = new OrderMetaData();
                ordmd.setIndexed(IndexedValue.getIndexedValue(getAttr(attrs, "indexed")));
                ordmd.setColumnName(getAttr(attrs, "column"));
                ordmd.setMappedBy(getAttr(attrs, "mapped-by"));
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                fmd.setOrderMetaData(ordmd);
                pushStack(ordmd);
            }
            else if (localName.equals("embedded"))
            {
                MetaData md = getStack();
                EmbeddedMetaData embmd = new EmbeddedMetaData();
                embmd.setOwnerMember(getAttr(attrs,"owner-field"));
                embmd.setNullIndicatorColumn(getAttr(attrs,"null-indicator-column"));
                embmd.setNullIndicatorValue(getAttr(attrs,"null-indicator-value"));
                if (md instanceof AbstractMemberMetaData)
                {
                    AbstractMemberMetaData fmd = (AbstractMemberMetaData)md;
                    fmd.setEmbeddedMetaData(embmd);
                }
                else if (md instanceof KeyMetaData)
                {
                    KeyMetaData kmd = (KeyMetaData)md;
                    kmd.setEmbeddedMetaData(embmd);
                }
                else if (md instanceof ValueMetaData)
                {
                    ValueMetaData vmd = (ValueMetaData)md;
                    vmd.setEmbeddedMetaData(embmd);
                }
                else if (md instanceof ElementMetaData)
                {
                    ElementMetaData elmd = (ElementMetaData)md;
                    elmd.setEmbeddedMetaData(embmd);
View Full Code Here

            ColumnMetaData[] colmds = null;
            JoinMetaData joinmd = null;
            ElementMetaData elemmd = null;
            KeyMetaData keymd = null;
            ValueMetaData valuemd = null;
            OrderMetaData ordermd = null;
            IndexMetaData idxmd = null;
            UniqueMetaData unimd = null;
            ForeignKeyMetaData fkmd = null;
            HashSet<ExtensionMetaData> extensions = null;

            for (int i=0;i<annotations.length;i++)
            {
                String annName = annotations[i].getName();
                HashMap<String, Object> annotationValues = annotations[i].getNameValueMap();
                if (annName.equals(JDOAnnotationUtils.PERSISTENT))
                {
                    String pk = "" + annotationValues.get("primaryKey");
                    String dfg = (String)annotationValues.get("defaultFetchGroup");
                    String nullValue = JDOAnnotationUtils.getNullValueString((NullValue)annotationValues.get("nullValue"));
                    String embedded = (String)annotationValues.get("embedded");
                    String serialized = (String)annotationValues.get("serialized");
                    String dependent = (String)annotationValues.get("dependent");
                    String valueStrategy = JDOAnnotationUtils.getIdentityStrategyString(
                        (IdGeneratorStrategy)annotationValues.get("valueStrategy"));
                    String customValueStrategy = (String)annotationValues.get("customValueStrategy");
                    if (!StringUtils.isWhitespace(customValueStrategy))
                    {
                        // User has provided an extension strategy
                        valueStrategy = customValueStrategy;
                    }
                    String modifier = JDOAnnotationUtils.getFieldPersistenceModifierString(
                        (PersistenceModifier)annotationValues.get("persistenceModifier"));
                    if (modifier == null)
                    {
                        modifier = FieldPersistenceModifier.PERSISTENT.toString();
                    }
                    String sequence = (String)annotationValues.get("sequence");
                    String mappedBy = (String)annotationValues.get("mappedBy");
                    String table = (String)annotationValues.get("table");
                    String column = (String)annotationValues.get("column");
                    String loadFetchGroup = (String)annotationValues.get("loadFetchGroup");
                    String fieldTypeName = null;
                    int recursionDepth = ((Integer)annotationValues.get("recursionDepth")).intValue();
                    cacheable = (String)annotationValues.get("cacheable");
                    Class[] fieldTypes = (Class[])annotationValues.get("types");
                    if (fieldTypes != null && fieldTypes.length > 0)
                    {
                        StringBuilder typeStr = new StringBuilder();
                        for (int j=0;j<fieldTypes.length;j++)
                        {
                            if (typeStr.length() > 0)
                            {
                                typeStr.append(',');
                            }
                            if (fieldTypes[j] != null && fieldTypes[j] != void.class)
                            {
                                typeStr.append(fieldTypes[j].getName());
                            }
                        }
                        fieldTypeName = typeStr.toString();
                    }
                    dependentElement = (String)annotationValues.get("dependentElement");
                    serializedElement = (String)annotationValues.get("serializedElement");
                    embeddedElement = (String)annotationValues.get("embeddedElement");
                    dependentKey = (String)annotationValues.get("dependentKey");
                    serializedKey = (String)annotationValues.get("serializedKey");
                    embeddedKey = (String)annotationValues.get("embeddedKey");
                    dependentValue = (String)annotationValues.get("dependentValue");
                    serializedValue = (String)annotationValues.get("serializedValue");
                    embeddedValue = (String)annotationValues.get("embeddedValue");

                    if (member.isProperty())
                    {
                        // Property
                        mmd = new PropertyMetaData(cmd, member.getName());
                    }
                    else
                    {
                        // Field
                        mmd = new FieldMetaData(cmd, member.getName());
                    }
                    mmd.setPersistenceModifier(modifier);
                    mmd.setDefaultFetchGroup(dfg);
                    mmd.setPrimaryKey(pk);
                    mmd.setEmbedded(embedded);
                    mmd.setSerialised(serialized);
                    mmd.setDependent(dependent);
                    mmd.setNullValue(org.datanucleus.metadata.NullValue.getNullValue(nullValue));
                    mmd.setMappedBy(mappedBy);
                    mmd.setColumn(column);
                    mmd.setTable(table);
                    mmd.setRecursionDepth(recursionDepth);
                    mmd.setLoadFetchGroup(loadFetchGroup);
                    mmd.setValueStrategy(valueStrategy);
                    mmd.setSequence(sequence);
                    mmd.setFieldTypes(fieldTypeName);

                    // Add any columns defined on the @Persistent
                    Column[] columns = (Column[])annotationValues.get("columns");
                    if (columns != null && columns.length > 0)
                    {
                        for (int j=0;j<columns.length;j++)
                        {
                            mmd.addColumn(JDOAnnotationUtils.getColumnMetaDataForColumnAnnotation(columns[j]));
                        }
                    }
                    JDOAnnotationUtils.addExtensionsToMetaData(mmd, (Extension[])annotationValues.get("extensions"));
                }
                else if (annName.equals(JDOAnnotationUtils.PRIMARY_KEY))
                {
                    primaryKey = true;
                    if (cmd.getIdentityType() == IdentityType.DATASTORE)
                    {
                        // ClassMetaData was created as DATASTORE so change it to APPLICATION
                        cmd.setIdentityType(IdentityType.APPLICATION);
                    }
                }
                else if (annName.equals(JDOAnnotationUtils.SERIALIZED))
                {
                    serialised = true;
                }
                else if (annName.equals(JDOAnnotationUtils.NOTPERSISTENT))
                {
                    nonPersistentField = true;
                }
                else if (annName.equals(JDOAnnotationUtils.TRANSACTIONAL))
                {
                    transactionalField = true;
                }
                else if (annName.equals(JDOAnnotationUtils.COLUMNS))
                {
                    // Multiple column specification
                    Column[] cols = (Column[])annotationValues.get("value");
                    if (cols != null && cols.length > 0)
                    {
                        colmds = new ColumnMetaData[cols.length];
                        for (int j=0;j<cols.length;j++)
                        {
                            colmds[j] = JDOAnnotationUtils.getColumnMetaDataForColumnAnnotation(cols[j]);
                            JDOAnnotationUtils.addExtensionsToMetaData(colmds[j], cols[j].extensions());
                        }
                    }
                }
                else if (annName.equals(JDOAnnotationUtils.COLUMN))
                {
                    // Single column specification
                    colmds = new ColumnMetaData[1];
                    colmds[0] = JDOAnnotationUtils.getColumnMetaDataForAnnotations(annotationValues);
                    JDOAnnotationUtils.addExtensionsToMetaData(colmds[0], (Extension[])annotationValues.get("extensions"));
                }
                else if (annName.equals(JDOAnnotationUtils.JOIN))
                {
                    String joinColumn = (String)annotationValues.get("column");
                    String joinOuter = (String)annotationValues.get("outer");
                    String deleteAction = JDOAnnotationUtils.getForeignKeyActionString(
                        (ForeignKeyAction)annotationValues.get("deleteAction"));
                    String pkName = (String)annotationValues.get("primaryKey");
                    String fkName = (String)annotationValues.get("foreignKey");
                    String generateFK = (String)annotationValues.get("generateForeignKey");
                    String indexed = (String)annotationValues.get("indexed");
                    String indexName = (String)annotationValues.get("index");
                    String unique = (String)annotationValues.get("unique");
                    String uniqueName = (String)annotationValues.get("uniqueKey");
                    String generatePK = (String)annotationValues.get("generatePrimaryKey");
                    if (!StringUtils.isWhitespace(uniqueName))
                    {
                        unique = "true";
                    }
                    if (!StringUtils.isWhitespace(indexName))
                    {
                        indexed = "true";
                    }
                    Column[] joinColumns = (Column[])annotationValues.get("columns");
                    joinmd = new JoinMetaData();
                    joinmd.setColumnName(joinColumn);
                    joinmd.setOuter(joinOuter);
                    joinmd.setIndexed(IndexedValue.getIndexedValue(indexed));
                    joinmd.setUnique(unique);
                    joinmd.setDeleteAction(deleteAction);

                    if (!StringUtils.isWhitespace(pkName))
                    {
                        PrimaryKeyMetaData pkmd = new PrimaryKeyMetaData();
                        pkmd.setName(pkName);
                        joinmd.setPrimaryKeyMetaData(pkmd);
                    }
                    else if (generatePK != null && generatePK.equalsIgnoreCase("true"))
                    {
                        joinmd.setPrimaryKeyMetaData(new PrimaryKeyMetaData());
                    }

                    if (!StringUtils.isWhitespace(fkName))
                    {
                        ForeignKeyMetaData joinFkmd = joinmd.getForeignKeyMetaData();
                        if (joinFkmd == null)
                        {
                            joinFkmd = new ForeignKeyMetaData();
                            joinFkmd.setName(fkName);
                            joinmd.setForeignKeyMetaData(joinFkmd);
                        }
                        else
                        {
                            joinFkmd.setName(fkName);
                        }
                    }
                    else if (generateFK != null && generateFK.equalsIgnoreCase("true"))
                    {
                        joinmd.setForeignKeyMetaData(new ForeignKeyMetaData());
                    }

                    if (!StringUtils.isWhitespace(indexName))
                    {
                        IndexMetaData joinIdxmd = joinmd.getIndexMetaData();
                        if (joinIdxmd == null)
                        {
                            joinIdxmd = new IndexMetaData();
                            joinmd.setIndexMetaData(joinIdxmd);
                        }
                        joinIdxmd.setName(indexName);
                    }

                    if (!StringUtils.isWhitespace(uniqueName))
                    {
                        UniqueMetaData joinUnimd = joinmd.getUniqueMetaData();
                        if (joinUnimd == null)
                        {
                            joinUnimd = new UniqueMetaData();
                            joinmd.setUniqueMetaData(joinUnimd);
                        }
                        joinUnimd.setName(uniqueName);
                    }
                    if (joinColumns != null && joinColumns.length > 0)
                    {
                        for (int j=0;j<joinColumns.length;j++)
                        {
                            joinmd.addColumn(JDOAnnotationUtils.getColumnMetaDataForColumnAnnotation(joinColumns[j]));
                        }
                    }
                    JDOAnnotationUtils.addExtensionsToMetaData(joinmd, (Extension[])annotationValues.get("extensions"));
                }
                else if (annName.equals(JDOAnnotationUtils.ELEMENT))
                {
                    // Element of a Collection/Array
                    elementTypes = (Class[])annotationValues.get("types");
                    embeddedElement = (String)annotationValues.get("embedded");
                    serializedElement = (String)annotationValues.get("serialized");
                    dependentElement = (String)annotationValues.get("dependent");
                    String elementColumn = (String)annotationValues.get("column");
                    String elementDeleteAction = JDOAnnotationUtils.getForeignKeyActionString(
                        (ForeignKeyAction)annotationValues.get("deleteAction"));
                    String elementUpdateAction = JDOAnnotationUtils.getForeignKeyActionString(
                        (ForeignKeyAction)annotationValues.get("updateAction"));
                    String elementMappedBy = (String)annotationValues.get("mappedBy");
                    Column[] elementColumns = (Column[])annotationValues.get("columns");
                    String fkName = (String)annotationValues.get("foreignKey");
                    String generateFK = (String)annotationValues.get("generateForeignKey");
                    String indexed = (String)annotationValues.get("indexed");
                    String indexName = (String)annotationValues.get("index");
                    String unique = (String)annotationValues.get("unique");
                    String uniqueName = (String)annotationValues.get("uniqueKey");
                    if (!StringUtils.isWhitespace(uniqueName))
                    {
                        unique = "true";
                    }
                    if (!StringUtils.isWhitespace(indexName))
                    {
                        indexed = "true";
                    }
                    elemmd = new ElementMetaData();
                    elemmd.setColumnName(elementColumn);
                    elemmd.setDeleteAction(elementDeleteAction);
                    elemmd.setUpdateAction(elementUpdateAction);
                    elemmd.setIndexed(IndexedValue.getIndexedValue(indexed));
                    elemmd.setUnique(unique);
                    elemmd.setMappedBy(elementMappedBy);
                    if (!StringUtils.isWhitespace(fkName))
                    {
                        ForeignKeyMetaData elemFkmd = elemmd.getForeignKeyMetaData();
                        if (elemFkmd == null)
                        {
                            elemFkmd = new ForeignKeyMetaData();
                            elemFkmd.setName(fkName);
                            elemmd.setForeignKeyMetaData(elemFkmd);
                        }
                        else
                        {
                            elemFkmd.setName(fkName);
                        }
                    }
                    else if (generateFK != null && generateFK.equalsIgnoreCase("true"))
                    {
                        elemmd.setForeignKeyMetaData(new ForeignKeyMetaData());
                    }

                    if (!StringUtils.isWhitespace(indexName))
                    {
                        IndexMetaData elemIdxmd = elemmd.getIndexMetaData();
                        if (elemIdxmd == null)
                        {
                            elemIdxmd = new IndexMetaData();
                            elemmd.setIndexMetaData(elemIdxmd);
                        }
                        elemIdxmd.setName(indexName);
                    }

                    if (!StringUtils.isWhitespace(uniqueName))
                    {
                        UniqueMetaData elemUnimd = elemmd.getUniqueMetaData();
                        if (elemUnimd == null)
                        {
                            elemUnimd = new UniqueMetaData();
                            elemmd.setUniqueMetaData(elemUnimd);
                        }
                        elemUnimd.setName(uniqueName);
                    }
                    if (elementColumns != null && elementColumns.length > 0)
                    {
                        for (int j=0;j<elementColumns.length;j++)
                        {
                            elemmd.addColumn(JDOAnnotationUtils.getColumnMetaDataForColumnAnnotation(elementColumns[j]));
                        }
                    }
                    JDOAnnotationUtils.addExtensionsToMetaData(elemmd, (Extension[])annotationValues.get("extensions"));

                    Embedded[] embeddedMappings = (Embedded[])annotationValues.get("embeddedMapping");
                    if (embeddedMappings != null && embeddedMappings.length > 0)
                    {
                        // Embedded element
                        EmbeddedMetaData embmd = new EmbeddedMetaData();
                        embmd.setOwnerMember(embeddedMappings[0].ownerMember());
                        embmd.setNullIndicatorColumn(embeddedMappings[0].nullIndicatorColumn());
                        embmd.setNullIndicatorValue(embeddedMappings[0].nullIndicatorValue());
                        elemmd.setEmbeddedMetaData(embmd);
                        embeddedElementMembers = embeddedMappings[0].members();
                        // Delay addition of embeddedElementMembers til completion of this loop so we have the element type
                    }
                }
                else if (annName.equals(JDOAnnotationUtils.KEY))
                {
                    // Key of a Map
                    Class[] keyTypes = (Class[])annotationValues.get("types");
                    if (keyTypes != null && keyTypes.length > 0)
                    {
                        // TODO Support more than 1 value
                        keyType = keyTypes[0];
                    }
                    embeddedKey = (String)annotationValues.get("embedded");
                    serializedKey = (String)annotationValues.get("serialized");
                    dependentKey = (String)annotationValues.get("dependent");
                    String keyColumn = (String)annotationValues.get("column");
                    String keyDeleteAction = JDOAnnotationUtils.getForeignKeyActionString(
                        (ForeignKeyAction)annotationValues.get("deleteAction"));
                    String keyUpdateAction = JDOAnnotationUtils.getForeignKeyActionString(
                        (ForeignKeyAction)annotationValues.get("updateAction"));
                    String keyMappedBy = (String)annotationValues.get("mappedBy");
                    Column[] keyColumns = (Column[])annotationValues.get("columns");
                    String fkName = (String)annotationValues.get("foreignKey");
                    String generateFK = (String)annotationValues.get("generateForeignKey");
                    String indexed = (String)annotationValues.get("indexed");
                    String indexName = (String)annotationValues.get("index");
                    String unique = (String)annotationValues.get("unique");
                    String uniqueName = (String)annotationValues.get("uniqueKey");
                    if (!StringUtils.isWhitespace(uniqueName))
                    {
                        unique = "true";
                    }
                    if (!StringUtils.isWhitespace(indexName))
                    {
                        indexed = "true";
                    }
                    keymd = new KeyMetaData();
                    keymd.setColumnName(keyColumn);
                    keymd.setDeleteAction(keyDeleteAction);
                    keymd.setUpdateAction(keyUpdateAction);
                    keymd.setIndexed(IndexedValue.getIndexedValue(indexed));
                    keymd.setUnique(unique);
                    keymd.setMappedBy(keyMappedBy);
                    if (!StringUtils.isWhitespace(fkName))
                    {
                        ForeignKeyMetaData keyFkmd = keymd.getForeignKeyMetaData();
                        if (keyFkmd == null)
                        {
                            keyFkmd = new ForeignKeyMetaData();
                            keyFkmd.setName(fkName);
                            keymd.setForeignKeyMetaData(keyFkmd);
                        }
                        else
                        {
                            keyFkmd.setName(fkName);
                        }
                    }
                    else if (generateFK != null && generateFK.equalsIgnoreCase("true"))
                    {
                        keymd.setForeignKeyMetaData(new ForeignKeyMetaData());
                    }

                    if (!StringUtils.isWhitespace(indexName))
                    {
                        IndexMetaData keyIdxmd = keymd.getIndexMetaData();
                        if (keyIdxmd == null)
                        {
                            keyIdxmd = new IndexMetaData();
                            keymd.setIndexMetaData(keyIdxmd);
                        }
                        keyIdxmd.setName(indexName);
                    }

                    if (!StringUtils.isWhitespace(uniqueName))
                    {
                        UniqueMetaData keyUnimd = keymd.getUniqueMetaData();
                        if (keyUnimd == null)
                        {
                            keyUnimd = new UniqueMetaData();
                            keymd.setUniqueMetaData(keyUnimd);
                        }
                        keyUnimd.setName(uniqueName);
                    }
                    if (keyColumns != null && keyColumns.length > 0)
                    {
                        for (int j=0;j<keyColumns.length;j++)
                        {
                            keymd.addColumn(JDOAnnotationUtils.getColumnMetaDataForColumnAnnotation(keyColumns[j]));
                        }
                    }
                    JDOAnnotationUtils.addExtensionsToMetaData(keymd, (Extension[])annotationValues.get("extensions"));

                    Embedded[] embeddedMappings = (Embedded[])annotationValues.get("embeddedMapping");
                    if (embeddedMappings != null && embeddedMappings.length > 0)
                    {
                        // Embedded key
                        EmbeddedMetaData embmd = new EmbeddedMetaData();
                        embmd.setOwnerMember(embeddedMappings[0].ownerMember());
                        embmd.setNullIndicatorColumn(embeddedMappings[0].nullIndicatorColumn());
                        embmd.setNullIndicatorValue(embeddedMappings[0].nullIndicatorValue());
                        keymd.setEmbeddedMetaData(embmd);
                        embeddedKeyMembers = embeddedMappings[0].members();
                        // Delay addition of embeddedKeyMembers til completion of this loop so we have the key type
                    }
                }
                else if (annName.equals(JDOAnnotationUtils.VALUE))
                {
                    // Value of a Map
                    Class[] valueTypes = (Class[])annotationValues.get("types");
                    if (valueTypes != null && valueTypes.length > 0)
                    {
                        // TODO Support more than 1 value
                        valueType = valueTypes[0];
                    }
                    embeddedValue = (String)annotationValues.get("embedded");
                    serializedValue = (String)annotationValues.get("serialized");
                    dependentValue = (String)annotationValues.get("dependent");
                    String valueColumn = (String)annotationValues.get("column");
                    String valueDeleteAction = JDOAnnotationUtils.getForeignKeyActionString(
                        (ForeignKeyAction)annotationValues.get("deleteAction"));
                    String valueUpdateAction = JDOAnnotationUtils.getForeignKeyActionString(
                        (ForeignKeyAction)annotationValues.get("updateAction"));
                    String valueMappedBy = (String)annotationValues.get("mappedBy");
                    Column[] valueColumns = (Column[])annotationValues.get("columns");
                    String fkName = (String)annotationValues.get("foreignKey");
                    String generateFK = (String)annotationValues.get("generateForeignKey");
                    String indexed = (String)annotationValues.get("indexed");
                    String indexName = (String)annotationValues.get("index");
                    String unique = (String)annotationValues.get("unique");
                    String uniqueName = (String)annotationValues.get("uniqueKey");
                    if (!StringUtils.isWhitespace(uniqueName))
                    {
                        unique = "true";
                    }
                    if (!StringUtils.isWhitespace(indexName))
                    {
                        indexed = "true";
                    }
                    valuemd = new ValueMetaData();
                    valuemd.setColumnName(valueColumn);
                    valuemd.setDeleteAction(valueDeleteAction);
                    valuemd.setUpdateAction(valueUpdateAction);
                    valuemd.setIndexed(IndexedValue.getIndexedValue(indexed));
                    valuemd.setUnique(unique);
                    valuemd.setMappedBy(valueMappedBy);
                    if (!StringUtils.isWhitespace(fkName))
                    {
                        ForeignKeyMetaData valueFkmd = valuemd.getForeignKeyMetaData();
                        if (valueFkmd == null)
                        {
                            valueFkmd = new ForeignKeyMetaData();
                            valueFkmd.setName(fkName);
                            valuemd.setForeignKeyMetaData(valueFkmd);
                        }
                        else
                        {
                            valueFkmd.setName(fkName);
                        }
                    }
                    else if (generateFK != null && generateFK.equalsIgnoreCase("true"))
                    {
                        valuemd.setForeignKeyMetaData(new ForeignKeyMetaData());
                    }

                    if (!StringUtils.isWhitespace(indexName))
                    {
                        IndexMetaData valueIdxmd = valuemd.getIndexMetaData();
                        if (valueIdxmd == null)
                        {
                            valueIdxmd = new IndexMetaData();
                            valuemd.setIndexMetaData(valueIdxmd);
                        }
                        valueIdxmd.setName(indexName);
                    }

                    if (!StringUtils.isWhitespace(uniqueName))
                    {
                        UniqueMetaData valueUnimd = valuemd.getUniqueMetaData();
                        if (valueUnimd == null)
                        {
                            valueUnimd = new UniqueMetaData();
                            valuemd.setUniqueMetaData(valueUnimd);
                        }
                        valueUnimd.setName(uniqueName);
                    }
                    if (valueColumns != null && valueColumns.length > 0)
                    {
                        for (int j=0;j<valueColumns.length;j++)
                        {
                            valuemd.addColumn(JDOAnnotationUtils.getColumnMetaDataForColumnAnnotation(valueColumns[j]));
                        }
                    }
                    JDOAnnotationUtils.addExtensionsToMetaData(valuemd, (Extension[])annotationValues.get("extensions"));

                    Embedded[] embeddedMappings = (Embedded[])annotationValues.get("embeddedMapping");
                    if (embeddedMappings != null && embeddedMappings.length > 0)
                    {
                        // Embedded value
                        EmbeddedMetaData embmd = new EmbeddedMetaData();
                        embmd.setOwnerMember(embeddedMappings[0].ownerMember());
                        embmd.setNullIndicatorColumn(embeddedMappings[0].nullIndicatorColumn());
                        embmd.setNullIndicatorValue(embeddedMappings[0].nullIndicatorValue());
                        valuemd.setEmbeddedMetaData(embmd);
                        embeddedValueMembers = embeddedMappings[0].members();
                        // Delay addition of embeddedValueMembers til completion of this loop so we have the value type
                    }
                }
                else if (annName.equals(JDOAnnotationUtils.ORDER))
                {
                    String orderColumn = (String)annotationValues.get("column");
                    String orderMappedBy = (String)annotationValues.get("mappedBy");
                    Column[] orderColumns = (Column[])annotationValues.get("columns");
                    ordermd = new OrderMetaData();
                    ordermd.setColumnName(orderColumn);
                    ordermd.setMappedBy(orderMappedBy);
                    if (orderColumns != null && orderColumns.length > 0)
                    {
                        for (int j=0;j<orderColumns.length;j++)
                        {
                            ordermd.addColumn(JDOAnnotationUtils.getColumnMetaDataForColumnAnnotation(orderColumns[j]));
                        }
                    }
                    JDOAnnotationUtils.addExtensionsToMetaData(ordermd, (Extension[])annotationValues.get("extensions"));
                }
                else if (annName.equals(JDOAnnotationUtils.EMBEDDED))
                {
                    embeddedOwnerField = (String)annotationValues.get("ownerMember");
                    embeddedNullIndicatorColumn = (String)annotationValues.get("nullIndicatorColumn");
                    embeddedNullIndicatorValue = (String)annotationValues.get("nullIndicatorValue");
                    embeddedMembers = (Persistent[])annotationValues.get("members");
                }
                else if (annName.equals(JDOAnnotationUtils.INDEX))
                {
                    // Index for the field
                    String name = (String)annotationValues.get("name");
                    String table = (String)annotationValues.get("table");
                    String unique = (String)annotationValues.get("unique");
                    String[] members = (String[])annotationValues.get("members");
                    Column[] columns = (Column[])annotationValues.get("columns");

                    idxmd = JDOAnnotationUtils.getIndexMetaData(name, table, unique, members, columns);
                }
                else if (annName.equals(JDOAnnotationUtils.UNIQUE))
                {
                    // Unique for the field
                    String name = (String)annotationValues.get("name");
                    String table = (String)annotationValues.get("table");
                    String deferred = (String)annotationValues.get("deferred");
                    String[] members = (String[])annotationValues.get("members");
                    Column[] columns = (Column[])annotationValues.get("columns");

                    unimd = JDOAnnotationUtils.getUniqueMetaData(name, table, deferred, members, columns);
                }
                else if (annName.equals(JDOAnnotationUtils.FOREIGNKEY))
                {
                    // ForeignKey for field
                    String name = (String)annotationValues.get("name");
                    String table = (String)annotationValues.get("table");
                    String unique = (String)annotationValues.get("unique");
                    String deferred = (String)annotationValues.get("deferred");
                    String deleteAction = JDOAnnotationUtils.getForeignKeyActionString(
                        (ForeignKeyAction)annotationValues.get("deleteAction"));
                    String updateAction = JDOAnnotationUtils.getForeignKeyActionString(
                        (ForeignKeyAction)annotationValues.get("updateAction"));
                    String[] members = (String[])annotationValues.get("members");
                    Column[] columns = (Column[])annotationValues.get("columns");

                    fkmd = JDOAnnotationUtils.getFKMetaData(name, table, unique, deferred, deleteAction, updateAction,
                        members, columns);
                }
                else if (annName.equals(JDOAnnotationUtils.CACHEABLE))
                {
                    String cache = (String)annotationValues.get("value");
                    if (cache != null)
                    {
                        cacheable = cache;
                    }
                }
                else if (annName.equals(JDOAnnotationUtils.EXTENSIONS))
                {
                    Extension[] values = (Extension[])annotationValues.get("value");
                    if (values != null && values.length > 0)
                    {
                        extensions = new HashSet<ExtensionMetaData>(values.length);
                        for (int j=0;j<values.length;j++)
                        {
                            ExtensionMetaData extmd = new ExtensionMetaData(values[j].vendorName(),
                                values[j].key().toString(), values[j].value().toString());
                            extensions.add(extmd);
                        }
                    }
                }
                else if (annName.equals(JDOAnnotationUtils.EXTENSION))
                {
                    ExtensionMetaData extmd = new ExtensionMetaData((String)annotationValues.get("vendorName"),
                        (String)annotationValues.get("key"), (String)annotationValues.get("value"));
                    extensions = new HashSet<ExtensionMetaData>(1);
                    extensions.add(extmd);
                }
                else
                {
                    NucleusLogger.METADATA.error(LOCALISER.msg("044203",
                        member.getName(), annotations[i].getName()));
                }
            }

            if (mmd == null &&
                (transactionalField || nonPersistentField || primaryKey || colmds != null || serialised ||
                 embeddedOwnerField != null || embeddedNullIndicatorColumn != null || embeddedNullIndicatorValue != null ||
                 embeddedMembers != null ||
                 elemmd != null || keymd != null || valuemd != null || ordermd != null ||
                 idxmd != null || unimd != null || fkmd != null || joinmd != null ||
                 extensions != null))
            {
                // @Persistent not supplied but other relevant annotations defined, so add default metadata element
                if (member.isProperty())
                {
                    mmd = new PropertyMetaData(cmd, member.getName());
                }
                else
                {
                    mmd = new FieldMetaData(cmd, member.getName());
                }
                if (primaryKey)
                {
                    mmd.setPersistenceModifier(FieldPersistenceModifier.PERSISTENT.toString());
                    mmd.setPrimaryKey("" + primaryKey);
                }
                if (serialised)
                {
                    mmd.setPersistenceModifier(FieldPersistenceModifier.PERSISTENT.toString());
                }
            }

            if (mmd != null)
            {
                cmd.addMember(mmd);

                if (primaryKey)
                {
                    mmd.setPrimaryKey(true);
                }
                if (serialised)
                {
                    mmd.setSerialised(true);
                }
                if (nonPersistentField)
                {
                    mmd.setNotPersistent();
                }
                if (transactionalField)
                {
                    mmd.setTransactional();
                }

                // Add any embedded info
                if (embeddedOwnerField != null || embeddedNullIndicatorColumn != null ||
                    embeddedNullIndicatorValue != null || embeddedMembers != null)
                {
                    EmbeddedMetaData embmd = new EmbeddedMetaData();
                    embmd.setOwnerMember(embeddedOwnerField);
                    embmd.setNullIndicatorColumn(embeddedNullIndicatorColumn);
                    embmd.setNullIndicatorValue(embeddedNullIndicatorValue);
                    mmd.setEmbeddedMetaData(embmd);
                    if (embeddedMembers != null && embeddedMembers.length > 0)
                    {
                        for (int j=0;j<embeddedMembers.length;j++)
                        {
                            // Add the metadata for the embedded field/property to the embedded metadata
                            String memberName = embeddedMembers[j].name();
                            if (memberName.indexOf('.') > 0)
                            {
                                memberName = memberName.substring(memberName.lastIndexOf('.')+1);
                            }
                            AbstractMemberMetaData embfmd = getFieldMetaDataForPersistent(embmd, embeddedMembers[j],
                                isMemberOfClassAField(member.getType(), memberName));
                            embmd.addMember(embfmd);
                        }
                    }
                }

                // If the field is a container then add its container element
                ContainerMetaData contmd = null;
                if (Collection.class.isAssignableFrom(member.getType()))
                {
                    Class collectionElementType = null;
                    StringBuilder elementTypeStr = new StringBuilder();
                    if (elementTypes != null && elementTypes.length > 0 && elementTypes[0] != void.class)
                    {
                        // User-specified element type(s)
                        for (int j=0;j<elementTypes.length;j++)
                        {
                            if (elementTypeStr.length() > 0)
                            {
                                elementTypeStr.append(',');
                            }
                            elementTypeStr.append(elementTypes[j].getName());
                        }
                        collectionElementType = elementTypes[0]; // Use the first only
                    }
                    else
                    {
                        // Try to derive element type from generics info
                        collectionElementType =
                            ClassUtils.getCollectionElementType(member.getType(), member.getGenericType());
                    }

                    contmd = new CollectionMetaData();
                    CollectionMetaData collmd = (CollectionMetaData)contmd;
                    collmd.setElementType(elementTypeStr.toString());
                    collmd.setEmbeddedElement(embeddedElement);
                    collmd.setSerializedElement(serializedElement);
                    collmd.setDependentElement(dependentElement);

                    // Add any embedded element mappings
                    if (embeddedElementMembers != null)
                    {
                        EmbeddedMetaData embmd = elemmd.getEmbeddedMetaData();
                        for (int j=0;j<embeddedElementMembers.length;j++)
                        {
                            // Add the metadata for the embedded element to the embedded metadata
                            String memberName = embeddedElementMembers[j].name();
                            if (memberName.indexOf('.') > 0)
                            {
                                memberName = memberName.substring(memberName.lastIndexOf('.')+1);
                            }
                            AbstractMemberMetaData embfmd = getFieldMetaDataForPersistent(embmd,
                                embeddedElementMembers[j],
                                isMemberOfClassAField(collectionElementType, memberName));
                            embmd.addMember(embfmd);
                        }
                    }
                }
                else if (member.getType().isArray())
                {
                    StringBuilder elementTypeStr = new StringBuilder();
                    if (elementTypes != null && elementTypes.length > 0 && elementTypes[0] != void.class)
                    {
                        // User-specified element type(s)
                        for (int j=0;j<elementTypes.length;j++)
                        {
                            if (elementTypeStr.length() > 0)
                            {
                                elementTypeStr.append(',');
                            }
                            elementTypeStr.append(elementTypes[j].getName());
                        }
                    }
                    else
                    {
                        // Derive from component type
                        elementTypeStr.append(member.getType().getComponentType().getName());
                    }

                    contmd = new ArrayMetaData();
                    ArrayMetaData arrmd = (ArrayMetaData)contmd;
                    arrmd.setElementType(elementTypeStr.toString());
                    arrmd.setEmbeddedElement(embeddedElement);
                    arrmd.setSerializedElement(serializedElement);
                    arrmd.setDependentElement(dependentElement);
                }
                else if (Map.class.isAssignableFrom(member.getType()))
                {
                    Class mapKeyType = null;
                    if (keyType != null && keyType != void.class)
                    {
                        // User-specified key type
                        mapKeyType = keyType;
                    }
                    else
                    {
                        // Try to derive key type from generics info
                        mapKeyType = ClassUtils.getMapKeyType(member.getType(), member.getGenericType());
                    }

                    Class mapValueType = null;
                    if (valueType != null && valueType != void.class)
                    {
                        // User-specified value type
                        mapValueType = valueType;
                    }
                    else
                    {
                        // Try to derive value type from generics info
                        mapValueType = ClassUtils.getMapValueType(member.getType(), member.getGenericType());
                    }

                    contmd = new MapMetaData();
                    MapMetaData mapmd = (MapMetaData)contmd;
                    mapmd.setKeyType((mapKeyType != null ? mapKeyType.getName() : null));
                    mapmd.setEmbeddedKey(embeddedKey);
                    mapmd.setSerializedKey(serializedKey);
                    mapmd.setDependentKey(dependentKey);
                    mapmd.setValueType((mapValueType != null ? mapValueType.getName() : null));
                    mapmd.setEmbeddedValue(embeddedValue);
                    mapmd.setSerializedValue(serializedValue);
                    mapmd.setDependentValue(dependentValue);

                    if (embeddedKeyMembers != null)
                    {
                        // Add any embedded key mappings
                        EmbeddedMetaData embmd = keymd.getEmbeddedMetaData();
                        for (int j=0;j<embeddedKeyMembers.length;j++)
                        {
                            // Add the metadata for the embedded key to the embedded metadata
                            String memberName = embeddedKeyMembers[j].name();
                            if (memberName.indexOf('.') > 0)
                            {
                                memberName = memberName.substring(memberName.lastIndexOf('.')+1);
                            }
                            AbstractMemberMetaData embfmd = getFieldMetaDataForPersistent(embmd, embeddedKeyMembers[j],
                                isMemberOfClassAField(mapKeyType, memberName));
                            embmd.addMember(embfmd);
                        }
                    }

                    if (embeddedValueMembers != null)
                    {
                        // Add any embedded value mappings
                        EmbeddedMetaData embmd = valuemd.getEmbeddedMetaData();
                        for (int j=0;j<embeddedValueMembers.length;j++)
                        {
                            // Add the metadata for the embedded value to the embedded metadata
                            String memberName = embeddedValueMembers[j].name();
                            if (memberName.indexOf('.') > 0)
                            {
                                memberName = memberName.substring(memberName.lastIndexOf('.')+1);
                            }
                            AbstractMemberMetaData embfmd = getFieldMetaDataForPersistent(embmd, embeddedValueMembers[j],
                                isMemberOfClassAField(mapValueType, memberName));
                            embmd.addMember(embfmd);
                        }
                    }
                }
                if (contmd != null)
                {
                    mmd.setContainer(contmd);
                   
                    if (elemmd != null)
                    {
                        elemmd.setParent(mmd);
                        mmd.setElementMetaData(elemmd);
                        if (elemmd.getMappedBy() != null && mmd.getMappedBy() == null)
                        {
                            // With collection/array this is the same as mapped-by on the field
                            mmd.setMappedBy(elemmd.getMappedBy());
                        }
                    }
                    if (keymd != null)
                    {
                        keymd.setParent(mmd);
                        mmd.setKeyMetaData(keymd);
                    }
                    if (valuemd != null)
                    {
                        valuemd.setParent(mmd);
                        mmd.setValueMetaData(valuemd);
                    }
                    if (ordermd != null)
                    {
                        ordermd.setParent(mmd);
View Full Code Here

            }
            else if (roleForMember == FieldRole.ROLE_MAP_VALUE)
            {
                // Creation of columns in join table for map of references as values
                ColumnMetaData[] colmds = null;
                ValueMetaData valuemd = mmd.getValueMetaData();
                if (valuemd != null && valuemd.getColumnMetaData() != null && valuemd.getColumnMetaData().length > 0)
                {
                    // Column mappings defined at this side (1-N, M-N)
                    colmds = valuemd.getColumnMetaData();
                }
                createPerImplementationColumnsForReferenceField(false, false, false, false,
                    roleForMember, colmds, clr);
            }
            else
View Full Code Here

            }
            // New value
            else if (localName.equals("value"))
            {
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                ValueMetaData valuemd = new ValueMetaData();
                valuemd.setColumnName(getAttr(attrs, "column"));
                valuemd.setDeleteAction(getAttr(attrs, "delete-action"));
                valuemd.setUpdateAction(getAttr(attrs, "update-action"));
                valuemd.setIndexed(IndexedValue.getIndexedValue(getAttr(attrs, "indexed")));
                valuemd.setUnique(getAttr(attrs, "unique"));
                valuemd.setMappedBy(getAttr(attrs, "mapped-by"));
                fmd.setValueMetaData(valuemd);
                pushStack(valuemd);
            }
            // New fetch-group
            else if (localName.equals("fetch-group"))
            {
                MetaData md = getStack();
                FetchGroupMetaData fgmd = new FetchGroupMetaData(getAttr(attrs,"name"));
                fgmd.setPostLoad(getAttr(attrs,"post-load"));
                if (md instanceof FetchGroupMetaData)
                {
                    FetchGroupMetaData fgmdParent = (FetchGroupMetaData)md;
                    fgmdParent.addFetchGroup(fgmd);
                }
                else if (md instanceof AbstractClassMetaData)
                {
                    AbstractClassMetaData cmd = (AbstractClassMetaData)md;
                    cmd.addFetchGroup(fgmd);
                }
                else if (md instanceof FetchPlanMetaData)
                {
                    FetchPlanMetaData fpmd = (FetchPlanMetaData)md;
                    fpmd.addFetchGroup(fgmd);
                }
                pushStack(fgmd);
            }
            else if (localName.equals("extension"))
            {
                MetaData md = getStack();
                md.addExtension(getAttr(attrs,"vendor-name"), getAttr(attrs,"key"), getAttr(attrs,"value"));
            }
            else if (localName.equals("version"))
            {
                AbstractClassMetaData cmd = (AbstractClassMetaData)getStack();
                VersionMetaData vermd = cmd.newVersionMetadata();
                vermd.setStrategy(getAttr(attrs,"strategy")).setColumnName(getAttr(attrs,"column"));
                vermd.setIndexed(IndexedValue.getIndexedValue(getAttr(attrs,"indexed")));
                pushStack(vermd);
            }
            else if (localName.equals("index"))
            {
                MetaData md = getStack();
                IndexMetaData idxmd = new IndexMetaData();
                idxmd.setName(getAttr(attrs,"name"));
                idxmd.setTable(getAttr(attrs,"table"));
                idxmd.setUnique(getAttr(attrs,"unique"));
                if (md instanceof AbstractClassMetaData)
                {
                    AbstractClassMetaData cmd = (AbstractClassMetaData)md;
                    cmd.addIndex(idxmd);
                }
                else if (md instanceof AbstractMemberMetaData)
                {
                    AbstractMemberMetaData fmd = (AbstractMemberMetaData)md;
                    fmd.setIndexMetaData(idxmd);
                }
                else if (md instanceof JoinMetaData)
                {
                    JoinMetaData jmd = (JoinMetaData)md;
                    jmd.setIndexMetaData(idxmd);
                }
                else if (md instanceof AbstractElementMetaData)
                {
                    AbstractElementMetaData elmd = (AbstractElementMetaData)md;
                    elmd.setIndexMetaData(idxmd);
                }
                else if (md instanceof OrderMetaData)
                {
                    OrderMetaData omd = (OrderMetaData)md;
                    omd.setIndexMetaData(idxmd);
                }
                else if (md instanceof VersionMetaData)
                {
                    VersionMetaData vermd = (VersionMetaData)md;
                    vermd.setIndexMetaData(idxmd);
                }
                else if (md instanceof DiscriminatorMetaData)
                {
                    DiscriminatorMetaData dismd = (DiscriminatorMetaData)md;
                    dismd.setIndexMetaData(idxmd);
                }
                pushStack(idxmd);
            }
            else if (localName.equals("unique"))
            {
                MetaData md = getStack();
                UniqueMetaData unimd = new UniqueMetaData();
                unimd.setName(getAttr(attrs,"name"));
                unimd.setTable(getAttr(attrs,"table"));
                unimd.setDeferred(getAttr(attrs,"deferred"));
                if (md instanceof AbstractClassMetaData)
                {
                    AbstractClassMetaData cmd = (AbstractClassMetaData)md;
                    cmd.addUniqueConstraint(unimd);
                }
                else if (md instanceof AbstractMemberMetaData)
                {
                    AbstractMemberMetaData fmd = (AbstractMemberMetaData)md;
                    fmd.setUniqueMetaData(unimd);
                }
                else if (md instanceof JoinMetaData)
                {
                    JoinMetaData jmd = (JoinMetaData)md;
                    jmd.setUniqueMetaData(unimd);
                }
                else if (md instanceof AbstractElementMetaData)
                {
                    AbstractElementMetaData elmd = (AbstractElementMetaData)md;
                    elmd.setUniqueMetaData(unimd);
                }
                pushStack(unimd);
            }
            else if (localName.equals("foreign-key"))
            {
                MetaData md = getStack();
                ForeignKeyMetaData fkmd = new ForeignKeyMetaData();
                fkmd.setName(getAttr(attrs,"name"));
                fkmd.setTable(getAttr(attrs,"table"));
                fkmd.setUnique(getAttr(attrs,"unique"));
                fkmd.setDeferred(getAttr(attrs,"deferred"));
                fkmd.setDeleteAction(ForeignKeyAction.getForeignKeyAction(getAttr(attrs,"delete-action")));
                fkmd.setUpdateAction(ForeignKeyAction.getForeignKeyAction(getAttr(attrs,"update-action")));
                if (md instanceof AbstractClassMetaData)
                {
                    AbstractClassMetaData cmd = (AbstractClassMetaData)md;
                    cmd.addForeignKey(fkmd);
                }
                else if (md instanceof AbstractMemberMetaData)
                {
                    AbstractMemberMetaData fmd = (AbstractMemberMetaData)md;
                    fmd.setForeignKeyMetaData(fkmd);
                }
                else if (md instanceof JoinMetaData)
                {
                    JoinMetaData jmd = (JoinMetaData)md;
                    jmd.setForeignKeyMetaData(fkmd);
                }
                else if (md instanceof AbstractElementMetaData)
                {
                    AbstractElementMetaData elmd = (AbstractElementMetaData)md;
                    elmd.setForeignKeyMetaData(fkmd);
                }
                pushStack(fkmd);
            }
            else if (localName.equals("order"))
            {
                OrderMetaData ordmd = new OrderMetaData();
                ordmd.setIndexed(IndexedValue.getIndexedValue(getAttr(attrs, "indexed")));
                ordmd.setColumnName(getAttr(attrs, "column"));
                ordmd.setMappedBy(getAttr(attrs, "mapped-by"));
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                fmd.setOrderMetaData(ordmd);
                pushStack(ordmd);
            }
            else if (localName.equals("embedded"))
            {
                MetaData md = getStack();
                EmbeddedMetaData embmd = new EmbeddedMetaData();
                embmd.setOwnerMember(getAttr(attrs,"owner-field"));
                embmd.setNullIndicatorColumn(getAttr(attrs,"null-indicator-column"));
                embmd.setNullIndicatorValue(getAttr(attrs,"null-indicator-value"));
                if (md instanceof AbstractMemberMetaData)
                {
                    AbstractMemberMetaData fmd = (AbstractMemberMetaData)md;
                    fmd.setEmbeddedMetaData(embmd);
                }
                else if (md instanceof KeyMetaData)
                {
                    KeyMetaData kmd = (KeyMetaData)md;
                    kmd.setEmbeddedMetaData(embmd);
                }
                else if (md instanceof ValueMetaData)
                {
                    ValueMetaData vmd = (ValueMetaData)md;
                    vmd.setEmbeddedMetaData(embmd);
                }
                else if (md instanceof ElementMetaData)
                {
                    ElementMetaData elmd = (ElementMetaData)md;
                    elmd.setEmbeddedMetaData(embmd);
View Full Code Here

        return unimd;
    }

    public ValueMetadata getValueMetadata()
    {
        ValueMetaData internalValmd = getInternal().getValueMetaData();
        if (internalValmd == null)
        {
            return null;
        }
        ValueMetadataImpl valmd = new ValueMetadataImpl(internalValmd);
View Full Code Here

TOP

Related Classes of org.datanucleus.metadata.ValueMetaData

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.