de.mguennewig.pobjects
Class AbstractContainer

java.lang.Object
  extended by de.mguennewig.pobjects.AbstractContainer
All Implemented Interfaces:
Container
Direct Known Subclasses:
ContainerWrapper, FileSystemContainer, JdbcContainer, MemoryContainer

public abstract class AbstractContainer
extends java.lang.Object
implements Container

Abstract base class for database connections.

Author:
Michael Günnewig

Field Summary
 
Fields inherited from interface de.mguennewig.pobjects.Container
SUPPORTS_BOOLEAN, SUPPORTS_INHERITS, SUPPORTS_JOIN, SUPPORTS_LIMIT_OFFSET, SUPPORTS_ORACLE_JOIN, SUPPORTS_SQL99_JOIN, USE_ARRAY_FOR_LOB, USE_STREAM_TO_INSERT_LOB
 
Constructor Summary
AbstractContainer(PObjDictionary dict, java.lang.String schema)
          Creates a container without a connection to any DBMS.
 
Method Summary
 void beginTransaction()
          Starts a new transaction.
 void commitTransaction()
          Commits all statements since the last Container.beginTransaction().
 Record createObject(TableExpr te)
          Creates a new Record instance for the given table expression without any binding to this container.
 int deleteAll(java.lang.Class<? extends Record> tableClass)
          Deletes all entries within the specified table.
 ClassDecl getClassDecl(java.lang.String schemaName)
          Returns the meta data definition for the table with the given schema name.
 java.util.Iterator<ClassDecl> getClassDecls()
          Returns an Iterator over all known class declarations.
 Record getData(TableExpr te)
          Returns a Record instance for the given table expression without reading any data from the DB.
 PObjDictionary getDictionary()
          Returns the used meta data dictionary.
 PObject getObject(java.lang.Class<? extends PObject> tableClass, java.lang.String id)
          Returns a PObject instance for the given table class without reading any data from the DB.
 PObject getObject(ClassDecl te, java.lang.String id)
          Returns a PObject instance for the given table expression without reading any data from the DB.
 java.lang.String getQualifiedName(SqlEntity entity)
          Returns the qualified name for the given SQL entity.
 java.lang.String getSchema()
          Returns the database schema prefix that is used to access the SQL entities.
 TableExpr getTableExpr(java.lang.Class<? extends Record> tableClass)
          
 boolean isStrictMode()
          Tests whether modified but unstored persistent objects will be denied upon a commit.
 void makePersistent(PObject obj)
          Creates the connection between the object and the database container.
 Query newQuery(java.lang.Class<? extends Record> tableClass)
          Creates a new query for all rows of the given table expression.
 Query newQuery(java.lang.Class<? extends Record>[] tableClasses, Predicate[] filters)
          Creates a new query with a filter on the given table expression.
 Query newQuery(java.lang.Class<? extends Record> tableClass, Predicate filter)
          Creates a new query with a filter on the given table expression.
 Query newQuery(java.lang.Class<? extends Record> tableClass, Predicate[] filters)
          Creates a new query with a filter on the given table expression.
 Query newQuery(TableExpr tableExpr)
          Creates a new query for all rows of the given table expression.
 Query newQuery(TableExpr[] tableExprs, Predicate[] filters)
          Creates a new query with a filter on the given table expressions.
 Query newQuery(TableExpr tableExpr, Predicate filter)
          Creates a new query with a filter on the given table expression.
 Query newQuery(TableExpr tableExpr, Predicate[] filters)
          Creates a new query with a filter on the given table expression.
 void notifyChange(PObject obj, boolean reverted)
          Notifies this container that the object has been changed.
 void reset()
          Resets the container.
 void rollbackTransaction()
          Rolls back all statements since the last Container.beginTransaction().
 void setStrictMode(boolean strictMode)
          Sets whether modified but unstored persistent objects will be denied upon a commit.
 void storeAll()
          Stores all changed objects belonging to this container.
 boolean supportsBoolean()
          Tests whether the database supports booleans natively.
 boolean supportsInherits()
          Tests whether the database supports the inheritance concept natively.
 boolean supportsLimitOffset()
          Tests whether the database supports limiting the result set.
 boolean supportsOracleJoin()
          Tests whether the database supports Oracle style joins.
 boolean supportsSQL99Join()
          Tests whether the database supports SQL99 style joins.
 boolean useArrayForLob()
          Tests whether the database requires to use an byte[] or char[] instead of a large object.
 boolean useStreamToInsertLob()
          Tests whether the database requires to use an InputStream or Reader instead of a large object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.mguennewig.pobjects.Container
close, deleteAll, deleteAll, deleteObject, deleteRecord, getCapabilities, getSequenceCurrentValue, getSequenceNextValue, insertObject, insertRecord, newEvalContext, newQuery, retrieveData, updateObject
 

Constructor Detail

AbstractContainer

public AbstractContainer(PObjDictionary dict,
                         java.lang.String schema)
Creates a container without a connection to any DBMS.

Method Detail

supportsBoolean

public final boolean supportsBoolean()
Tests whether the database supports booleans natively.

Specified by:
supportsBoolean in interface Container
See Also:
Container.SUPPORTS_BOOLEAN

supportsInherits

public final boolean supportsInherits()
Tests whether the database supports the inheritance concept natively.

Specified by:
supportsInherits in interface Container
See Also:
Container.SUPPORTS_INHERITS

supportsLimitOffset

public final boolean supportsLimitOffset()
Tests whether the database supports limiting the result set.

Specified by:
supportsLimitOffset in interface Container
See Also:
Container.SUPPORTS_LIMIT_OFFSET

supportsOracleJoin

public final boolean supportsOracleJoin()
Tests whether the database supports Oracle style joins.

Specified by:
supportsOracleJoin in interface Container
See Also:
Container.SUPPORTS_ORACLE_JOIN

supportsSQL99Join

public final boolean supportsSQL99Join()
Tests whether the database supports SQL99 style joins.

Specified by:
supportsSQL99Join in interface Container
See Also:
Container.SUPPORTS_SQL99_JOIN

useStreamToInsertLob

public final boolean useStreamToInsertLob()
Tests whether the database requires to use an InputStream or Reader instead of a large object.

Specified by:
useStreamToInsertLob in interface Container
See Also:
Container.USE_STREAM_TO_INSERT_LOB

useArrayForLob

public final boolean useArrayForLob()
Tests whether the database requires to use an byte[] or char[] instead of a large object.

Specified by:
useArrayForLob in interface Container
See Also:
Container.USE_ARRAY_FOR_LOB

getDictionary

public final PObjDictionary getDictionary()
Returns the used meta data dictionary.

Specified by:
getDictionary in interface Container

getSchema

public final java.lang.String getSchema()
Returns the database schema prefix that is used to access the SQL entities.

Specified by:
getSchema in interface Container
See Also:
Container.getQualifiedName(SqlEntity)

getQualifiedName

public java.lang.String getQualifiedName(SqlEntity entity)
Returns the qualified name for the given SQL entity.

Specified by:
getQualifiedName in interface Container
See Also:
Module.getSchemaPrefix(), Container.getSchema()

isStrictMode

public final boolean isStrictMode()
Tests whether modified but unstored persistent objects will be denied upon a commit.

Specified by:
isStrictMode in interface Container
Returns:
true if there will be raised an exception for an modified but unstored object upon a commit, otherwise false.

setStrictMode

public void setStrictMode(boolean strictMode)
Sets whether modified but unstored persistent objects will be denied upon a commit.

Specified by:
setStrictMode in interface Container
See Also:
Container.isStrictMode(), Container.commitTransaction()

getTableExpr

public TableExpr getTableExpr(java.lang.Class<? extends Record> tableClass)

Specified by:
getTableExpr in interface Container

getClassDecl

public ClassDecl getClassDecl(java.lang.String schemaName)
Returns the meta data definition for the table with the given schema name.

Specified by:
getClassDecl in interface Container
See Also:
Container.getClassDecls()

getClassDecls

public final java.util.Iterator<ClassDecl> getClassDecls()
Returns an Iterator over all known class declarations.

Specified by:
getClassDecls in interface Container

beginTransaction

public void beginTransaction()
                      throws PObjSQLException
Starts a new transaction.

Specified by:
beginTransaction in interface Container
Throws:
PObjSQLException - if the DBMS is unable to start a new transaction.

commitTransaction

public void commitTransaction()
                       throws PObjSQLException
Commits all statements since the last Container.beginTransaction().

If Container.isStrictMode() yields false then just a warning for each dirty object is written, otherwise an exception is raised.

Specified by:
commitTransaction in interface Container
Throws:
PObjSQLException - if the DBMS in unable to finish the current transaction by committing it or if an modified but unstored object is detected while in strict mode.

rollbackTransaction

public void rollbackTransaction()
                         throws PObjSQLException
Rolls back all statements since the last Container.beginTransaction().

The in-memory data will be reverted also as far as possible.

Specified by:
rollbackTransaction in interface Container
Throws:
PObjSQLException - if the DBMS is unable to stop the current transaction by rolling back all made changes within it.
See Also:
PObject.revert()

reset

public void reset()
Resets the container.

Use this method to forget all changes made to any object.

NOTE: Any running transaction will be rolled back.

Specified by:
reset in interface Container
See Also:
Container.rollbackTransaction()

createObject

public Record createObject(TableExpr te)
Creates a new Record instance for the given table expression without any binding to this container.

Specified by:
createObject in interface Container
See Also:
Container.getObject(ClassDecl,String), Container.getData(TableExpr), Class.newInstance()

getData

public Record getData(TableExpr te)
Returns a Record instance for the given table expression without reading any data from the DB.

Specified by:
getData in interface Container
See Also:
Container.getObject(ClassDecl,String), TableExpr.isWritableClass()

getObject

public PObject getObject(ClassDecl te,
                         java.lang.String id)
Returns a PObject instance for the given table expression without reading any data from the DB.

Specified by:
getObject in interface Container
See Also:
Container.getData(TableExpr), Container.retrieveData(PObject)

getObject

public PObject getObject(java.lang.Class<? extends PObject> tableClass,
                         java.lang.String id)
Returns a PObject instance for the given table class without reading any data from the DB.

Specified by:
getObject in interface Container
See Also:
Container.getTableExpr(Class), Container.getObject(ClassDecl,String)

makePersistent

public void makePersistent(PObject obj)
Creates the connection between the object and the database container.

This method tells the object the database container and the container that this pbject is a newly created one that might be added to the DBMS.

Specified by:
makePersistent in interface Container
See Also:
ForeignKeyConstraint

notifyChange

public void notifyChange(PObject obj,
                         boolean reverted)
Notifies this container that the object has been changed.

Specified by:
notifyChange in interface Container
See Also:
PObject.set(Column,Object), PObject.revert()

storeAll

public final void storeAll()
                    throws PObjConstraintException,
                           PObjSQLException
Stores all changed objects belonging to this container.

The current implementation of this method may fail for some kinds of cyclical data references involving delete and update operations, as no reordering will be done currently. The order of the made changes to the objects will be used, so that the object which got changed first will be the first stored.

Specified by:
storeAll in interface Container
Throws:
PObjConstraintException
PObjSQLException
See Also:
PObject.store()

deleteAll

public final int deleteAll(java.lang.Class<? extends Record> tableClass)
                    throws PObjSQLException,
                           PObjConstraintException
Deletes all entries within the specified table.

NOTE: The objects which represent a row of this table or refer to rows within it aren't updated. So the best way to ensure consistency is to finish the current active transaction before calling this method and afterwards doing a Container.reset().

Specified by:
deleteAll in interface Container
Throws:
PObjSQLException - if any other database error occurs.
PObjConstraintException - if a database constraint will be violated.
See Also:
Container.deleteAll(ClassDecl), Container.getTableExpr(Class)

newQuery

public final Query newQuery(TableExpr tableExpr)
Creates a new query for all rows of the given table expression.

Specified by:
newQuery in interface Container

newQuery

public final Query newQuery(TableExpr tableExpr,
                            Predicate filter)
Creates a new query with a filter on the given table expression.

Specified by:
newQuery in interface Container

newQuery

public final Query newQuery(TableExpr tableExpr,
                            Predicate[] filters)
Creates a new query with a filter on the given table expression.

Specified by:
newQuery in interface Container

newQuery

public final Query newQuery(TableExpr[] tableExprs,
                            Predicate[] filters)
Creates a new query with a filter on the given table expressions.

Specified by:
newQuery in interface Container

newQuery

public final Query newQuery(java.lang.Class<? extends Record> tableClass)
Creates a new query for all rows of the given table expression.

Specified by:
newQuery in interface Container
See Also:
Container.getTableExpr(Class), Container.newQuery(TableExpr)

newQuery

public final Query newQuery(java.lang.Class<? extends Record> tableClass,
                            Predicate filter)
Creates a new query with a filter on the given table expression.

Specified by:
newQuery in interface Container
See Also:
Container.getTableExpr(Class), Container.newQuery(TableExpr,Predicate)

newQuery

public final Query newQuery(java.lang.Class<? extends Record> tableClass,
                            Predicate[] filters)
Creates a new query with a filter on the given table expression.

Specified by:
newQuery in interface Container
See Also:
Container.getTableExpr(Class), Container.newQuery(TableExpr,Predicate[])

newQuery

public final Query newQuery(java.lang.Class<? extends Record>[] tableClasses,
                            Predicate[] filters)
Creates a new query with a filter on the given table expression.

Specified by:
newQuery in interface Container
See Also:
Container.getTableExpr(Class), Container.newQuery(TableExpr[],Predicate[])