use of org.eclipse.persistence.sequencing.NativeSequence in project eclipselink by eclipse-ee4j.
the class SequenceGeneratorMetadata method process.
/**
* INTERNAL:
*/
public NativeSequence process(MetadataLogger logger) {
NativeSequence sequence = new NativeSequence();
// Process the sequence name.
if (m_sequenceName == null || m_sequenceName.equals("")) {
logger.logConfigMessage(MetadataLogger.SEQUENCE_GENERATOR_SEQUENCE_NAME, m_name, getAccessibleObject(), getLocation());
sequence.setName(m_name);
} else {
sequence.setName(m_sequenceName);
}
// Set the should use identity flag.
sequence.setShouldUseIdentityIfPlatformSupports(m_useIdentityIfPlatformSupports);
// Process the allocation size
sequence.setPreallocationSize(m_allocationSize == null ? Integer.valueOf(50) : m_allocationSize);
// Process the initial value
sequence.setInitialValue(m_initialValue == null ? Integer.valueOf(1) : m_initialValue);
// Process the schema and catalog qualifier
sequence.setQualifier(processQualifier());
return sequence;
}
use of org.eclipse.persistence.sequencing.NativeSequence in project eclipselink by eclipse-ee4j.
the class SessionsFactory method buildSequence.
/**
* INTERNAL:
* Builds a Sequence from the given SequenceConfig.
*/
protected Sequence buildSequence(SequenceConfig sequenceConfig) {
if (sequenceConfig == null) {
return null;
}
String name = sequenceConfig.getName();
int size = sequenceConfig.getPreallocationSize();
if (sequenceConfig instanceof DefaultSequenceConfig) {
return new DefaultSequence(name, size);
} else if (sequenceConfig instanceof NativeSequenceConfig) {
return new NativeSequence(name, size);
} else if (sequenceConfig instanceof TableSequenceConfig) {
TableSequenceConfig tsc = (TableSequenceConfig) sequenceConfig;
return new TableSequence(name, size, tsc.getTable(), tsc.getNameField(), tsc.getCounterField());
} else if (sequenceConfig instanceof UnaryTableSequenceConfig) {
UnaryTableSequenceConfig utsc = (UnaryTableSequenceConfig) sequenceConfig;
return new UnaryTableSequence(name, size, utsc.getCounterField());
} else if (sequenceConfig instanceof XMLFileSequenceConfig) {
try {
// Can no longer reference class directly as in a different project.
@SuppressWarnings({ "unchecked" }) Class<Sequence> xmlClass = (Class<Sequence>) Class.forName("org.eclipse.persistence.eis.adapters.xmlfile.XMLFileSequence");
Sequence sequence = xmlClass.getConstructor().newInstance();
sequence.setName(name);
sequence.setInitialValue(size);
return sequence;
} catch (Exception missing) {
return null;
}
} else {
// Unknown SequenceConfig subclass - should never happen
return null;
}
}
use of org.eclipse.persistence.sequencing.NativeSequence in project eclipselink by eclipse-ee4j.
the class LoadBuildProject method applyLOGIN.
protected void applyLOGIN() {
org.eclipse.persistence.sessions.DatabaseLogin login = new org.eclipse.persistence.sessions.DatabaseLogin();
login.setUserName(System.getProperty(PROP_PERFDB_USER, DFLT_PERFDB_USER));
login.setPassword(System.getProperty(PROP_PERFDB_PWD, DFLT_PERFDB_PWD));
login.setDriverClassName(System.getProperty(PROP_PERFDB_DRIVER, DFLT_PERFDB_DRIVER));
login.setConnectionString(System.getProperty(PROP_PERFDB_URI, DFLT_PERFDB_URI));
login.setPlatformClassName(System.getProperty(PROP_PERFDB_PLATFORM, DFLT_PERFDB_PLATFORM));
NativeSequence sequence = new NativeSequence();
sequence.setPreallocationSize(500);
login.setDefaultSequence(sequence);
setLogin(login);
}
use of org.eclipse.persistence.sequencing.NativeSequence in project eclipselink by eclipse-ee4j.
the class OracleNativeSeqInitTest method setup.
@Override
public void setup() {
if (!getSession().getPlatform().supportsSequenceObjects()) {
throw new TestWarningException("This test requires a platform that supports sequence objects");
}
ClassDescriptor descriptor = getSession().getDescriptor(Employee.class);
if (!descriptor.usesSequenceNumbers()) {
throw new TestWarningException("Employee doesn't use sequencing");
}
originalSequence = getSession().getPlatform().getSequence(descriptor.getSequenceNumberName());
usesNativeSequencingOriginal = (originalSequence instanceof NativeSequence || (originalSequence instanceof DefaultSequence && getSession().getPlatform().getDefaultSequence() instanceof NativeSequence)) && !originalSequence.shouldAcquireValueAfterInsert();
if (!usesNativeSequencingOriginal) {
NativeSequence newSequence = new NativeSequence(originalSequence.getName(), originalSequence.getPreallocationSize());
newSequence.onConnect(originalSequence.getDatasourcePlatform());
getAbstractSession().getPlatform().addSequence(newSequence);
sequence = newSequence;
} else {
sequence = originalSequence;
}
seqPreallocationSizeOriginal = originalSequence.getPreallocationSize();
lastSeqNumberOriginal = getSession().getNextSequenceNumberValue(Employee.class).intValue() - 1;
usesBatchWritingOriginal = getSession().getPlatform().usesBatchWriting();
shouldCacheAllStatementsOriginal = getSession().getPlatform().shouldCacheAllStatements();
getDatabaseSession().getSequencingControl().initializePreallocated();
sequenceDefinition = new SequenceObjectDefinition(sequence);
sequenceDefinition.setQualifier(getSession().getLogin().getTableQualifier());
if (shouldUseSchemaManager) {
schemaManager = new SchemaManager(getDatabaseSession());
// make sure that upcoming DROP and CREATE haven't been cached
// and therefore for sure will go through
getSession().getPlatform().setShouldCacheAllStatements(false);
// This is the worst case scenario settings - SchemaManager should handle it.
getSession().getPlatform().setUsesBatchWriting(true);
getSession().getPlatform().setShouldCacheAllStatements(true);
} else {
getSession().getPlatform().setUsesBatchWriting(false);
getSession().getPlatform().setShouldCacheAllStatements(false);
}
// all three modes start with dropping an existing sequence (if any)
try {
drop();
} catch (DatabaseException exception) {
// Ignore already deleted
}
if (mode == DROP_CREATE) {
// sequence doesn't exist.
// create sequence with seqPreallocationSize.
// note that both increment and starting value are set to
// sequenceDefinition.getIncrement()
sequence.setInitialValue(1);
sequence.setPreallocationSize(seqPreallocationSize);
create();
// next available sequence number.
idExpected = 1;
} else if (mode == CREATE_CREATE) {
// sequence doesn't exist,
// create sequence with seqPreallocationSizeOld
// note that both increment and starting value are set to
// sequenceDefinition.getIncrement()
sequence.setInitialValue(1);
sequence.setPreallocationSize(seqPreallocationSizeOld);
create();
// now sequence exists,
// create sequence with seqPreallocationSize
// Note that createOnDatabase will call alterOnDatabase
sequence.setInitialValue(1);
sequence.setPreallocationSize(seqPreallocationSize);
create();
// next available sequence number.
// note that the second createOnDatabase selects NEXTVAL during existance check,
// because it is the first call to NEXTVAL, the starting sequence value is returned,
// and this value was set to seqPreallocationSizeOld by the first createOnDatabase
idExpected = 1 + seqPreallocationSizeOld;
} else if (mode == NEXTVAL_ALTER) {
// sequence doesn't exist,
// create sequence with seqPreallocationSizeOld
// note that both increment and starting value are set to
// sequenceDefinition.getIncrement()
sequence.setInitialValue(1);
sequence.setPreallocationSize(seqPreallocationSizeOld);
create();
// now sequence exists,
// select NEXTVAL
// because it is the first call to NEXTVAL, the starting sequence value is returned,
// and this value was set to seqPreallocationSizeOld by the first createOnDatabase
sequenceDefinition.checkIfExist((AbstractSession) getSession());
// alter increment of sequence with seqPreallocationSize.
sequence.setInitialValue(1);
sequence.setPreallocationSize(seqPreallocationSize);
alter();
// next available sequence number.
// because there was just one call to NEXTVAL, the starting sequence value is returned,
// and this value was set to seqPreallocationSizeOld by createOnDatabase
idExpected = 1 + seqPreallocationSizeOld;
} else if (mode == CREATE_ALTER) {
// sequence doesn't exist,
// create sequence with seqPreallocationSizeOld
// note that both increment and starting value are set to
// sequenceDefinition.getIncrement()
sequence.setInitialValue(1);
sequence.setPreallocationSize(seqPreallocationSizeOld);
create();
// alter increment of sequence with seqPreallocationSize.
sequence.setInitialValue(1);
sequence.setPreallocationSize(seqPreallocationSize);
alter();
// next available sequence number.
idExpected = 1;
}
getSession().getPlatform().getSequence(descriptor.getSequenceNumberName()).setPreallocationSize(seqPreallocationSize);
}
use of org.eclipse.persistence.sequencing.NativeSequence in project eclipselink by eclipse-ee4j.
the class DefaultTableGenerator method initTableSchema.
/**
* Build tables/fields information into the table creator object from a EclipseLink descriptor.
* This should handle most of the direct/relational mappings except many-to-many and direct
* collection/map mappings, which must be down in postInit method.
*/
protected void initTableSchema(ClassDescriptor descriptor) {
TableDefinition tableDefintion = null;
if (descriptor.hasTablePerClassPolicy() && descriptor.isAbstract()) {
return;
}
// create a table definition for each mapped database table
for (DatabaseTable table : descriptor.getTables()) {
tableDefintion = getTableDefFromDBTable(table);
}
// build each field definition and figure out which table it goes
for (DatabaseField dbField : descriptor.getFields()) {
if (dbField.isCreatable()) {
boolean isPKField = false;
// first check if the field is a pk field in the default table.
isPKField = descriptor.getPrimaryKeyFields().contains(dbField);
// then check if the field is a pk field in the secondary table(s), this is only applied to the multiple tables case.
Map<DatabaseField, DatabaseField> secondaryKeyMap = descriptor.getAdditionalTablePrimaryKeyFields().get(dbField.getTable());
if (secondaryKeyMap != null) {
isPKField = isPKField || secondaryKeyMap.containsValue(dbField);
}
// Now check if it is a tenant discriminat column primary key field.
isPKField = isPKField || dbField.isPrimaryKey();
// build or retrieve the field definition.
FieldDefinition fieldDef = getFieldDefFromDBField(dbField);
if (isPKField) {
fieldDef.setIsPrimaryKey(true);
// Check if the generation strategy is IDENTITY
String sequenceName = descriptor.getSequenceNumberName();
DatabaseLogin login = this.project.getLogin();
Sequence seq = login.getSequence(sequenceName);
if (seq instanceof DefaultSequence) {
seq = login.getDefaultSequence();
}
// The native sequence whose value should be acquired after insert is identity sequence
boolean isIdentity = seq instanceof NativeSequence && seq.shouldAcquireValueAfterInsert();
fieldDef.setIsIdentity(isIdentity);
}
// find the table the field belongs to, and add it to the table, only if not already added.
tableDefintion = this.tableMap.get(dbField.getTableName());
if ((tableDefintion != null) && !tableDefintion.getFields().contains(fieldDef)) {
tableDefintion.addField(fieldDef);
}
}
}
}
Aggregations