org.jpox.store.rdbms.query
Class BaseSQLQuery

java.lang.Object
  extended byorg.jpox.store.query.Query
      extended byorg.jpox.store.rdbms.query.BaseSQLQuery
All Implemented Interfaces:
javax.jdo.Query, java.io.Serializable
Direct Known Subclasses:
JPOXSQLQuery, SQLQuery

public abstract class BaseSQLQuery
extends Query

Base definition of a query using SQL.

Version:
$Revision: 1.1 $
See Also:
Query, Serialized Form

Nested Class Summary
 
Nested classes inherited from class org.jpox.store.query.Query
Query.ResultObjectFactory
 
Field Summary
protected  java.util.List fieldColumnNames
           
protected  int[] fieldNumbers
           
protected  java.lang.String jdbcSqlText
           
protected static Localiser LOCALISER_RDBMS
          Localiser for messages.
protected  java.lang.String sqlText
           
protected  StatementExpressionIndex[] statementExpressionIndex
           
 
Fields inherited from class org.jpox.store.query.Query
candidateClass, candidateClassName, dba, extensions, fetchPlan, filter, fromInclNo, grouping, ignoreCache, imports, isCompiled, isPreCompile, LOCALISER, ordering, parameterNames, parameters, parameterTypesByName, parsedImports, pm, queryResults, range, result, resultClass, resultClassName, subclasses, toExclNo, unique, unmodifiable, variableNames, variables, variableTypesByName
 
Fields inherited from interface javax.jdo.Query
JDOQL, SQL
 
Constructor Summary
BaseSQLQuery(PersistenceManager pm, BaseSQLQuery query)
          Constructs a new query instance from the existing query.
BaseSQLQuery(PersistenceManager pm, java.lang.String sql_text)
          Constructs a new query instance having the same criteria as the given query.
 
Method Summary
 void compile()
          Verify the elements of the query and provide a hint to the query to prepare and optimize an execution plan.
 void declareVariables(java.lang.String variables)
          Declare the unbound variables to be used in the query.
protected  void discardCompiled()
          Utility to discard any compiled query.
protected abstract  void generateQueryStatement()
          Convenience method to take the user specified SQL statement, and align it with field names for the candidate class etc.
protected  QueryResult getQueryResultForNoCandidateClass(java.sql.ResultSet rs)
          Utility to take a ResultSet and return a QueryResult for those results, assuming that no candidate class is supplied.
protected  long performDeletePersistentAll(java.util.Map parameters)
          Execute the query to delete persistent objects.
abstract  java.util.Collection performExecute(java.util.Map parameters)
          Execute the query and return the filtered QueryResult.
 void setCandidates(java.util.Collection pcs)
          Set the candidate Collection to query.
 void setCandidates(javax.jdo.Extent pcs)
          Set the candidate Extent to query.
 void setFilter(java.lang.String filter)
          Set the filter for the query.
 void setGrouping(java.lang.String grouping)
          Set the grouping specification for the result Collection.
 void setOrdering(java.lang.String ordering)
          Set the ordering specification for the result Collection.
 void setRange(int fromIncl, int toExcl)
          Set the range of the results.
 void setResult(java.lang.String result)
          Set the result for the results.
 void setSubclasses(boolean subclasses)
          Method to set whether to use subclasses.
protected  boolean shouldReturnSingleRow()
          Convenience method to return whether the query should return a single row.
 
Methods inherited from class org.jpox.store.query.Query
addExtension, assertIsModifiable, close, closeAll, declareImports, declareParameters, deletePersistentAll, deletePersistentAll, deletePersistentAll, equals, execute, execute, execute, execute, executeQuery, executeWithArray, executeWithMap, getCandidateClass, getCandidateLoader, getExtension, getFetchPlan, getIgnoreCache, getPersistenceManager, getResultSetConcurrency, getResultSetType, getStatement, getStatement, getStoreManager, hashCode, isSubclasses, isUnmodifiable, prepareStatementForExecution, resolveClassDeclaration, setCandidateClassName, setClass, setExtensions, setIgnoreCache, setRange, setRange, setResultClass, setResultClassName, setUnique, setUnmodifiable
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER_RDBMS

protected static final Localiser LOCALISER_RDBMS
Localiser for messages.


sqlText

protected final transient java.lang.String sqlText

jdbcSqlText

protected transient java.lang.String jdbcSqlText

fieldNumbers

protected transient int[] fieldNumbers

fieldColumnNames

protected transient java.util.List fieldColumnNames

statementExpressionIndex

protected transient StatementExpressionIndex[] statementExpressionIndex
Constructor Detail

BaseSQLQuery

public BaseSQLQuery(PersistenceManager pm,
                    BaseSQLQuery query)
Constructs a new query instance from the existing query.

Parameters:
pm - Persistence Manager
query - Existing query

BaseSQLQuery

public BaseSQLQuery(PersistenceManager pm,
                    java.lang.String sql_text)
Constructs a new query instance having the same criteria as the given query.

Parameters:
pm - The PersistenceManager
sql_text - The SQL query string
Method Detail

discardCompiled

protected void discardCompiled()
Utility to discard any compiled query.

Overrides:
discardCompiled in class Query
See Also:
Query.discardCompiled()

shouldReturnSingleRow

protected boolean shouldReturnSingleRow()
Convenience method to return whether the query should return a single row.

Specified by:
shouldReturnSingleRow in class Query
Returns:
Whether a single row should result

setCandidates

public void setCandidates(javax.jdo.Extent pcs)
Set the candidate Extent to query.

This implementation always throws a JDOUserException since this concept doesn't apply to SQL queries.

Specified by:
setCandidates in interface javax.jdo.Query
Specified by:
setCandidates in class Query
Parameters:
pcs - the Candidate Extent.
Throws:
javax.jdo.JDOUserException - Always thrown.
See Also:
Query.setCandidates(javax.jdo.Extent)

setCandidates

public void setCandidates(java.util.Collection pcs)
Set the candidate Collection to query.

This implementation always throws a JDOUserException since this concept doesn't apply to SQL queries.

Specified by:
setCandidates in interface javax.jdo.Query
Specified by:
setCandidates in class Query
Parameters:
pcs - the Candidate collection.
Throws:
javax.jdo.JDOUserException - Always thrown.
See Also:
Query.setCandidates(java.util.Collection)

setResult

public void setResult(java.lang.String result)
Set the result for the results. The application might want to get results from a query that are not instances of the candidate class. The results might be fields of persistent instances, instances of classes other than the candidate class, or aggregates of fields.

This implementation always throws a JDOUserException since this concept doesn't apply to SQL queries.

Specified by:
setResult in interface javax.jdo.Query
Overrides:
setResult in class Query
Parameters:
result - The result parameter consists of the optional keyword distinct followed by a commaseparated list of named result expressions or a result class specification.
Since:
1.1
See Also:
Query.setResult(java.lang.String)

setRange

public void setRange(int fromIncl,
                     int toExcl)
Set the range of the results. Not applicable to SQL/JPOXSQL queries.

Parameters:
fromIncl - From element no (inclusive) to return
toExcl - To element no (exclusive) to return
Since:
1.1
See Also:
Query.setRange(long, long)

setSubclasses

public void setSubclasses(boolean subclasses)
Method to set whether to use subclasses. This is not used with JPOXSQL.

Overrides:
setSubclasses in class Query
Parameters:
subclasses - Whether to use subclasses

setFilter

public void setFilter(java.lang.String filter)
Set the filter for the query.

This implementation always throws a JDOUserException since this concept doesn't apply to SQL queries.

Specified by:
setFilter in interface javax.jdo.Query
Overrides:
setFilter in class Query
Parameters:
filter - the query filter.
Throws:
javax.jdo.JDOUserException - Always thrown.
See Also:
Query.setFilter(java.lang.String)

declareVariables

public void declareVariables(java.lang.String variables)
Declare the unbound variables to be used in the query.

This implementation always throws a JDOUserException since this concept doesn't apply to SQL queries.

Specified by:
declareVariables in interface javax.jdo.Query
Overrides:
declareVariables in class Query
Parameters:
variables - the variables separated by semicolons.
Throws:
javax.jdo.JDOUserException - Always thrown.
See Also:
Query.declareVariables(java.lang.String)

setGrouping

public void setGrouping(java.lang.String grouping)
Set the grouping specification for the result Collection.

Specified by:
setGrouping in interface javax.jdo.Query
Overrides:
setGrouping in class Query
Parameters:
grouping - the grouping specification.
See Also:
Query.setGrouping(java.lang.String)

setOrdering

public void setOrdering(java.lang.String ordering)
Set the ordering specification for the result Collection.

This implementation always throws a JDOUserException since this concept doesn't apply to SQL queries.

Specified by:
setOrdering in interface javax.jdo.Query
Overrides:
setOrdering in class Query
Parameters:
ordering - the ordering specification.
Throws:
javax.jdo.JDOUserException - Always thrown.
See Also:
Query.setOrdering(java.lang.String)

compile

public void compile()
Verify the elements of the query and provide a hint to the query to prepare and optimize an execution plan.

Specified by:
compile in interface javax.jdo.Query
Overrides:
compile in class Query
See Also:
Query.compile()

generateQueryStatement

protected abstract void generateQueryStatement()
Convenience method to take the user specified SQL statement, and align it with field names for the candidate class etc.


performExecute

public abstract java.util.Collection performExecute(java.util.Map parameters)
Execute the query and return the filtered QueryResult.

Specified by:
performExecute in class Query
Parameters:
parameters - the Map containing all of the parameters.
Returns:
the filtered QueryResult.

getQueryResultForNoCandidateClass

protected QueryResult getQueryResultForNoCandidateClass(java.sql.ResultSet rs)
                                                 throws java.sql.SQLException
Utility to take a ResultSet and return a QueryResult for those results, assuming that no candidate class is supplied. The QueryResult will return either a result class type, or Object/Object[] depending on whether a ResultClass has been defined.

Parameters:
rs - The ResultSet
Returns:
The QueryResult
Throws:
java.sql.SQLException - Thrown when an error occurs creating the QueryResult

performDeletePersistentAll

protected long performDeletePersistentAll(java.util.Map parameters)
Execute the query to delete persistent objects.

Specified by:
performDeletePersistentAll in class Query
Parameters:
parameters - the Map containing all of the parameters.
Returns:
the filtered QueryResult of the deleted objects.


Copyright © -2007 . All Rights Reserved.