Package org.jpox.metadata

Examples of org.jpox.metadata.IndexMetaData


                        if (values != null && values.length > 0)
                        {
                            indices = new HashSet<IndexMetaData>(values.length);
                            for (int j=0;j<values.length;j++)
                            {
                                IndexMetaData idxmd = JDOAnnotationUtils.getIndexMetaData(values[j].name(), values[j].table(),
                                    "" + values[j].unique(), values[j].members(), values[j].columns());
                                if (idxmd.getNumberOfColumns() == 0 && idxmd.getNumberOfMembers() == 0)
                                {
                                    JPOXLogger.METADATA.warn(LOCALISER.msg("MetaData.Annotations.IndexAtClassWithoutFieldsColumns",
                                        cls.getName()));
                                }
                                else
                                {
                                    indices.add(idxmd);
                                }
                            }
                        }
                    }
                    else if (annName.equals(JDOAnnotationUtils.INDEX))
                    {
                        // Single Index for the class
                        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");

                        IndexMetaData idxmd = JDOAnnotationUtils.getIndexMetaData(name, table, unique, members, columns);
                        if (idxmd.getNumberOfColumns() == 0 && idxmd.getNumberOfMembers() == 0)
                        {
                            JPOXLogger.METADATA.warn(LOCALISER.msg("MetaData.Annotations.IndexAtClassWithoutFieldsColumns",
                                cls.getName()));
                        }
                        else
                        {
                            indices = new HashSet<IndexMetaData>(1);
                            indices.add(idxmd);
                        }
                    }
                    else if (annName.equals(JDOAnnotationUtils.UNIQUES))
                    {
                        // Multiple Unique Constraints for the class
                        Unique[] values = (Unique[])annotationValues.get("value");
                        if (values != null && values.length > 0)
                        {
                            uniqueKeys = new HashSet<UniqueMetaData>(values.length);
                            for (int j=0;j<values.length;j++)
                            {
                                UniqueMetaData unimd = JDOAnnotationUtils.getUniqueMetaData(values[j].name(),
                                    values[j].table(), "" + values[j].deferred(), values[j].members(), values[j].columns());
                                if (unimd.getNumberOfColumns() == 0 && unimd.getNumberOfMembers() == 0)
                                {
                                    JPOXLogger.METADATA.warn(LOCALISER.msg("MetaData.Annotations.UniqueAtClassWithoutFieldsColumns",
                                        cls.getName()));
                                }
                                else
                                {
                                    uniqueKeys.add(unimd);
                                }
                            }
                        }
                    }
                    else if (annName.equals(JDOAnnotationUtils.UNIQUE))
                    {
                        // Single Unique constraint for the class
                        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");

                        UniqueMetaData unimd = JDOAnnotationUtils.getUniqueMetaData(name, table, deferred, members, columns);
                        if (unimd.getNumberOfColumns() == 0 && unimd.getNumberOfMembers() == 0)
                        {
                            JPOXLogger.METADATA.warn(LOCALISER.msg("MetaData.Annotations.UniqueAtClassWithoutFieldsColumns",
                                cls.getName()));
                        }
                        else
                        {
                            uniqueKeys = new HashSet<UniqueMetaData>(1);
                            uniqueKeys.add(unimd);
                        }
                    }
                    else if (annName.equals(JDOAnnotationUtils.FOREIGNKEYS))
                    {
                        // Multiple FKs for the class
                        ForeignKey[] values = (ForeignKey[])annotationValues.get("value");
                        if (values != null && values.length > 0)
                        {
                            fks = new HashSet<ForeignKeyMetaData>(values.length);
                            for (int j=0;j<values.length;j++)
                            {
                                String deleteAction = JDOAnnotationUtils.getForeignKeyActionString(values[j].deleteAction());
                                String updateAction = JDOAnnotationUtils.getForeignKeyActionString(values[j].deleteAction());
                                ForeignKeyMetaData fkmd = JDOAnnotationUtils.getFKMetaData(values[j].name(),
                                    values[j].table(), values[j].unique(), "" + values[j].deferred(),
                                    deleteAction, updateAction, values[j].members(), values[j].columns());
                                if (fkmd.getNumberOfColumns() == 0 && fkmd.getNumberOfMembers() == 0)
                                {
                                    JPOXLogger.METADATA.warn(LOCALISER.msg("MetaData.Annotations.FKAtClassWithoutFieldsColumns",
                                        cls.getName()));
                                }
                                else
                                {
                                    fks.add(fkmd);
                                }
                            }
                        }
                    }
                    else if (annName.equals(JDOAnnotationUtils.FOREIGNKEY))
                    {
                        // Single FK constraint for the class
                        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");

                        ForeignKeyMetaData fkmd = JDOAnnotationUtils.getFKMetaData(name, table, unique, deferred,
                            deleteAction, updateAction, members, columns);
                        if (fkmd.getNumberOfColumns() == 0 && fkmd.getNumberOfMembers() == 0)
                        {
                            JPOXLogger.METADATA.warn(LOCALISER.msg("MetaData.Annotations.FKAtClassWithoutFieldsColumns",
                                cls.getName()));
                        }
                        else
                        {
                            fks = new HashSet<ForeignKeyMetaData>(1);
                            fks.add(fkmd);
                        }
                    }
                    else if (annName.equals(JDOAnnotationUtils.COLUMNS))
                    {
                        // Unmapped column specification
                        Column[] cols = (Column[])annotationValues.get("value");
                        if (cols != null && cols.length > 0)
                        {
                            unmappedColumns = new ColumnMetaData[cols.length];
                            for (int j=0;j<cols.length;j++)
                            {
                                unmappedColumns[j] = JDOAnnotationUtils.getColumnMetaDataForColumn(cmd, cols[j]);
                                JDOAnnotationUtils.addExtensionsToMetaData(unmappedColumns[j], cols[j].extensions());
                            }
                        }
                    }
                    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
                    {
                        JPOXLogger.METADATA.error(LOCALISER.msg("MetaData.Annotations.AnnotationNotProcessed",
                            cls.getName(), annotations[i].getName()));
                    }
                }
            }

            if (cmd != null)
            {
                // Either PersistenceCapable, PersistenceAware or PersistentInterface so build up the metadata
                JPOXLogger.METADATA.info(LOCALISER.msg("MetaData.Annotations.ClassUsingAnnotations", cls.getName(), "JDO"));

                if (cmd instanceof ClassMetaData)
                {
                    pmd.addClass((ClassMetaData)cmd);
                }
                else if (cmd instanceof InterfaceMetaData)
                {
                    pmd.addInterface((InterfaceMetaData)cmd);
                }

                if (embeddedOnly)
                {
                    cmd.setEmbeddedOnly();
                }
                if (idmd != null)
                {
                    // Datastore identity
                    idmd.setParent(cmd);
                    cmd.setIdentityMetaData(idmd);
                }
                if (pkmd != null)
                {
                    // Primary Key
                    pkmd.setParent(cmd);
                    cmd.setPrimaryKeyMetaData(pkmd);
                }

                if (vermd != null)
                {
                    // Version
                    vermd.setParent(cmd);
                    cmd.setVersionMetaData(vermd);
                }

                if (inhmd != null)
                {
                    // Inheritance
                    if (dismd != null)
                    {
                        inhmd.setDiscriminatorMetaData(dismd);
                    }
                    inhmd.setParent(cmd);
                    cmd.setInheritanceMetaData(inhmd);
                }

                if (joins != null && joins.length > 0)
                {
                    // Joins
                    for (int i=0;i<joins.length;i++)
                    {
                        joins[i].setParent(cmd);
                        cmd.addJoin(joins[i]);
                    }
                }
                if (queries != null && queries.length > 0)
                {
                    // Named Queries
                    for (int i=0;i<queries.length;i++)
                    {
                        queries[i].setParent(cmd);
                        cmd.addQuery(queries[i]);
                    }
                }
                if (fetchGroups != null && fetchGroups.length > 0)
                {
                    // Fetch Groups
                    for (int i=0;i<fetchGroups.length;i++)
                    {
                        fetchGroups[i].setParent(cmd);
                        cmd.addFetchGroup(fetchGroups[i]);
                    }
                }

                if (seqmd != null)
                {
                    // Sequence - currently only allowing 1 per class (should really be on the package)
                    seqmd.setParent(cmd.getPackageMetaData());
                    cmd.getPackageMetaData().addSequence(seqmd);
                }

                if (indices != null)
                {
                    Iterator iter = indices.iterator();
                    while (iter.hasNext())
                    {
                        IndexMetaData idxmd = (IndexMetaData)iter.next();
                        idxmd.setParent(cmd);
                        cmd.addIndex(idxmd);
                    }
                }
                if (uniqueKeys != null)
                {
View Full Code Here


            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 a JPOX 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();
                        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 = mgr.getMetaDataFactory().newPropertyObject(cmd, member.getName(), pk,
                                modifier, dfg, nullValue, embedded, serialized, dependent, mappedBy, column,
                                table, null, null, null, null, null, "" + recursionDepth,
                                loadFetchGroup, valueStrategy, sequence, fieldTypeName, null);
                        }
                        else
                        {
                            // Field
                            mmd = mgr.getMetaDataFactory().newFieldObject(cmd, member.getName(), pk,
                                modifier, dfg, nullValue, embedded, serialized, dependent, mappedBy, column,
                                table, null, null, null, null, null, "" + recursionDepth,
                                loadFetchGroup, valueStrategy, sequence, 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.getColumnMetaDataForColumn(mmd, 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.getColumnMetaDataForColumn(mmd, 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(null, 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(null, null, null, null, joinColumn, joinOuter, deleteAction, indexed, unique);

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

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

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

                        if (!StringUtils.isWhitespace(uniqueName))
                        {
                            UniqueMetaData joinUnimd = joinmd.getUniqueMetaData();
                            if (joinUnimd == null)
                            {
                                joinUnimd = new UniqueMetaData(uniqueName, null, null);
                                joinmd.setUniqueMetaData(joinUnimd);
                            }
                            else
                            {
                                joinUnimd.setName(uniqueName);
                            }
                        }
                        if (joinColumns != null && joinColumns.length > 0)
                        {
                            for (int j=0;j<joinColumns.length;j++)
                            {
                                joinmd.addColumn(JDOAnnotationUtils.getColumnMetaDataForColumn(joinmd, 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(null, elementColumn, elementDeleteAction, elementUpdateAction,
                            indexed,  unique, elementMappedBy);
                        if (!StringUtils.isWhitespace(fkName))
                        {
                            ForeignKeyMetaData elemFkmd = elemmd.getForeignKeyMetaData();
                            if (elemFkmd == null)
                            {
                                elemFkmd = new ForeignKeyMetaData(fkName, null, null, null, null, null);
                                elemmd.setForeignKeyMetaData(elemFkmd);
                            }
                            else
                            {
                                elemFkmd.setName(fkName);
                            }
                        }
                        else if (generateFK != null && generateFK.equalsIgnoreCase("true"))
                        {
                            elemmd.setForeignKeyMetaData(new ForeignKeyMetaData(null, null, null, null, null, null));
                        }

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

                        if (!StringUtils.isWhitespace(uniqueName))
                        {
                            UniqueMetaData elemUnimd = elemmd.getUniqueMetaData();
                            if (elemUnimd == null)
                            {
                                elemUnimd = new UniqueMetaData(uniqueName, null, null);
                                elemmd.setUniqueMetaData(elemUnimd);
                            }
                            else
                            {
                                elemUnimd.setName(uniqueName);
                            }
                        }
                        if (elementColumns != null && elementColumns.length > 0)
                        {
                            for (int j=0;j<elementColumns.length;j++)
                            {
                                elemmd.addColumn(JDOAnnotationUtils.getColumnMetaDataForColumn(elemmd, 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(elemmd, embeddedMappings[0].ownerMember(),
                                embeddedMappings[0].nullIndicatorColumn(), 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(null, keyColumn, keyDeleteAction, keyUpdateAction, indexed, unique,
                            keyMappedBy);
                        if (!StringUtils.isWhitespace(fkName))
                        {
                            ForeignKeyMetaData keyFkmd = keymd.getForeignKeyMetaData();
                            if (keyFkmd == null)
                            {
                                keyFkmd = new ForeignKeyMetaData(fkName, null, null, null, null, null);
                                keymd.setForeignKeyMetaData(keyFkmd);
                            }
                            else
                            {
                                keyFkmd.setName(fkName);
                            }
                        }
                        else if (generateFK != null && generateFK.equalsIgnoreCase("true"))
                        {
                            keymd.setForeignKeyMetaData(new ForeignKeyMetaData(null, null, null, null, null, null));
                        }

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

                        if (!StringUtils.isWhitespace(uniqueName))
                        {
                            UniqueMetaData keyUnimd = keymd.getUniqueMetaData();
                            if (keyUnimd == null)
                            {
                                keyUnimd = new UniqueMetaData(uniqueName, null, null);
                                keymd.setUniqueMetaData(keyUnimd);
                            }
                            else
                            {
                                keyUnimd.setName(uniqueName);
                            }
                        }
                        if (keyColumns != null && keyColumns.length > 0)
                        {
                            for (int j=0;j<keyColumns.length;j++)
                            {
                                keymd.addColumn(JDOAnnotationUtils.getColumnMetaDataForColumn(keymd, 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(keymd, embeddedMappings[0].ownerMember(),
                                embeddedMappings[0].nullIndicatorColumn(), 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(null, valueColumn, valueDeleteAction, valueUpdateAction, indexed,
                            unique, valueMappedBy);
                        if (!StringUtils.isWhitespace(fkName))
                        {
                            ForeignKeyMetaData valueFkmd = valuemd.getForeignKeyMetaData();
                            if (valueFkmd == null)
                            {
                                valueFkmd = new ForeignKeyMetaData(fkName, null, null, null, null, null);
                                valuemd.setForeignKeyMetaData(valueFkmd);
                            }
                            else
                            {
                                valueFkmd.setName(fkName);
                            }
                        }
                        else if (generateFK != null && generateFK.equalsIgnoreCase("true"))
                        {
                            valuemd.setForeignKeyMetaData(new ForeignKeyMetaData(null, null, null, null, null, null));
                        }

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

                        if (!StringUtils.isWhitespace(uniqueName))
                        {
View Full Code Here

     * @param columns Columns to apply the constraint across (optional)
     * @return The IndexMetaData
     */
    public static IndexMetaData getIndexMetaData(String name, String table, String unique, String[] fields, Column[] columns)
    {
        IndexMetaData idxmd = new IndexMetaData(name, table, unique);
        if (fields != null && fields.length > 0)
        {
            for (int j=0;j<fields.length;j++)
            {
                FieldMetaData fmd = new FieldMetaData(idxmd, fields[j]);
                idxmd.addMember(fmd);
            }
        }
        if (idxmd.getNumberOfMembers() == 0 && columns != null && columns.length > 0)
        {
            for (int j=0;j<columns.length;j++)
            {
                ColumnMetaData colmd = JDOAnnotationUtils.getColumnMetaDataForColumn(idxmd, columns[j]);
                idxmd.addColumn(colmd);
            }
        }

        return idxmd;
    }
View Full Code Here

                    ForeignKeyMetaData fkmd = (ForeignKeyMetaData)md;
                    fkmd.addMember(fmd);
                }
                else if (md instanceof IndexMetaData)
                {
                    IndexMetaData imd = (IndexMetaData)md;
                    imd.addMember(fmd);
                }
                else if (md instanceof UniqueMetaData)
                {
                    UniqueMetaData umd = (UniqueMetaData)md;
                    umd.addMember(fmd);
                }
                pushStack(fmd);
            }
            // New join
            else if (localName.equals("join"))
            {
                MetaData parent = getStack();
                JoinMetaData jnmd = new JoinMetaData(parent,
                                                   getAttr(attrs, "table"),
                                                   null, null,
                                                   getAttr(attrs, "column"),
                                                   getAttr(attrs, "outer"),
                                                   getAttr(attrs, "delete-action"),
                                                   getAttr(attrs, "indexed"),
                                                   getAttr(attrs, "unique"));
                if (parent instanceof AbstractMemberMetaData)
                {
                    AbstractMemberMetaData fmd = (AbstractMemberMetaData)parent;
                    fmd.setJoinMetaData(jnmd);
                }
                else if (parent instanceof AbstractClassMetaData)
                {
                    AbstractClassMetaData cmd = (AbstractClassMetaData)parent;
                    cmd.addJoin(jnmd);
                }
                else if (parent instanceof InheritanceMetaData)
                {
                    InheritanceMetaData imd = (InheritanceMetaData)parent;
                    imd.setJoinMetaData(jnmd);
                }
                pushStack(jnmd);
            }
            // New map container for this field
            else if (localName.equals("map"))
            {
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                MapMetaData map = new MapMetaData(fmd,
                                getAttr(attrs,"key-type"),
                                getAttr(attrs,"embedded-key"),
                                getAttr(attrs,"dependent-key"),
                                getAttr(attrs,"serialized-key"),
                                getAttr(attrs,"value-type"),
                                getAttr(attrs,"embedded-value"),
                                getAttr(attrs,"dependent-value"),
                                getAttr(attrs,"serialized-value"));
                fmd.setContainer(map);
                pushStack(map);
            }
            // New array container for this field
            else if (localName.equals("array"))
            {
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                ArrayMetaData amd = new ArrayMetaData(fmd,
                                getAttr(attrs, "element-type"),
                                getAttr(attrs, "embedded-element"),
                                getAttr(attrs, "dependent-element"),
                                getAttr(attrs, "serialized-element"));
                fmd.setContainer(amd);
                pushStack(amd);
            }
            // New collection container for this field
            else if (localName.equals("collection"))
            {
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                CollectionMetaData colmd = new CollectionMetaData(fmd,
                                getAttr(attrs,"element-type"),
                                getAttr(attrs,"embedded-element"),
                                getAttr(attrs,"dependent-element"),
                                getAttr(attrs,"serialized-element"));
                fmd.setContainer(colmd);
                pushStack(colmd);
            }
            // New column
            else if (localName.equals("column"))
            {
                MetaData md = getStack();
                ColumnMetaData clnmd = new ColumnMetaData(md,
                                getAttr(attrs,"name"),
                                getAttr(attrs,"target"),
                                getAttr(attrs,"target-field"),
                                getAttr(attrs,"jdbc-type"),
                                getAttr(attrs,"sql-type"),
                                getAttr(attrs,"length"),
                                getAttr(attrs,"scale"),
                                getAttr(attrs,"allows-null"),
                                getAttr(attrs,"default-value"),
                                getAttr(attrs,"insert-value"),
                                null, null, null);
                if (md instanceof AbstractMemberMetaData)
                {
                    AbstractMemberMetaData fmd = (AbstractMemberMetaData)md;
                    fmd.addColumn(clnmd);
                }
                else if (md instanceof AbstractElementMetaData)
                {
                    AbstractElementMetaData elemd = (AbstractElementMetaData)md;
                    elemd.addColumn(clnmd);
                }
                else if (md instanceof JoinMetaData)
                {
                    JoinMetaData jnmd = (JoinMetaData)md;
                    jnmd.addColumn(clnmd);
                }
                else if (md instanceof IdentityMetaData)
                {
                    IdentityMetaData idmd = (IdentityMetaData)md;
                    idmd.addColumn(clnmd);
                }
                else if (md instanceof ForeignKeyMetaData)
                {
                    ForeignKeyMetaData fkmd = (ForeignKeyMetaData)md;
                    fkmd.addColumn(clnmd);
                }
                else if (md instanceof IndexMetaData)
                {
                    IndexMetaData idxmd = (IndexMetaData)md;
                    idxmd.addColumn(clnmd);
                }
                else if (md instanceof UniqueMetaData)
                {
                    UniqueMetaData unimd = (UniqueMetaData)md;
                    unimd.addColumn(clnmd);
                }
                else if (md instanceof OrderMetaData)
                {
                    OrderMetaData ormd = (OrderMetaData)md;
                    ormd.addColumn(clnmd);
                }
                else if (md instanceof DiscriminatorMetaData)
                {
                    DiscriminatorMetaData dismd = (DiscriminatorMetaData)md;
                    dismd.setColumnMetaData(clnmd);
                }
                else if (md instanceof VersionMetaData)
                {
                    VersionMetaData vermd = (VersionMetaData)md;
                    vermd.addColumn(clnmd);
                }
                else if (md instanceof AbstractClassMetaData)
                {
                    AbstractClassMetaData cmd = (AbstractClassMetaData)md;
                    cmd.addUnmappedColumn(clnmd);
                }
                else if (md instanceof PrimaryKeyMetaData)
                {
                    PrimaryKeyMetaData pkmd = (PrimaryKeyMetaData)md;
                    pkmd.addColumn(clnmd);
                }
                pushStack(clnmd);
            }
            // New element
            else if (localName.equals("element"))
            {
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                ElementMetaData elemd = new ElementMetaData(fmd,
                                getAttr(attrs, "column"),
                                getAttr(attrs, "delete-action"),
                                getAttr(attrs, "update-action"),
                                getAttr(attrs, "indexed"),
                                getAttr(attrs, "unique"),
                                getAttr(attrs, "mapped-by"));
                fmd.setElementMetaData(elemd);
                pushStack(elemd);
            }
            // New key
            else if (localName.equals("key"))
            {
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                KeyMetaData keymd = new KeyMetaData(fmd,
                                getAttr(attrs, "column"),
                                getAttr(attrs, "delete-action"),
                                getAttr(attrs, "update-action"),
                                getAttr(attrs, "indexed"),
                                getAttr(attrs, "unique"),
                                getAttr(attrs, "mapped-by"));
                fmd.setKeyMetaData(keymd);
                pushStack(keymd);
            }
            // New value
            else if (localName.equals("value"))
            {
                AbstractMemberMetaData fmd = (AbstractMemberMetaData)getStack();
                ValueMetaData valuemd = new ValueMetaData(fmd,
                                getAttr(attrs, "column"),
                                getAttr(attrs, "delete-action"),
                                getAttr(attrs, "update-action"),
                                getAttr(attrs, "indexed"),
                                getAttr(attrs, "unique"),
                                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(md, getAttr(attrs,"post-load"), getAttr(attrs,"name"));
                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);
            }
            // New extension for this tag
            else if (localName.equals("extension"))
            {
                MetaData md = getStack();
                md.addExtension(getAttr(attrs,"vendor-name"), getAttr(attrs,"key"), getAttr(attrs,"value"));
            }
            // New version
            else if (localName.equals("version"))
            {
                AbstractClassMetaData cmd = (AbstractClassMetaData)getStack();
                VersionMetaData vermd = new VersionMetaData(
                                getAttr(attrs,"strategy"),
                                getAttr(attrs,"column"),
                                getAttr(attrs,"indexed"));
                cmd.setVersionMetaData(vermd);
                pushStack(vermd);
            }
            // New index
            else if (localName.equals("index"))
            {
                MetaData md = getStack();
                IndexMetaData idxmd = new IndexMetaData(
                                getAttr(attrs,"name"),
                                getAttr(attrs,"table"),
                                getAttr(attrs,"unique"));
                if (md instanceof AbstractClassMetaData)
                {
View Full Code Here

                // Add indexes for fields of this embedded PC object
                EmbeddedPCMapping embMapping = (EmbeddedPCMapping)fieldMapping;
                for (int i=0;i<embMapping.getNumberOfJavaTypeMappings();i++)
                {
                    JavaTypeMapping embFieldMapping = embMapping.getJavaTypeMapping(i);
                    IndexMetaData imd = embFieldMapping.getFieldMetaData().getIndexMetaData();
                    if (imd != null)
                    {
                        Index index = TableUtils.getIndexForField(this, imd, embFieldMapping);
                        if (index != null)
                        {
                            indices.add(index);
                        }
                    }
                }
            }
            else
            {
                // Add any required index for this field
                IndexMetaData imd = fmd.getIndexMetaData();
                if (imd != null)
                {
                    Index index = TableUtils.getIndexForField(this, imd, fieldMapping);
                    if (index != null)
                    {
                        indices.add(index);
                    }
                }
            }
        }

        // Check if any version column needs indexing
        if (versionMapping != null)
        {
            IndexMetaData idxmd = getVersionMetaData().getIndexMetaData();
            if (idxmd != null)
            {
                Index index = new Index(this,
                    idxmd.isUnique() != null ? idxmd.isUnique().booleanValue() : false,
                    idxmd.getValueForExtension("extended-setting"));
                if (idxmd.getName() != null)
                {
                    index.setName(idxmd.getName());
                }
                int countVersionFields = versionMapping.getNumberOfDatastoreFields();
                for (int i=0; i<countVersionFields; i++)
                {
                    index.addDatastoreField(versionMapping.getDataStoreMapping(i).getDatastoreField());
                }
                indices.add(index);
            }
        }

        // Check if any discriminator column needs indexing
        if (discriminatorMapping != null)
        {
            DiscriminatorMetaData dismd = getDiscriminatorMetaData();
            IndexMetaData idxmd = dismd.getIndexMetaData();
            if (idxmd != null)
            {
                Index index = new Index(this,
                    idxmd.isUnique() != null ? idxmd.isUnique().booleanValue() : false,
                    idxmd.getValueForExtension("extended-setting"));
                if (idxmd.getName() != null)
                {
                    index.setName(idxmd.getName());
                }
                int countDiscrimFields = discriminatorMapping.getNumberOfDatastoreFields();
                for (int i=0; i<countDiscrimFields; i++)
                {
                    index.addDatastoreField(discriminatorMapping.getDataStoreMapping(i).getDatastoreField());
View Full Code Here

            EmbeddedElementPCMapping embMapping = (EmbeddedElementPCMapping)elementMapping;
            for (int i=0;i<embMapping.getNumberOfJavaTypeMappings();i++)
            {
                // Add indexes for fields of this embedded PC object
                JavaTypeMapping embFieldMapping = embMapping.getJavaTypeMapping(i);
                IndexMetaData imd = embFieldMapping.getFieldMetaData().getIndexMetaData();
                if (imd != null)
                {
                    Index index = TableUtils.getIndexForField(this, imd, embFieldMapping);
                    if (index != null)
                    {
View Full Code Here

            // Add all indices required by fields of the embedded key
            EmbeddedKeyPCMapping embMapping = (EmbeddedKeyPCMapping)keyMapping;
            for (int i=0;i<embMapping.getNumberOfJavaTypeMappings();i++)
            {
                JavaTypeMapping embFieldMapping = embMapping.getJavaTypeMapping(i);
                IndexMetaData imd = embFieldMapping.getFieldMetaData().getIndexMetaData();
                if (imd != null)
                {
                    Index index = TableUtils.getIndexForField(this, imd, embFieldMapping);
                    if (index != null)
                    {
                        indices.add(index);
                    }
                }
            }
        }

        if (valueMapping instanceof EmbeddedValuePCMapping)
        {
            // Add all indices required by fields of the embedded value
            EmbeddedValuePCMapping embMapping = (EmbeddedValuePCMapping)valueMapping;
            for (int i=0;i<embMapping.getNumberOfJavaTypeMappings();i++)
            {
                JavaTypeMapping embFieldMapping = embMapping.getJavaTypeMapping(i);
                IndexMetaData imd = embFieldMapping.getFieldMetaData().getIndexMetaData();
                if (imd != null)
                {
                    Index index = TableUtils.getIndexForField(this, imd, embFieldMapping);
                    if (index != null)
                    {
View Full Code Here

TOP

Related Classes of org.jpox.metadata.IndexMetaData

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.