Package helma.objectmodel.db

# Class NodeManager

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

public final class NodeManager extends 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

Fields
Modifier and Type
Field
Description
`protected Application`
`app`
`protected IDatabase`
`db`
`protected IDGenerator`
`idgen`
`final WrappedNodeManager`
`safe`

## Constructor Summary

Constructors
Constructor
Description
`NodeManager(Application app)`
Create a new NodeManager for Application app.

## Method Summary

Modifier and Type
Method
Description
`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.
`protected List`
`collectMissingKeys(SubnodeList list, int start, int length)`
`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, ResultSet rs, DbColumn[] columns, int offset)`
Create a new Node from a ResultSet.
`void`
`deleteNode(Node node)`
Delete a node from the database.
`void`
`deleteNode(IDatabase db, ITransaction txn, Node node)`
Performs the actual deletion of a node from either the embedded or an external SQL database.
`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(List inserted, List updated, List deleted, List parents)`
Called by transactors after committing.
`String`
`generateID(DbMapping map)`
Generate a new ID for a given type, delegating to our IDGenerator if set.
`Object[]`
`getCacheEntries()`
Get an array of the the keys currently held in the object cache
`Map`
`getCacheStatistics()`
Returns a map with statistics about the cache
`DbMapping`
`getDbMapping(String protoname)`
Get a DbMapping for a given prototype name.
`Node`
`getNode(Key key)`
Get a node by key.
`Node`
`getNode(Node home, String kstr, Relation rel)`
Get a node by relation, using the home node, the relation and a key to apply.
`List`
`getNodeIDs(Node home, Relation rel)`
Loades subnodes via subnode relation.
`List`
`getNodes(Node home, Relation rel)`
Loades subnodes via subnode relation.
`Vector`
`getPropertyNames(Node home, Relation rel)`
Similar to getNodeIDs, but returns a List that contains 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(File dbHome, 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, 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, SubnodeList list, int start, int length)`
`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`
`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(Properties props)`
app.properties file has been updated.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### app

protected Application app

### db

protected IDatabase db

### idgen

protected IDGenerator idgen

### safe

public final WrappedNodeManager safe

## Constructor Details

### NodeManager

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

## Method Details

### init

public void init(File dbHome, Properties props) throws DatabaseException, ClassNotFoundException, IllegalAccessException, 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`
  `ClassNotFoundException`
  `IllegalAccessException`
  `InstantiationException`

### getRootNode

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

Throws:
  `Exception`

### isRootNode

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

### updateProperties

public void updateProperties(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 Exception
Delete a node from the database.

Throws:
  `Exception`

### getNode

public Node getNode(Key key) throws 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:
  `Exception`

### getNode

public Node getNode(Node home, String kstr, Relation rel) throws 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:
  `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 IOException, SQLException, ClassNotFoundException
Insert a new node in the embedded database or a relational database table, depending on its db mapping.

Throws:
  `IOException`
  `SQLException`
  `ClassNotFoundException`

### exportNode

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

Throws:
  `SQLException`
  `ClassNotFoundException`

### exportNode

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

Throws:
  `SQLException`
  `ClassNotFoundException`

### insertRelationalNode

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

Throws:
  `ClassNotFoundException`
  `SQLException`

### updateNode

public boolean updateNode(IDatabase db, ITransaction txn, Node node) throws IOException, SQLException, 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:
  `IOException`
  `SQLException`
  `ClassNotFoundException`

### deleteNode

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

Throws:
  `Exception`

### generateID

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

Throws:
  `Exception`

### doGenerateID

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

Throws:
  `Exception`

### getNodeIDs

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

Throws:
  `Exception`

### getNodes

public List getNodes(Node home, Relation rel) throws 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:
  `Exception`

### collectMissingKeys

protected List collectMissingKeys(SubnodeList list, int start, int length)

### prefetchNodes

public void prefetchNodes(Node home, Relation rel, SubnodeList list, int start, int length) throws Exception

Throws:
  `Exception`

### countNodes

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

Throws:
  `Exception`

### getPropertyNames

public Vector getPropertyNames(Node home, Relation rel) throws Exception
Similar to getNodeIDs, but returns a List that contains the nodes property names instead of IDs

Throws:
  `Exception`

### createNode

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

Throws:
  `SQLException`
  `IOException`
  `ClassNotFoundException`

### getDbMapping

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

### getCacheEntries

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

### getCacheStatistics

public Map getCacheStatistics()
Returns a map with statistics about the cache

### 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(List inserted, List updated, List deleted, List parents)
Called by transactors after committing.