use of org.eclipse.persistence.tools.schemaframework.SchemaManager in project eclipselink by eclipse-ee4j.
the class TestStoredProcedures method createSimpleStoredProcedure.
/**
* Creates a simple stored procedure for the given EntityManagerFactory
* @return boolean indicating if storedProcedure was created
*/
private static boolean createSimpleStoredProcedure(EntityManagerFactory emf) {
// Setup a stored procedure
EntityManager em = emf.createEntityManager();
try {
StoredProcedureDefinition proc = new StoredProcedureDefinition();
proc.setName("simple_order_procedure");
proc.addArgument("in_param_one", String.class, 10);
proc.addArgument("in_param_two", String.class, 10);
proc.addArgument("in_param_three", String.class, 10);
proc.addOutputArgument("out_param_one", String.class, 30);
DatabaseSession dbs = ((EntityManagerImpl) em).getDatabaseSession();
SchemaManager manager = new SchemaManager(dbs);
Platform platform = dbs.getDatasourcePlatform();
// Add more platform specific diction to support more platforms
if (platform.isMySQL()) {
proc.addStatement("SET out_param_one = CONCAT('One: ',in_param_one,' Two: ',in_param_two,' Three: ',in_param_three)");
} else if (platform.isOracle()) {
proc.addStatement("out_param_one := 'One: ' || in_param_one || ' Two: ' || in_param_two || ' Three: ' || in_param_three");
} else if (platform.isDB2() || platform.isDB2Z()) {
proc.addStatement("SET out_param_one = 'One: ' || in_param_one || ' Two: ' || in_param_two || ' Three: ' || in_param_three");
} else {
return false;
}
try {
manager.dropObject(proc);
} catch (Exception e) {
// Ignore any drop exceptions since the procedure may not exist yet
}
manager.createObject(proc);
return true;
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
if (em.isOpen()) {
em.close();
}
}
}
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();
// unitOfWork.removeAllReadOnlyClasses();
PopulationManager.getDefaultManager().addAllObjectsForClass(Employee.class, allObjects);
PopulationManager.getDefaultManager().addAllObjectsForClass(SmallProject.class, allObjects);
PopulationManager.getDefaultManager().addAllObjectsForClass(LargeProject.class, allObjects);
PopulationManager.getDefaultManager().addAllObjectsForClass(Runner.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(buildStoredProcedureParameterTest(platform));
schema.replaceObject(buildStoredProcedureReadFromAddress(platform));
schema.replaceObject(buildStoredProcedureReadFromAddressMappedNamed(platform));
schema.replaceObject(buildStoredProcedureReadFromAddressMappedNumbered(platform));
schema.replaceObject(buildStoredProcedureUpdateFromAddress(platform));
schema.replaceObject(buildStoredProcedureResultSetAndUpdateFromAddress(platform));
schema.replaceObject(buildStoredProcedureReadAllAddresses());
schema.replaceObject(buildStoredProcedureReadAllEmployees());
schema.replaceObject(buildStoredProcedureReadAddressCity(platform));
schema.replaceObject(buildStoredProcedureDeleteAllResponsibilities());
if (platform.isOracle()) {
schema.replaceObject(buildOraclePackage());
schema.replaceObject(buildStoredProcedureReadUsingNamedRefCursor());
schema.replaceObject(buildStoredProcedureReadUsingPosRefCursor());
schema.replaceObject(buildStoredProcedureReadUsingSysCursor());
}
if (platform.isMySQL()) {
schema.replaceObject(buildMySQLResultSetProcedure());
schema.replaceObject(buildStoredProcedureReadNoAddresses());
}
} 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);
}
}
use of org.eclipse.persistence.tools.schemaframework.SchemaManager in project eclipselink by eclipse-ee4j.
the class NativeSequencingTestSuite method clearSimpleTypeInstances.
@Before
public void clearSimpleTypeInstances() {
final DatabasePlatform platform = JpaHelper.getServerSession(emf).getPlatform();
if (!platform.isMySQL()) {
JpaHelper.getServerSession(emf).getSessionLog().log(SessionLog.WARNING, NativeSequencingTestSuite.class.getName() + " requires MySQL.");
}
assumeTrue(platform.isMySQL());
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.createQuery("DELETE FROM " + ENTITY_TYPE).executeUpdate();
em.createNativeQuery("ALTER TABLE " + TABLE_NAME + " DROP COLUMN SID").executeUpdate();
em.createNativeQuery("ALTER TABLE " + TABLE_NAME + " ADD COLUMN SID INTEGER PRIMARY KEY AUTO_INCREMENT FIRST").executeUpdate();
em.close();
Server session = JpaHelper.getServerSession(emf);
new SchemaManager(session).replaceSequences();
session.getSequencingControl().initializePreallocated();
}
use of org.eclipse.persistence.tools.schemaframework.SchemaManager in project eclipselink by eclipse-ee4j.
the class CustomFeaturesJUnitTestSuite method buildOracleStoredProcedureReadFromEmployeeInOut.
public void buildOracleStoredProcedureReadFromEmployeeInOut(Session session) {
if (TestCase.supportsStoredProcedures(session)) {
StoredProcedureDefinition proc = new StoredProcedureDefinition();
proc.setName("Read_Employee_InOut");
proc.addInOutputArgument("employee_id_v", Integer.class);
proc.addOutputArgument("nchar_v", "NCHAR");
String statement = "SELECT NCHARTYPE INTO nchar_v FROM CUSTOM_FEATURE_EMPLOYEE WHERE (ID = employee_id_v)";
proc.addStatement(statement);
SchemaManager schema = new SchemaManager(((DatabaseSession) session));
schema.replaceObject(proc);
} else
fail("store procedure is not supported!");
}
use of org.eclipse.persistence.tools.schemaframework.SchemaManager in project eclipselink by eclipse-ee4j.
the class CustomFeaturesJUnitTestSuite method buildOraclePackage.
public PackageDefinition buildOraclePackage(Session session) {
if (TestCase.supportsStoredProcedures(session)) {
PackageDefinition types = new PackageDefinition();
types.setName("Cursor_Type");
types.addStatement("Type Any_Cursor is REF CURSOR");
SchemaManager schema = new SchemaManager(((DatabaseSession) session));
schema.replaceObject(types);
return types;
} else {
fail("store procedure is not supported!");
return null;
}
}
Aggregations