use of org.eclipse.persistence.tools.schemaframework.SchemaManager in project eclipselink by eclipse-ee4j.
the class TablesCheckTestSuite method setup.
/**
* Tests suite setup: Creates database table for the tests.
*/
@Override
public void setup() {
final TableCreator creator = new TableCreator();
creator.addTableDefinition(BEER_TD);
final DatabaseSession session = getDatabaseSession();
final SchemaManager manager = new SchemaManager(getDatabaseSession());
// Table life cycle is related to this test life cycle.
creator.createTables(session, manager);
}
use of org.eclipse.persistence.tools.schemaframework.SchemaManager 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.tools.schemaframework.SchemaManager in project eclipselink by eclipse-ee4j.
the class TogglingFastTableCreator method replaceTables.
@Override
public void replaceTables(DatabaseSession session) {
// on Symfoware, to avoid table locking issues only the first invocation
// of an instance of this class (drops & re-)creates the tables
// if the system property is set.
session.getSessionLog().log(SessionLog.FINEST, "TogglingFastTableCreator: useFastTableCreatorAfterInitialCreate: " + useFastTableCreatorAfterInitialCreate);
boolean isFirstCreate = !isFastTableCreator();
session.getSessionLog().log(SessionLog.FINEST, "TogglingFastTableCreator: " + getTableCreatorName() + " - isFirstCreate: " + isFirstCreate);
session.getSessionLog().log(SessionLog.FINEST, "TogglingFastTableCreator: Current fastTableCreators: " + fastTableCreators);
if (useFastTableCreatorAfterInitialCreate && !isFirstCreate) {
session.getSessionLog().log(SessionLog.FINEST, "TogglingFastTableCreator: " + getTableCreatorName() + " - toggling true");
String sequenceTableName = getSequenceTableName(session);
List<TableDefinition> tables = getTableDefinitions();
for (TableDefinition table : tables) {
if (!table.getName().equals(sequenceTableName)) {
SchemaManager schemaManager = new SchemaManager(session);
AbstractSession abstarctSession = schemaManager.getSession();
try {
abstarctSession.priviledgedExecuteNonSelectingCall(new org.eclipse.persistence.queries.SQLCall("DELETE FROM " + table.getFullName()));
} catch (DatabaseException ex) {
// Ignore database exception. eg. If there is no table to delete, it gives database exception.
}
}
}
} else {
super.replaceTables(session);
}
// next time just delete the rows instead.
if (useFastTableCreatorAfterInitialCreate) {
setFastTableCreator();
session.getSessionLog().log(SessionLog.FINEST, "TogglingFastTableCreator: " + getTableCreatorName() + " added to fastTableCreators");
}
}
use of org.eclipse.persistence.tools.schemaframework.SchemaManager in project eclipselink by eclipse-ee4j.
the class EmployeePopulator method persistExample.
public void persistExample(Session session) {
Vector allObjects = new Vector();
UnitOfWork unitOfWork = session.acquireUnitOfWork();
// Disable the read-only classes for model population. Specifically,
// in this case we want to be able to create EquipmentCode objects.
unitOfWork.removeAllReadOnlyClasses();
PopulationManager.getDefaultManager().addAllObjectsForClass(Employee.class, allObjects);
PopulationManager.getDefaultManager().addAllObjectsForClass(SmallProject.class, allObjects);
PopulationManager.getDefaultManager().addAllObjectsForClass(LargeProject.class, allObjects);
/* PopulationManager.getDefaultManager().addAllObjectsForClass(GoldBuyer.class, allObjects);
PopulationManager.getDefaultManager().addAllObjectsForClass(PlatinumBuyer.class, allObjects);*/
PopulationManager.getDefaultManager().addAllObjectsForClass(EquipmentCode.class, allObjects);
unitOfWork.registerAllObjects(allObjects);
unitOfWork.commit();
if (TestCase.supportsStoredProcedures(session)) {
boolean orig_FAST_TABLE_CREATOR = SchemaManager.FAST_TABLE_CREATOR;
// of an instance of this class (drops & re-)creates the tables.
if (useFastTableCreatorAfterInitialCreate && !isFirstCreation) {
SchemaManager.FAST_TABLE_CREATOR = true;
}
try {
SchemaManager schema = new SchemaManager((DatabaseSession) session);
schema.replaceObject(buildOracleStoredProcedureReadFromAddress((DatabaseSession) session));
schema.replaceObject(buildOracleStoredProcedureReadInOut((DatabaseSession) session));
} finally {
if (useFastTableCreatorAfterInitialCreate && !isFirstCreation) {
SchemaManager.FAST_TABLE_CREATOR = orig_FAST_TABLE_CREATOR;
}
}
// next time it deletes the rows instead.
isFirstCreation = false;
}
// Force uppercase for Postgres.
if (session.getPlatform().isPostgreSQL()) {
session.getLogin().setShouldForceFieldNamesToUpperCase(true);
}
}
use of org.eclipse.persistence.tools.schemaframework.SchemaManager in project eclipselink by eclipse-ee4j.
the class EmployeePopulator method persistExample.
public void persistExample(Session session) {
Vector allObjects = new Vector();
UnitOfWork unitOfWork = session.acquireUnitOfWork();
PopulationManager.getDefaultManager().addAllObjectsForClass(Employee.class, allObjects);
PopulationManager.getDefaultManager().addAllObjectsForClass(SmallProject.class, allObjects);
PopulationManager.getDefaultManager().addAllObjectsForClass(LargeProject.class, allObjects);
unitOfWork.registerAllObjects(allObjects);
unitOfWork.commit();
DatabasePlatform platform = session.getLogin().getPlatform();
if (TestCase.supportsStoredProcedures(session)) {
boolean orig_FAST_TABLE_CREATOR = SchemaManager.FAST_TABLE_CREATOR;
// of an instance of this class (drops & re-)creates the tables.
if (useFastTableCreatorAfterInitialCreate && !isFirstCreation) {
SchemaManager.FAST_TABLE_CREATOR = true;
}
try {
SchemaManager schema = new SchemaManager((DatabaseSession) session);
schema.replaceObject(buildStoredProcedureReadFromAddress(platform));
schema.replaceObject(buildStoredProcedureReadFromAddressMappedNamed(platform));
schema.replaceObject(buildStoredProcedureReadFromAddressMappedNumbered(platform));
schema.replaceObject(buildStoredProcedureReadAllAddresses());
if (platform.isOracle()) {
schema.replaceObject(buildOraclePackage());
schema.replaceObject(buildStoredProcedureReadUsingNamedRefCursor());
schema.replaceObject(buildStoredProcedureReadUsingUnNamedRefCursor());
}
if (platform.isMySQL()) {
schema.replaceObject(buildMySQLResultSetProcedure());
}
} finally {
if (useFastTableCreatorAfterInitialCreate && !isFirstCreation) {
SchemaManager.FAST_TABLE_CREATOR = orig_FAST_TABLE_CREATOR;
}
}
// next time it deletes the rows instead.
isFirstCreation = false;
}
// Force uppercase for Postgres.
if (platform.isPostgreSQL()) {
session.getLogin().setShouldForceFieldNamesToUpperCase(true);
}
}
Aggregations