Revision: 9141
http://datanucleus.svn.sourceforge.net/datanucleus/?rev=9141&view=rev
Author: andy_jefferson
Date: 2010-03-13 11:29:53 +0000 (Sat, 13 Mar 2010)
Log Message:
-----------
Catch any SQLException thrown by ps.cancel since some JDBC can't be bothered to implement it
Modified Paths:
--------------
platform/store.rdbms/trunk/src/java/org/datanucleus/store/rdbms/query/JDOQLQuery.java
Modified: platform/store.rdbms/trunk/src/java/org/datanucleus/store/rdbms/query/JDOQLQuery.java
===================================================================
--- platform/store.rdbms/trunk/src/java/org/datanucleus/store/rdbms/query/JDOQLQuery.java 2010-03-13 10:43:19 UTC (rev 9140)
+++ platform/store.rdbms/trunk/src/java/org/datanucleus/store/rdbms/query/JDOQLQuery.java 2010-03-13 11:29:53 UTC (rev 9141)
@@ -295,7 +295,6 @@
}
Object stmtMap = resultMapping.getMappingForResultExpression(0);
- NucleusLogger.GENERAL.info(">> JDOQLQuery.compileInternal stmtMap=" + stmtMap);
if (stmtMap instanceof StatementMappingIndex)
{
StatementMappingIndex idx = (StatementMappingIndex)stmtMap;
@@ -518,148 +517,148 @@
RDBMSStoreManager storeMgr = (RDBMSStoreManager)getStoreManager();
ClassLoaderResolver clr = om.getClassLoaderResolver();
AbstractClassMetaData acmd = getObjectManager().getMetaDataManager().getMetaDataForClass(candidateClass, clr);
+ SQLController sqlControl = storeMgr.getSQLController();
+ PreparedStatement ps = null;
try
{
- SQLController sqlControl = storeMgr.getSQLController();
- PreparedStatement ps = null;
- try
+ if (type == Query.SELECT)
{
- if (type == Query.SELECT)
+ // Create PreparedStatement and apply parameters, result settings etc
+ ps = RDBMSQueryUtils.getPreparedStatementForQuery(mconn,
+ datastoreCompilation.getSQL(), this);
+ SQLStatementHelper.applyParametersToStatement(ps, om,
+ datastoreCompilation.getStatementParameters(), parameters);
+ RDBMSQueryUtils.prepareStatementForExecution(ps, this, false);
+
+ // Execute the query as a task so we can allow timeout/cancel
+ ResultSet rs = (ResultSet)performExecuteTask(new Object[] {sqlControl, mconn, ps});
+
+ QueryResult qr = null;
+ try
{
- // Create PreparedStatement and apply parameters, result settings etc
- ps = RDBMSQueryUtils.getPreparedStatementForQuery(mconn,
- datastoreCompilation.getSQL(), this);
- SQLStatementHelper.applyParametersToStatement(ps, om,
- datastoreCompilation.getStatementParameters(), parameters);
- RDBMSQueryUtils.prepareStatementForExecution(ps, this, false);
+ if (inMemory)
+ {
+ // IN-MEMORY EVALUATION
+ ResultObjectFactory rof = storeMgr.newResultObjectFactory(acmd,
+ datastoreCompilation.getResultDefinitionForClass(),
+ RDBMSQueryUtils.useUpdateLockForQuery(this), getFetchPlan(),
+ candidateClass);
- // Execute the query as a task so we can allow timeout/cancel
- ResultSet rs = (ResultSet)performExecuteTask(new Object[] {sqlControl, mconn, ps});
+ // Just instantiate the candidates for later in-memory processing
+ // TODO Use a queryResult rather than an ArrayList so we load when required
+ List candidates = new ArrayList();
+ while (rs.next())
+ {
+ candidates.add(rof.getObject(om, rs));
+ }
- QueryResult qr = null;
- try
+ // Perform in-memory filter/result/order etc
+ JavaQueryEvaluator resultMapper =
+ new JDOQLEvaluator(this, candidates, compilation, parameters, clr);
+ results = resultMapper.execute(true, true, true, true, true);
+ }
+ else
{
- if (inMemory)
+ // IN-DATASTORE EVALUATION
+ ResultObjectFactory rof = null;
+ if (result != null)
{
- // IN-MEMORY EVALUATION
- ResultObjectFactory rof = storeMgr.newResultObjectFactory(acmd,
+ // Each result row is of a result type
+ rof = new ResultClassROF(resultClass, datastoreCompilation.getResultDefinition());
+ }
+ else if (resultClass != null)
+ {
+ rof = new ResultClassROF(resultClass, datastoreCompilation.getResultDefinitionForClass());
+ }
+ else
+ {
+ // Each result row is a candidate object
+ rof = storeMgr.newResultObjectFactory(acmd,
datastoreCompilation.getResultDefinitionForClass(),
RDBMSQueryUtils.useUpdateLockForQuery(this), getFetchPlan(),
candidateClass);
+ }
- // Just instantiate the candidates for later in-memory processing
- // TODO Use a queryResult rather than an ArrayList so we load when required
- List candidates = new ArrayList();
- while (rs.next())
- {
- candidates.add(rof.getObject(om, rs));
- }
-
- // Perform in-memory filter/result/order etc
- JavaQueryEvaluator resultMapper =
- new JDOQLEvaluator(this, candidates, compilation, parameters, clr);
- results = resultMapper.execute(true, true, true, true, true);
+ // Create the required type of QueryResult
+ String resultSetType = RDBMSQueryUtils.getResultSetTypeForQuery(this);
+ if (resultSetType.equals("scroll-insensitive") ||
+ resultSetType.equals("scroll-sensitive"))
+ {
+ qr = new ScrollableQueryResult(this, rof, rs,
+ getResultDistinct() ? null : candidateCollection);
}
else
{
- // IN-DATASTORE EVALUATION
- ResultObjectFactory rof = null;
- if (result != null)
- {
- // Each result row is of a result type
- rof = new ResultClassROF(resultClass, datastoreCompilation.getResultDefinition());
- }
- else if (resultClass != null)
- {
- rof = new ResultClassROF(resultClass, datastoreCompilation.getResultDefinitionForClass());
- }
- else
- {
- // Each result row is a candidate object
- rof = storeMgr.newResultObjectFactory(acmd,
- datastoreCompilation.getResultDefinitionForClass(),
- RDBMSQueryUtils.useUpdateLockForQuery(this), getFetchPlan(),
- candidateClass);
- }
+ qr = new ForwardQueryResult(this, rof, rs,
+ getResultDistinct() ? null : candidateCollection);
+ }
- // Create the required type of QueryResult
- String resultSetType = RDBMSQueryUtils.getResultSetTypeForQuery(this);
- if (resultSetType.equals("scroll-insensitive") ||
- resultSetType.equals("scroll-sensitive"))
+ final QueryResult qr1 = qr;
+ final ManagedConnection mconn1 = mconn;
+ ManagedConnectionResourceListener listener =
+ new ManagedConnectionResourceListener()
+ {
+ public void managedConnectionPreClose(){}
+ public void managedConnectionPostClose(){}
+ public void managedConnectionFlushed()
{
- qr = new ScrollableQueryResult(this, rof, rs,
- getResultDistinct() ? null : candidateCollection);
+ // Disconnect the query from this ManagedConnection (read in unread rows etc)
+ qr1.disconnect();
}
- else
+ public void resourcePostClose()
{
- qr = new ForwardQueryResult(this, rof, rs,
- getResultDistinct() ? null : candidateCollection);
+ mconn1.removeListener(this);
}
-
- final QueryResult qr1 = qr;
- final ManagedConnection mconn1 = mconn;
- ManagedConnectionResourceListener listener =
- new ManagedConnectionResourceListener()
- {
- public void managedConnectionPreClose(){}
- public void managedConnectionPostClose(){}
- public void managedConnectionFlushed()
- {
- // Disconnect the query from this ManagedConnection (read in unread rows etc)
- qr1.disconnect();
- }
- public void resourcePostClose()
- {
- mconn1.removeListener(this);
- }
- };
- mconn.addListener(listener);
- ((AbstractRDBMSQueryResult)qr).addConnectionListener(listener);
- results = qr;
- }
+ };
+ mconn.addListener(listener);
+ ((AbstractRDBMSQueryResult)qr).addConnectionListener(listener);
+ results = qr;
}
- finally
+ }
+ finally
+ {
+ if (qr == null)
{
- if (qr == null)
- {
- rs.close();
- }
+ rs.close();
}
}
- else if (type == Query.BULK_UPDATE)
- {
- // Create PreparedStatement and apply parameters, result settings etc
- ps = sqlControl.getStatementForUpdate(mconn, datastoreCompilation.getSQL(), false);
- SQLStatementHelper.applyParametersToStatement(ps, om,
- datastoreCompilation.getStatementParameters(), parameters);
- RDBMSQueryUtils.prepareStatementForExecution(ps, this, false);
+ }
+ else if (type == Query.BULK_UPDATE)
+ {
+ // Create PreparedStatement and apply parameters, result settings etc
+ ps = sqlControl.getStatementForUpdate(mconn, datastoreCompilation.getSQL(), false);
+ SQLStatementHelper.applyParametersToStatement(ps, om,
+ datastoreCompilation.getStatementParameters(), parameters);
+ RDBMSQueryUtils.prepareStatementForExecution(ps, this, false);
- // Execute the query as a task so we can allow timeout/cancel
- results = performExecuteTask(new Object[] {sqlControl, mconn, ps});
- }
- else if (type == Query.BULK_DELETE)
- {
- // Create PreparedStatement and apply parameters, result settings etc
- // TODO Cater for multiple DELETE statements
- ps = sqlControl.getStatementForUpdate(mconn, datastoreCompilation.getSQL(), false);
- SQLStatementHelper.applyParametersToStatement(ps, om,
- datastoreCompilation.getStatementParameters(), parameters);
- RDBMSQueryUtils.prepareStatementForExecution(ps, this, false);
+ // Execute the query as a task so we can allow timeout/cancel
+ results = performExecuteTask(new Object[] {sqlControl, mconn, ps});
+ }
+ else if (type == Query.BULK_DELETE)
+ {
+ // Create PreparedStatement and apply parameters, result settings etc
+ // TODO Cater for multiple DELETE statements
+ ps = sqlControl.getStatementForUpdate(mconn, datastoreCompilation.getSQL(), false);
+ SQLStatementHelper.applyParametersToStatement(ps, om,
+ datastoreCompilation.getStatementParameters(), parameters);
+ RDBMSQueryUtils.prepareStatementForExecution(ps, this, false);
- // Execute the query as a task so we can allow timeout/cancel
- results = performExecuteTask(new Object[] {sqlControl, mconn, ps});
- }
+ // Execute the query as a task so we can allow timeout/cancel
+ results = performExecuteTask(new Object[] {sqlControl, mconn, ps});
}
- catch (QueryInterruptedException qie)
+ }
+ catch (QueryInterruptedException qie)
+ {
+ // Execution was cancelled so cancel the PreparedStatement
+ try
{
- // Execution was cancelled so cancel the PreparedStatement
ps.cancel();
- throw qie;
}
catch (SQLException sqle)
{
- throw new NucleusException(LOCALISER.msg("021042"), sqle);
+ // Some JDBC are too lazy to implement this
}
+ throw qie;
}
catch (SQLException sqle)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|