Package org.datanucleus.metadata

Examples of org.datanucleus.metadata.FieldMetaData


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


            // Try as field
            try
            {
                Field overrideMember = type.getDeclaredField(baseMemberName);
                ammd = new FieldMetaData(embmd, baseMemberName);
                type = overrideMember.getType();
            }
            catch (Exception e)
            {
            }
            if (ammd == null)
            {
                // Try as property
                try
                {
                    Method overrideMember = type.getDeclaredMethod(ClassUtils.getJavaBeanGetterName(baseMemberName, false));
                    ammd = new FieldMetaData(embmd, baseMemberName);
                    type = overrideMember.getReturnType();
                }
                catch (Exception e)
                {
                }
            }
            if (ammd == null)
            {
                throw new NucleusException("Cannot obtain override field/property "+
                    overriddenName + " of class " + type + " for persistent class " + mmd.getClassName(true));
            }

            embmd.addMember(ammd);
            ammd.setParent(embmd);

            // Recurse to nested field type
            processEmbeddedAttributeOverride(ammd, nestedMemberName, type, column);
        }
        else
        {
            Member overriddenMember = null;
            java.lang.reflect.Member overrideMember = null;
            AbstractMemberMetaData ammd = null;

            // Try as field
            try
            {
                overrideMember = type.getDeclaredField(overriddenName);
                overriddenMember = new Member((Field)overrideMember);
                ammd = new FieldMetaData(embmd, overriddenName);
            }
            catch (Exception e)
            {
            }
View Full Code Here

        {
            fmd = new PropertyMetaData(cmd, field.getName());
        }
        else
        {
            fmd = new FieldMetaData(cmd, field.getName());
        }
        fmd.setPersistenceModifier(modifier);
        fmd.setPrimaryKey(pk);
        fmd.setDefaultFetchGroup(dfg);
        fmd.setEmbedded(embedded);
View Full Code Here

            {
                mmd = new PropertyMetaData(acmd, getAttr(attrs,"name"));
            }
            else
            {
                mmd = new FieldMetaData(acmd, getAttr(attrs,"name"));
            }
            mmd.setPersistenceModifier(FieldPersistenceModifier.PERSISTENT.toString());
            mmd.setDefaultFetchGroup(dfg);
            mmd.setDependent(getAttr(attrs,"dependent"));
            mmd.setMappedBy(getAttr(attrs,"mapped-by"));
View Full Code Here

            {
                mmd = new PropertyMetaData(acmd, getAttr(attrs, "name"));
            }
            else
            {
                mmd = new FieldMetaData(acmd, getAttr(attrs, "name"));
            }
            mmd.setPersistenceModifier(FieldPersistenceModifier.PERSISTENT.toString());
            mmd.setPrimaryKey(true);
            if (defaultCascadePersist)
            {
View Full Code Here

        {
            mmd = new PropertyMetaData(md, name);
        }
        else
        {
            mmd = new FieldMetaData(md, name);
        }
        mmd.setNotPersistent();
        if (defaultCascadePersist)
        {
            // This file has <persistence-unit-defaults> set to cascade-persist all fields
View Full Code Here

        {
            mmd = new PropertyMetaData(md, name);
        }
        else
        {
            mmd = new FieldMetaData(md, name);
        }
        mmd.setEmbedded(true);
        if (defaultCascadePersist)
        {
            // This file has <persistence-unit-defaults> set to cascade-persist all fields
View Full Code Here

        {
            mmd = new PropertyMetaData(md, "#UNKNOWN." + getAttr(attrs, "name"));
        }
        else
        {
            mmd = new FieldMetaData(md, "#UNKNOWN." + getAttr(attrs, "name"));
        }
        String colName = getAttr(attrs, "column");
        if (colName != null)
        {
            mmd.setColumn(colName);
View Full Code Here

            {
                mmd = new PropertyMetaData(embmd, baseMemberName);
            }
            else
            {
                mmd = new FieldMetaData(embmd, baseMemberName);
            }

            EmbeddedMetaData nestedEmbmd = new EmbeddedMetaData();
            nestedEmbmd.setParent(mmd);
            mmd.setEmbeddedMetaData(nestedEmbmd);

            AbstractMemberMetaData nestedEmbMmd = newOverriddenEmbeddedFieldObject(nestedEmbmd, nestedMemberName, columnName);
            nestedEmbmd.addMember(nestedEmbMmd);
            overrideMmd = nestedEmbMmd;
            return mmd;
        }
        else
        {
            AbstractMemberMetaData mmd = null;
            if (propertyAccess)
            {
                mmd = new PropertyMetaData(embmd, memberName);
            }
            else
            {
                mmd = new FieldMetaData(embmd, memberName);
            }
            mmd.setParent(embmd);

            if (columnName != null)
            {
View Full Code Here

                        MemberAnnotationHandler handler = annMgr.getHandlerForMemberAnnotation(annName);
                        if (handler != null)
                        {
                            if (mmd == null)
                            {
                                mmd = new FieldMetaData(cmd, field.getMember().getName());
                                cmd.addMember(mmd);
                            }
                            handler.processMemberAnnotation(annotations[i], mmd, clr);
                        }
                    }
View Full Code Here

TOP

Related Classes of org.datanucleus.metadata.FieldMetaData

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.