Class 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.
    • 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 java.util.List 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 java.util.List 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
      • collectMissingKeys

        protected java.util.List collectMissingKeys​(SubnodeList list,
                                                    int start,
                                                    int length)
      • prefetchNodes

        public void prefetchNodes​(Node home,
                                  Relation rel,
                                  SubnodeList list,
                                  int start,
                                  int length)
                           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 List that contains 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.
      • getCacheStatistics

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