to.etc.webapp.query
Class QAbstractDataContext

java.lang.Object
  extended by to.etc.webapp.query.QAbstractDataContext
All Implemented Interfaces:
QDataContext
Direct Known Subclasses:
BuggyHibernateBaseContext

public abstract class QAbstractDataContext
extends java.lang.Object
implements QDataContext

A QDataContext proxy which allows queries to be sent to multiple rendering/selecting implementations. It delegates all query handling to the appropriate query handler.

Author:
Frits Jalvingh Created on Apr 29, 2010

Constructor Summary
protected QAbstractDataContext(QDataContextFactory contextFactory)
           
 
Method Summary
 void attach(java.lang.Object o)
          If the object was from an earlier database session reattach it to another, live session.
 void delete(java.lang.Object o)
          EXPERIMENTAL/NOT FINAL Cause the object to be deleted from the database.
<T> T
find(java.lang.Class<T> clz, java.lang.Object pk)
          Load the persistent object with the specified type and primary key from the database.
<T> T
find(ICriteriaTableDef<T> metatable, java.lang.Object pk)
           
 QDataContextFactory getFactory()
          Returns the context source which created this DataContext.
protected  QQueryExecutorRegistry getHandlerFactory()
           
<T> T
getInstance(java.lang.Class<T> clz, java.lang.Object pk)
          Load the persistent object with the specified type and primary key from the database.
<T> T
getInstance(ICriteriaTableDef<T> metatable, java.lang.Object pk)
           
<T> java.util.List<T>
query(QCriteria<T> q)
          Execute the query specified by q and return a list of results.
 java.util.List<java.lang.Object[]> query(QSelection<?> sel)
          Issue a selection query, where multiple fields or projections on fields are selected from a base class.
<T> T
queryOne(QCriteria<T> q)
          Execute the query specified by q, and expect and return at most 1 result.
 java.lang.Object[] queryOne(QSelection<?> sel)
          Execute the selection query specified by q, and expect and return at most 1 result.
 void refresh(java.lang.Object o)
          EXPERIMENTAL/NOT FINAL Refresh with latest content in the database.
 void save(java.lang.Object o)
          EXPERIMENTAL/NOT FINAL Cause the object to be inserted in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface to.etc.webapp.query.QDataContext
addCommitAction, close, commit, getConnection, inTransaction, rollback, setIgnoreClose, startTransaction
 

Constructor Detail

QAbstractDataContext

protected QAbstractDataContext(QDataContextFactory contextFactory)
Method Detail

getHandlerFactory

protected QQueryExecutorRegistry getHandlerFactory()

getFactory

public QDataContextFactory getFactory()
Returns the context source which created this DataContext. This context source is used to get query listeners to execute when a query is done.

Specified by:
getFactory in interface QDataContext
Returns:

find

public <T> T find(java.lang.Class<T> clz,
                  java.lang.Object pk)
       throws java.lang.Exception
Load the persistent object with the specified type and primary key from the database. This will execute an actual select in the database if the object is not yet cached, ensuring that the object actually exists. If the object does not exist this will return null.

Specified by:
find in interface QDataContext
Type Parameters:
T - The object type.
Parameters:
clz - The persistent class for which an instance is being sought.
pk - The PK for the instance required.
Returns:
Null if the instance does not exist, the actual and fully initialized instance (or proxy) otherwise.
Throws:
java.lang.Exception
See Also:
QDataContext.find(java.lang.Class, java.lang.Object)

find

public <T> T find(ICriteriaTableDef<T> metatable,
                  java.lang.Object pk)
       throws java.lang.Exception
Specified by:
find in interface QDataContext
Throws:
java.lang.Exception

getInstance

public <T> T getInstance(java.lang.Class<T> clz,
                         java.lang.Object pk)
              throws java.lang.Exception
Load the persistent object with the specified type and primary key from the database. This will return an object always even if the object does not exist in the database! This should only be used when you need an instance representing a given primary key that you know exists. This usually returns a proxy, meaning that nonexistent objects will throw exceptions as soon as properties other than it's primary key are accessed. To get an object and be sure it is present in the database use QDataContext.find(Class, Object).

Specified by:
getInstance in interface QDataContext
Type Parameters:
T - The object type
Parameters:
clz - The persistent class for which an instance is being sought.
pk - The PK for the instance required.
Returns:
Always returns an instance; it can be invalid when it does not really exist on the backing store.
Throws:
java.lang.Exception
See Also:
QDataContext.getInstance(java.lang.Class, java.lang.Object)

getInstance

public <T> T getInstance(ICriteriaTableDef<T> metatable,
                         java.lang.Object pk)
              throws java.lang.Exception
Specified by:
getInstance in interface QDataContext
Throws:
java.lang.Exception

query

public <T> java.util.List<T> query(QCriteria<T> q)
                        throws java.lang.Exception
Execute the query specified by q and return a list of results. Before and after the query execution all registered listeners will be called.

Specified by:
query in interface QDataContext
Type Parameters:
T - The return type for this query, a persistent class type
Parameters:
q - The selection criteria
Returns:
Throws:
java.lang.Exception
See Also:
QDataContext.query(to.etc.webapp.query.QCriteria)

query

public java.util.List<java.lang.Object[]> query(QSelection<?> sel)
                                         throws java.lang.Exception
Issue a selection query, where multiple fields or projections on fields are selected from a base class. This overrides the behaviour of Hibernate where a single-column selection does not return an array but that single object, for consistency's sake. It is slightly more expensive because an Object[1] is needed for every row, but compared with the heaps of memory Hibernate is already wasting this is peanuts.

Specified by:
query in interface QDataContext
Returns:
Throws:
java.lang.Exception
See Also:
QDataContext.query(to.etc.webapp.query.QSelection)

queryOne

public <T> T queryOne(QCriteria<T> q)
           throws java.lang.Exception
Execute the query specified by q, and expect and return at most 1 result. If the query has no result this will return null. If more than one result is obtained this will throw an IllegalStateException.

Specified by:
queryOne in interface QDataContext
Returns:
Throws:
java.lang.Exception
See Also:
QDataContext.queryOne(to.etc.webapp.query.QCriteria)

queryOne

public java.lang.Object[] queryOne(QSelection<?> sel)
                            throws java.lang.Exception
Execute the selection query specified by q, and expect and return at most 1 result. If the query has no result this will return null. If more than one result is obtained this will throw an IllegalStateException.

Specified by:
queryOne in interface QDataContext
Returns:
Throws:
java.lang.Exception
See Also:
QDataContext.queryOne(to.etc.webapp.query.QCriteria)

attach

public void attach(java.lang.Object o)
            throws java.lang.Exception
If the object was from an earlier database session reattach it to another, live session.

Specified by:
attach in interface QDataContext
Throws:
java.lang.Exception
See Also:
QDataContext.attach(java.lang.Object)

delete

public void delete(java.lang.Object o)
            throws java.lang.Exception
EXPERIMENTAL/NOT FINAL Cause the object to be deleted from the database.

Specified by:
delete in interface QDataContext
Throws:
java.lang.Exception
See Also:
QDataContext.delete(java.lang.Object)

save

public void save(java.lang.Object o)
          throws java.lang.Exception
EXPERIMENTAL/NOT FINAL Cause the object to be inserted in the database.

Specified by:
save in interface QDataContext
Throws:
java.lang.Exception
See Also:
QDataContext.save(java.lang.Object)

refresh

public void refresh(java.lang.Object o)
             throws java.lang.Exception
EXPERIMENTAL/NOT FINAL Refresh with latest content in the database.

Specified by:
refresh in interface QDataContext
Throws:
java.lang.Exception
See Also:
QDataContext.refresh(java.lang.Object)