helma.objectmodel.db
Class NodeManager

java.lang.Object
  extended by helma.objectmodel.db.NodeManager

public final class NodeManager
extends java.lang.Object

The NodeManager is responsible for fetching Nodes from the internal or external data sources, caching them in a least-recently-used Hashtable, and writing changes back to the databases.


Field Summary
protected  Application app
           
protected  IDatabase db
           
protected  IDGenerator idgen
           
protected  boolean logReplication
           
 WrappedNodeManager safe
           
 
Constructor Summary
NodeManager(Application app)
          Create a new NodeManager for Application app.
 
Method Summary
 void addNodeChangeListener(NodeChangeListener listener)
          Add a listener that is notified each time a transaction commits that adds, modifies or deletes any Nodes.
 void clearCache()
          Clear the object cache, causing all objects to be recreated.
 int countCacheEntries()
          Get the number of elements in the object cache
 int countNodes(Node home, Relation rel)
          Count the nodes contained in the child collection of the home node which is defined by Relation rel.
 Node createNode(DbMapping dbm, java.sql.ResultSet rs, DbColumn[] columns, int offset)
          Create a new Node from a ResultSet.
 void deleteNode(IDatabase db, ITransaction txn, Node node)
          Performs the actual deletion of a node from either the embedded or an external SQL database.
 void deleteNode(Node node)
          Delete a node from the database.
 java.lang.String doGenerateID(DbMapping map)
          Actually generates an ID, using a method matching the given DbMapping.
 void evictKey(Key key)
          Used when a key stops being valid for a node.
 void evictNode(Node node)
          Remove a node from the node cache.
 void evictNodeByKey(Key key)
          Remove a node from the node cache.
 void exportNode(Node node, DbMapping dbm)
          Insert a node into a different (relational) database than its default one.
 void exportNode(Node node, DbSource dbs)
          Insert a node into a different (relational) database than its default one.
protected  void fireNodeChangeEvent(java.util.List inserted, java.util.List updated, java.util.List deleted, java.util.List parents)
          Called by transactors after committing.
 java.lang.String generateID(DbMapping map)
          Generate a new ID for a given type, delegating to our IDGenerator if set.
 java.lang.Object[] getCacheEntries()
          Get an array of the the keys currently held in the object cache
 DbMapping getDbMapping(java.lang.String protoname)
          Get a DbMapping for a given prototype name.
 Node getNode(Key key)
          Get a node by key.
 Node getNode(Node home, java.lang.String kstr, Relation rel)
          Get a node by relation, using the home node, the relation and a key to apply.
 SubnodeList getNodeIDs(Node home, Relation rel)
          Loades subnodes via subnode relation.
 SubnodeList getNodes(Node home, Relation rel)
          Loades subnodes via subnode relation.
 java.util.Vector getPropertyNames(Node home, Relation rel)
          Similar to getNodeIDs, but returns a Vector that return's the nodes property names instead of IDs
 Node getRootNode()
          Gets the application's root node.
protected  boolean hasNodeChangeListeners()
          Let transactors know if they should collect and fire NodeChangeListener events
 void init(java.io.File dbHome, java.util.Properties props)
          Initialize the NodeManager for the given dbHome and application properties.
 void insertNode(IDatabase db, ITransaction txn, Node node)
          Insert a new node in the embedded database or a relational database table, depending on its db mapping.
protected  void insertRelationalNode(Node node, DbMapping dbm, java.sql.Connection con)
          Insert a node into a relational database.
 boolean isRootNode(Node node)
          Checks if the given node is the application's root node.
 void prefetchNodes(Node home, Relation rel, Key[] keys)
           
 void registerNode(Node node)
          Register a node in the node cache.
protected  void registerNode(Node node, Key key)
          Register a node in the node cache using the key argument.
 void removeNodeChangeListener(NodeChangeListener listener)
          Remove a previously added NodeChangeListener.
 void replicateCache(java.util.Vector add, java.util.Vector delete)
          Receive notification from a remote app that objects in its cache have been modified.
 void shutdown()
          Shut down this node manager.
 boolean updateNode(IDatabase db, ITransaction txn, Node node)
          Updates a modified node in the embedded db or an external relational database, depending on its database mapping.
 void updateProperties(java.util.Properties props)
          app.properties file has been updated.
 int updateSubnodeList(Node home, Relation rel)
          Update a UpdateableSubnodeList retrieving all values having higher Values according to the updateCriteria's set for this Collection's Relation The returned Map-Object has two Properties: addedNodes = an Integer representing the number of Nodes added to this collection newNodes = an Integer representing the number of Records returned by the Select-Statement These two values may be different if a max-size is defined for this Collection and a new node would be outside of this Border because of the ordering of this collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

app

protected Application app

db

protected IDatabase db

idgen

protected IDGenerator idgen

logReplication

protected boolean logReplication

safe

public final WrappedNodeManager safe
Constructor Detail

NodeManager

public NodeManager(Application app)
Create a new NodeManager for Application app.

Method Detail

init

public void init(java.io.File dbHome,
                 java.util.Properties props)
          throws DatabaseException,
                 java.lang.ClassNotFoundException,
                 java.lang.IllegalAccessException,
                 java.lang.InstantiationException
Initialize the NodeManager for the given dbHome and application properties. An embedded database will be created in dbHome if one doesn't already exist.

Throws:
DatabaseException
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException

getRootNode

public Node getRootNode()
                 throws java.lang.Exception
Gets the application's root node.

Throws:
java.lang.Exception

isRootNode

public boolean isRootNode(Node node)
Checks if the given node is the application's root node.


updateProperties

public void updateProperties(java.util.Properties props)
app.properties file has been updated. Reread some settings.


shutdown

public void shutdown()
              throws DatabaseException
Shut down this node manager. This is called when the application using this node manager is stopped.

Throws:
DatabaseException

deleteNode

public void deleteNode(Node node)
                throws java.lang.Exception
Delete a node from the database.

Throws:
java.lang.Exception

getNode

public Node getNode(Key key)
             throws java.lang.Exception
Get a node by key. This is called from a node that already holds a reference to another node via a NodeHandle/Key.

Throws:
java.lang.Exception

getNode

public Node getNode(Node home,
                    java.lang.String kstr,
                    Relation rel)
             throws java.lang.Exception
Get a node by relation, using the home node, the relation and a key to apply. In contrast to getNode (Key key), this is usually called when we don't yet know whether such a node exists.

Throws:
java.lang.Exception

registerNode

public void registerNode(Node node)
Register a node in the node cache.


registerNode

protected void registerNode(Node node,
                            Key key)
Register a node in the node cache using the key argument.


evictNode

public void evictNode(Node node)
Remove a node from the node cache. If at a later time it is accessed again, it will be refetched from the database.


evictNodeByKey

public void evictNodeByKey(Key key)
Remove a node from the node cache. If at a later time it is accessed again, it will be refetched from the database.


evictKey

public void evictKey(Key key)
Used when a key stops being valid for a node. The cached node itself remains valid, if it is present in the cache by other keys.


insertNode

public void insertNode(IDatabase db,
                       ITransaction txn,
                       Node node)
                throws java.io.IOException,
                       java.sql.SQLException,
                       java.lang.ClassNotFoundException
Insert a new node in the embedded database or a relational database table, depending on its db mapping.

Throws:
java.io.IOException
java.sql.SQLException
java.lang.ClassNotFoundException

exportNode

public void exportNode(Node node,
                       DbSource dbs)
                throws java.sql.SQLException,
                       java.lang.ClassNotFoundException
Insert a node into a different (relational) database than its default one.

Throws:
java.sql.SQLException
java.lang.ClassNotFoundException

exportNode

public void exportNode(Node node,
                       DbMapping dbm)
                throws java.sql.SQLException,
                       java.lang.ClassNotFoundException
Insert a node into a different (relational) database than its default one.

Throws:
java.sql.SQLException
java.lang.ClassNotFoundException

insertRelationalNode

protected void insertRelationalNode(Node node,
                                    DbMapping dbm,
                                    java.sql.Connection con)
                             throws java.lang.ClassNotFoundException,
                                    java.sql.SQLException
Insert a node into a relational database.

Throws:
java.lang.ClassNotFoundException
java.sql.SQLException

updateNode

public boolean updateNode(IDatabase db,
                          ITransaction txn,
                          Node node)
                   throws java.io.IOException,
                          java.sql.SQLException,
                          java.lang.ClassNotFoundException
Updates a modified node in the embedded db or an external relational database, depending on its database mapping.

Returns:
true if the DbMapping of the updated Node is to be marked as updated via DbMapping.setLastDataChange
Throws:
java.io.IOException
java.sql.SQLException
java.lang.ClassNotFoundException

deleteNode

public void deleteNode(IDatabase db,
                       ITransaction txn,
                       Node node)
                throws java.lang.Exception
Performs the actual deletion of a node from either the embedded or an external SQL database.

Throws:
java.lang.Exception

generateID

public java.lang.String generateID(DbMapping map)
                            throws java.lang.Exception
Generate a new ID for a given type, delegating to our IDGenerator if set.

Throws:
java.lang.Exception

doGenerateID

public java.lang.String doGenerateID(DbMapping map)
                              throws java.lang.Exception
Actually generates an ID, using a method matching the given DbMapping.

Throws:
java.lang.Exception

getNodeIDs

public SubnodeList getNodeIDs(Node home,
                              Relation rel)
                       throws java.lang.Exception
Loades subnodes via subnode relation. Only the ID index is loaded, the nodes are loaded later on demand.

Throws:
java.lang.Exception

getNodes

public SubnodeList getNodes(Node home,
                            Relation rel)
                     throws java.lang.Exception
Loades subnodes via subnode relation. This is similar to getNodeIDs, but it actually loades all nodes in one go, which is better for small node collections. This method is used when xxx.loadmode=aggressive is specified.

Throws:
java.lang.Exception

updateSubnodeList

public int updateSubnodeList(Node home,
                             Relation rel)
                      throws java.lang.Exception
Update a UpdateableSubnodeList retrieving all values having higher Values according to the updateCriteria's set for this Collection's Relation The returned Map-Object has two Properties: addedNodes = an Integer representing the number of Nodes added to this collection newNodes = an Integer representing the number of Records returned by the Select-Statement These two values may be different if a max-size is defined for this Collection and a new node would be outside of this Border because of the ordering of this collection.

Parameters:
home - the home of this subnode-list
rel - the relation the home-node has to the nodes contained inside the subnodelist
Returns:
A map having two properties of type String (newNodes (number of nodes retreived by the select-statment), addedNodes (nodes added to the collection))
Throws:
java.lang.Exception

prefetchNodes

public void prefetchNodes(Node home,
                          Relation rel,
                          Key[] keys)
                   throws java.lang.Exception
Throws:
java.lang.Exception

countNodes

public int countNodes(Node home,
                      Relation rel)
               throws java.lang.Exception
Count the nodes contained in the child collection of the home node which is defined by Relation rel.

Throws:
java.lang.Exception

getPropertyNames

public java.util.Vector getPropertyNames(Node home,
                                         Relation rel)
                                  throws java.lang.Exception
Similar to getNodeIDs, but returns a Vector that return's the nodes property names instead of IDs

Throws:
java.lang.Exception

createNode

public Node createNode(DbMapping dbm,
                       java.sql.ResultSet rs,
                       DbColumn[] columns,
                       int offset)
                throws java.sql.SQLException,
                       java.io.IOException,
                       java.lang.ClassNotFoundException
Create a new Node from a ResultSet.

Throws:
java.sql.SQLException
java.io.IOException
java.lang.ClassNotFoundException

getDbMapping

public DbMapping getDbMapping(java.lang.String protoname)
Get a DbMapping for a given prototype name. This is just a proxy method to the app's getDbMapping() method.


getCacheEntries

public java.lang.Object[] getCacheEntries()
Get an array of the the keys currently held in the object cache


countCacheEntries

public int countCacheEntries()
Get the number of elements in the object cache


clearCache

public void clearCache()
Clear the object cache, causing all objects to be recreated.


addNodeChangeListener

public void addNodeChangeListener(NodeChangeListener listener)
Add a listener that is notified each time a transaction commits that adds, modifies or deletes any Nodes.


removeNodeChangeListener

public void removeNodeChangeListener(NodeChangeListener listener)
Remove a previously added NodeChangeListener.


hasNodeChangeListeners

protected boolean hasNodeChangeListeners()
Let transactors know if they should collect and fire NodeChangeListener events


fireNodeChangeEvent

protected void fireNodeChangeEvent(java.util.List inserted,
                                   java.util.List updated,
                                   java.util.List deleted,
                                   java.util.List parents)
Called by transactors after committing.


replicateCache

public void replicateCache(java.util.Vector add,
                           java.util.Vector delete)
Receive notification from a remote app that objects in its cache have been modified.



Copyright © 1998-1998-${year} Helma.org. All Rights Reserved.