Package org.jpox.metadata

Examples of org.jpox.metadata.VersionMetaData


                    // Version field
                    ClassMetaData cmd = (ClassMetaData)getStack();
                    AbstractMemberMetaData mmd = newFieldObject(cmd, attrs);

                    // Tag this field as the version field
                    VersionMetaData vermd = new VersionMetaData(VersionStrategy.VERSION_NUMBER.toString(), mmd.getName());
                    cmd.setVersionMetaData(vermd);

                    pushStack(mmd);
                }
            }
View Full Code Here


        }

        if (version != null)
        {
            // Tag this field as the version field
            VersionMetaData vermd = new VersionMetaData(VersionStrategy.VERSION_NUMBER.toString(), fmd.getName());
            cmd.setVersionMetaData(vermd);
        }

        cmd.addMember(fmd);
View Full Code Here

        {
            InheritanceMetaData inhmd = null;
            DiscriminatorMetaData dismd = null;
            IdentityMetaData idmd = null;
            PrimaryKeyMetaData pkmd = null;
            VersionMetaData vermd = null;
            JoinMetaData[] joins = null;
            QueryMetaData[] queries = null;
            FetchPlanMetaData[] fetchPlans = null;
            FetchGroupMetaData[] fetchGroups = null;
            SequenceMetaData seqmd = null;
            String tableName = null;
            String catalogName = null;
            String schemaName = null;
            boolean embeddedOnly = false;
            ColumnMetaData[] unmappedColumns = null;
            HashSet<IndexMetaData> indices = null;
            HashSet<UniqueMetaData> uniqueKeys = null;
            HashSet<ForeignKeyMetaData> fks = null;
            HashSet<ExtensionMetaData> extensions = null;

            for (int i=0;i<annotations.length;i++)
            {
                if (isSupportedAnnotation(annotations[i].getName()))
                {
                    HashMap<String, Object> annotationValues = annotations[i].getNameValueMap();
                    String annName = annotations[i].getName();
                    if (annName.equals(JDOAnnotationUtils.PERSISTENCE_CAPABLE))
                    {
                        // PersistenceCapable class
                        String embeddedOnlyString = (String)annotationValues.get("embeddedOnly");
                        String requiresExtent = (String)annotationValues.get("requiresExtent");
                        String detachable = (String)annotationValues.get("detachable");
                        tableName = (String)annotationValues.get("table");
                        catalogName = (String)annotationValues.get("catalog");
                        schemaName = (String)annotationValues.get("schema");

                        javax.jdo.annotations.IdentityType idTypeVal = (javax.jdo.annotations.IdentityType)annotationValues.get("identityType");
                        String identityType = JDOAnnotationUtils.getIdentityTypeString(idTypeVal);

                        String idClassName = null;
                        Class idClass = (Class)annotationValues.get("objectIdClass");
                        if (idClass != null && idClass != void.class)
                        {
                            idClassName = idClass.getName();
                        }

                        if (cls.isInterface())
                        {
                            cmd = mgr.getMetaDataFactory().newInterfaceObject(pmd, ClassUtils.getClassNameForClass(cls),
                                identityType, idClassName, requiresExtent, detachable,
                                embeddedOnlyString, catalogName, schemaName, tableName, null);
                        }
                        else
                        {
                            cmd = mgr.getMetaDataFactory().newClassObject(pmd, ClassUtils.getClassNameForClass(cls),
                                identityType, idClassName, requiresExtent, detachable,
                                embeddedOnlyString, "persistence-capable", null, catalogName, schemaName, tableName, null);
                        }
                        JDOAnnotationUtils.addExtensionsToMetaData(cmd, (Extension[])annotationValues.get("extensions"));

                        // Members typically providing specification of overridden fields/properties
                        Persistent[] members = (Persistent[])annotationValues.get("members");
                        if (members != null)
                        {
                            // Add on the fields/properties direct to the metadata for the class/interface
                            for (int j=0;j<members.length;j++)
                            {
                                String memberName = members[j].name();
                                if (memberName.indexOf('.') > 0)
                                {
                                    memberName = memberName.substring(memberName.lastIndexOf('.')+1);
                                }
                                boolean isField = isMemberOfClassAField(cls, memberName);
                                AbstractMemberMetaData fmd = getFieldMetaDataForPersistent(cmd, members[j], isField);
                                cmd.addMember(fmd);
                            }
                        }
                    }
                    else if (annName.equals(JDOAnnotationUtils.PERSISTENCE_AWARE))
                    {
                        // PersistenceAware class
                        cmd = mgr.getMetaDataFactory().newClassObject(pmd, ClassUtils.getClassNameForClass(cls), null,
                            null, null, null, null, "persistence-aware",
                            null, null, null, null, null);
                    }
                    else if (annName.equals(JDOAnnotationUtils.EMBEDDED_ONLY))
                    {
                        embeddedOnly = true;
                    }
                    else if (annName.equals(JDOAnnotationUtils.VERSION))
                    {
                        VersionStrategy versionStrategy = (VersionStrategy)annotationValues.get("strategy");
                        String strategy = JDOAnnotationUtils.getVersionStrategyString(versionStrategy);
                        String indexed = (String)annotationValues.get("indexed");
                        String column = (String)annotationValues.get("column");
                        Column[] columns = (Column[])annotationValues.get("columns");
                        vermd = new VersionMetaData(strategy, column, indexed);
                        if (columns != null && columns.length > 0)
                        {
                            // Only use the first column
                            ColumnMetaData colmd = JDOAnnotationUtils.getColumnMetaDataForColumn(vermd, columns[0]);
                            vermd.addColumn(colmd);
                        }
                        JDOAnnotationUtils.addExtensionsToMetaData(vermd, (Extension[])annotationValues.get("extensions"));
                    }
                    else if (annName.equals(JDOAnnotationUtils.DATASTORE_IDENTITY))
                    {
                        String strategy = JDOAnnotationUtils.getIdentityStrategyString(
                            (IdGeneratorStrategy)annotationValues.get("strategy"));
                        String customStrategy = (String)annotationValues.get("customStrategy");
                        if (!StringUtils.isWhitespace(customStrategy))
                        {
                            // User has provided a JPOX extension strategy
                            strategy = customStrategy;
                        }
                        String sequence = (String)annotationValues.get("sequence");
                        String column = (String)annotationValues.get("column");
                        Column[] columns = (Column[])annotationValues.get("columns");
                        idmd = new IdentityMetaData(cmd, column, strategy, sequence);
                        if (columns != null && columns.length > 0)
                        {
                            // Only use the first column
                            ColumnMetaData colmd = JDOAnnotationUtils.getColumnMetaDataForColumn(idmd, columns[0]);
                            idmd.addColumn(colmd);
                        }
                        JDOAnnotationUtils.addExtensionsToMetaData(idmd, (Extension[])annotationValues.get("extensions"));
                    }
                    else if (annName.equals(JDOAnnotationUtils.PRIMARY_KEY))
                    {
                        String pkName = (String)annotationValues.get("name");
                        String pkColumn = (String)annotationValues.get("column");
                        Column[] columns = (Column[])annotationValues.get("columns");
                        pkmd = new PrimaryKeyMetaData(null, pkName, pkColumn);
                        if (columns != null && columns.length > 0)
                        {
                            for (int j=0;j<columns.length;j++)
                            {
                                pkmd.addColumn(JDOAnnotationUtils.getColumnMetaDataForColumn(pkmd, columns[j]));
                            }
                        }
                    }
                    else if (annName.equals(JDOAnnotationUtils.JOINS))
                    {
                        if (joins != null)
                        {
                            JPOXLogger.METADATA.warn(LOCALISER.msg("MetaData.Annotations.JoinSpecificationConflict",
                                cmd.getFullClassName()));
                        }
                        Join[] js = (Join[])annotationValues.get("value");
                        if (js != null && js.length > 0)
                        {
                            joins = new JoinMetaData[js.length];
                            for (int j=0;j<js.length;j++)
                            {
                                String deleteAction = JDOAnnotationUtils.getForeignKeyActionString(js[j].deleteAction());
                                joins[j] = new JoinMetaData(cmd, js[j].table(), null, null,
                                    js[j].column(), js[j].outer(), deleteAction, js[i].indexed(), js[i].unique());
                            }
                        }
                    }
                    else if (annName.equals(JDOAnnotationUtils.JOIN))
                    {
                        if (joins != null)
                        {
                            JPOXLogger.METADATA.warn(LOCALISER.msg("MetaData.Annotations.JoinSpecificationConflict",
                                cmd.getFullClassName()));
                        }
                        joins = new JoinMetaData[1];
                        joins[0] = new JoinMetaData(cmd, (String)annotationValues.get("table"), null, null,
                            (String)annotationValues.get("column"), (String)annotationValues.get("outer"),
                            ((ForeignKeyAction)annotationValues.get("deleteAction")).toString(),
                            (String)annotationValues.get("indexed"),
                            (String)annotationValues.get("unique"));
                        JDOAnnotationUtils.addExtensionsToMetaData(joins[0], (Extension[])annotationValues.get("extensions"));
                    }
                    else if (annName.equals(JDOAnnotationUtils.INHERITANCE))
                    {
                        String strategy = JDOAnnotationUtils.getInheritanceStrategyString(
                            (InheritanceStrategy)annotationValues.get("strategy"));
                        String customStrategy = (String)annotationValues.get("customStrategy");
                        if (!StringUtils.isWhitespace(customStrategy))
                        {
                            // User has provided a JPOX extension strategy
                            strategy = customStrategy;
                        }
                        inhmd = new InheritanceMetaData(cmd, strategy);
                    }
                    else if (annName.equals(JDOAnnotationUtils.DISCRIMINATOR))
                    {
                        DiscriminatorStrategy discriminatorStrategy = (DiscriminatorStrategy)annotationValues.get("strategy");
                        String strategy = JDOAnnotationUtils.getDiscriminatorStrategyString(discriminatorStrategy);
                        String column = (String)annotationValues.get("column");
                        String indexed = (String)annotationValues.get("indexed");
                        String value = (String)annotationValues.get("value");
                        Column[] columns = (Column[])annotationValues.get("columns");
                        dismd = new DiscriminatorMetaData(null, column, value, strategy, indexed);
                        if (columns != null && columns.length > 0)
                        {
                            // Only use the first column
                            ColumnMetaData colmd = JDOAnnotationUtils.getColumnMetaDataForColumn(dismd, columns[0]);
                            dismd.setColumnMetaData(colmd);
                        }
                    }
                    else if (annName.equals(JDOAnnotationUtils.QUERIES))
                    {
                        if (queries != null)
                        {
                            JPOXLogger.METADATA.warn(LOCALISER.msg("MetaData.Annotations.QuerySpecificationConflict",
                                cmd.getFullClassName()));
                        }
                        Query[] qs = (Query[])annotationValues.get("value");
                        queries = new QueryMetaData[qs.length];
                        for (int j=0;j<queries.length;j++)
                        {
                            String lang = JDOAnnotationUtils.getQueryLanguageName(qs[j].language());
                            String resultClassName = (qs[j].resultClass() != null && qs[j].resultClass() != void.class ?
                                    qs[j].resultClass().getName() : null);
                            queries[j] = new QueryMetaData(cmd, cls.getName(), qs[j].name(), lang,
                                "" + qs[j].unmodifiable(), resultClassName, null, qs[j].unique(), qs[j].fetchPlan());
                            queries[j].setQuery(qs[j].value());
                            JDOAnnotationUtils.addExtensionsToMetaData(queries[j], qs[j].extensions());
                        }
                    }
                    else if (annName.equals(JDOAnnotationUtils.QUERY))
                    {
                        if (queries != null)
                        {
                            JPOXLogger.METADATA.warn(LOCALISER.msg("MetaData.Annotations.QuerySpecificationConflict",
                                cmd.getFullClassName()));
                        }
                        queries = new QueryMetaData[1];
                        String unmodifiable = "" + annotationValues.get("unmodifiable");
                        Class resultClassValue = (Class)annotationValues.get("resultClass");
                        String resultClassName =
                            (resultClassValue != null && resultClassValue != void.class ? resultClassValue.getName() : null);
                        String lang = JDOAnnotationUtils.getQueryLanguageName((String)annotationValues.get("language"));
                        queries[0] = new QueryMetaData(cmd, cls.getName(), (String)annotationValues.get("name"),
                            lang.toString(), unmodifiable, resultClassName, null, (String)annotationValues.get("unique"),
                            (String)annotationValues.get("fetchPlan"));
                        queries[0].setQuery((String)annotationValues.get("value"));
                        JDOAnnotationUtils.addExtensionsToMetaData(queries[0], (Extension[])annotationValues.get("extensions"));
                    }
                    else if (annName.equals(JDOAnnotationUtils.FETCHPLANS))
                    {
                        if (fetchPlans != null)
                        {
                            JPOXLogger.METADATA.warn(LOCALISER.msg("MetaData.Annotations.FetchPlanSpecificationConflict",
                                cmd.getFullClassName()));
                        }
                        FetchPlan[] plans = (FetchPlan[])annotationValues.get("value");
                        fetchPlans = new FetchPlanMetaData[plans.length];
                        for (int j=0;j<plans.length;j++)
                        {
                            fetchPlans[j] = new FetchPlanMetaData(cmd, plans[j].name(), "" + plans[j].maxFetchDepth(),
                                "" + plans[j].fetchSize());
                            int numGroups = plans[j].fetchGroups().length;
                            for (int k=0;k<numGroups;k++)
                            {
                                FetchGroupMetaData fgmd = new FetchGroupMetaData(fetchPlans[j], null,
                                    plans[j].fetchGroups()[k]);
                                fetchPlans[j].addFetchGroup(fgmd);
                            }
                        }
                    }
                    else if (annName.equals(JDOAnnotationUtils.FETCHPLAN))
                    {
                        if (fetchPlans != null)
                        {
                            JPOXLogger.METADATA.warn(LOCALISER.msg("MetaData.Annotations.FetchPlanSpecificationConflict",
                                cmd.getFullClassName()));
                        }
                        fetchPlans = new FetchPlanMetaData[1];
                        int maxFetchDepth = ((Integer)annotationValues.get("max-fetch-depth")).intValue();
                        int fetchSize = ((Integer)annotationValues.get("fetch-size")).intValue();
                        fetchPlans[0] = new FetchPlanMetaData(cmd, (String)annotationValues.get("name"),
                            "" + maxFetchDepth, "" + fetchSize);
                    }
                    else if (annName.equals(JDOAnnotationUtils.FETCHGROUPS))
                    {
                        if (fetchGroups != null)
                        {
                            JPOXLogger.METADATA.warn(LOCALISER.msg("MetaData.Annotations.FetchGroupSpecificationConflict",
                                cmd.getFullClassName()));
                        }
                        FetchGroup[] groups = (FetchGroup[])annotationValues.get("value");
                        fetchGroups = new FetchGroupMetaData[groups.length];
                        for (int j=0;j<groups.length;j++)
                        {
                            fetchGroups[j] = new FetchGroupMetaData(cmd, groups[j].postLoad(), groups[j].name());
                            int numFields = groups[j].members().length;
                            for (int k=0;k<numFields;k++)
                            {
                                FieldMetaData fmd = mgr.getMetaDataFactory().newFieldObject(fetchGroups[j],
                                    groups[j].members()[k].name(),
                                    null, null, null, null, null, null, null, null, null, null, null,
                                    null, null, null, null, "" + groups[j].members()[k].recursionDepth(), null, null, null, null);
                                fetchGroups[j].addMember(fmd);
                            }
                        }
                    }
                    else if (annName.equals(JDOAnnotationUtils.FETCHGROUP))
                    {
                        if (fetchGroups != null)
                        {
                            JPOXLogger.METADATA.warn(LOCALISER.msg("MetaData.Annotations.FetchGroupSpecificationConflict",
                                cmd.getFullClassName()));
                        }
                        fetchGroups = new FetchGroupMetaData[1];
                        fetchGroups[0] = new FetchGroupMetaData(cmd, (String)annotationValues.get("postLoad"),
                            (String)annotationValues.get("name"));
                        Persistent[] fields = (Persistent[])annotationValues.get("members");
                        if (fields != null)
                        {
                            for (int j=0;j<fields.length;j++)
                            {
                                FieldMetaData fmd = mgr.getMetaDataFactory().newFieldObject(fetchGroups[0], fields[j].name(),
                                    null, null, null, null, null, null, null, null, null, null, null,
                                    null, null, null, null, "" + fields[j].recursionDepth(), null, null, null, null);
                                fetchGroups[0].addMember(fmd);
                            }
                        }
                    }
                    else if (annName.equals(JDOAnnotationUtils.SEQUENCE))
                    {
                        String seqName = (String)annotationValues.get("name");
                        String seqStrategy = JDOAnnotationUtils.getSequenceStrategyString(
                            (SequenceStrategy)annotationValues.get("strategy"));
                        String seqSeq = (String)annotationValues.get("datastoreSequence");
                        Class seqFactory = (Class)annotationValues.get("factoryClass");
                        String seqFactoryClassName = null;
                        if (seqFactory != null && seqFactory != void.class)
                        {
                            seqFactoryClassName = seqFactory.getName();
                        }
                        seqmd = new SequenceMetaData(null, seqName, seqSeq, seqFactoryClassName, seqStrategy, null, null);
                        JDOAnnotationUtils.addExtensionsToMetaData(seqmd, (Extension[])annotationValues.get("extensions"));
                    }
                    else if (annName.equals(JDOAnnotationUtils.INDICES))
                    {
                        // Multiple Indices for the class
                        Index[] values = (Index[])annotationValues.get("value");
                        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)
                {
View Full Code Here

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

            }
        }

        // Set the version of the object where possible
        int versionFieldNumber = -1;
        VersionMetaData vermd = table.getVersionMetaData();
        if (vermd != null && vermd.getFieldName() != null)
        {
            // Version stored in a normal field
            // TODO Should only do this if the version was just retrieved
            versionFieldNumber = acmd.getMetaDataForMember(vermd.getFieldName()).getAbsoluteFieldNumber();
            StateManager objSM = om.findStateManager(obj);
            Object verFieldValue = objSM.provideField(versionFieldNumber);
            if (verFieldValue != null)
            {
                objSM.setVersion(verFieldValue);
View Full Code Here

        while (currentTable != null)
        {
            // Add the required fields (and any discriminator) present in this table
            currentTable.provideMappingsForFields(consumer, fieldMetaData, true);
            currentTable.provideDiscriminatorMappings(consumer);
            VersionMetaData currentVermd = currentTable.getVersionMetaData();
            if (currentVermd != null)
            {
                if (currentVermd.getFieldName() == null)
                {
                    // Surrogate version is stored in this table, so fetch it
                    currentTable.provideVersionMappings(consumer);
                    fetchingSurrogateVersion = true;
                    versionMetaData = currentVermd;
                }
                else
                {
                    // Version field
                    versionFieldName = currentVermd.getFieldName();
                    versionMetaData = currentVermd;
                    AbstractMemberMetaData[] mmds = new AbstractMemberMetaData[1];
                    mmds[0] = cmd.getMetaDataForMember(currentVermd.getFieldName());
                    currentTable.provideMappingsForFields(consumer, mmds, true);
                }
            }

            currentTable = currentTable.getSuperDatastoreClass();
View Full Code Here

            JPOXLogger.PERSISTENCE.debug(LOCALISER.msg("052207", StringUtils.toJVMIDString(sm.getObject()), table));
        }

        try
        {
            VersionMetaData vermd = table.getVersionMetaData();
            if (vermd != null && vermd.getFieldName() != null)
            {
                // Version field - Update the version in the object
                AbstractMemberMetaData verfmd =
                    ((AbstractClassMetaData)vermd.getParent()).getMetaDataForMember(vermd.getFieldName());
                Object currentVersion = sm.getObjectManager().getApiAdapter().getVersion(sm);
                if (currentVersion instanceof Integer)
                {
                    // Cater for Integer based versions TODO Generalise this
                    currentVersion = new Long(((Integer)currentVersion).longValue());
                }
                Object nextOptimisticVersion =
                    VersionMapping.getNextVersion(table.getVersionMetaData(), currentVersion);
                if (verfmd.getType() == Integer.class || verfmd.getType() == int.class)
                {
                    // Cater for Integer based versions TODO Generalise this
                    nextOptimisticVersion = new Integer(((Long)nextOptimisticVersion).intValue());
                }
                sm.replaceField(verfmd.getAbsoluteFieldNumber(), nextOptimisticVersion, false);
            }

            // Set the state to "inserting" (may already be at this state if multiple inheritance level INSERT)
            sm.changeActivityState(ActivityState.INSERTING, table);

            ObjectManager om = sm.getObjectManager();
            RDBMSManager storeMgr = (RDBMSManager)om.getStoreManager();
            SQLController sqlControl = storeMgr.getSQLController();
            ManagedConnection mconn = storeMgr.getConnection(om);
            try
            {
                PreparedStatement ps = sqlControl.getStatementForUpdate(mconn, insertStmt, batch);

                try
                {
                    // Provide the primary key field(s)
                    if (table.getIdentityType() == IdentityType.DATASTORE)
                    {
                        if (!table.isObjectIDDatastoreAttributed() || !table.isBaseDatastoreClass())
                        {
                            int[] paramNumber = {IDPARAMNUMBER};
                            table.getDataStoreObjectIdMapping().setObject(om, ps, paramNumber, sm.getInternalObjectId());
                        }
                    }
                    else if (table.getIdentityType() == IdentityType.APPLICATION)
                    {
                        sm.provideFields(pkFieldNumbers, new ParameterSetter(sm, ps, statementExpressionIndex, true));
                    }

                    // Provide all non-key fields needed for the insert.
                    // This provides "persistence-by-reachability" for these fields
                    int numberOfFieldsToProvide = 0;
                    for (int i = 0; i < insertFieldNumbers.length; i++)
                    {
                        if (insertFieldNumbers[i] < sm.getHighestFieldNumber())
                        {
                            numberOfFieldsToProvide++;
                        }
                    }
                    int j = 0;
                    int[] classFieldNumbers = new int[numberOfFieldsToProvide];
                    for (int i = 0; i < insertFieldNumbers.length; i++)
                    {
                        if (insertFieldNumbers[i] < sm.getHighestFieldNumber())
                        {
                            classFieldNumbers[j++] = insertFieldNumbers[i];
                        }
                        else
                        {
                            // Any fields out of range for the class, we default or null.
                            // This happens when we insert a base class object
                            // and the sub-class is persisted to the same table ("superclass-table").
                            StatementExpressionIndex stmtExprIndex = statementExpressionIndex[insertFieldNumbers[i]];
                            stmtExprIndex.getMapping().setDefault(om, ps, stmtExprIndex.getParameterIndex());
                        }
                    }
                    sm.provideFields(classFieldNumbers, new ParameterSetter(sm, ps, statementExpressionIndex, true));

                    if (table.getVersionMapping(false) != null)
                    {
                        // Surrogate version - set the new version for the object
                        Object currentVersion = sm.getObjectManager().getApiAdapter().getVersion(sm);
                        Object nextOptimisticVersion = VersionMapping.getNextVersion(table.getVersionMetaData(),
                            currentVersion);
                        table.getVersionMapping(false).setObject(om, ps, versionStatementExpressionIndex.getParameterIndex(), nextOptimisticVersion);
                        sm.setTransactionalVersion(nextOptimisticVersion);
                    }
                    else if (vermd != null && vermd.getFieldName() != null)
                    {
                        // Version field - set the new version for the object
                        Object currentVersion = sm.getObjectManager().getApiAdapter().getVersion(sm);
                        Object nextOptimisticVersion = VersionMapping.getNextVersion(table.getVersionMetaData(),
                            currentVersion);
View Full Code Here

TOP

Related Classes of org.jpox.metadata.VersionMetaData

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.