Search in sources :

Example 26 with TestWarningException

use of org.eclipse.persistence.testing.framework.TestWarningException in project eclipselink by eclipse-ee4j.

the class ErrorOnInsertTest method test.

@Override
protected void test() {
    if (getSession().isClientSession() || getSession().isDistributedSession()) {
        throw new TestWarningException("Unable to trigger error in ClientSession or Remote UnitOfWork");
    }
    mary = new Employee();
    mary.setFirstName("Mary");
    mary.setLastName("Magdalene");
    mary.setId(new BigDecimal(100002929));
    mary.setPeriod(new EmploymentPeriod(new Date(3), new Date(3455)));
    UnitOfWorkImpl uow = (UnitOfWorkImpl) getSession().acquireUnitOfWork();
    DatabaseAccessor accessor = (DatabaseAccessor) uow.getParent().getAccessor();
    uow.getParent().setAccessor(new DummyAccessor(accessor));
    Employee maryClone = (Employee) uow.registerObject(mary);
    UnitOfWorkChangeSet uowcs = (UnitOfWorkChangeSet) uow.getCurrentChanges();
    try {
        uow.commitAndResumeWithPreBuiltChangeSet(uowcs);
    } catch (Exception ex) {
    }
    uow.revertAndResume();
    uow.getParent().setAccessor(accessor);
    try {
        uow.commitAndResumeWithPreBuiltChangeSet(uowcs);
    } catch (QueryException ex) {
        if (ex.getErrorCode() == 6004) {
            throw new TestErrorException("New Object was not inserted because cachekey was not removed");
        } else {
            throw ex;
        }
    }
    uow.commit();
}
Also used : EmploymentPeriod(org.eclipse.persistence.testing.models.employee.domain.EmploymentPeriod) QueryException(org.eclipse.persistence.exceptions.QueryException) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) UnitOfWorkChangeSet(org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) UnitOfWorkImpl(org.eclipse.persistence.internal.sessions.UnitOfWorkImpl) DatabaseAccessor(org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor) BigDecimal(java.math.BigDecimal) Date(java.sql.Date) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) TestWarningException(org.eclipse.persistence.testing.framework.TestWarningException) QueryException(org.eclipse.persistence.exceptions.QueryException) DatabaseException(org.eclipse.persistence.exceptions.DatabaseException) TestWarningException(org.eclipse.persistence.testing.framework.TestWarningException)

Example 27 with TestWarningException

use of org.eclipse.persistence.testing.framework.TestWarningException in project eclipselink by eclipse-ee4j.

the class NestedUnitOfWorkReadOnlyClassTest method setup.

@Override
public void setup() {
    if (!isSequenceNumberEnabled()) {
        throw new TestWarningException("This test uses sequence numbers.");
    }
    getAbstractSession().beginTransaction();
    postalCode = "AB7J98";
    UnitOfWork uow = getSession().acquireUnitOfWork();
    Address address = (Address) uow.registerObject(new Address());
    uow.assignSequenceNumber(address);
    address.setPostalCode(postalCode);
    address.setCity("Toronto");
    address.setCountry("CANADA");
    uow.commit();
    getAbstractSession().commitTransaction();
    originalAddress = address;
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Address(org.eclipse.persistence.testing.models.employee.domain.Address) TestWarningException(org.eclipse.persistence.testing.framework.TestWarningException)

Example 28 with TestWarningException

use of org.eclipse.persistence.testing.framework.TestWarningException in project eclipselink by eclipse-ee4j.

the class ShouldPrepareTest method setup.

@Override
public void setup() {
    if (getSession().getPlatform().isDB2()) {
        throw new TestWarningException("This test is not supposed to work with DB2. " + org.eclipse.persistence.internal.helper.Helper.cr() + "\t\tBecause as expected, sql string contains (t0.F_NAME = NULL) when the query is executed the second time with argument null, and '=NULL' is illegal syntax on DB2." + org.eclipse.persistence.internal.helper.Helper.cr() + "\t\tHence, executing the query would result in runtime exception.");
    }
    query = (ReadObjectQuery) getSession().getDescriptor(org.eclipse.persistence.testing.models.employee.domain.Employee.class).getQueryManager().getQuery("shouldPrepareQuery");
    queryCopy = (ReadObjectQuery) query.clone();
    ExpressionBuilder ex = new ExpressionBuilder();
    queryCopy.setSelectionCriteria(ex.get("firstName").equal(ex.getParameter("firstName1")));
    queryCopy.addArgument("firstName1");
    vec = new Vector();
    vec.add("Bob");
    getSession().executeQuery(queryCopy, vec);
}
Also used : ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) Vector(java.util.Vector) TestWarningException(org.eclipse.persistence.testing.framework.TestWarningException)

Example 29 with TestWarningException

use of org.eclipse.persistence.testing.framework.TestWarningException in project eclipselink by eclipse-ee4j.

the class UnwrapConnectionCustomSQLTestModel method setup.

@Override
public void setup() {
    if (!getSession().getPlatform().isOracle()) {
        throw new TestWarningException("WARNING: This model is not supposed to be run on databases other than Oracle.");
    }
    DatabaseSession session = (DatabaseSession) getSession();
    session.logout();
    // save the connector to restore later
    originalConnector = session.getLogin().getConnector();
    DataSource dataSource = new TestOracleDataSource(session.getLogin().getDriverClassName(), session.getLogin().getConnectionString(), (Properties) session.getLogin().getProperties().clone());
    session.getLogin().setConnector(new JNDIConnector(dataSource));
    originalServerPlatform = session.getServerPlatform();
    session.setServerPlatform(new TestServerPlatform(session));
    originalShouldUseExternalConnectionPooling = session.getLogin().shouldUseExternalConnectionPooling();
    session.getLogin().useExternalConnectionPooling();
    session.login();
    super.setup();
}
Also used : DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) JNDIConnector(org.eclipse.persistence.sessions.JNDIConnector) TestWarningException(org.eclipse.persistence.testing.framework.TestWarningException) DataSource(javax.sql.DataSource)

Aggregations

TestWarningException (org.eclipse.persistence.testing.framework.TestWarningException)29 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)9 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)7 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)5 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)4 BigDecimal (java.math.BigDecimal)3 Vector (java.util.Vector)3 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)3 Employee (org.eclipse.persistence.testing.models.employee.domain.Employee)3 DataSource (javax.sql.DataSource)2 DatabasePlatform (org.eclipse.persistence.internal.databaseaccess.DatabasePlatform)2 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)2 ReportQuery (org.eclipse.persistence.queries.ReportQuery)2 ScrollableCursor (org.eclipse.persistence.queries.ScrollableCursor)2 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)2 JNDIConnector (org.eclipse.persistence.sessions.JNDIConnector)2 TestProblemException (org.eclipse.persistence.testing.framework.TestProblemException)2 Address (org.eclipse.persistence.testing.models.employee.domain.Address)2 Order (org.eclipse.persistence.testing.models.transparentindirection.Order)2 Connection (java.sql.Connection)1