Search in sources :

Example 16 with DatabasePlatform

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);
    }
}
Also used : FieldTypeDefinition(org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition) DatabasePlatform(org.eclipse.persistence.internal.databaseaccess.DatabasePlatform) IOException(java.io.IOException)

Example 17 with DatabasePlatform

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);
    }
}
Also used : FieldTypeDefinition(org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition) DatabasePlatform(org.eclipse.persistence.internal.databaseaccess.DatabasePlatform) IOException(java.io.IOException)

Example 18 with DatabasePlatform

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);
    }
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) DatabasePlatform(org.eclipse.persistence.internal.databaseaccess.DatabasePlatform) SchemaManager(org.eclipse.persistence.tools.schemaframework.SchemaManager) Vector(java.util.Vector)

Example 19 with DatabasePlatform

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);
}
Also used : EntityManager(jakarta.persistence.EntityManager) Query(jakarta.persistence.Query) List(java.util.List) DatabasePlatform(org.eclipse.persistence.internal.databaseaccess.DatabasePlatform)

Example 20 with DatabasePlatform

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);
    }
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) DatabasePlatform(org.eclipse.persistence.internal.databaseaccess.DatabasePlatform) SchemaManager(org.eclipse.persistence.tools.schemaframework.SchemaManager) Vector(java.util.Vector)

Aggregations

DatabasePlatform (org.eclipse.persistence.internal.databaseaccess.DatabasePlatform)52 EntityManager (jakarta.persistence.EntityManager)12 DatabaseCall (org.eclipse.persistence.internal.databaseaccess.DatabaseCall)11 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)9 EntityManagerFactoryImpl (org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl)9 Test (org.junit.Test)9 GenericEntity (org.eclipse.persistence.jpa.test.property.model.GenericEntity)8 PersistenceException (jakarta.persistence.PersistenceException)6 Platform (org.eclipse.persistence.internal.databaseaccess.Platform)6 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)6 ResultSetMetaData (java.sql.ResultSetMetaData)5 DatabaseAccessor (org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor)5 FieldTypeDefinition (org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition)5 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)5 IOException (java.io.IOException)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Vector (java.util.Vector)4