use of org.eclipse.persistence.testing.framework.TestWarningException in project eclipselink by eclipse-ee4j.
the class UnitOfWorkComplexRefreshTest method setup.
@Override
public void setup() {
if (getSession().isClientSession()) {
listener = checkTransactionIsolation();
}
if (getSession().isRemoteSession() && getSession().getDatasourcePlatform().isDerby()) {
throw new TestWarningException("This test uses functionality that does not work over remote sessions in Apache Derby.");
}
getAbstractSession().beginTransaction();
uow1 = getSession().acquireUnitOfWork();
uow2 = getSession().acquireUnitOfWork();
Expression exp = new ExpressionBuilder().get("firstName").equal("Charles");
dbEmployee1 = (Employee) uow1.readObject(Employee.class, exp);
dbEmployee2 = (Employee) uow2.readObject(Employee.class, exp);
dbEmployee1.getAddress().setCity("Bobstown");
}
use of org.eclipse.persistence.testing.framework.TestWarningException in project eclipselink by eclipse-ee4j.
the class UnitOfWorkRevertAndResumeWithNewTest method test.
@Override
protected void test() {
if (getSession().isDistributedSession()) {
throw new TestWarningException("Test unavailable on Remote UnitOfWork");
}
if (getSession().getPlatform().isPostgreSQL()) {
throwWarning("Postgres aborts transaction after error.");
}
UnitOfWork uow = getSession().acquireUnitOfWork();
Vector results = uow.readAllObjects(Employee.class);
Address address = new Address();
address.setId(this.addressId);
address.setStreet("Wallace");
address.setCity("Wallace");
address = (Address) uow.registerObject(address);
Employee emp = (Employee) results.firstElement();
emp.setAddress(address);
try {
uow.commitAndResume();
// Exception expected because Emp with null PK
} catch (Exception e) {
uow.revertAndResume();
}
results = uow.readAllObjects(Employee.class);
address = new Address();
address.setStreet("Wallace2");
address.setCity("Wallace2");
address = (Address) uow.registerObject(address);
emp = (Employee) results.firstElement();
emp.setAddress(address);
uow.commitAndResume();
}
use of org.eclipse.persistence.testing.framework.TestWarningException in project eclipselink by eclipse-ee4j.
the class PredefinedQueryToUpperOnParameterTest method setup.
@Override
protected void setup() {
if (getSession().getLogin().getDatasourcePlatform().isDB2()) {
throw new TestWarningException("DB2 doesn't support UCASE() on Parameter");
}
ExpressionBuilder builder = new ExpressionBuilder();
Expression firstNameExpression = builder.get("firstName").toUpperCase().equal((builder.getParameter("firstName").toUpperCase()));
Expression lastNameExpression = builder.get("lastName").equal(builder.getParameter("lastName"));
ReadObjectQuery query = new ReadObjectQuery();
query.setReferenceClass(Employee.class);
query.setSelectionCriteria(firstNameExpression.and(lastNameExpression));
query.addArgument("firstName");
query.addArgument("lastName");
ClassDescriptor descriptor;
if (getSession() instanceof org.eclipse.persistence.sessions.remote.RemoteSession) {
descriptor = org.eclipse.persistence.testing.tests.remote.RemoteModel.getServerSession().getDescriptor(Employee.class);
} else {
descriptor = getSession().getDescriptor(Employee.class);
}
getSession().removeQuery("getEmployee");
descriptor.getQueryManager().addQuery("getEmployee", query);
}
use of org.eclipse.persistence.testing.framework.TestWarningException in project eclipselink by eclipse-ee4j.
the class UnwrapConnectionBaseTestModel 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();
}
use of org.eclipse.persistence.testing.framework.TestWarningException in project eclipselink by eclipse-ee4j.
the class ReadNcharTest method setup.
@Override
@SuppressWarnings("deprecation")
protected void setup() {
super.setup();
// #Bug5200836, the added line ensures the connection is available when tests being switched
// from the corresponding unwrapConnectionTestModel to this model.
((AbstractSession) getSession()).getAccessor().incrementCallCount((AbstractSession) getSession());
java.sql.ResultSet resultSet = null;
try {
java.sql.DatabaseMetaData metaData = ((AbstractSession) getSession()).getAccessor().getConnection().getMetaData();
/*"TEST"*/
resultSet = metaData.getColumns(null, null, "CHARNCHAR", null);
int i = 1;
while (resultSet.next()) {
resultSet.getString("COLUMN_NAME");
// TYPE_NAME String => Data source dependent type name,
resultSet.getString("TYPE_NAME");
i++;
}
} catch (java.sql.SQLException sqlException) {
}
// insert directly an NCHAR-containing record into the db
// obtain an id to use
int id = getSession().getNextSequenceNumberValue(CharNchar.class).intValue();
char ch = 'a';
char nCh = '\u4010';
int stringSize = 5;
// It is important that clobSize1 < 4K (or 5.9K?)
int clobSize1 = 5;
// clobSize2 is arbitrary
int clobSize2 = 8000;
controlObject = new CharNchar(ch, nCh, stringSize, clobSize1, clobSize2);
controlObject.setId(id);
try {
Connection originConnection = ((AbstractSession) getSession()).getAccessor().getConnection();
Connection unWrappedConnection;
if (originConnection instanceof TestOracleConnection) {
unWrappedConnection = ((TestOracleConnection) originConnection).getPhysicalConnection();
} else {
unWrappedConnection = originConnection;
}
oracle.jdbc.OraclePreparedStatement pstmt;
pstmt = (oracle.jdbc.OraclePreparedStatement) unWrappedConnection.prepareStatement("insert into CHARNCHAR (ID,CH,NCH,STR,NSTR,CLB,NCLB,CLB2,NCLB2) values(?,?,?,?,?,?,?,?,?)");
pstmt.setInt(1, controlObject.getId());
pstmt.setObject(2, controlObject.getChar().toString());
pstmt.setFormOfUse(3, oracle.jdbc.OraclePreparedStatement.FORM_NCHAR);
pstmt.setObject(3, controlObject.getNchar().toString());
pstmt.setObject(4, controlObject.getStr());
pstmt.setFormOfUse(5, oracle.jdbc.OraclePreparedStatement.FORM_NCHAR);
pstmt.setObject(5, controlObject.getNstr());
// Also possible:
// pstmt.setCharacterStream(6, new java.io.CharArrayReader(controlObject.getClob()), controlObject.getClob().length);
pstmt.setObject(6, new String(controlObject.getClob()));
pstmt.setFormOfUse(7, oracle.jdbc.OraclePreparedStatement.FORM_NCHAR);
// Also possible:
// pstmt.setCharacterStream(7, new java.io.CharArrayReader(controlObject.getNclob()), controlObject.getNclob().length);
pstmt.setObject(7, new String(controlObject.getNclob()));
// insert a dummy empty CLOB
pstmt.setObject(8, " ");
// insert a dummy empty NCLOB
pstmt.setFormOfUse(9, oracle.jdbc.OraclePreparedStatement.FORM_NCHAR);
pstmt.setObject(9, " ");
pstmt.execute();
pstmt.close();
// Handle clob2, nClob2
getAbstractSession().beginTransaction();
java.sql.Statement stmt = ((AbstractSession) getSession()).getAccessor().getConnection().createStatement();
java.sql.ResultSet clobs = stmt.executeQuery("select CLB2, NCLB2 from CHARNCHAR " + "where ID = '" + controlObject.getId() + "' for update");
if (clobs.next()) {
oracle.sql.CLOB clob = (oracle.sql.CLOB) clobs.getObject("CLB2");
java.io.Writer clobWriter = clob.getCharacterOutputStream();
clobWriter.write(controlObject.getClob2(), 0, controlObject.getClob2().length);
clobWriter.close();
oracle.sql.CLOB nclob = (oracle.sql.CLOB) clobs.getObject("NCLB2");
java.io.Writer nclobWriter = nclob.getCharacterOutputStream();
nclobWriter.write(controlObject.getNclob2(), 0, controlObject.getNclob2().length);
nclobWriter.close();
}
clobs.close();
stmt.close();
getAbstractSession().commitTransaction();
} catch (java.sql.SQLException ex) {
// attempt to write a "big" CLOB (>4K? >5.9K?) in "small" way may cause disconnection
boolean disconnected = false;
try {
if (!getAbstractSession().isInTransaction()) {
getAbstractSession().beginTransaction();
}
getAbstractSession().rollbackTransaction();
} catch (org.eclipse.persistence.exceptions.DatabaseException ex2) {
disconnected = true;
}
if (disconnected) {
((AbstractSession) getSession()).setAccessor(getSession().getLogin().buildAccessor());
((org.eclipse.persistence.sessions.DatabaseSession) getSession()).login();
}
throw new TestWarningException("Failed to insert a new record into the db. Internal java.sql.Exception: " + ex.getMessage());
} catch (java.io.IOException exIO) {
if (getAbstractSession().isInTransaction()) {
getAbstractSession().rollbackTransaction();
}
throw new TestWarningException("Failed to insert a new record into the db. Internal java.io.IOException: " + exIO.getMessage());
}
((AbstractSession) getSession()).getAccessor().decrementCallCount();
}
Aggregations