Package helma.objectmodel.db
Class NodeManager
java.lang.Object
helma.objectmodel.db.NodeManager
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
FieldsModifier and TypeFieldDescriptionprotected Application
protected IDatabase
protected IDGenerator
final WrappedNodeManager
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addNodeChangeListener
(NodeChangeListener listener) Add a listener that is notified each time a transaction commits that adds, modifies or deletes any Nodes.void
Clear the object cache, causing all objects to be recreated.protected List
collectMissingKeys
(SubnodeList list, int start, int length) int
Get the number of elements in the object cacheint
countNodes
(Node home, Relation rel) Count the nodes contained in the child collection of the home node which is defined by Relation rel.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.doGenerateID
(DbMapping map) Actually generates an ID, using a method matching the given DbMapping.void
Used when a key stops being valid for a node.void
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.generateID
(DbMapping map) Generate a new ID for a given type, delegating to our IDGenerator if set.Object[]
Get an array of the the keys currently held in the object cacheReturns a map with statistics about the cachegetDbMapping
(String protoname) Get a DbMapping for a given prototype name.Get a node by key.Get a node by relation, using the home node, the relation and a key to apply.getNodeIDs
(Node home, Relation rel) Loades subnodes via subnode relation.Loades subnodes via subnode relation.getPropertyNames
(Node home, Relation rel) Similar to getNodeIDs, but returns a List that contains the nodes property names instead of IDsGets the application's root node.protected boolean
Let transactors know if they should collect and fire NodeChangeListener eventsvoid
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.
-
Field Details
-
app
-
db
-
idgen
-
safe
-
-
Constructor Details
-
NodeManager
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. -
getRootNode
Gets the application's root node.- Throws:
Exception
-
isRootNode
Checks if the given node is the application's root node. -
updateProperties
app.properties file has been updated. Reread some settings. -
shutdown
Shut down this node manager. This is called when the application using this node manager is stopped.- Throws:
DatabaseException
-
deleteNode
Delete a node from the database.- Throws:
Exception
-
getNode
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
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
Register a node in the node cache. -
registerNode
Register a node in the node cache using the key argument. -
evictNode
Remove a node from the node cache. If at a later time it is accessed again, it will be refetched from the database. -
evictNodeByKey
Remove a node from the node cache. If at a later time it is accessed again, it will be refetched from the database. -
evictKey
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. -
exportNode
Insert a node into a different (relational) database than its default one.- Throws:
SQLException
ClassNotFoundException
-
exportNode
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
Performs the actual deletion of a node from either the embedded or an external SQL database.- Throws:
Exception
-
generateID
Generate a new ID for a given type, delegating to our IDGenerator if set.- Throws:
Exception
-
doGenerateID
Actually generates an ID, using a method matching the given DbMapping.- Throws:
Exception
-
getNodeIDs
Loades subnodes via subnode relation. Only the ID index is loaded, the nodes are loaded later on demand.- Throws:
Exception
-
getNodes
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
-
prefetchNodes
public void prefetchNodes(Node home, Relation rel, SubnodeList list, int start, int length) throws Exception - Throws:
Exception
-
countNodes
Count the nodes contained in the child collection of the home node which is defined by Relation rel.- Throws:
Exception
-
getPropertyNames
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. -
getDbMapping
Get a DbMapping for a given prototype name. This is just a proxy method to the app's getDbMapping() method. -
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
Returns a map with statistics about the cache -
addNodeChangeListener
Add a listener that is notified each time a transaction commits that adds, modifies or deletes any Nodes. -
removeNodeChangeListener
Remove a previously added NodeChangeListener. -
hasNodeChangeListeners
protected boolean hasNodeChangeListeners()Let transactors know if they should collect and fire NodeChangeListener events -
fireNodeChangeEvent
Called by transactors after committing.
-