use of org.apache.cayenne.tx.BaseTransaction in project cayenne by apache.
the class DataContextProcedureQueryIT method testUpdateNoParam.
@Test
public void testUpdateNoParam() throws Exception {
if (!accessStackAdapter.supportsStoredProcedures()) {
return;
}
// create an artist with painting in the database
createArtist(1000.0);
ProcedureQuery q = new ProcedureQuery(UPDATE_STORED_PROCEDURE_NOPARAM);
// since stored procedure commits its stuff, we must use an explicit
// non-committing transaction
BaseTransaction t = new ExternalTransaction(jdbcEventLogger);
BaseTransaction.bindThreadTransaction(t);
try {
context.performGenericQuery(q);
} finally {
BaseTransaction.bindThreadTransaction(null);
t.commit();
}
// check that price have doubled
SelectQuery select = new SelectQuery(Artist.class);
select.addPrefetch("paintingArray");
List<?> artists = context.performQuery(select);
assertEquals(1, artists.size());
Artist a = (Artist) artists.get(0);
Painting p = a.getPaintingArray().get(0);
assertEquals(2000, p.getEstimatedPrice().intValue());
}
use of org.apache.cayenne.tx.BaseTransaction in project cayenne by apache.
the class ProcedureCallIT method runProcedureSelect.
protected <T> ProcedureResult<T> runProcedureSelect(ProcedureCall<T> q) throws Exception {
// Sybase blows whenever a transaction wraps a SP, so turn off
// transactions
// TODO: it is quite the opposite with PostgreSQL. If an SP returns an
// open refcursor, it actually expects a TX in progress, so while we
// don't have refcursor unit tests, this is something to keep in mind
// e.g.
// http://stackoverflow.com/questions/16921942/porting-apache-cayenne-from-oracle-to-postgresql
BaseTransaction t = new ExternalTransaction(jdbcEventLogger);
BaseTransaction.bindThreadTransaction(t);
try {
return q.call(context);
} finally {
BaseTransaction.bindThreadTransaction(null);
t.commit();
}
}
use of org.apache.cayenne.tx.BaseTransaction in project cayenne by apache.
the class MappedQueryIT method runProcedureSelect.
protected QueryResponse runProcedureSelect(AbstractMappedQuery q) throws Exception {
// Sybase blows whenever a transaction wraps a SP, so turn off
// transactions
// TODO: it is quite the opposite with PostgreSQL. If an SP returns an
// open refcursor, it actually expects a TX in progress, so while we
// don't have refcursor unit tests, this is something to keep in mind
// e.g.
// http://stackoverflow.com/questions/16921942/porting-apache-cayenne-from-oracle-to-postgresql
BaseTransaction t = new ExternalTransaction(jdbcEventLogger);
BaseTransaction.bindThreadTransaction(t);
try {
return context.performGenericQuery(q);
} finally {
BaseTransaction.bindThreadTransaction(null);
t.commit();
}
}
use of org.apache.cayenne.tx.BaseTransaction in project cayenne by apache.
the class DataContextProcedureQueryIT method testUpdate.
@Test
public void testUpdate() throws Exception {
if (!accessStackAdapter.supportsStoredProcedures()) {
return;
}
// create an artist with painting in the database
createArtist(1000.0);
ProcedureQuery q = new ProcedureQuery(UPDATE_STORED_PROCEDURE);
q.addParameter("paintingPrice", new Integer(3000));
// since stored procedure commits its stuff, we must use an explicit
// non-committing transaction
BaseTransaction t = new ExternalTransaction(jdbcEventLogger);
BaseTransaction.bindThreadTransaction(t);
try {
context.performGenericQuery(q);
} finally {
BaseTransaction.bindThreadTransaction(null);
t.commit();
}
// check that price have doubled
SelectQuery select = new SelectQuery(Artist.class);
select.addPrefetch("paintingArray");
List<?> artists = context.performQuery(select);
assertEquals(1, artists.size());
Artist a = (Artist) artists.get(0);
Painting p = a.getPaintingArray().get(0);
assertEquals(2000, p.getEstimatedPrice().intValue());
}
use of org.apache.cayenne.tx.BaseTransaction in project cayenne by apache.
the class DataContextProcedureQueryIT method runProcedureSelect.
protected List<DataRow> runProcedureSelect(ProcedureQuery q) throws Exception {
// Sybase blows whenever a transaction wraps a SP, so turn off
// transactions
// TODO: it is quite the opposite with PostgreSQL. If an SP returns an
// open refcursor, it actually expects a TX in progress, so while we
// don't have refcursor unit tests, this is something to keep in mind
// e.g.
// http://stackoverflow.com/questions/16921942/porting-apache-cayenne-from-oracle-to-postgresql
BaseTransaction t = new ExternalTransaction(jdbcEventLogger);
BaseTransaction.bindThreadTransaction(t);
try {
return context.performQuery(q);
} finally {
BaseTransaction.bindThreadTransaction(null);
t.commit();
}
}
Aggregations