Package org.datanucleus.metadata

Examples of org.datanucleus.metadata.SequenceMetaData


                String allocSize = getAttr(attrs, "allocation-size");
                if (StringUtils.isWhitespace(allocSize))
                {
                    allocSize = "50"; // JPA default
                }
                SequenceMetaData seqmd = pmd.newSequenceMetadata(getAttr(attrs, "name"), null);
                String datastoreSeqName = getAttr(attrs, "sequence-name");
                if (StringUtils.isWhitespace(datastoreSeqName))
                {
                    datastoreSeqName = seqmd.getName();
                }
                seqmd.setDatastoreSequence(datastoreSeqName);
                seqmd.setInitialValue(initValue);
                seqmd.setAllocationSize(allocSize);
            }
            else if (localName.equals("table-generator"))
            {
                // Find the package for this table generator
                PackageMetaData pmd = null;
View Full Code Here


        Integer allocationSize = (Integer)annotationValues.get("allocationSize");
        if (allocationSize == null)
        {
            allocationSize = Integer.valueOf(50); // JPA default
        }
        SequenceMetaData seqmd = pmd.newSequenceMetadata(name, null);
        seqmd.setDatastoreSequence(seqName);
        seqmd.setInitialValue(initialValue.intValue());
        seqmd.setAllocationSize(allocationSize.intValue());
    }
View Full Code Here

        Integer max = null;
        Integer start = null;
        Integer increment = null;
        Integer cacheSize = null;

        SequenceMetaData seqmd = getMetaDataManager().getMetaDataForSequence(clr, seq);
        if (seqmd != null)
        {
            seqName = seqmd.getDatastoreSequence();
            if (seqmd.getAllocationSize() > 0)
            {
                increment = Integer.valueOf(seqmd.getAllocationSize());
            }
            if (seqmd.getInitialValue() >= 0)
            {
                start = Integer.valueOf(seqmd.getInitialValue());
            }
            md = seqmd;
        }
        if (md.hasExtension("key-min-value"))
        {
View Full Code Here

        String fieldName = null;
        IdentityStrategy strategy = null;
        String sequence = null;
        String valueGeneratorName = null;
        TableGeneratorMetaData tableGeneratorMetaData = null;
        SequenceMetaData sequenceMetaData = null;
        if (absoluteFieldNumber >= 0)
        {
            // real field
            mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(absoluteFieldNumber);
            fieldName = mmd.getFullFieldName();
View Full Code Here

     * @param packageSequenceName Fully qualified name of the sequence (inc package name)
     * @return The SequenceMetaData for this named sequence
     **/
    public SequenceMetaData getMetaDataForSequence(ClassLoaderResolver clr, String packageSequenceName)
    {
        SequenceMetaData seqmd = super.getMetaDataForSequence(clr, packageSequenceName);
        if (seqmd != null)
        {
            return seqmd;
        }

View Full Code Here

                }
            }
            else if (localName.equals("sequence"))
            {
                PackageMetaData pmd = (PackageMetaData)getStack();
                SequenceMetaData seqmd =
                    pmd.newSequenceMetadata(getAttr(attrs,"name"), getAttr(attrs,"strategy"));
                seqmd.setFactoryClass(getAttr(attrs,"factory-class"));
                seqmd.setDatastoreSequence(getAttr(attrs,"datastore-sequence"));
                String seqSize = getAttr(attrs, "allocation-size");
                if (seqSize != null)
                {
                    seqmd.setAllocationSize(seqSize);
                }
                String seqStart = getAttr(attrs, "initial-value");
                if (seqStart != null)
                {
                    seqmd.setInitialValue(seqStart);
                }
                pushStack(seqmd);
            }
            else if (localName.equals("field"))
            {
View Full Code Here

                VersionMetaData vermd = null;
                JoinMetaData[] joins = null;
                QueryMetaData[] queries = null;
                FetchPlanMetaData[] fetchPlans = null;
                FetchGroupMetaData[] fetchGroups = null;
                SequenceMetaData seqmd = null;
                String cacheable = 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++)
                {
                    HashMap<String, Object> annotationValues = annotations[i].getNameValueMap();
                    String annName = annotations[i].getName();
                    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();
                        vermd.setStrategy(strategy);
                        vermd.setColumnName(column);
                        vermd.setIndexed(IndexedValue.getIndexedValue(indexed));
                        if (columns != null && columns.length > 0)
                        {
                            // Only use the first column
                            ColumnMetaData colmd =
                                JDOAnnotationUtils.getColumnMetaDataForColumnAnnotation(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 an 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();
                        idmd.setColumnName(column);
                        idmd.setValueStrategy(IdentityStrategy.getIdentityStrategy(strategy));
                        idmd.setSequence(sequence);
                        if (columns != null && columns.length > 0)
                        {
                            // Only use the first column
                            ColumnMetaData colmd =
                                JDOAnnotationUtils.getColumnMetaDataForColumnAnnotation(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();
                        pkmd.setName(pkName);
                        pkmd.setColumnName(pkColumn);
                        if (columns != null && columns.length > 0)
                        {
                            for (int j=0;j<columns.length;j++)
                            {
                                pkmd.addColumn(JDOAnnotationUtils.getColumnMetaDataForColumnAnnotation(columns[j]));
                            }
                        }
                    }
                    else if (annName.equals(JDOAnnotationUtils.JOINS))
                    {
                        if (joins != null)
                        {
                            NucleusLogger.METADATA.warn(LOCALISER.msg("044210", 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++)
                            {
                                joins[j] = new JoinMetaData();
                                joins[j].setTable(js[j].table());
                                joins[j].setColumnName(js[j].column());
                                joins[j].setIndexed(IndexedValue.getIndexedValue(js[j].indexed()));
                                joins[j].setOuter(js[j].outer());
                                joins[j].setUnique(js[j].unique());
                                joins[j].setDeleteAction(JDOAnnotationUtils.getForeignKeyActionString(js[j].deleteAction()));
                            }
                        }
                    }
                    else if (annName.equals(JDOAnnotationUtils.JOIN))
                    {
                        if (joins != null)
                        {
                            NucleusLogger.METADATA.warn(LOCALISER.msg("044210", cmd.getFullClassName()));
                        }
                        joins = new JoinMetaData[1];
                        joins[0] = new JoinMetaData();
                        joins[0].setTable((String)annotationValues.get("table"));
                        joins[0].setColumnName((String)annotationValues.get("column"));
                        joins[0].setIndexed(IndexedValue.getIndexedValue((String)annotationValues.get("indexed")));
                        joins[0].setOuter((String)annotationValues.get("outer"));
                        joins[0].setUnique((String)annotationValues.get("unique"));
                        joins[0].setDeleteAction(((ForeignKeyAction)annotationValues.get("deleteAction")).toString());
                        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 an extension strategy
                            strategy = customStrategy;
                        }
                        inhmd = new InheritanceMetaData();
                        inhmd.setStrategy(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();
                        dismd.setColumnName(column);
                        dismd.setValue(value);
                        dismd.setStrategy(strategy);
                        dismd.setIndexed(indexed);
                        if (columns != null && columns.length > 0)
                        {
                            // Only use the first column
                            ColumnMetaData colmd =
                                JDOAnnotationUtils.getColumnMetaDataForColumnAnnotation(columns[0]);
                            dismd.setColumnMetaData(colmd);
                        }
                    }
                    else if (annName.equals(JDOAnnotationUtils.QUERIES))
                    {
                        if (queries != null)
                        {
                            NucleusLogger.METADATA.warn(LOCALISER.msg("044209", 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(qs[j].name());
                            queries[j].setScope(cls.getName());
                            queries[j].setLanguage(lang);
                            queries[j].setUnmodifiable(qs[j].unmodifiable());
                            queries[j].setResultClass(resultClassName);
                            queries[j].setUnique(qs[j].unique());
                            queries[j].setFetchPlanName(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)
                        {
                            NucleusLogger.METADATA.warn(LOCALISER.msg("044209", 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((String)annotationValues.get("name"));
                        queries[0].setScope(cls.getName());
                        queries[0].setLanguage(lang);
                        queries[0].setUnmodifiable(unmodifiable);
                        queries[0].setResultClass(resultClassName);
                        queries[0].setUnique((String)annotationValues.get("unique"));
                        queries[0].setFetchPlanName((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)
                        {
                            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(JDOAnnotationUtils.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(JDOAnnotationUtils.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].name());
                                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(JDOAnnotationUtils.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"));
                        Persistent[] fields = (Persistent[])annotationValues.get("members");
                        if (fields != null)
                        {
                            for (int j=0;j<fields.length;j++)
                            {
                                FieldMetaData fmd = new FieldMetaData(fetchGroups[0],
                                    fields[j].name());
                                fmd.setRecursionDepth(fields[j].recursionDepth());
                                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();
                        }
                        Integer seqSize = (Integer)annotationValues.get("allocationSize");
                        Integer seqStart = (Integer)annotationValues.get("initialValue");

                        seqmd = new SequenceMetaData(seqName, seqStrategy);
                        seqmd.setFactoryClass(seqFactoryClassName);
                        seqmd.setDatastoreSequence(seqSeq);
                        if (seqSize != null)
                        {
                            seqmd.setAllocationSize(seqSize);
                        }
                        if (seqStart != null)
                        {
                            seqmd.setInitialValue(seqStart);
                        }
                        JDOAnnotationUtils.addExtensionsToMetaData(seqmd, (Extension[])annotationValues.get("extensions"));
                    }
                    else if (annName.equals(JDOAnnotationUtils.INDICES))
                    {
View Full Code Here

     */
    public Sequence getSequence(String sequenceName)
    {
        assertIsOpen();

        SequenceMetaData seqmd = om.getMetaDataManager().getMetaDataForSequence(om.getClassLoaderResolver(),sequenceName);
        if (seqmd == null)
        {
            throw new JDOUserException(LOCALISER.msg("017000", sequenceName));
        }

        Sequence seq = null;
        if (seqmd.getFactoryClass() != null)
        {
            // User has specified a factory class
            seq = pmf.getSequenceForFactoryClass(seqmd.getFactoryClass());
            if (seq == null)
            {
                // Create a new instance of the factory class and obtain the Sequence
                Class factory = om.getClassLoaderResolver().classForName(seqmd.getFactoryClass());
                if (factory == null)
                {
                    throw new JDOUserException(LOCALISER.msg("017001", sequenceName, seqmd.getFactoryClass()));
                }

                Class[] argTypes = null;
                Object[] arguments = null;
                if (seqmd.getStrategy() != null)
                {
                    argTypes = new Class[2];
                    argTypes[0] = String.class;
                    argTypes[1] = String.class;
                    arguments = new Object[2];
                    arguments[0] = seqmd.getName();
                    arguments[1] = seqmd.getStrategy().toString();
                }
                else
                {
                    argTypes = new Class[1];
                    argTypes[0] = String.class;
                    arguments = new Object[1];
                    arguments[0] = seqmd.getName();
                }

                Method newInstanceMethod;
                try
                {
                    // Obtain the sequence from the static "newInstance(...)" method
                    newInstanceMethod = factory.getMethod("newInstance", argTypes);
                    seq = (Sequence) newInstanceMethod.invoke(null, arguments);
                }
                catch (Exception e)
                {
                    throw new JDOUserException(LOCALISER.msg("017002", seqmd.getFactoryClass(), e.getMessage()));
                }

                // Register the sequence with the PMF
                pmf.addSequenceForFactoryClass(seqmd.getFactoryClass(), seq);
            }
        }
        else
        {
            NucleusSequence nucSeq = om.getStoreManager().getNucleusSequence(om, seqmd);
View Full Code Here

        nonRepeatableRelationTypes.put(relationClass, ammd.getName());
      }
    }

    if (ammd.getValueGeneratorName() != null) {
      SequenceMetaData sequenceMetaData = metaDataManager.getMetaDataForSequence(clr, ammd.getValueGeneratorName());
      if (sequenceMetaData != null && sequenceMetaData.getInitialValue() != 1) {
        handleIgnorableMapping(acmd, ammd, "AppEngine.MetaData.SequenceInitialSizeNotSupported",
            "The first value for this sequence will be 1.");
      }
    }
  }
View Full Code Here

    }

    sequenceName = determineSequenceName(acmd);
    if (sequenceName != null) {
      // Fetch the sequence data
      SequenceMetaData sequenceMetaData = mdm.getMetaDataForSequence(clr, sequenceName);
      if (sequenceMetaData != null) {
        // derive allocation size and sequence name from the sequence meta data
        if (sequenceMetaData.hasExtension(KEY_CACHE_SIZE_PROPERTY)) {
          allocationSize = Integer.parseInt(sequenceMetaData.getValueForExtension(KEY_CACHE_SIZE_PROPERTY));
        } else {
          allocationSize = longToInt(sequenceMetaData.getAllocationSize());
        }
        sequenceName = sequenceMetaData.getDatastoreSequence();
      } else {
        // key cache size is passed in as a prop for JDO when the sequence
        // is used directly (pm.getSequence())
        if (properties.getProperty(KEY_CACHE_SIZE_PROPERTY) != null) {
          allocationSize = Integer.parseInt(properties.getProperty(KEY_CACHE_SIZE_PROPERTY));
View Full Code Here

TOP

Related Classes of org.datanucleus.metadata.SequenceMetaData

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.