Package org.datanucleus.metadata

Examples of org.datanucleus.metadata.JoinMetaData


                String outer = getAttr(attrs, "outer");
                IndexedValue indexed = IndexedValue.getIndexedValue(getAttr(attrs, "indexed"));
                String unique = getAttr(attrs, "unique");
                String deleteAction = getAttr(attrs, "delete-action");

                JoinMetaData joinmd = null;
                if (parent instanceof AbstractMemberMetaData)
                {
                    AbstractMemberMetaData fmd = (AbstractMemberMetaData)parent;
                    joinmd = fmd.newJoinMetadata();
                }
                else if (parent instanceof AbstractClassMetaData)
                {
                    AbstractClassMetaData cmd = (AbstractClassMetaData)parent;
                    joinmd = new JoinMetaData();
                    cmd.addJoin(joinmd);
                }
                else if (parent instanceof InheritanceMetaData)
                {
                    InheritanceMetaData inhmd = (InheritanceMetaData)parent;
                    joinmd = inhmd.newJoinMetadata();
                }
                joinmd.setTable(tableName);
                joinmd.setColumnName(columnName);
                joinmd.setOuter(outer);
                joinmd.setIndexed(indexed);
                joinmd.setUnique(unique);
                joinmd.setDeleteAction(deleteAction);
                pushStack(joinmd);
            }
            else if (localName.equals("map"))
            {
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                MapMetaData mapmd = fmd.newMapMetaData();
                mapmd.setKeyType(getAttr(attrs,"key-type"));
                mapmd.setEmbeddedKey(getAttr(attrs,"embedded-key"));
                mapmd.setSerializedKey(getAttr(attrs,"serialized-key"));
                mapmd.setDependentKey(getAttr(attrs,"dependent-key"));
                mapmd.setValueType(getAttr(attrs,"value-type"));
                mapmd.setEmbeddedValue(getAttr(attrs,"embedded-value"));
                mapmd.setSerializedValue(getAttr(attrs,"serialized-value"));
                mapmd.setDependentValue(getAttr(attrs,"dependent-value"));
                pushStack(mapmd);
            }
            else if (localName.equals("array"))
            {
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                ArrayMetaData arrmd = fmd.newArrayMetaData();
                arrmd.setElementType(getAttr(attrs, "element-type"));
                arrmd.setEmbeddedElement(getAttr(attrs, "embedded-element"));
                arrmd.setSerializedElement(getAttr(attrs, "serialized-element"));
                arrmd.setDependentElement(getAttr(attrs, "dependent-element"));
                pushStack(arrmd);
            }
            else if (localName.equals("collection"))
            {
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                CollectionMetaData collmd = fmd.newCollectionMetaData();
                collmd.setElementType(getAttr(attrs,"element-type"));
                collmd.setEmbeddedElement(getAttr(attrs,"embedded-element"));
                collmd.setSerializedElement(getAttr(attrs,"serialized-element"));
                collmd.setDependentElement(getAttr(attrs,"dependent-element"));
                pushStack(collmd);
            }
            else if (localName.equals("column"))
            {
                MetaData md = getStack();
                ColumnMetaData colmd = new ColumnMetaData();
                colmd.setName(getAttr(attrs,"name"));
                colmd.setTarget(getAttr(attrs,"target"));
                colmd.setTargetMember(getAttr(attrs,"target-field"));
                colmd.setJdbcType(getAttr(attrs,"jdbc-type"));
                colmd.setSqlType(getAttr(attrs,"sql-type"));
                colmd.setLength(getAttr(attrs,"length"));
                colmd.setScale(getAttr(attrs,"scale"));
                colmd.setAllowsNull(getAttr(attrs,"allows-null"));
                colmd.setDefaultValue(getAttr(attrs,"default-value"));
                colmd.setInsertValue(getAttr(attrs,"insert-value"));
                if (md instanceof AbstractMemberMetaData)
                {
                    AbstractMemberMetaData fmd = (AbstractMemberMetaData)md;
                    fmd.addColumn(colmd);
                }
                else if (md instanceof AbstractElementMetaData)
                {
                    AbstractElementMetaData elemd = (AbstractElementMetaData)md;
                    elemd.addColumn(colmd);
                }
                else if (md instanceof JoinMetaData)
                {
                    JoinMetaData jnmd = (JoinMetaData)md;
                    jnmd.addColumn(colmd);
                }
                else if (md instanceof IdentityMetaData)
                {
                    IdentityMetaData idmd = (IdentityMetaData)md;
                    idmd.addColumn(colmd);
                }
                else if (md instanceof ForeignKeyMetaData)
                {
                    ForeignKeyMetaData fkmd = (ForeignKeyMetaData)md;
                    fkmd.addColumn(colmd);
                }
                else if (md instanceof IndexMetaData)
                {
                    IndexMetaData idxmd = (IndexMetaData)md;
                    idxmd.addColumn(colmd);
                }
                else if (md instanceof UniqueMetaData)
                {
                    UniqueMetaData unimd = (UniqueMetaData)md;
                    unimd.addColumn(colmd);
                }
                else if (md instanceof OrderMetaData)
                {
                    OrderMetaData ormd = (OrderMetaData)md;
                    ormd.addColumn(colmd);
                }
                else if (md instanceof DiscriminatorMetaData)
                {
                    DiscriminatorMetaData dismd = (DiscriminatorMetaData)md;
                    dismd.setColumnMetaData(colmd);
                }
                else if (md instanceof VersionMetaData)
                {
                    VersionMetaData vermd = (VersionMetaData)md;
                    vermd.addColumn(colmd);
                }
                else if (md instanceof AbstractClassMetaData)
                {
                    AbstractClassMetaData cmd = (AbstractClassMetaData)md;
                    cmd.addUnmappedColumn(colmd);
                }
                else if (md instanceof PrimaryKeyMetaData)
                {
                    PrimaryKeyMetaData pkmd = (PrimaryKeyMetaData)md;
                    pkmd.addColumn(colmd);
                }
                pushStack(colmd);
            }
            else if (localName.equals("element"))
            {
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                ElementMetaData elemmd = new ElementMetaData();
                elemmd.setColumnName(getAttr(attrs, "column"));
                elemmd.setDeleteAction(getAttr(attrs, "delete-action"));
                elemmd.setUpdateAction(getAttr(attrs, "update-action"));
                elemmd.setIndexed(IndexedValue.getIndexedValue(getAttr(attrs, "indexed")));
                elemmd.setUnique(getAttr(attrs, "unique"));
                elemmd.setMappedBy(getAttr(attrs, "mapped-by"));
                fmd.setElementMetaData(elemmd);
                pushStack(elemmd);
            }
            else if (localName.equals("key"))
            {
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                KeyMetaData keymd = new KeyMetaData();
                keymd.setColumnName(getAttr(attrs, "column"));
                keymd.setDeleteAction(getAttr(attrs, "delete-action"));
                keymd.setUpdateAction(getAttr(attrs, "update-action"));
                keymd.setIndexed(IndexedValue.getIndexedValue(getAttr(attrs, "indexed")));
                keymd.setUnique(getAttr(attrs, "unique"));
                keymd.setMappedBy(getAttr(attrs, "mapped-by"));
                fmd.setKeyMetaData(keymd);
                pushStack(keymd);
            }
            // 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);
View Full Code Here


            }
            else if (localName.equals("secondary-table"))
            {
                // Join for this entity
                ClassMetaData cmd = (ClassMetaData)getStack();
                JoinMetaData joinmd = new JoinMetaData();
                joinmd.setTable(getAttr(attrs, "name"));
                joinmd.setCatalog(getAttr(attrs, "catalog"));
                joinmd.setSchema(getAttr(attrs, "schema"));
                cmd.addJoin(joinmd);
                pushStack(joinmd);
            }
            else if (localName.equals("primary-key-join-column"))
            {
                MetaData md = getStack();
                if (md instanceof ClassMetaData)
                {
                    // Join columns between PK of subclass table and PK of base class table
                    ClassMetaData cmd = (ClassMetaData)md;
                    ColumnMetaData colmd = new ColumnMetaData();
                    colmd.setName(getAttr(attrs, "name"));
                    colmd.setTarget(getAttr(attrs, "referenced-column-name"));
                    String columnDdl = getAttr(attrs, "column-definition");
                    if (columnDdl != null)
                    {
                        colmd.setColumnDdl(columnDdl);
                    }
                    InheritanceMetaData inhmd = cmd.getInheritanceMetaData();
                    if (inhmd == null)
                    {
                        inhmd = new InheritanceMetaData();
                        cmd.setInheritanceMetaData(inhmd);
                    }
                    JoinMetaData inhJoinmd = inhmd.getJoinMetaData();
                    if (inhJoinmd == null)
                    {
                        inhJoinmd = new JoinMetaData();
                    }
                    inhJoinmd.addColumn(colmd);
                }
                else if (md instanceof JoinMetaData)
                {
                    // Join columns between PK of secondary table and PK of primary table
                    JoinMetaData joinmd = (JoinMetaData)md;
                    ColumnMetaData colmd = new ColumnMetaData();
                    colmd.setName(getAttr(attrs, "name"));
                    colmd.setTarget(getAttr(attrs, "referenced-column-name"));
                    joinmd.addColumn(colmd);
                }
            }
            else if (localName.equals("id"))
            {
                // Identity field
                ClassMetaData cmd = (ClassMetaData)getStack();
                AbstractMemberMetaData mmd = newPKFieldObject(cmd, attrs);

                pushStack(mmd);
            }
            else if (localName.equals("embedded-id"))
            {
                // Embedded identity field
                ClassMetaData cmd = (ClassMetaData)getStack();
                AbstractMemberMetaData mmd = newPKFieldObject(cmd, attrs);

                pushStack(mmd);
            }
            else if (localName.equals("basic"))
            {
                // Basic field
                AbstractClassMetaData cmd = (AbstractClassMetaData)getStack();
                AbstractMemberMetaData mmd = newFieldObject(cmd, attrs);

                pushStack(mmd);
            }
            else if (localName.equals("lob"))
            {
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                fmd.setStoreInLob(); // Just mark it as to be stored in a "lob" and let the MetaData sort it out
            }
            else if (localName.equals("enumerated"))
            {
                // Processed elsewhere
            }
            else if (localName.equals("temporal"))
            {
                // Processed elsewhere
            }
            else if (localName.equals("transient"))
            {
                // Transient field
                ClassMetaData cmd = (ClassMetaData)getStack();
                AbstractMemberMetaData mmd = newTransientFieldObject(cmd, getAttr(attrs, "name"));
                cmd.addMember(mmd);

                pushStack(mmd);
            }
            else if (localName.equals("one-to-many"))
            {
                // 1-N field
                ClassMetaData cmd = (ClassMetaData)getStack();
                AbstractMemberMetaData mmd = newFieldObject(cmd, attrs);
                String targetEntityName = getAttr(attrs, "target-entity");
                if (!StringUtils.isWhitespace(targetEntityName))
                {
                    mmd.setTargetClassName(targetEntityName);
                }
                mmd.setOrdered(); // Mark as ordered so we know we're using JPA
                String jpaLevel = mgr.getOMFContext().getPersistenceConfiguration().getStringProperty("datanucleus.jpa.level");
                if (mmd.getMappedBy() == null && mmd.getJoinMetaData() == null &&
                    jpaLevel.equalsIgnoreCase("JPA1"))
                {
                    // JPA1 : 1-N uni with no join specified (yet) so add one (see JPA1 spec [9.1.24])
                    mmd.setJoinMetaData(new JoinMetaData());
                }

                pushStack(mmd);
            }
            else if (localName.equals("one-to-one"))
            {
                // 1-1 field
                ClassMetaData cmd = (ClassMetaData)getStack();
                AbstractMemberMetaData mmd = newFieldObject(cmd, attrs);
                String targetEntityName = getAttr(attrs, "target-entity");
                if (!StringUtils.isWhitespace(targetEntityName))
                {
                    mmd.setTargetClassName(targetEntityName);
                }

                pushStack(mmd);
            }
            else if (localName.equals("many-to-one"))
            {
                // N-1 field
                ClassMetaData cmd = (ClassMetaData)getStack();
                AbstractMemberMetaData mmd = newFieldObject(cmd, attrs);
                String targetEntityName = getAttr(attrs, "target-entity");
                if (!StringUtils.isWhitespace(targetEntityName))
                {
                    mmd.setTargetClassName(targetEntityName);
                }

                pushStack(mmd);
            }
            else if (localName.equals("many-to-many"))
            {
                // M-N field
                ClassMetaData cmd = (ClassMetaData)getStack();
                AbstractMemberMetaData mmd = newFieldObject(cmd, attrs);
                String targetEntityName = getAttr(attrs, "target-entity");
                if (!StringUtils.isWhitespace(targetEntityName))
                {
                    mmd.setTargetClassName(targetEntityName);
                }
                mmd.setOrdered(); // Mark as ordered so we know we're using JPA
                if (mmd.getMappedBy() == null && mmd.getJoinMetaData() == null)
                {
                    // M-N and no join specified (yet) so add one
                    mmd.setJoinMetaData(new JoinMetaData());
                }

                pushStack(mmd);
            }
            else if (localName.equals("map-key"))
            {
                // Key of a Map (field/property of the value class)
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                String mappedByFieldName = getAttr(attrs, "name");
                if (StringUtils.isWhitespace(mappedByFieldName))
                {
                    mappedByFieldName = "#PK"; // Special value understood by MapMetaData.populate()
                }
                KeyMetaData keymd = new KeyMetaData();
                keymd.setMappedBy(mappedByFieldName);
                fmd.setKeyMetaData(keymd);
            }
            else if (localName.equals("order-by"))
            {
                // Processed in endElement()
            }
            else if (localName.equals("order-column"))
            {
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                String columnName = getAttr(attrs, "name");
                OrderMetaData ordermd = new OrderMetaData();
                ordermd.setColumnName(columnName);

                String orderingOrigin = getAttr(attrs, "base");
                if (orderingOrigin != null)
                {
                    try
                    {
                        int origin = new Integer(orderingOrigin).intValue();
                        ordermd.setOrderOrigin(origin);
                    }
                    catch (NumberFormatException nfe)
                    {
                    }
                }

                ColumnMetaData colmd = new ColumnMetaData();
                colmd.setName(getAttr(attrs, "name"));
                colmd.setAllowsNull(getAttr(attrs, "nullable"));
                colmd.setInsertable(getAttr(attrs, "insertable"));
                colmd.setUpdateable(getAttr(attrs, "updatable"));
                String columnDdl = getAttr(attrs, "column-definition");
                if (columnDdl != null)
                {
                    colmd.setColumnDdl(columnDdl);
                }
                ordermd.addColumn(colmd);
                fmd.setOrderMetaData(ordermd);
            }
            else if (localName.equals("cascade"))
            {
                // Do nothing
            }
            else if (localName.equals("cascade-type"))
            {
                // Handled in elements below
            }
            else if (localName.equals("cascade-all"))
            {
                AbstractMemberMetaData mmd = (AbstractMemberMetaData)getStack();
                mmd.setCascadePersist(true);
                mmd.setCascadeUpdate(true);
                mmd.setCascadeDelete(true);
                mmd.setCascadeRefresh(true);
            }
            else if (localName.equals("cascade-persist"))
            {
                MetaData md = getStack();
                if (md instanceof AbstractMemberMetaData)
                {
                    AbstractMemberMetaData mmd = (AbstractMemberMetaData)md;
                    mmd.setCascadePersist(true);
                }
                else if (md instanceof FileMetaData)
                {
                    // Specified at <persistence-unit-defaults>
                    defaultCascadePersist = true;
                }
            }
            else if (localName.equals("cascade-merge"))
            {
                AbstractMemberMetaData mmd = (AbstractMemberMetaData)getStack();
                mmd.setCascadeUpdate(true);
            }
            else if (localName.equals("cascade-remove"))
            {
                AbstractMemberMetaData mmd = (AbstractMemberMetaData)getStack();
                mmd.setCascadeDelete(true);
            }
            else if (localName.equals("cascade-refresh"))
            {
                AbstractMemberMetaData mmd = (AbstractMemberMetaData)getStack();
                mmd.setCascadeRefresh(true);
            }
            else if (localName.equals("version"))
            {
                if (getStack() instanceof ClassMetaData)
                {
                    // Version field
                    ClassMetaData cmd = (ClassMetaData)getStack();
                    AbstractMemberMetaData mmd = newFieldObject(cmd, attrs);

                    // Tag this field as the version field
                    VersionMetaData vermd = cmd.newVersionMetadata();
                    vermd.setStrategy(VersionStrategy.VERSION_NUMBER).setFieldName(mmd.getName());

                    pushStack(mmd);
                }
            }
            else if (localName.equals("discriminator-value"))
            {
                // Processed in endElement()
            }
            else if (localName.equals("discriminator-column"))
            {
                ClassMetaData cmd = (ClassMetaData)getStack();
                InheritanceMetaData inhmd = cmd.getInheritanceMetaData();
                if (inhmd == null)
                {
                    // Add an empty inheritance specification
                    inhmd = new InheritanceMetaData();
                    cmd.setInheritanceMetaData(inhmd);
                }
                DiscriminatorMetaData dismd = inhmd.getDiscriminatorMetaData();
                if (dismd == null)
                {
                    // User hasn't specified discriminator value so use "provider-specific function" (JPA 9.1.3.1) - what a joke spec
                    dismd = inhmd.newDiscriminatorMetadata();
                    dismd.setStrategy(DiscriminatorStrategy.VALUE_MAP);
                    dismd.setValue(cmd.getFullClassName()); // Default to class name as value unless set
                    dismd.setIndexed("true");
                }
                String jdbcType = null;
                String discType = getAttr(attrs, "discriminator-type");
                if (discType != null)
                {
                    if (discType.equalsIgnoreCase("STRING"))
                    {
                        jdbcType = "VARCHAR";
                    }
                    else if (discType.equalsIgnoreCase("CHAR"))
                    {
                        jdbcType = "CHAR";
                    }
                    else if (discType.equalsIgnoreCase("INTEGER"))
                    {
                        jdbcType = "INTEGER";
                    }
                }
                ColumnMetaData colmd = new ColumnMetaData();
                colmd.setName(getAttr(attrs, "name"));
                colmd.setJdbcType(jdbcType);
                String columnDdl = getAttr(attrs, "column-definition");
                if (columnDdl != null)
                {
                    colmd.setColumnDdl(columnDdl);
                }
                dismd.setColumnMetaData(colmd);
            }
            else if (localName.equals("generated-value"))
            {
                // generated value for this field
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                String strategy = getAttr(attrs, "strategy");
                if (strategy != null)
                {
                    if (strategy.equalsIgnoreCase("auto"))
                    {
                        fmd.setValueStrategy(IdentityStrategy.NATIVE);
                    }
                    else if (strategy.equalsIgnoreCase("table"))
                    {
                        fmd.setValueStrategy(IdentityStrategy.INCREMENT);
                    }
                    else if (strategy.equalsIgnoreCase("sequence"))
                    {
                        fmd.setValueStrategy(IdentityStrategy.SEQUENCE);
                    }
                    else if (strategy.equalsIgnoreCase("identity"))
                    {
                        fmd.setValueStrategy(IdentityStrategy.IDENTITY);
                    }
                }
                fmd.setValueGeneratorName(getAttr(attrs, "generator"));
            }
            else if (localName.equals("join-table"))
            {
                // Join table for this field
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                JoinMetaData joinmd = new JoinMetaData();
                String tableName = getAttr(attrs, "name");
                String schemaName = getAttr(attrs, "schema");
                String catalogName = getAttr(attrs, "catalog");

                fmd.setJoinMetaData(joinmd);
                if (!StringUtils.isWhitespace(tableName))
                {
                    fmd.setTable(tableName);
                }
                if (!StringUtils.isWhitespace(schemaName))
                {
                    fmd.setSchema(schemaName);
                }
                if (!StringUtils.isWhitespace(catalogName))
                {
                    fmd.setSchema(catalogName);
                }
                pushStack(joinmd);
            }
            else if (localName.equals("column"))
            {
                // Column for the current field
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                ColumnMetaData colmd = new ColumnMetaData();
                colmd.setName(getAttr(attrs, "name"));
                colmd.setLength(getAttr(attrs, "length"));
                colmd.setScale(getAttr(attrs, "scale"));
                colmd.setAllowsNull(getAttr(attrs, "nullable"));
                colmd.setInsertable(getAttr(attrs, "insertable"));
                colmd.setUpdateable(getAttr(attrs, "updatable"));
                colmd.setUnique(getAttr(attrs, "unique"));
                String columnDdl = getAttr(attrs, "column-definition");
                if (columnDdl != null)
                {
                    colmd.setColumnDdl(columnDdl);
                }
                fmd.addColumn(colmd);
                String table = getAttr(attrs, "table");
                if (!StringUtils.isWhitespace(table))
                {
                    // Using secondary table
                    fmd.setTable(table);
                }
            }
            else if (localName.equals("join-column"))
            {
                MetaData md = getStack();
                if (md instanceof JoinMetaData)
                {
                    JoinMetaData joinmd = (JoinMetaData)md;
                    ColumnMetaData colmd = new ColumnMetaData();
                    colmd.setName(getAttr(attrs, "name"));
                    colmd.setTarget(getAttr(attrs, "referenced-column-name"));
                    colmd.setAllowsNull(getAttr(attrs, "nullable"));
                    colmd.setInsertable(getAttr(attrs, "insertable"));
                    colmd.setUpdateable(getAttr(attrs, "updatable"));
                    colmd.setUnique(getAttr(attrs, "unique"));
                    String columnDdl = getAttr(attrs, "column-definition");
                    if (columnDdl != null)
                    {
                        colmd.setColumnDdl(columnDdl);
                    }
                    joinmd.addColumn(colmd);
                }
                else if (md instanceof AbstractMemberMetaData)
                {
                    // N-1, 1-1, 1-N (FK). Just set <column> for the field. Is this correct for 1-N FK ?
                    AbstractMemberMetaData fmd = (AbstractMemberMetaData)md;
                    ColumnMetaData colmd = new ColumnMetaData();
                    colmd.setName(getAttr(attrs, "name"));
                    colmd.setTarget(getAttr(attrs, "referenced-column-name"));
                    colmd.setAllowsNull(getAttr(attrs, "nullable"));
                    colmd.setInsertable(getAttr(attrs, "insertable"));
                    colmd.setUpdateable(getAttr(attrs, "updatable"));
                    colmd.setUnique(getAttr(attrs, "unique"));
                    fmd.addColumn(colmd);
                }
            }
            else if (localName.equals("inverse-join-column"))
            {
                MetaData md = getStack();
                if (md instanceof JoinMetaData)
                {
                    // Join table column that is FK to the element table
                    JoinMetaData joinmd = (JoinMetaData)md;
                    ElementMetaData elemmd = null;
                    AbstractMemberMetaData fmd = (AbstractMemberMetaData)joinmd.getParent();
                    if (fmd.getElementMetaData() != null)
                    {
                        elemmd = fmd.getElementMetaData();
                    }
                    else
                    {
                        elemmd = new ElementMetaData();
                        fmd.setElementMetaData(elemmd);
                    }
                    ColumnMetaData colmd = new ColumnMetaData();
                    colmd.setName(getAttr(attrs, "name"));
                    colmd.setTarget(getAttr(attrs, "referenced-column-name"));
                    colmd.setAllowsNull(getAttr(attrs, "nullable"));
                    colmd.setInsertable(getAttr(attrs, "insertable"));
                    colmd.setUpdateable(getAttr(attrs, "updatable"));
                    colmd.setUnique(getAttr(attrs, "unique"));
                    elemmd.addColumn(colmd);
                }
            }
            else if (localName.equals("unique-constraint"))
            {
                MetaData md = getStack();
                if (md instanceof AbstractClassMetaData)
                {
                    // Unique constraint on primary table
                    AbstractClassMetaData cmd = (AbstractClassMetaData)md;
                    UniqueMetaData unimd = new UniqueMetaData();
                    unimd.setTable(cmd.getTable()); // Columns are in subelement
                    cmd.addUniqueConstraint(unimd);
                    pushStack(unimd);
                }
                else if (md instanceof JoinMetaData)
                {
                    // Unique constraint on secondary table or join table
                    JoinMetaData joinmd = (JoinMetaData)md;
                    UniqueMetaData unimd = new UniqueMetaData();
                    joinmd.setUniqueMetaData(unimd);
                    pushStack(unimd);
                }
            }
            else if (localName.equals("entity-listeners"))
            {
View Full Code Here

    /* (non-Javadoc)
     * @see javax.jdo.metadata.InheritanceMetadata#getJoinMetaData()
     */
    public JoinMetadata getJoinMetadata()
    {
        JoinMetaData internalJoinmd = getInternal().getJoinMetaData();
        if (internalJoinmd == null)
        {
            return null;
        }
        JoinMetadataImpl joinmd = new JoinMetadataImpl(internalJoinmd);
View Full Code Here

    /* (non-Javadoc)
     * @see javax.jdo.metadata.InheritanceMetadata#newJoinMetadata()
     */
    public JoinMetadata newJoinMetadata()
    {
        JoinMetaData internalJoinmd = getInternal().newJoinMetadata();
        JoinMetadataImpl joinmd = new JoinMetadataImpl(internalJoinmd);
        joinmd.parent = this;
        return joinmd;
    }
View Full Code Here

            // Create the Field/Property MetaData so we have something to add to
            AbstractMemberMetaData mmd = newMetaDataForMember(cmd, member, annotations);

            // Process other annotations
            ColumnMetaData[] columnMetaData = null;
            JoinMetaData joinmd = null;
            boolean oneToMany = false;
            boolean manyToMany = false;
            for (int i=0;annotations != null && i<annotations.length;i++)
            {
                if (isSupportedAnnotation(annotations[i].getName()))
                {
                    String annName = annotations[i].getName();
                    HashMap<String, Object> annotationValues = annotations[i].getNameValueMap();
                    if (annName.equals(JPAAnnotationUtils.JOIN_COLUMNS))
                    {
                        // 1-1 FK columns, or 1-N FK columns, or N-1 FK columns
                        JoinColumn[] cols = (JoinColumn[])annotationValues.get("value");
                        if (cols != null)
                        {
                            columnMetaData = new ColumnMetaData[cols.length];
                            for (int j=0;j<cols.length;j++)
                            {
                                columnMetaData[j] = new ColumnMetaData();
                                columnMetaData[j].setName(cols[j].name());
                                columnMetaData[j].setTarget(cols[j].referencedColumnName());
                                columnMetaData[j].setAllowsNull(cols[j].nullable());
                                columnMetaData[j].setInsertable(cols[j].insertable());
                                columnMetaData[j].setUpdateable(cols[j].updatable());
                                columnMetaData[j].setUnique(cols[j].unique());
                            }
                        }
                    }
                    else if (annName.equals(JPAAnnotationUtils.JOIN_COLUMN))
                    {
                        // 1-1 FK column, or 1-N FK column, or N-1 FK column
                        columnMetaData = new ColumnMetaData[1];
                        String colNullable = null;
                        String colInsertable = null;
                        String colUpdateable = null;
                        String colUnique = 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();
                        }
                        if (annotationValues.get("unique") != null)
                        {
                            colUnique = annotationValues.get("unique").toString();
                        }
                        columnMetaData[0] = new ColumnMetaData();
                        columnMetaData[0].setName((String)annotationValues.get("name"));
                        columnMetaData[0].setTarget((String)annotationValues.get("referencedColumnName"));
                        columnMetaData[0].setAllowsNull(colNullable);
                        columnMetaData[0].setInsertable(colInsertable);
                        columnMetaData[0].setUpdateable(colUpdateable);
                        columnMetaData[0].setUnique(colUnique);
                    }
                    else if (annName.equals(JPAAnnotationUtils.ATTRIBUTE_OVERRIDES) && mmd.isEmbedded())
                    {
                        // Embedded field overrides
                        EmbeddedMetaData embmd = new EmbeddedMetaData();
                        embmd.setOwnerMember(mmd.getName());
                        mmd.setEmbeddedMetaData(embmd);                           
                        AttributeOverride[] attributeOverride = (AttributeOverride[])annotationValues.get("value");
                        for (int j=0; j<attributeOverride.length; j++)
                        {
                            AbstractMemberMetaData apmd = new FieldMetaData(embmd, attributeOverride[j].name());
                            embmd.addMember(apmd);
                            try
                            {
                                //needs to do the same for methods
                                Field overrideField = member.getType().getDeclaredField(attributeOverride[j].name());
                                apmd.addColumn(JPAAnnotationUtils.getColumnMetaDataForColumnAnnotation(apmd,
                                    new Member(overrideField), attributeOverride[j].column()));
                            }
                            catch (SecurityException e)
                            {
                                throw new NucleusException("Cannot obtain override field "+
                                    attributeOverride[j].name()+" of class "+member.getType()+
                                    " for persistent class "+cmd.getName(),e);
                            }
                            catch (NoSuchFieldException e)
                            {
                                throw new NucleusException("Override field "+attributeOverride[j].name()+
                                    " does not exist in class "+member.getType()+" for persistent class "+
                                    cmd.getName(),e);
                            }
                        }
                    }
                    else if (annName.equals(JPAAnnotationUtils.JOIN_TABLE))
                    {
                        // Process @JoinTable to generate JoinMetaData
                        mmd.setTable((String)annotationValues.get("name"));
                        mmd.setCatalog((String)annotationValues.get("catalog"));
                        mmd.setSchema((String)annotationValues.get("schema"));

                        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);
                            }
                        }
                        if (annotationValues.get("inverseJoinColumns") != null)
                        {
                            ArrayList<JoinColumn> elementColumns = new ArrayList<JoinColumn>();
                            elementColumns.addAll(Arrays.asList((JoinColumn[])annotationValues.get("inverseJoinColumns")));
                            ElementMetaData elmd = new ElementMetaData();
                            mmd.setElementMetaData(elmd);
                            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());
                                elmd.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) &&
                        (jpaLevel.equalsIgnoreCase("JPA2") || jpaLevel.equalsIgnoreCase("DataNucleus")))
                    {
                        // Process @CollectionTable to generate JoinMetaData
                        mmd.setTable((String)annotationValues.get("name"));
                        mmd.setCatalog((String)annotationValues.get("catalog"));
                        mmd.setSchema((String)annotationValues.get("schema"));

                        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))
                    {
                        String keyMappedBy = (String)annotationValues.get("name");
                        if (keyMappedBy != null)
                        {
                            KeyMetaData keymd = new KeyMetaData();
                            keymd.setMappedBy(keyMappedBy);
                            mmd.setKeyMetaData(keymd);
                            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.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");
                        int orderingOrigin = ((Integer)annotationValues.get("base")).intValue();
                        OrderMetaData ordermd = new OrderMetaData();
                        ordermd.setColumnName(columnName);
                        ordermd.setOrderOrigin(orderingOrigin);

                        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)
View Full Code Here

        if (addJoin)
        {
            if (fmd.getJoinMetaData() == null)
            {
                JoinMetaData joinmd = new JoinMetaData();
                fmd.setJoinMetaData(joinmd);
            }
        }

        // Extensions
View Full Code Here

                SecondaryTable[] secTableAnns = (SecondaryTable[])annotationValues.get("value");
                if (secTableAnns != null)
                {
                    for (int j=0;j<secTableAnns.length;j++)
                    {
                        JoinMetaData joinmd = new JoinMetaData();
                        joinmd.setTable(secTableAnns[j].name());
                        joinmd.setCatalog(secTableAnns[j].catalog());
                        joinmd.setSchema(secTableAnns[j].schema());
                        PrimaryKeyJoinColumn[] pkJoinCols = secTableAnns[j].pkJoinColumns();
                        if (pkJoinCols != null)
                        {
                            for (int k = 0; k < pkJoinCols.length; k++)
                            {
                                ColumnMetaData colmd = new ColumnMetaData();
                                colmd.setName(pkJoinCols[k].name());
                                colmd.setTarget(pkJoinCols[k].referencedColumnName());
                                joinmd.addColumn(colmd);
                            }
                        }
                        joins.add(joinmd);
                        cmd.addJoin(joinmd);

                        UniqueConstraint[] constrs = secTableAnns[j].uniqueConstraints();
                        if (constrs != null && constrs.length > 0)
                        {
                            for (int k=0;k<constrs.length;k++)
                            {
                                UniqueMetaData unimd = new UniqueMetaData();
                                unimd.setTable((String)annotationValues.get("table"));
                                for (int l=0;l<constrs[k].columnNames().length;l++)
                                {
                                    ColumnMetaData colmd = new ColumnMetaData();
                                    colmd.setName(constrs[k].columnNames()[l]);
                                    unimd.addColumn(colmd);
                                }
                                joinmd.setUniqueMetaData(unimd); // JDO only allows one unique
                            }
                        }
                    }
                }
            }
            else if (annName.equals(JPAAnnotationUtils.SECONDARY_TABLE))
            {
                JoinMetaData joinmd = new JoinMetaData();
                joinmd.setTable((String)annotationValues.get("name"));
                joinmd.setCatalog((String)annotationValues.get("catalog"));
                joinmd.setSchema((String)annotationValues.get("schema"));
                if (annotationValues.get("pkJoinColumns") != null)
                {
                    PrimaryKeyJoinColumn[] joinCols = (PrimaryKeyJoinColumn[])annotationValues.get("pkJoinColumns");
                    for (int j = 0; j < joinCols.length; j++)
                    {
                        ColumnMetaData colmd = new ColumnMetaData();
                        colmd.setName(joinCols[j].name());
                        colmd.setTarget(joinCols[j].referencedColumnName());
                        joinmd.addColumn(colmd);
                    }
                }
                joins.add(joinmd);
                cmd.addJoin(joinmd);

                UniqueConstraint[] constrs = (UniqueConstraint[])annotationValues.get("uniqueConstraints");
                if (constrs != null && constrs.length > 0)
                {
                    for (int j=0;j<constrs.length;j++)
                    {
                        UniqueMetaData unimd = new UniqueMetaData();
                        unimd.setTable((String)annotationValues.get("table"));
                        for (int k=0;k<constrs[j].columnNames().length;k++)
                        {
                            ColumnMetaData colmd = new ColumnMetaData();
                            colmd.setName(constrs[j].columnNames()[k]);
                            unimd.addColumn(colmd);
                        }
                        joinmd.setUniqueMetaData(unimd); // JDO only allows one unique
                    }
                }
            }
        }
        return (JoinMetaData[])joins.toArray(new JoinMetaData[joins.size()]);
View Full Code Here

                            if (js != null && js.length > 0)
                            {
                                joins = new JoinMetaData[js.length];
                                for (int j=0;j<js.length;j++)
                                {
                                    joins[j] = new JoinMetaData();
                                    joins[j].setTable(js[j].table());
                                    joins[j].setColumnName(js[j].column());
                                    joins[j].setIndexed(IndexedValue.getIndexedValue(js[i].indexed()));
                                    joins[j].setOuter(js[j].outer());
                                    joins[j].setUnique(js[i].unique());
                                    joins[j].setDeleteAction(JDOAnnotationUtils.getForeignKeyActionString(js[j].deleteAction()));
                                }
                            }
                        }
                        else if (annName.equals(JDOAnnotationUtils.JOIN))
                        {
                            if (joins != null)
                            {
                                NucleusLogger.METADATA.warn(LOCALISER.msg("044210", cmd.getFullClassName()));
                            }
                            joins = new JoinMetaData[1];
                            joins[0] = new JoinMetaData();
                            joins[0].setTable((String)annotationValues.get("table"));
                            joins[0].setColumnName((String)annotationValues.get("column"));
                            joins[0].setIndexed(IndexedValue.getIndexedValue((String)annotationValues.get("indexed")));
                            joins[0].setOuter((String)annotationValues.get("outer"));
                            joins[0].setUnique((String)annotationValues.get("unique"));
View Full Code Here

            Persistent[] embeddedElementMembers = null;
            Persistent[] embeddedKeyMembers = null;
            Persistent[] embeddedValueMembers = null;

            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++)
            {
                if (isSupportedAnnotation(annotations[i].getName()))
                {
                    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)
                        {
                            StringBuffer typeStr = new StringBuffer();
                            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))
View Full Code Here

        return null;
    }

    public JoinMetadata getJoinMetadata()
    {
        JoinMetaData internalJoinmd = getInternal().getJoinMetaData();
        if (internalJoinmd == null)
        {
            return null;
        }
        JoinMetadataImpl joinmd = new JoinMetadataImpl(internalJoinmd);
View Full Code Here

TOP

Related Classes of org.datanucleus.metadata.JoinMetaData

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.