de.mguennewig.pobjects.event
Class ContainerWrapper

java.lang.Object
  extended by de.mguennewig.pobjects.AbstractContainer
      extended by de.mguennewig.pobjects.event.ContainerWrapper
All Implemented Interfaces:
Container

public class ContainerWrapper
extends AbstractContainer

This is a simple wrapper around a database container to notify about (possible) database changes.

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
ContainerWrapper(Container db)
          Creates a new ContainerWrapper.
 
Method Summary
 void addPObjContainerListener(PObjContainerListener l)
          Adds a new container listener that will be notified about database changes done by the pobject library.
 void beginTransaction()
          Starts a new transaction.
 void close()
          
 void commitTransaction()
          Commits all statements since the last Container.beginTransaction().
 int deleteAll(ClassDecl cdecl)
          Deletes all entries within the specified table.
 int deleteAll(ClassDecl cl, Column fk, java.lang.Object value)
          Deletes all entries within the specified table whose foreign key fk equals the given value.
 void deleteObject(PObject obj)
          Deletes the given persistent object from the database.
 boolean deleteRecord(Record obj)
          
 int getCapabilities()
          Returns the capabilities of the DBMS.
 Container getContainer()
          Returns the wrapped/watched database container.
 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 getSequenceCurrentValue(Sequence seq)
          Returns the current value of the given sequence.
 java.lang.String getSequenceNextValue(Sequence seq)
          Returns a new value of the given sequence.
 java.lang.String insertObject(PObject obj)
          Inserts the given object into the database.
 boolean insertRecord(Record obj)
          
 EvalContext newEvalContext(int numColumns)
          
 Query newQuery()
          Creates a new empty query.
 void notifyChange(PObject obj, boolean reverted)
          Notifies this container that the object has been changed.
 void removePObjContainerListener(PObjContainerListener l)
          Removes the given container listener for the list of notifiers.
 void reset()
          Resets the container.
 void retrieveData(PObject obj)
          Retrieves the data for the given persistent object from the database.
 void rollbackTransaction()
          Rolls back all statements since the last Container.beginTransaction().
 void updateObject(PObject obj)
          Updates the given persistent object in the database.
 
Methods inherited from class de.mguennewig.pobjects.AbstractContainer
createObject, deleteAll, getClassDecl, getClassDecls, getData, getDictionary, getObject, getQualifiedName, getSchema, getTableExpr, isStrictMode, makePersistent, newQuery, newQuery, newQuery, newQuery, newQuery, newQuery, newQuery, newQuery, setStrictMode, storeAll, supportsBoolean, supportsInherits, supportsLimitOffset, supportsOracleJoin, supportsSQL99Join, useArrayForLob, useStreamToInsertLob
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContainerWrapper

public ContainerWrapper(Container db)
Creates a new ContainerWrapper.

Method Detail

addPObjContainerListener

public void addPObjContainerListener(PObjContainerListener l)
Adds a new container listener that will be notified about database changes done by the pobject library.


removePObjContainerListener

public void removePObjContainerListener(PObjContainerListener l)
Removes the given container listener for the list of notifiers.


getContainer

public final Container getContainer()
Returns the wrapped/watched database container.


getCapabilities

public int getCapabilities()
Returns the capabilities of the DBMS.

See Also:
"The SUPPORTS_* constants."

beginTransaction

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

Specified by:
beginTransaction in interface Container
Overrides:
beginTransaction in class AbstractContainer
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
Overrides:
commitTransaction in class AbstractContainer
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
Overrides:
rollbackTransaction in class AbstractContainer
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
Overrides:
reset in class AbstractContainer
See Also:
Container.rollbackTransaction()

close

public void close()
           throws PObjSQLException

Throws:
PObjSQLException

getSequenceCurrentValue

public java.lang.String getSequenceCurrentValue(Sequence seq)
                                         throws PObjSQLException
Returns the current value of the given sequence.

Throws:
PObjSQLException - if any database error occurs.

getSequenceNextValue

public java.lang.String getSequenceNextValue(Sequence seq)
                                      throws PObjSQLException
Returns a new value of the given sequence.

Throws:
PObjSQLException - if any database error occurs.

insertRecord

public boolean insertRecord(Record obj)
                     throws PObjConstraintException,
                            PObjSQLException

Throws:
PObjConstraintException
PObjSQLException

deleteRecord

public boolean deleteRecord(Record obj)
                     throws PObjConstraintException,
                            PObjSQLException

Throws:
PObjConstraintException
PObjSQLException

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
Overrides:
getObject in class AbstractContainer
See Also:
Container.getData(TableExpr), Container.retrieveData(PObject)

insertObject

public java.lang.String insertObject(PObject obj)
                              throws PObjConstraintException,
                                     PObjSQLException
Inserts the given object into the database.

Throws:
PObjConstraintException - if a database constraint will be violated.
PObjSQLException - if any other database error occurs.

updateObject

public void updateObject(PObject obj)
                  throws PObjConstraintException,
                         PObjSQLException
Updates the given persistent object in the database.

Throws:
PObjConstraintException - if a database constraint will be violated.
PObjSQLException - if any other database error occurs.
See Also:
PObject.isPersistent()

deleteObject

public void deleteObject(PObject obj)
                  throws PObjConstraintException,
                         PObjSQLException
Deletes the given persistent object from the database.

Throws:
PObjConstraintException - if a database constraint will be violated.
PObjSQLException - if any other database error occurs.
See Also:
PObject.isPersistent()

notifyChange

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

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

deleteAll

public int deleteAll(ClassDecl cdecl)
              throws PObjConstraintException,
                     PObjSQLException
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().

Throws:
PObjConstraintException - if a database constraint will be violated.
PObjSQLException - if any other database error occurs.

deleteAll

public int deleteAll(ClassDecl cl,
                     Column fk,
                     java.lang.Object value)
              throws PObjSQLException,
                     PObjConstraintException
Deletes all entries within the specified table whose foreign key fk equals the given value.

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

Throws:
PObjSQLException - if any other database error occurs.
PObjConstraintException - if a database constraint will be violated.

retrieveData

public void retrieveData(PObject obj)
Retrieves the data for the given persistent object from the database.


newEvalContext

public EvalContext newEvalContext(int numColumns)


newQuery

public Query newQuery()
Creates a new empty query.