public String getXMLForMetaData(SequenceMetaData seqmd, String prefix, String indent) { StringBuilder str = new StringBuilder(); str.append(prefix).append("<sequence name=\"" + seqmd.getName() + "\""); if (seqmd.getDatastoreSequence() != null) { str.append(" datastore-sequence=\"" + seqmd.getDatastoreSequence() + "\""); } if (seqmd.getFactoryClass() != null) { str.append(" factory-class=\"" + seqmd.getFactoryClass() + "\""); } if (seqmd.getInitialValue() >= 0) { str.append(" initial-value=\"" + seqmd.getInitialValue() + "\""); } if (seqmd.getAllocationSize() >= 0) { str.append(" allocation-size=\"" + seqmd.getAllocationSize() + "\""); } if (seqmd.getStrategy() != null) { str.append(" strategy=\"" + seqmd.getStrategy() + "\">"); } str.append(">\n"); // Add extensions processExtensions(seqmd.getExtensions(), str, prefix, indent); str.append(prefix + "</sequence>\n"); return str.toString(); }
/** * Process a @SequenceGenerator annotation. * @param pmd Package MetaData to add the sequence to * @param annotationValues The annotation info */ private void processSequenceGeneratorAnnotation(PackageMetaData pmd, HashMap<String, Object> annotationValues) { // Sequence generator, so store it against the package that we are under String name = (String)annotationValues.get("name"); String seqName = (String)annotationValues.get("sequenceName"); Integer initialValue = (Integer)annotationValues.get("initialValue"); if (initialValue == null) { initialValue = new Integer(1); // JPA default } Integer allocationSize = (Integer)annotationValues.get("allocationSize"); if (allocationSize == null) { allocationSize = new Integer(50); // JPA default } SequenceMetaData seqmd = new SequenceMetaData(pmd, name, seqName, null, null, "" + initialValue.intValue(), "" + allocationSize.intValue()); pmd.addSequence(seqmd); }
/** * Process a @SequenceGenerator annotation. * @param pmd Package MetaData to add the sequence to * @param annotationValues The annotation info */ private void processSequenceGeneratorAnnotation(PackageMetaData pmd, HashMap<String, Object> annotationValues) { // Sequence generator, so store it against the package that we are under String name = (String)annotationValues.get("name"); String seqName = (String)annotationValues.get("sequenceName"); if (StringUtils.isWhitespace(seqName)) { seqName = name; // Fallback to the name of the sequence definition } Integer initialValue = (Integer)annotationValues.get("initialValue"); if (initialValue == null) { initialValue = Integer.valueOf(1); // JPA default } 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()); }
if (seqmd.getSchemaName() != null) properties.put(ValueGenerator.PROPERTY_SEQUENCETABLE_SCHEMA, seqmd.getSchemaName()); if (seqmd.getCatalogName() != null) properties.put(ValueGenerator.PROPERTY_SEQUENCETABLE_CATALOG, seqmd.getCatalogName()); if (seqmd.getName() != null) properties.put(ValueGenerator.PROPERTY_SEQUENCE_NAME, seqmd.getName()); if (seqmd.getDatastoreSequence() != null) if (seqmd.getInitialValue() >= 0) properties.put(ValueGenerator.PROPERTY_KEY_INITIAL_VALUE, "" + seqmd.getInitialValue()); if (seqmd.getAllocationSize() > 0) properties.put(ValueGenerator.PROPERTY_KEY_CACHE_SIZE, "" + seqmd.getAllocationSize()); properties.put(ValueGenerator.PROPERTY_KEY_CACHE_SIZE, "" + allocSize); properties.put(ValueGenerator.PROPERTY_SEQUENCE_NAME, "" + seqmd.getDatastoreSequence()); Map<String, String> seqExtensions = seqmd.getExtensions(); if (seqExtensions != null && seqExtensions.size() > 0)
Map<String, String> seqExtensions = seqMetaData.getExtensions(); if (seqExtensions != null && seqExtensions.size() > 0) props.put(ValueGenerator.PROPERTY_SEQUENCE_NAME, seqMetaData.getDatastoreSequence()); if (seqMetaData.getAllocationSize() > 0) props.put(ValueGenerator.PROPERTY_KEY_CACHE_SIZE, "" + seqMetaData.getAllocationSize()); if (seqMetaData.getInitialValue() > 0) props.put(ValueGenerator.PROPERTY_KEY_INITIAL_VALUE, "" + seqMetaData.getInitialValue()); generator = mgr.createValueGenerator(valueGeneratorName, seqMetaData.getName(), props, connProvider); if (NucleusLogger.PERSISTENCE.isDebugEnabled()) NucleusLogger.PERSISTENCE.debug(Localiser.msg("017003", seqMetaData.getName(), valueGeneratorName));
SequenceMetaData seqmd = new SequenceMetaData(seqName, seqStrategy); seqmd.setFactoryClass(seqFactoryClassName); seqmd.setDatastoreSequence(seqSeq); if (seqSize != null) seqmd.setAllocationSize(seqSize); seqmd.setInitialValue(seqStart);
if (seqmd != null) seqName = seqmd.getDatastoreSequence(); if (seqmd.getAllocationSize() > 0) increment = Integer.valueOf(seqmd.getAllocationSize()); if (seqmd.getInitialValue() >= 0) start = Integer.valueOf(seqmd.getInitialValue());
if (sequenceMetaData != null) { if (sequenceMetaData.hasExtension(KEY_CACHE_SIZE_PROPERTY)) { allocationSize = Integer.parseInt(sequenceMetaData.getValueForExtension(KEY_CACHE_SIZE_PROPERTY)); } else { allocationSize = sequenceMetaData.getAllocationSize(); sequenceName = sequenceMetaData.getDatastoreSequence(); } else {
if (StringUtils.isWhitespace(datastoreSeqName)) datastoreSeqName = seqmd.getName(); seqmd.setDatastoreSequence(datastoreSeqName); seqmd.setInitialValue(initValue); seqmd.setAllocationSize(allocSize);
if (seqmd.getFactoryClass() != null) seq = pmf.getSequenceForFactoryClass(seqmd.getFactoryClass()); if (seq == null) Class factory = ec.getClassLoaderResolver().classForName(seqmd.getFactoryClass()); if (factory == null) throw new JDOUserException(Localiser.msg("017001", sequenceName, seqmd.getFactoryClass())); if (seqmd.getStrategy() != null) argTypes[1] = String.class; arguments = new Object[2]; arguments[0] = seqmd.getName(); arguments[1] = seqmd.getStrategy().toString(); argTypes[0] = String.class; arguments = new Object[1]; arguments[0] = seqmd.getName(); throw new JDOUserException(Localiser.msg("017002", seqmd.getFactoryClass(), e.getMessage())); pmf.addSequenceForFactoryClass(seqmd.getFactoryClass(), seq);
public Integer getInitialValue() { return getInternal().getInitialValue(); }
public Integer getAllocationSize() { return getInternal().getAllocationSize(); }
public String getName() { return getInternal().getName(); }
public String getDatastoreSequence() { return getInternal().getDatastoreSequence(); }
seqmd = new SequenceMetaData(null, seqName, seqSeq, seqFactoryClassName, seqStrategy, null, null); JDOAnnotationUtils.addExtensionsToMetaData(seqmd, (Extension[])annotationValues.get("extensions")); seqmd.setParent(cmd.getPackageMetaData()); cmd.getPackageMetaData().addSequence(seqmd);
public SequenceMetadata setAllocationSize(int size) { getInternal().setAllocationSize(size); return this; }
public SequenceMetadata setDatastoreSequence(String seq) { getInternal().setDatastoreSequence(seq); return this; }
public SequenceMetadata setInitialValue(int value) { getInternal().setInitialValue(value); return this; } }
seqmd.setFactoryClass(getAttr(attrs, "factory-class")); seqmd.setDatastoreSequence(getAttr(attrs, "datastore-sequence")); String seqSize = getAttr(attrs, "allocation-size"); if (seqSize != null) seqmd.setAllocationSize(seqSize); seqmd.setInitialValue(seqStart);
if (sequenceMetaData != null && sequenceMetaData.getInitialValue() != 1) { handleIgnorableMapping(acmd, ammd, "AppEngine.MetaData.SequenceInitialSizeNotSupported", "The first value for this sequence will be 1.");