use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.
the class StoredProcedureDefinition method printInOutputArgument.
/**
* Print the argument and its type.
* @param argument Stored procedure argument.
* @param writer Target writer where to write argument string.
* @param session Current session context.
* @throws ValidationException When invalid or inconsistent data were found.
*/
protected void printInOutputArgument(final FieldDefinition argument, final Writer writer, final AbstractSession session) throws ValidationException {
try {
final DatabasePlatform platform = session.getPlatform();
final FieldTypeDefinition fieldType = getFieldTypeDefinition(session, argument.type, argument.typeName);
writer.write(platform.getProcedureArgumentString());
if (platform.shouldPrintOutputTokenAtStart()) {
writer.write(" ");
writer.write(platform.getCreationInOutputProcedureToken());
writer.write(" ");
}
writer.write(argument.name);
if ((!platform.shouldPrintOutputTokenAtStart()) && platform.shouldPrintOutputTokenBeforeType()) {
writer.write(" ");
writer.write(platform.getCreationInOutputProcedureToken());
}
writer.write(" ");
writer.write(fieldType.getName());
if (fieldType.isSizeAllowed() && platform.allowsSizeInProcedureArguments() && ((argument.size != 0) || (fieldType.isSizeRequired()))) {
writer.write("(");
if (argument.size == 0) {
writer.write(Integer.toString(fieldType.getDefaultSize()));
} else {
writer.write(Integer.toString(argument.size));
}
if (argument.subSize != 0) {
writer.write(",");
writer.write(Integer.toString(argument.subSize));
} else if (fieldType.getDefaultSubSize() != 0) {
writer.write(",");
writer.write(Integer.toString(fieldType.getDefaultSubSize()));
}
writer.write(")");
}
if ((!platform.shouldPrintOutputTokenAtStart()) && (!platform.shouldPrintOutputTokenBeforeType())) {
writer.write(" ");
writer.write(platform.getCreationInOutputProcedureToken());
}
} catch (IOException ioException) {
throw ValidationException.fileError(ioException);
}
}
use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.
the class StoredProcedureDefinition method printOutputArgument.
/**
* Print the argument and its type.
* @param argument Stored procedure argument.
* @param writer Target writer where to write argument string.
* @param session Current session context.
* @throws ValidationException When invalid or inconsistent data were found.
*/
protected void printOutputArgument(final FieldDefinition argument, final Writer writer, final AbstractSession session) throws ValidationException {
try {
final DatabasePlatform platform = session.getPlatform();
final FieldTypeDefinition fieldType = getFieldTypeDefinition(session, argument.type, argument.typeName);
writer.write(platform.getProcedureArgumentString());
if (platform.shouldPrintOutputTokenAtStart()) {
writer.write(" ");
writer.write(platform.getCreationOutputProcedureToken());
writer.write(" ");
}
writer.write(argument.name);
if ((!platform.shouldPrintOutputTokenAtStart()) && platform.shouldPrintOutputTokenBeforeType()) {
writer.write(" ");
writer.write(platform.getCreationOutputProcedureToken());
}
writer.write(" ");
writer.write(fieldType.getName());
if (fieldType.isSizeAllowed() && platform.allowsSizeInProcedureArguments() && ((argument.size != 0) || (fieldType.isSizeRequired()))) {
writer.write("(");
if (argument.size == 0) {
writer.write(Integer.toString(fieldType.getDefaultSize()));
} else {
writer.write(Integer.toString(argument.size));
}
if (argument.subSize != 0) {
writer.write(",");
writer.write(Integer.toString(argument.subSize));
} else if (fieldType.getDefaultSubSize() != 0) {
writer.write(",");
writer.write(Integer.toString(fieldType.getDefaultSubSize()));
}
writer.write(")");
}
if ((!platform.shouldPrintOutputTokenAtStart()) && !platform.shouldPrintOutputTokenBeforeType()) {
writer.write(" ");
writer.write(platform.getCreationOutputProcedureToken());
}
} catch (IOException ioException) {
throw ValidationException.fileError(ioException);
}
}
use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform 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);
}
}
use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.
the class DelimitedPUTestSuite method testNativeQuery.
public void testNativeQuery() {
clearCache("delimited");
EntityManager em = createEntityManager("delimited");
Query query = em.createNamedQuery("findAllSQLEmployees");
// Native SQL may need to be different on some platforms.
DatabasePlatform platform = getServerSession("delimited").getPlatform();
if (platform.getStartDelimiter() != "\"") {
query = em.createNativeQuery("select * from " + platform.getStartDelimiter() + "CMP3_DEL_EMPLOYEE" + platform.getEndDelimiter(), Employee.class);
}
List result = query.getResultList();
Assert.assertTrue("testNativeQuery did not return result ", result.size() >= 2);
closeEntityManager(em);
}
use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform 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);
}
}
Aggregations