* @return The iterator
*/
public Iterator findByOQL(String query, Object[] queryParams) throws Exception
{
OTMKit kit = SimpleKit.getInstance();
OTMConnection conn = null;
Transaction tx = null;
try
{
conn = kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
tx = kit.getTransaction(conn);
OQLQuery oql = conn.newOQLQuery();
oql.create(query);
if (queryParams != null)
{
for (int idx = 0; idx < queryParams.length; ++idx)
{
oql.bind(queryParams[idx]);
}
}
tx.begin();
Iterator results = conn.getIteratorByOQLQuery(oql);
tx.commit();
return results;
}
catch (QueryInvalidException ex)
{
if (tx.isInProgress())
{
tx.rollback();
}
throw new Exception("Invalid OQl expression given");
}
catch (QueryParameterCountInvalidException ex)
{
if (tx.isInProgress())
{
tx.rollback();
}
throw new Exception("Incorrect number of bindings given");
}
catch (QueryParameterTypeInvalidException ex)
{
if (tx.isInProgress())
{
tx.rollback();
}
throw new Exception("Incorrect type of object given as binding");
}
finally
{
conn.close();
}
}