de.mguennewig.pobjects.memdb
Class MemoryContainer

java.lang.Object
  extended by de.mguennewig.pobjects.AbstractContainer
      extended by de.mguennewig.pobjects.memdb.MemoryContainer
All Implemented Interfaces:
Container

public class MemoryContainer
extends AbstractContainer

A simple object container that simulates a database, but stores everything in memory.

This container is more based on a feasibility study and was quite helpful to cleanup the Container and Query infrastructure, then to be a useful tool.

The implementation is very naive and in no way optimized for speed or memory usage. Possible improvements:

SelectExpr and ViewDecl are not supported.

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
MemoryContainer(PObjDictionary dict, java.lang.String schema)
          Creates a new MemoryContainer.
 
Method Summary
 void close()
          
 void commitTransaction()
          Commits all statements since the last Container.beginTransaction().
 int deleteAll(ClassDecl te)
          Deletes all entries within the specified table.
 int deleteAll(ClassDecl te, 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)
          
 void dump(java.io.PrintStream out, java.lang.String name)
           
 int getCapabilities()
          Returns the capabilities of the DBMS.
 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 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
beginTransaction, createObject, deleteAll, getClassDecl, getClassDecls, getData, getDictionary, getObject, getObject, getQualifiedName, getSchema, getTableExpr, isStrictMode, makePersistent, newQuery, newQuery, newQuery, newQuery, newQuery, newQuery, newQuery, newQuery, notifyChange, 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

MemoryContainer

public MemoryContainer(PObjDictionary dict,
                       java.lang.String schema)
Creates a new MemoryContainer.

Method Detail

close

public void close()


getCapabilities

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

See Also:
"The SUPPORTS_* constants."

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.

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

insertRecord

public boolean insertRecord(Record obj)
                     throws PObjConstraintException,
                            PObjSQLException

Throws:
PObjConstraintException
PObjSQLException

deleteRecord

public boolean deleteRecord(Record obj)
                     throws PObjConstraintException,
                            PObjSQLException

Throws:
PObjConstraintException
PObjSQLException

retrieveData

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


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

deleteAll

public int deleteAll(ClassDecl te)
              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().

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

deleteAll

public int deleteAll(ClassDecl te,
                     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.

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

newEvalContext

public EvalContext newEvalContext(int numColumns)


newQuery

public Query newQuery()
Creates a new empty query.


dump

public final void dump(java.io.PrintStream out,
                       java.lang.String name)