_db = _category.getDatabase();
}
public void runTest() throws PersistenceException, SQLException {
OQLQuery oql;
QueryResults enumeration;
Entity object;
_db.begin();
// Determine if test object exists, if not create it.
// If it exists, set the name to some predefined value
// that this test will later override.
oql = _db.getOQLQuery(
"SELECT object FROM " + Entity.class.getName() + " object WHERE id = $1");
oql.bind(50);
enumeration = oql.execute();
if (enumeration.hasMore()) {
object = (Entity) enumeration.next();
LOG.debug("Retrieved object: " + object);
object.setValue1(Entity.DEFAULT_VALUE_1);
object.setValue2(Entity.DEFAULT_VALUE_2);
} else {
object = new Entity();
object.setId(50);
LOG.debug("Creating new object: " + object);
_db.create(object);
}
oql.close();
_db.commit();
try {
LOG.debug("CALL SQL query with object part of an extend hierarchy");
_db.begin();
oql = _db.getOQLQuery("CALL SQL "
+ "SELECT tc3x_entity.id,tc3x_entity.value1,tc3x_entity.value2,"
+ "tc3x_extends.id,tc3x_extends.value3,tc3x_extends.value4 "
+ "FROM tc3x_entity LEFT OUTER JOIN tc3x_extends "
+ "ON tc3x_entity.id=tc3x_extends.id "
+ "WHERE (tc3x_entity.id = $1) AS " + Entity.class.getName());
oql.bind(50);
enumeration = oql.execute();
if (enumeration.hasMore()) {
object = (Entity) enumeration.next();
LOG.debug("Retrieved object: " + object);
} else {
fail("test object not found");
}
oql.close();
_db.commit();
} catch (Exception ex) {
fail("Exception thrown " + ex);
}
LOG.debug("CALL SQL query with simple (stand-alone) object");
_db.begin();
CallEntity test = new CallEntity();
test.setId(55);
test.setValue1("value1");
test.setValue2("value2");
_db.create(test);
_db.commit();
_db.begin();
oql = _db.getOQLQuery(
"CALL SQL SELECT id, value1 , value2 "
+ "FROM tc3x_call WHERE (id = $1) AS " + CallEntity.class.getName());
oql.bind(55);
enumeration = oql.execute();
CallEntity objectEx = null;
if (enumeration.hasMore()) {
objectEx = (CallEntity) enumeration.next();
LOG.debug("Retrieved object: " + objectEx);
} else {
fail("test object not found");
}
oql.close();