Examples of ClassMetaData


Examples of org.datanucleus.metadata.ClassMetaData

            else if (localName.equals("discriminator-value"))
            {
                if (md instanceof ClassMetaData)
                {
                    // Add the discriminator value
                    ClassMetaData cmd = (ClassMetaData)md;
                    InheritanceMetaData inhmd = cmd.getInheritanceMetaData();
                    if (inhmd == null)
                    {
                        // Add an empty inheritance specification
                        inhmd = new InheritanceMetaData();
                        cmd.setInheritanceMetaData(inhmd);
                    }
                    String discrimValue = currentString;
                    DiscriminatorMetaData dismd = inhmd.getDiscriminatorMetaData();
                    if (dismd == null)
                    {
View Full Code Here

Examples of org.datanucleus.metadata.ClassMetaData

     */
    protected AbstractClassMetaData processClassAnnotations(PackageMetaData pmd, Class cls,
            AnnotationObject[] annotations, ClassLoaderResolver clr)
    {
        this.clr = clr;
        ClassMetaData cmd = null;

        if (annotations != null && annotations.length > 0)
        {
            if (isClassPersistenceCapable(cls))
            {
                cmd = pmd.newClassMetadata(ClassUtils.getClassNameForClass(cls));
                cmd.setPersistenceModifier(ClassPersistenceModifier.PERSISTENCE_CAPABLE);
            }
            else if (isClassPersistenceAware(cls))
            {
                cmd = pmd.newClassMetadata(ClassUtils.getClassNameForClass(cls));
                cmd.setPersistenceModifier(ClassPersistenceModifier.PERSISTENCE_AWARE);
            }

            if (cmd != null)
            {
                IdentityType identityType = IdentityType.APPLICATION;
                String identityColumn = null;
                String identityStrategy = null;
                String identityGenerator = null;

                String cacheable = "true";
                String requiresExtent = "true";
                String detachable = "true"; // In JPA default is true.
                String embeddedOnly = "false";
                String idClassName = null;
                String catalog = null;
                String schema = null;
                String table = null;
                String inheritanceStrategyForTree = null;
                String inheritanceStrategy = null;
                String discriminatorColumnName = null;
                String discriminatorColumnType = null;
                Integer discriminatorColumnLength = null;
                String discriminatorColumnDdl = null;
                String discriminatorValue = null;
                String entityName = null;
                Class[] entityListeners = null;
                boolean excludeSuperClassListeners = false;
                boolean excludeDefaultListeners = false;
                ColumnMetaData[] pkColumnMetaData = null;
                HashSet<UniqueMetaData> uniques = null;
                HashSet<AbstractMemberMetaData> overriddenFields = null;
                HashSet<QueryMetaData> namedQueries = null;
                List<QueryResultMetaData> resultMappings = null;
                FetchPlanMetaData[] fetchPlans = null;
                FetchGroupMetaData[] fetchGroups = null;
                HashSet<ExtensionMetaData> extensions = null;

                String jpaLevel = mgr.getNucleusContext().getPersistenceConfiguration().getStringProperty("datanucleus.jpa.level");
                for (int i=0;i<annotations.length;i++)
                {
                    HashMap<String, Object> annotationValues = annotations[i].getNameValueMap();
                    String annName = annotations[i].getName();
                    if (annName.equals(JPAAnnotationUtils.ENTITY))
                    {
                        entityName = (String) annotationValues.get("name");
                        if (entityName == null || entityName.length() == 0)
                        {
                            entityName = ClassUtils.getClassNameForClass(cls);
                        }
                    }
                    else if (annName.equals(JPAAnnotationUtils.MAPPED_SUPERCLASS))
                    {
                        if (isClassPersistenceCapable(cls))
                        {
                            inheritanceStrategy = InheritanceStrategy.SUBCLASS_TABLE.toString();
                        }
                    }
                    else if (annName.equals(JPAAnnotationUtils.DATASTORE_IDENTITY) && jpaLevel.equalsIgnoreCase("DataNucleus"))
                    {
                        // extension to allow datastore-identity
                        identityType = IdentityType.DATASTORE;
                        identityColumn = (String)annotationValues.get("column");
                        GenerationType type = (GenerationType) annotationValues.get("generationType");
                        identityStrategy = JPAAnnotationUtils.getIdentityStrategyString(type);
                        identityGenerator = (String) annotationValues.get("generator");
                    }
                    else if (annName.equals(JPAAnnotationUtils.TABLE))
                    {
                        table = (String)annotationValues.get("name");
                        catalog = (String)annotationValues.get("catalog");
                        schema = (String)annotationValues.get("schema");
                        UniqueConstraint[] constrs = (UniqueConstraint[])annotationValues.get("uniqueConstraints");
                        if (constrs != null && constrs.length > 0)
                        {
                            for (int j=0;j<constrs.length;j++)
                            {
                                UniqueMetaData unimd = new UniqueMetaData();
                                unimd.setTable((String)annotationValues.get("name"));
                                for (int k=0;k<constrs[j].columnNames().length;k++)
                                {
                                    ColumnMetaData colmd = new ColumnMetaData();
                                    colmd.setName(constrs[j].columnNames()[k]);
                                    unimd.addColumn(colmd);
                                }
                                if (uniques == null)
                                {
                                    uniques = new HashSet<UniqueMetaData>();
                                }
                                uniques.add(unimd);
                            }
                        }
                    }
                    else if (annName.equals(JPAAnnotationUtils.ID_CLASS))
                    {
                        idClassName = ((Class)annotationValues.get("value")).getName();
                    }
                    else if (annName.equals(JPAAnnotationUtils.INHERITANCE))
                    {
                        // Only valid in the root class
                        InheritanceType inhType = (InheritanceType)annotationValues.get("strategy");
                        inheritanceStrategyForTree = inhType.toString();
                        if (inhType == InheritanceType.JOINED)
                        {
                            inheritanceStrategy = InheritanceStrategy.NEW_TABLE.toString();
                        }
                        else if (inhType == InheritanceType.TABLE_PER_CLASS)
                        {
                            inheritanceStrategy = InheritanceStrategy.COMPLETE_TABLE.toString();
                        }
                        else if (inhType == InheritanceType.SINGLE_TABLE)
                        {
                            // Translated to root class as "new-table" and children as "superclass-table"
                            // and @Inheritance should only be specified on root class so defaults to internal default
                        }
                    }
                    else if (annName.equals(JPAAnnotationUtils.DISCRIMINATOR_COLUMN))
                    {
                        discriminatorColumnName = (String)annotationValues.get("name");
                        DiscriminatorType type = (DiscriminatorType)annotationValues.get("discriminatorType");
                        if (type == DiscriminatorType.CHAR)
                        {
                            discriminatorColumnType = "CHAR";
                        }
                        else if (type == DiscriminatorType.INTEGER)
                        {
                            discriminatorColumnType = "INTEGER";
                        }
                        else if (type == DiscriminatorType.STRING)
                        {
                            discriminatorColumnType = "VARCHAR";
                        }
                        discriminatorColumnLength = (Integer)annotationValues.get("length");
                        String tmp = (String)annotationValues.get("columnDefinition");
                        if (!StringUtils.isWhitespace(tmp))
                        {
                            discriminatorColumnDdl = tmp;
                        }
                    }
                    else if (annName.equals(JPAAnnotationUtils.DISCRIMINATOR_VALUE))
                    {
                        discriminatorValue = (String)annotationValues.get("value");
                    }
                    else if (annName.equals(JPAAnnotationUtils.EMBEDDABLE))
                    {
                        embeddedOnly = "true";
                        identityType = IdentityType.NONDURABLE;
                    }
                    else if (annName.equals(JPAAnnotationUtils.CACHEABLE))
                    {
                        Boolean cacheableVal = (Boolean)annotationValues.get("value");
                        if (cacheableVal == Boolean.FALSE)
                        {
                            cacheable = "false";
                        }
                    }
                    else if (annName.equals(JPAAnnotationUtils.ENTITY_LISTENERS))
                    {
                        entityListeners = (Class[])annotationValues.get("value");
                    }
                    else if (annName.equals(JPAAnnotationUtils.EXCLUDE_SUPERCLASS_LISTENERS))
                    {
                        excludeSuperClassListeners = true;
                    }
                    else if (annName.equals(JPAAnnotationUtils.EXCLUDE_DEFAULT_LISTENERS))
                    {
                        excludeDefaultListeners = true;
                    }
                    else if (annName.equals(JPAAnnotationUtils.SEQUENCE_GENERATOR))
                    {
                        processSequenceGeneratorAnnotation(pmd, annotationValues);
                    }
                    else if (annName.equals(JPAAnnotationUtils.TABLE_GENERATOR))
                    {
                        processTableGeneratorAnnotation(pmd, annotationValues);
                    }
                    else if (annName.equals(JPAAnnotationUtils.PRIMARY_KEY_JOIN_COLUMN))
                    {
                        // Override the PK column name when we have a persistent superclass
                        pkColumnMetaData = new ColumnMetaData[1];
                        pkColumnMetaData[0] = new ColumnMetaData();
                        pkColumnMetaData[0].setName((String)annotationValues.get("name"));
                        pkColumnMetaData[0].setTarget((String)annotationValues.get("referencedColumnName"));
                    }
                    else if (annName.equals(JPAAnnotationUtils.PRIMARY_KEY_JOIN_COLUMNS))
                    {
                        // Override the PK column names when we have a persistent superclass
                        PrimaryKeyJoinColumn[] values = (PrimaryKeyJoinColumn[])annotationValues.get("value");
                        pkColumnMetaData = new ColumnMetaData[values.length];
                        for (int j=0;j<values.length;j++)
                        {
                            pkColumnMetaData[j] = new ColumnMetaData();
                            pkColumnMetaData[j].setName(values[j].name());
                            pkColumnMetaData[j].setTarget(values[j].referencedColumnName());
                            if (!StringUtils.isWhitespace(values[j].columnDefinition()))
                            {
                                pkColumnMetaData[j].setColumnDdl(values[j].columnDefinition());
                            }
                        }
                    }
                    else if (annName.equals(JPAAnnotationUtils.ATTRIBUTE_OVERRIDES))
                    {
                        AttributeOverride[] overrides = (AttributeOverride[])annotationValues.get("value");
                        if (overrides != null)
                        {
                            if (overriddenFields == null)
                            {
                                overriddenFields = new HashSet<AbstractMemberMetaData>();
                            }

                            for (int j=0;j<overrides.length;j++)
                            {
                                AbstractMemberMetaData fmd = new FieldMetaData(cmd,
                                    "#UNKNOWN." + overrides[j].name());
                                fmd.setPersistenceModifier(FieldPersistenceModifier.PERSISTENT.toString());
                                Column col = overrides[j].column();
                                // TODO Make inferrals about jdbctype, length etc if the field is 1 char etc
                                ColumnMetaData colmd = new ColumnMetaData();
                                colmd.setName(col.name());
                                colmd.setLength(col.length());
                                colmd.setScale(col.scale());
                                colmd.setAllowsNull(col.nullable());
                                colmd.setInsertable(col.insertable());
                                colmd.setUpdateable(col.updatable());
                                colmd.setUnique(col.unique());
                                fmd.addColumn(colmd);
                                overriddenFields.add(fmd);
                            }
                        }
                    }
                    else if (annName.equals(JPAAnnotationUtils.ATTRIBUTE_OVERRIDE))
                    {
                        if (overriddenFields == null)
                        {
                            overriddenFields = new HashSet<AbstractMemberMetaData>();
                        }

                        AbstractMemberMetaData fmd = new FieldMetaData(cmd,
                            "#UNKNOWN." + (String)annotationValues.get("name"));
                        Column col = (Column)annotationValues.get("column");
                        // TODO Make inferrals about jdbctype, length etc if the field is 1 char etc
                        ColumnMetaData colmd = new ColumnMetaData();
                        colmd.setName(col.name());
                        colmd.setLength(col.length());
                        colmd.setScale(col.scale());
                        colmd.setAllowsNull(col.nullable());
                        colmd.setInsertable(col.insertable());
                        colmd.setUpdateable(col.updatable());
                        colmd.setUnique(col.unique());
                        fmd.addColumn(colmd);
                        overriddenFields.add(fmd);
                    }
                    else if (annName.equals(JPAAnnotationUtils.ASSOCIATION_OVERRIDES))
                    {
                        AssociationOverride[] overrides = (AssociationOverride[])annotationValues.get("value");
                        if (overrides != null)
                        {
                            if (overriddenFields == null)
                            {
                                overriddenFields = new HashSet<AbstractMemberMetaData>();
                            }

                            for (int j=0;j<overrides.length;j++)
                            {
                                AbstractMemberMetaData fmd = new FieldMetaData(cmd,
                                    "#UNKNOWN." + overrides[j].name());
                                JoinColumn[] cols = overrides[j].joinColumns();
                                for (int k=0;k<cols.length;k++)
                                {
                                    ColumnMetaData colmd = new ColumnMetaData();
                                    colmd.setName(cols[k].name());
                                    colmd.setTarget(cols[k].referencedColumnName());
                                    colmd.setAllowsNull(cols[k].nullable());
                                    colmd.setInsertable(cols[k].insertable());
                                    colmd.setUpdateable(cols[k].updatable());
                                    colmd.setUnique(cols[k].unique());
                                    fmd.addColumn(colmd);
                                }
                                overriddenFields.add(fmd);
                            }
                        }
                    }
                    else if (annName.equals(JPAAnnotationUtils.ASSOCIATION_OVERRIDE))
                    {
                        if (overriddenFields == null)
                        {
                            overriddenFields = new HashSet<AbstractMemberMetaData>();
                        }

                        AbstractMemberMetaData fmd = new FieldMetaData(cmd,
                            "#UNKNOWN." + (String)annotationValues.get("name"));
                        JoinColumn[] cols = (JoinColumn[])annotationValues.get("joinColumns");
                        for (int k=0;k<cols.length;k++)
                        {
                            ColumnMetaData colmd = new ColumnMetaData();
                            colmd.setName(cols[k].name());
                            colmd.setTarget(cols[k].referencedColumnName());
                            colmd.setAllowsNull(cols[k].nullable());
                            colmd.setInsertable(cols[k].insertable());
                            colmd.setUpdateable(cols[k].updatable());
                            colmd.setUnique(cols[k].unique());
                            fmd.addColumn(colmd);
                        }
                        overriddenFields.add(fmd);
                    }
                    else if (annName.equals(JPAAnnotationUtils.NAMED_QUERIES))
                    {
                        NamedQuery[] queries = (NamedQuery[])annotationValues.get("value");
                        if (namedQueries == null)
                        {
                            namedQueries = new HashSet<QueryMetaData>();
                        }
                        for (int j=0;j<queries.length;j++)
                        {
                            QueryMetaData qmd = new QueryMetaData(queries[j].name());
                            qmd.setLanguage(QueryLanguage.JPQL.toString());
                            qmd.setUnmodifiable(true);
                            qmd.setQuery(queries[j].query());
                            namedQueries.add(qmd);
                        }
                    }
                    else if (annName.equals(JPAAnnotationUtils.NAMED_QUERY))
                    {
                        if (namedQueries == null)
                        {
                            namedQueries = new HashSet<QueryMetaData>();
                        }
                        QueryMetaData qmd = new QueryMetaData((String)annotationValues.get("name"));
                        qmd.setLanguage(QueryLanguage.JPQL.toString());
                        qmd.setUnmodifiable(true);
                        qmd.setQuery((String)annotationValues.get("query"));
                        namedQueries.add(qmd);
                    }
                    else if (annName.equals(JPAAnnotationUtils.NAMED_NATIVE_QUERIES))
                    {
                        NamedNativeQuery[] queries = (NamedNativeQuery[])annotationValues.get("value");
                        if (namedQueries == null)
                        {
                            namedQueries = new HashSet<QueryMetaData>();
                        }
                        for (int j=0;j<queries.length;j++)
                        {
                            String resultClassName = null;
                            if (queries[j].resultClass() != null && queries[j].resultClass() != void.class)
                            {
                                resultClassName = queries[j].resultClass().getName();
                            }
                            String resultMappingName = null;
                            if (queries[j].resultSetMapping() != null)
                            {
                                resultMappingName = queries[j].resultSetMapping();
                            }
                            QueryMetaData qmd = new QueryMetaData(queries[j].name());
                            qmd.setLanguage(QueryLanguage.SQL.toString());
                            qmd.setUnmodifiable(true);
                            qmd.setResultClass(resultClassName);
                            qmd.setResultMetaDataName(resultMappingName);
                            qmd.setQuery(queries[j].query());
                            namedQueries.add(qmd);
                        }
                    }
                    else if (annName.equals(JPAAnnotationUtils.NAMED_NATIVE_QUERY))
                    {
                        if (namedQueries == null)
                        {
                            namedQueries = new HashSet<QueryMetaData>();
                        }

                        Class resultClass = (Class)annotationValues.get("resultClass");
                        String resultClassName = null;
                        if (resultClass != null && resultClass != void.class)
                        {
                            resultClassName = resultClass.getName();
                        }
                        String resultMappingName = (String)annotationValues.get("resultSetMapping");
                        if (StringUtils.isWhitespace(resultMappingName))
                        {
                            resultMappingName = null;
                        }
                        QueryMetaData qmd = new QueryMetaData((String)annotationValues.get("name"));
                        qmd.setLanguage(QueryLanguage.SQL.toString());
                        qmd.setUnmodifiable(true);
                        qmd.setResultClass(resultClassName);
                        qmd.setResultMetaDataName(resultMappingName);
                        qmd.setQuery((String)annotationValues.get("query"));
                        namedQueries.add(qmd);
                    }
                    else if (annName.equals(JPAAnnotationUtils.SQL_RESULTSET_MAPPINGS))
                    {
                        SqlResultSetMapping[] mappings = (SqlResultSetMapping[])annotationValues.get("value");
                        if (resultMappings == null)
                        {
                            resultMappings = new ArrayList<QueryResultMetaData>();
                        }

                        for (int j=0;j<mappings.length;j++)
                        {
                            QueryResultMetaData qrmd = new QueryResultMetaData(mappings[j].name());
                            EntityResult[] entityResults = (EntityResult[])mappings[j].entities();
                            if (entityResults != null)
                            {
                                for (int k=0;k<entityResults.length;k++)
                                {
                                    String entityClassName = entityResults[k].entityClass().getName();
                                    qrmd.addPersistentTypeMapping(entityClassName, null,
                                        entityResults[k].discriminatorColumn());
                                    FieldResult[] fields = entityResults[k].fields();
                                    if (fields != null)
                                    {
                                        for (int l=0;l<fields.length;l++)
                                        {
                                            qrmd.addMappingForPersistentTypeMapping(entityClassName, fields[l].name(), fields[l].column());
                                        }
                                    }
                                }
                            }
                            ColumnResult[] colResults = (ColumnResult[])mappings[j].columns();
                            if (colResults != null)
                            {
                                for (int k=0;k<colResults.length;k++)
                                {
                                    qrmd.addScalarColumn(colResults[k].name());
                                }
                            }

                            resultMappings.add(qrmd);
                        }
                    }
                    else if (annName.equals(JPAAnnotationUtils.SQL_RESULTSET_MAPPING))
                    {
                        if (resultMappings == null)
                        {
                            resultMappings = new ArrayList<QueryResultMetaData>();
                        }

                        QueryResultMetaData qrmd = new QueryResultMetaData((String)annotationValues.get("name"));
                        EntityResult[] entityResults = (EntityResult[])annotationValues.get("entities");
                        if (entityResults != null)
                        {
                            for (int j=0;j<entityResults.length;j++)
                            {
                                String entityClassName = entityResults[j].entityClass().getName();
                                qrmd.addPersistentTypeMapping(entityClassName, null,
                                    entityResults[j].discriminatorColumn());
                                FieldResult[] fields = entityResults[j].fields();
                                if (fields != null)
                                {
                                    for (int k=0;k<fields.length;k++)
                                    {
                                        qrmd.addMappingForPersistentTypeMapping(entityClassName, fields[k].name(), fields[k].column());
                                    }
                                }
                            }
                        }
                        ColumnResult[] colResults = (ColumnResult[])annotationValues.get("columns");
                        if (colResults != null)
                        {
                            for (int j=0;j<colResults.length;j++)
                            {
                                qrmd.addScalarColumn(colResults[j].name());
                            }
                        }
                        resultMappings.add(qrmd);
                    }
                    else if (annName.equals(JPAAnnotationUtils.SECONDARY_TABLES))
                    {
                        // processed below in newJoinMetaData
                    }
                    else if (annName.equals(JPAAnnotationUtils.SECONDARY_TABLE))
                    {
                        // processed below in newJoinMetaData
                    }
                    else if (annName.equals(JPAAnnotationUtils.FETCHPLANS))
                    {
                        if (fetchPlans != null)
                        {
                            NucleusLogger.METADATA.warn(LOCALISER.msg("044207", 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(plans[j].name());
                            fetchPlans[j].setMaxFetchDepth(plans[j].maxFetchDepth());
                            fetchPlans[j].setFetchSize(plans[j].fetchSize());
                            int numGroups = plans[j].fetchGroups().length;
                            for (int k=0;k<numGroups;k++)
                            {
                                FetchGroupMetaData fgmd = new FetchGroupMetaData(plans[j].fetchGroups()[k]);
                                fetchPlans[j].addFetchGroup(fgmd);
                            }
                        }
                    }
                    else if (annName.equals(JPAAnnotationUtils.FETCHPLAN))
                    {
                        if (fetchPlans != null)
                        {
                            NucleusLogger.METADATA.warn(LOCALISER.msg("044207", cmd.getFullClassName()));
                        }
                        fetchPlans = new FetchPlanMetaData[1];
                        int maxFetchDepth = ((Integer)annotationValues.get("maxFetchDepth")).intValue();
                        int fetchSize = ((Integer)annotationValues.get("fetchSize")).intValue();
                        fetchPlans[0] = new FetchPlanMetaData((String)annotationValues.get("name"));
                        fetchPlans[0].setMaxFetchDepth(maxFetchDepth);
                        fetchPlans[0].setFetchSize(fetchSize);
                    }
                    else if (annName.equals(JPAAnnotationUtils.FETCHGROUPS))
                    {
                        if (fetchGroups != null)
                        {
                            NucleusLogger.METADATA.warn(LOCALISER.msg("044208", 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(groups[j].name());
                            fetchGroups[j].setPostLoad(groups[j].postLoad());
                            int numFields = groups[j].members().length;
                            for (int k=0;k<numFields;k++)
                            {
                                FieldMetaData fmd = new FieldMetaData(fetchGroups[j],
                                    groups[j].members()[k].value());
                                fmd.setRecursionDepth(groups[j].members()[k].recursionDepth());
                                fetchGroups[j].addMember(fmd);
                            }
                            int numGroups = groups[j].fetchGroups().length;
                            for (int k=0;k<numGroups;k++)
                            {
                                FetchGroupMetaData subgrp = new FetchGroupMetaData(groups[j].fetchGroups()[k]);
                                fetchGroups[j].addFetchGroup(subgrp);
                            }
                        }
                    }
                    else if (annName.equals(JPAAnnotationUtils.FETCHGROUP))
                    {
                        if (fetchGroups != null)
                        {
                            NucleusLogger.METADATA.warn(LOCALISER.msg("044208", cmd.getFullClassName()));
                        }
                        fetchGroups = new FetchGroupMetaData[1];
                        fetchGroups[0] = new FetchGroupMetaData((String)annotationValues.get("name"));
                        fetchGroups[0].setPostLoad((String)annotationValues.get("postLoad"));
                        FetchMember[] fields = (FetchMember[])annotationValues.get("members");
                        if (fields != null)
                        {
                            for (int j=0;j<fields.length;j++)
                            {
                                FieldMetaData fmd = new FieldMetaData(fetchGroups[0],
                                    fields[j].value());
                                fmd.setRecursionDepth(fields[j].recursionDepth());
                                fetchGroups[0].addMember(fmd);
                            }
                        }
                    }
                    else if (annName.equals(JPAAnnotationUtils.EXTENSION))
                    {
                        // extension
                        ExtensionMetaData extmd = new ExtensionMetaData((String)annotationValues.get("vendorName"),
                            (String)annotationValues.get("key"), (String)annotationValues.get("value"));
                        if (extensions == null)
                        {
                            extensions = new HashSet<ExtensionMetaData>(1);
                        }
                        extensions.add(extmd);
                    }
                    else if (annName.equals(JPAAnnotationUtils.EXTENSIONS))
                    {
                        // extension
                        Extension[] values = (Extension[])annotationValues.get("value");
                        if (values != null && values.length > 0)
                        {
                            if (extensions == null)
                            {
                                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
                    {
                        NucleusLogger.METADATA.error(LOCALISER.msg("044203",
                            cls.getName(), annotations[i].getName()));
                    }
                }

                if (entityName == null || entityName.length() == 0)
                {
                    entityName = ClassUtils.getClassNameForClass(cls);
                }

                NucleusLogger.METADATA.info(LOCALISER.msg("044200", cls.getName(), "JPA"));

                cmd.setTable(table);
                cmd.setCatalog(catalog);
                cmd.setSchema(schema);
                cmd.setEntityName(entityName);
                cmd.setDetachable(detachable);
                cmd.setRequiresExtent(requiresExtent);
                cmd.setObjectIdClass(idClassName);
                cmd.setEmbeddedOnly(embeddedOnly);
                cmd.setCacheable(cacheable);
                cmd.setIdentityType(identityType);
                if (isClassPersistenceCapable(cls.getSuperclass()))
                {
                    cmd.setPersistenceCapableSuperclass(cls.getSuperclass().getName());
                }
                if (excludeSuperClassListeners)
                {
                    cmd.excludeSuperClassListeners();
                }
                if (excludeDefaultListeners)
                {
                    cmd.excludeDefaultListeners();
                }
                if (entityListeners != null)
                {
                    for (int i=0; i<entityListeners.length; i++)
                    {
                        // Any EventListener will not have their callback methods registered at this point
                        EventListenerMetaData elmd = new EventListenerMetaData(entityListeners[i].getName());
                        cmd.addListener(elmd);
                    }
                }

                // Inheritance
                InheritanceMetaData inhmd = null;
                if (inheritanceStrategy != null)
                {
                    // Strategy specified so create inheritance data
                    inhmd = cmd.newInheritanceMetadata().setStrategy(inheritanceStrategy);
                    inhmd.setStrategyForTree(inheritanceStrategyForTree);
                }
                else if (discriminatorValue != null || discriminatorColumnName != null ||
                        discriminatorColumnLength != null || discriminatorColumnType != null)
                {
                    // Discriminator specified so we need inheritance data
                    inhmd = cmd.newInheritanceMetadata().setStrategyForTree(inheritanceStrategyForTree);
                }

                if (discriminatorValue != null || discriminatorColumnName != null ||
                    discriminatorColumnLength != null || discriminatorColumnType != null)
                {
                    // Add discriminator information to the inheritance of this class
                    DiscriminatorMetaData dismd = inhmd.newDiscriminatorMetadata();
                    if (discriminatorValue != null)
                    {
                        // Value specified so assumed to be value-map
                        dismd.setColumnName(discriminatorColumnName);
                        dismd.setValue(discriminatorValue).setStrategy("value-map").setIndexed("false");
                    }
                    else
                    {
                        // No value so use class-name
                        discriminatorValue = cls.getName();
                        dismd.setColumnName(discriminatorColumnName);
                        dismd.setValue(discriminatorValue).setStrategy("value-map").setIndexed("false");
                    }

                    ColumnMetaData discolmd = null;
                    if (discriminatorColumnLength != null || discriminatorColumnName != null || discriminatorColumnType != null)
                    {
                        discolmd = new ColumnMetaData();
                        discolmd.setName(discriminatorColumnName);
                        if (discriminatorColumnType != null)
                        {
                            discolmd.setJdbcType(discriminatorColumnType);
                        }
                        if (discriminatorColumnLength != null)
                        {
                            discolmd.setLength(discriminatorColumnLength);
                        }
                        dismd.setColumnMetaData(discolmd);
                        if (discriminatorColumnDdl != null)
                        {
                            discolmd.setColumnDdl(discriminatorColumnDdl);
                        }
                    }
                }

                // extension - datastore-identity
                if (identityType == IdentityType.DATASTORE)
                {
                    IdentityMetaData idmd = cmd.newIdentityMetadata();
                    idmd.setColumnName(identityColumn);
                    idmd.setValueStrategy(IdentityStrategy.getIdentityStrategy(identityStrategy));
                    if (identityGenerator != null)
                    {
                        idmd.setSequence(identityGenerator);
                        idmd.setValueGeneratorName(identityGenerator);
                    }
                }

                if (pkColumnMetaData != null)
                {
                    // PK columns overriding those in the root class
                    PrimaryKeyMetaData pkmd = cmd.newPrimaryKeyMetadata();
                    for (int i=0;i<pkColumnMetaData.length;i++)
                    {
                        pkmd.addColumn(pkColumnMetaData[i]);
                    }
                }
                if (uniques != null && uniques.size() > 0)
                {
                    // Unique constraints for the primary/secondary tables
                    Iterator<UniqueMetaData> uniquesIter = uniques.iterator();
                    while (uniquesIter.hasNext())
                    {
                        cmd.addUniqueConstraint(uniquesIter.next());
                    }
                }

                if (overriddenFields != null)
                {
                    // Fields overridden from superclasses
                    Iterator<AbstractMemberMetaData> iter = overriddenFields.iterator();
                    while (iter.hasNext())
                    {
                        cmd.addMember(iter.next());
                    }
                }
                if (namedQueries != null)
                {
                    Iterator<QueryMetaData> iter = namedQueries.iterator();
                    while (iter.hasNext())
                    {
                        cmd.addQuery(iter.next());
                    }
                }
                if (resultMappings != null)
                {
                    Iterator<QueryResultMetaData> iter = resultMappings.iterator();
                    while (iter.hasNext())
                    {
                        cmd.addQueryResultMetaData(iter.next());
                    }
                }
                if (extensions != null)
                {
                    Iterator<ExtensionMetaData> iter = extensions.iterator();
                    while (iter.hasNext())
                    {
                        ExtensionMetaData extmd = iter.next();
                        cmd.addExtension(extmd.getVendorName(), extmd.getKey(), extmd.getValue());
                    }
                }
            }

            // Process any secondary tables
View Full Code Here

Examples of org.datanucleus.metadata.ClassMetaData

                PackageMetaData pmd = filemd.getPackage(i);

                // Register all classes into the respective lookup maps
                for (int j = 0; j < pmd.getNoOfClasses(); j++)
                {
                    ClassMetaData cmd = pmd.getClass(j);
                    if (classesWithoutPersistenceInfo.contains(cmd.getFullClassName()))
                    {
                        // Remove from unknown classes now that we have some metadata
                        classesWithoutPersistenceInfo.remove(cmd.getFullClassName());
                    }
                    if (cmd.getEntityName() != null)
                    {
                        // Register the metadata under the entity name
                        classMetaDataByEntityName.put(cmd.getEntityName(), cmd);
                    }
                    if (cmd.getInheritanceMetaData() != null)
                    {
                        // Register the metadata under the discriminator name
                        DiscriminatorMetaData dismd = cmd.getInheritanceMetaData().getDiscriminatorMetaData();
                        if (dismd != null)
                        {
                            if (dismd.getStrategy() == DiscriminatorStrategy.CLASS_NAME)
                            {
                                classMetaDataByDiscriminatorName.put(cmd.getFullClassName(), cmd);
                            }
                            else if (dismd.getStrategy() == DiscriminatorStrategy.VALUE_MAP)
                            {
                                classMetaDataByDiscriminatorName.put(dismd.getValue(), cmd);
                            }
                        }
                    }
                    registerMetaDataForClass(cmd.getFullClassName(), cmd);

                    postProcessClassMetaData(cmd, clr);
                }
            }
        }
View Full Code Here

Examples of org.datanucleus.metadata.ClassMetaData

                    }

                    // Pass through the classes and create necessary tables
                    while (iter.hasNext())
                    {
                        ClassMetaData cmd = (ClassMetaData) iter.next();
                        addClassTable(cmd, clr);
                    }

                    // For data where the table wasn't defined, make a second pass.
                    // This is necessary where a subclass uses "superclass-table" and the superclass' table
                    // hadn't been defined at the point of adding this class
                    Iterator<RDBMSStoreData> addedIter = new HashSet(this.schemaDataAdded).iterator();
                    while (addedIter.hasNext())
                    {
                        RDBMSStoreData data = addedIter.next();
                        if (data.getDatastoreContainerObject() == null && data.isFCO())
                        {
                            AbstractClassMetaData cmd = (AbstractClassMetaData) data.getMetaData();
                            InheritanceMetaData imd = cmd.getInheritanceMetaData();
                            if (imd.getStrategy() == InheritanceStrategy.SUPERCLASS_TABLE)
                            {
                                AbstractClassMetaData[] managingCmds = getClassesManagingTableForClass(cmd, clr);
                                DatastoreClass superTable = null;
                                if (managingCmds != null && managingCmds.length == 1)
                                {
                                    RDBMSStoreData superData =
                                        (RDBMSStoreData) storeDataMgr.get(managingCmds[0].getFullClassName());

                                    // Assert that managing class is in the set of storeDataByClass
                                    if (superData == null)
                                    {
                                        this.addClassTables(new String[]{managingCmds[0].getFullClassName()}, clr);
                                        superData = (RDBMSStoreData) storeDataMgr.get(managingCmds[0].getFullClassName());
                                    }
                                    if (superData == null)
                                    {
                                        String msg = LOCALISER_RDBMS.msg("050013",
                                            cmd.getFullClassName());
                                        NucleusLogger.PERSISTENCE.error(msg);
                                        throw new NucleusUserException(msg);
                                    }
                                    superTable = (DatastoreClass) superData.getDatastoreContainerObject();
                                    data.setDatastoreContainerObject(superTable);
View Full Code Here

Examples of org.datanucleus.metadata.ClassMetaData

     */
    public void providePrimaryKeyMappings(MappingConsumer consumer)
    {
        consumer.preConsumeMapping(highestMemberNumber + 1);

        ClassMetaData cmd = primaryTable.getClassMetaData();
        if (pkMappings != null)
        {
            // Application identity
            int[] primaryKeyFieldNumbers = cmd.getPKMemberPositions();
            for (int i=0;i<pkMappings.length;i++)
            {
                // Make the assumption that the pkMappings are in the same order as the absolute field numbers
                AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(primaryKeyFieldNumbers[i]);
                consumer.consumeMapping(pkMappings[i], fmd);
            }
        }
        else
        {
            // Datastore identity
            int[] primaryKeyFieldNumbers = cmd.getPKMemberPositions();
            int countPkFields = cmd.getNoOfPrimaryKeyMembers();
            for (int i = 0; i < countPkFields; i++)
            {
                AbstractMemberMetaData pkfmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(primaryKeyFieldNumbers[i]);
                consumer.consumeMapping(getMemberMapping(pkfmd), pkfmd);
            }
        }
    }
View Full Code Here

Examples of org.datanucleus.metadata.ClassMetaData

        // Find the ClassMetaData for these classes and all referenced by these classes
        Iterator iter = getMetaDataManager().getReferencedClasses(filteredClassNames, clr).iterator();
        while (iter.hasNext())
        {
            ClassMetaData cmd = (ClassMetaData)iter.next();
            if (cmd.getPersistenceModifier() == ClassPersistenceModifier.PERSISTENCE_CAPABLE)
            {
                if (!storeDataMgr.managesClass(cmd.getFullClassName()))
                {
                    registerStoreData(newStoreData(cmd, clr));
                }
            }
        }
View Full Code Here

Examples of org.gradle.build.docs.dsl.source.model.ClassMetaData

    }

    public DocComment parse(final PropertyMetaData propertyMetaData, final GenerationListener listener) {
        listener.start(String.format("property %s", propertyMetaData));
        try {
            ClassMetaData ownerClass = propertyMetaData.getOwnerClass();
            String rawCommentText = propertyMetaData.getRawCommentText();
            try {
                CommentSource commentSource = new InheritedPropertyCommentSource(propertyMetaData, listener);
                DocCommentImpl docComment = parse(rawCommentText, ownerClass, commentSource, listener);
                adjustGetterComment(docComment);
                return docComment;
            } catch (Exception e) {
                throw new GradleException(String.format("Could not convert javadoc comment to docbook.%nClass: %s%nProperty: %s%nComment: %s", ownerClass.getClassName(), propertyMetaData.getName(), rawCommentText), e);
            }
        } finally {
            listener.finish();
        }
    }
View Full Code Here

Examples of org.hibernate.metadata.ClassMetadata

    if (null != sessionFactory && entityTypes.isEmpty()) {
      StopWatch watch = new StopWatch();
      watch.start();
      Map<String, ClassMetadata> classMetadatas = sessionFactory.getAllClassMetadata();
      for (Iterator<ClassMetadata> iter = classMetadatas.values().iterator(); iter.hasNext();) {
        ClassMetadata cm = (ClassMetadata) iter.next();
        buildEntityType(sessionFactory, cm.getEntityName());
      }
      logger.info("Find {} entities,{} collections from hibernate in {} ms",
          new Object[] { entityTypes.size(), collectionTypes.size(), watch.getTime() });
      if (logger.isDebugEnabled()) {
        loggerTypeInfo();
View Full Code Here

Examples of org.hibernate.metadata.ClassMetadata

   * @return
   */
  private EntityType buildEntityType(SessionFactory sessionFactory, String entityName) {
    EntityType entityType = (EntityType) entityTypes.get(entityName);
    if (null == entityType) {
      ClassMetadata cm = sessionFactory.getClassMetadata(entityName);
      if (null == cm) {
        logger.error("Cannot find ClassMetadata for {}", entityName);
        return null;
      }
      entityType = new EntityType();
      entityType.setEntityName(cm.getEntityName());
      entityType.setIdPropertyName(cm.getIdentifierPropertyName());
      entityType.setEntityClass(cm.getMappedClass(EntityMode.POJO));
      entityTypes.put(cm.getEntityName(), entityType);

      Map<String, Type> propertyTypes = entityType.getPropertyTypes();
      String[] ps = cm.getPropertyNames();
      for (int i = 0; i < ps.length; i++) {
        org.hibernate.type.Type type = cm.getPropertyType(ps[i]);
        if (type.isEntityType()) {
          propertyTypes.put(ps[i], buildEntityType(sessionFactory, type.getName()));
        } else if (type.isComponentType()) {
          propertyTypes.put(ps[i], buildComponentType(sessionFactory, entityName, ps[i]));
        } else if (type.isCollectionType()) {
View Full Code Here

Examples of org.hibernate.metadata.ClassMetadata

    if (null != entityType) {
      Type propertyType = (Type) entityType.getPropertyTypes().get(propertyName);
      if (null != propertyType) { return (ComponentType) propertyType; }
    }

    ClassMetadata cm = sessionFactory.getClassMetadata(entityName);
    org.hibernate.type.ComponentType hcType = (org.hibernate.type.ComponentType) cm
        .getPropertyType(propertyName);
    String[] propertyNames = hcType.getPropertyNames();

    ComponentType cType = new ComponentType(hcType.getReturnedClass());
    Map<String, Type> propertyTypes = cType.getPropertyTypes();
    for (int j = 0; j < propertyNames.length; j++) {
      org.hibernate.type.Type type = cm.getPropertyType(propertyName + "." + propertyNames[j]);
      if (type.isEntityType()) {
        propertyTypes.put(propertyNames[j], buildEntityType(sessionFactory, type.getName()));
      } else if (type.isComponentType()) {
        propertyTypes
            .put(propertyNames[j],
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.