to.etc.webapp.query
Interface QDataContext

All Known Implementing Classes:
BuggyHibernateBaseContext, HibernateLongSessionContext, HibernateQDataContext, HibernateReattachingDataContext, JdbcDataContext, QAbstractDataContext

public interface QDataContext

Generalized thingy representing a database connection, and state associated with objects. Equals the "DataContext" or "Hibernate Session". This is a controlled resource.

Author:
Frits Jalvingh Created on Jun 25, 2008

Method Summary
 void addCommitAction(IRunnable cx)
          Add an action which should be executed after a succesful commit on this context.
 void attach(java.lang.Object o)
          If the object was from an earlier database session reattach it to another, live session.
 void close()
          This will close and fully discard all resources belonging to this context, provided ignoreClose is not true.
 void commit()
           
 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)
           
 java.sql.Connection getConnection()
           
 QDataContextFactory getFactory()
          Returns the context source which created this DataContext.
<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> clz, java.lang.Object pk)
           
 boolean inTransaction()
           
<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<?> q)
          Execute the selection query specified by q, and expect and return at most 1 result.
 void refresh(java.lang.Object o)
          Deprecated. 
 void rollback()
           
 void save(java.lang.Object o)
          EXPERIMENTAL/NOT FINAL Cause the object to be inserted in the database.
 void setIgnoreClose(boolean on)
          When ignoreClose is set to T the close call must be silently ignored.
 void startTransaction()
           
 

Method Detail

getFactory

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.

Returns:

setIgnoreClose

void setIgnoreClose(boolean on)
When ignoreClose is set to T the close call must be silently ignored. Ugly, but for a lot of reasons (all having to do with the very strained object model around the ViewPoint database code) this is the least invasive method to allow for per-conversation shared contexts. Please do not replace this with any kind of wrapper/proxy based solution; it will not work.

Parameters:
on -

close

void close()
This will close and fully discard all resources belonging to this context, provided ignoreClose is not true. A closed context cannot be reused anymore and should be discarded.


query

<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.

Type Parameters:
T - The return type for this query, a persistent class type
Parameters:
q - The selection criteria
Returns:
Throws:
java.lang.Exception

queryOne

<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.

Type Parameters:
T -
Parameters:
q -
Returns:
Throws:
java.lang.Exception

query

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.

Parameters:
sel -
Returns:
Throws:
java.lang.Exception

queryOne

java.lang.Object[] queryOne(QSelection<?> q)
                            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.

Type Parameters:
T -
Parameters:
q -
Returns:
Throws:
java.lang.Exception

find

<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.

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

find

<T> T find(ICriteriaTableDef<T> metatable,
           java.lang.Object pk)
       throws java.lang.Exception
Throws:
java.lang.Exception

getInstance

<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 find(Class, Object).

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

getInstance

<T> T getInstance(ICriteriaTableDef<T> clz,
                  java.lang.Object pk)
              throws java.lang.Exception
Throws:
java.lang.Exception

attach

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.

Parameters:
o -
Throws:
java.lang.Exception

save

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

Parameters:
o -
Throws:
java.lang.Exception

refresh

@Deprecated
void refresh(java.lang.Object o)
             throws java.lang.Exception
Deprecated. 

EXPERIMENTAL/NOT FINAL Refresh with latest content in the database.

Parameters:
o -
Throws:
java.lang.Exception

delete

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

Parameters:
o -
Throws:
java.lang.Exception

startTransaction

void startTransaction()
                      throws java.lang.Exception
Throws:
java.lang.Exception

commit

void commit()
            throws java.lang.Exception
Throws:
java.lang.Exception

rollback

void rollback()
              throws java.lang.Exception
Throws:
java.lang.Exception

inTransaction

boolean inTransaction()
                      throws java.lang.Exception
Throws:
java.lang.Exception

getConnection

java.sql.Connection getConnection()
                                  throws java.lang.Exception
Throws:
java.lang.Exception

addCommitAction

void addCommitAction(IRunnable cx)
Add an action which should be executed after a succesful commit on this context.

Parameters:
cx -