use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.
the class LOBTestWrapper method reset.
@Override
public void reset() throws Throwable {
super.reset();
DatabasePlatform platform = getSession().getPlatform();
if (!shouldUseLocatorForLOBWrite) {
platform.setUsesStringBinding(usesStringBindingOriginal);
}
if (platform instanceof Oracle8Platform) {
Oracle8Platform platform8 = (Oracle8Platform) platform;
if (shouldSetUseLocatorForLOBWriteIntoPlatform) {
platform8.setShouldUseLocatorForLOBWrite(shouldUseLocatorForLOBWriteOriginal);
}
}
}
use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.
the class BaseNcharTest method setup.
@Override
protected void setup() {
if (!getSession().getPlatform().isOracle()) {
throw new TestWarningException("This test case works on Oracle only");
}
try {
getOracle9Platform();
} catch (ClassCastException ex) {
DatabasePlatform platform = getSession().getPlatform();
try {
getSession().getLogin().usePlatform(new org.eclipse.persistence.platform.database.oracle.Oracle9Platform());
getDatabaseSession().logout();
getDatabaseSession().login();
platformOriginal = platform;
getOracle9Platform();
} catch (Exception ex2) {
throw new TestWarningException("This test case works with Oracle9 platform or higher");
}
}
DatabasePlatform platform = getSession().getPlatform();
if (!platform.shouldBindAllParameters()) {
// without binding string binding must be enabled to so that a big String for NCLOB is still bound.
usesStringBindingOriginal = platform.usesStringBinding();
platform.setUsesStringBinding(true);
}
}
use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testNativeSequences.
public void testNativeSequences() {
SessionBroker broker = getSessionBroker();
DatabasePlatform platform = (DatabasePlatform) broker.getPlatform(Address.class);
boolean doesPlatformSupportIdentity = platform.supportsIdentity();
boolean doesPlatformSupportSequenceObjects = platform.supportsSequenceObjects();
String errorMsg = "";
if (doesPlatformSupportIdentity != doesPlatformSupportSequenceObjects) {
// SEQ_GEN_IDENTITY sequence defined by
// @GeneratedValue(strategy=IDENTITY)
Sequence identitySequence = platform.getSequence("SEQ_GEN_IDENTITY");
if (identitySequence != null) {
boolean isIdentity = identitySequence.shouldAcquireValueAfterInsert();
if (doesPlatformSupportIdentity != isIdentity) {
errorMsg = "SEQ_GEN_IDENTITY: doesPlatformSupportIdentity = " + doesPlatformSupportIdentity + ", but isIdentity = " + isIdentity + "; ";
}
}
}
// ADDRESS_BR1_SEQ sequence defined by
// @GeneratedValue(generator="ADDRESS_BR1_SEQ")
// @SequenceGenerator(name="ADDRESS_BR1_SEQ", allocationSize=25)
boolean isSequenceObject = !platform.getSequence("ADDRESS_BR1_SEQ").shouldAcquireValueAfterInsert();
if (doesPlatformSupportSequenceObjects != isSequenceObject) {
errorMsg = errorMsg + "ADDRESS_BR1_SEQ: doesPlatformSupportSequenceObjects = " + doesPlatformSupportSequenceObjects + ", but isSequenceObject = " + isSequenceObject;
}
if (errorMsg.length() > 0) {
fail(errorMsg);
}
}
use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.
the class TestParameterBinding method testIN_ForceBindJPQLParameters.
@Test
public void testIN_ForceBindJPQLParameters() {
EntityManager em = forceBindEMF.createEntityManager();
try {
// Test all the operands of an IN predicate
TypedQuery<GenericEntity> query = em.createQuery("SELECT 2 FROM GenericEntity s " + "WHERE ?1 IN (?2, ?3, ?4)", GenericEntity.class);
query.setParameter(1, 4);
query.setParameter(2, 4);
query.setParameter(3, 5);
query.setParameter(4, 6);
query.getResultList();
DatabaseCall call = ((JpaQuery<GenericEntity>) query).getDatabaseQuery().getCall();
Assert.assertFalse("Expected query parameter binding to not be set for the DatabaseCall", call.isUsesBindingSet());
DatabasePlatform pl = (DatabasePlatform) forceBindEMF.unwrap(EntityManagerFactoryImpl.class).getDatabaseSession().getDatasourcePlatform();
if (pl.isDB2Z() || pl.isDerby()) {
Assert.fail("Expected a failure from " + pl);
}
if (pl.shouldBindLiterals()) {
Assert.assertEquals("The number of parameters found does not match the number supplied", 5, call.getParameters().size());
} else {
Assert.assertEquals("The number of parameters found does not match the number supplied", 4, call.getParameters().size());
}
} catch (PersistenceException e) {
Platform pl = forceBindEMF.unwrap(EntityManagerFactoryImpl.class).getDatabaseSession().getDatasourcePlatform();
if (pl.isDB2Z()) {
// When all the operands of an IN predicate are untyped parameters, error on DB2/z
Assert.assertEquals(DatabaseException.class, e.getCause().getClass());
Assert.assertEquals("com.ibm.db2.jcc.am.SqlSyntaxErrorException", e.getCause().getCause().getClass().getName());
} else if (pl.isDerby()) {
// Use as the left operand of an IN list is not allowed when all operands are untyped parameters, error 42X35 on Derby
Assert.assertEquals(DatabaseException.class, e.getCause().getClass());
Assert.assertEquals("java.sql.SQLSyntaxErrorException", e.getCause().getCause().getClass().getName());
} else {
Assert.fail("Unexpected failure: " + e);
}
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
if (em.isOpen()) {
em.close();
}
}
em = forceBindEMF.createEntityManager();
try {
// Test the first and second operands of an IN predicate
TypedQuery<GenericEntity> query = em.createQuery("SELECT 2 FROM GenericEntity s " + "WHERE ?1 IN (?2, 'b', 'c')", GenericEntity.class);
query.setParameter(1, "a");
query.setParameter(2, "a");
query.getResultList();
DatabaseCall call = ((JpaQuery<GenericEntity>) query).getDatabaseQuery().getCall();
Assert.assertFalse("Expected query parameter binding to not be set for the DatabaseCall", call.isUsesBindingSet());
DatabasePlatform pl = (DatabasePlatform) forceBindEMF.unwrap(EntityManagerFactoryImpl.class).getDatabaseSession().getDatasourcePlatform();
if (pl.shouldBindLiterals()) {
Assert.assertEquals("The number of parameters found does not match the number supplied", 5, call.getParameters().size());
} else {
Assert.assertEquals("The number of parameters found does not match the number supplied", 2, call.getParameters().size());
}
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
if (em.isOpen()) {
em.close();
}
}
em = forceBindEMF.createEntityManager();
try {
// Test the first operand of an IN predicate and zero or more operands of the IN list except for the first operand of the IN list
TypedQuery<GenericEntity> query = em.createQuery("SELECT 2 FROM GenericEntity s " + "WHERE ?1 IN (5, ?2, 6)", GenericEntity.class);
query.setParameter(1, 4);
query.setParameter(2, 4);
query.getResultList();
DatabaseCall call = ((JpaQuery<GenericEntity>) query).getDatabaseQuery().getCall();
Assert.assertFalse("Expected query parameter binding to not be set for the DatabaseCall", call.isUsesBindingSet());
DatabasePlatform pl = (DatabasePlatform) forceBindEMF.unwrap(EntityManagerFactoryImpl.class).getDatabaseSession().getDatasourcePlatform();
if (pl.shouldBindLiterals()) {
Assert.assertEquals("The number of parameters found does not match the number supplied", 5, call.getParameters().size());
} else {
Assert.assertEquals("The number of parameters found does not match the number supplied", 2, call.getParameters().size());
}
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
if (em.isOpen()) {
em.close();
}
}
em = forceBindEMF.createEntityManager();
try {
// Test any or all operands of the IN list of the IN predicate and the first operand of the IN predicate is not an untyped parameter marker
TypedQuery<GenericEntity> query = em.createQuery("SELECT 2 FROM GenericEntity s " + "WHERE s.itemString1 IN (?1, 'b', ?2)", GenericEntity.class);
query.setParameter(1, "a");
query.setParameter(2, "c");
query.getResultList();
DatabaseCall call = ((JpaQuery<GenericEntity>) query).getDatabaseQuery().getCall();
Assert.assertFalse("Expected query parameter binding to not be set for the DatabaseCall", call.isUsesBindingSet());
DatabasePlatform pl = (DatabasePlatform) forceBindEMF.unwrap(EntityManagerFactoryImpl.class).getDatabaseSession().getDatasourcePlatform();
if (pl.shouldBindLiterals()) {
Assert.assertEquals("The number of parameters found does not match the number supplied", 4, call.getParameters().size());
} else {
Assert.assertEquals("The number of parameters found does not match the number supplied", 2, call.getParameters().size());
}
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
if (em.isOpen()) {
em.close();
}
}
}
use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.
the class TestParameterBinding method testLIKE_ForceBindJPQLParameters.
@Test
public void testLIKE_ForceBindJPQLParameters() {
EntityManager em = forceBindEMF.createEntityManager();
try {
// Test the first operand of a LIKE predicate (the match-expression) is untyped parameter
// when at least one other operand (the pattern-expression or escape-expression)
// is not an untyped parameter marker
TypedQuery<GenericEntity> query = em.createQuery("SELECT 1 FROM GenericEntity s " + "WHERE ?1 LIKE ?2 ESCAPE '_'", GenericEntity.class);
query.setParameter(1, "HELLO_WORLD");
query.setParameter(2, "HELLO%");
query.getResultList();
DatabaseCall call = ((JpaQuery<GenericEntity>) query).getDatabaseQuery().getCall();
Assert.assertFalse("Expected query parameter binding to not be set for the DatabaseCall", call.isUsesBindingSet());
DatabasePlatform pl = (DatabasePlatform) forceBindEMF.unwrap(EntityManagerFactoryImpl.class).getDatabaseSession().getDatasourcePlatform();
if (pl.shouldBindLiterals()) {
Assert.assertEquals("The number of parameters found does not match the number supplied", 4, call.getParameters().size());
} else {
Assert.assertEquals("The number of parameters found does not match the number supplied", 2, call.getParameters().size());
}
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
if (em.isOpen()) {
em.close();
}
}
em = forceBindEMF.createEntityManager();
try {
// Test the first operand of a LIKE predicate (the match-expression) is untyped parameter
// when at least one other operand (the pattern-expression or escape-expression)
// is not an untyped parameter marker
TypedQuery<GenericEntity> query = em.createQuery("SELECT 1 FROM GenericEntity s " + "WHERE s.itemString1 LIKE ?2", GenericEntity.class);
query.setParameter(2, "HELLO%");
query.getResultList();
DatabaseCall call = ((JpaQuery<GenericEntity>) query).getDatabaseQuery().getCall();
Assert.assertFalse("Expected query parameter binding to not be set for the DatabaseCall", call.isUsesBindingSet());
DatabasePlatform pl = (DatabasePlatform) forceBindEMF.unwrap(EntityManagerFactoryImpl.class).getDatabaseSession().getDatasourcePlatform();
if (pl.shouldBindLiterals()) {
Assert.assertEquals("The number of parameters found does not match the number supplied", 2, call.getParameters().size());
} else {
Assert.assertEquals("The number of parameters found does not match the number supplied", 1, call.getParameters().size());
}
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
if (em.isOpen()) {
em.close();
}
}
}
Aggregations