Package helma.objectmodel.db
Class Node
- java.lang.Object
-
- helma.objectmodel.db.Node
-
- All Implemented Interfaces:
IPathElement
,INode
,INodeState
public final class Node extends java.lang.Object implements INode
An implementation of INode that can be stored in the internal database or an external relational database.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
anonymous
protected long
created
protected long
lastmodified
protected NodeHandle
parentHandle
protected short
version
-
Constructor Summary
Constructors Modifier Constructor Description protected
Node(long timestamp)
Creates an empty, uninitialized Node with the given create and modify time.Node(Node home, java.lang.String propname, WrappedNodeManager nmgr, java.lang.String prototype)
Constructor used for virtual nodes.protected
Node(WrappedNodeManager nmgr)
Creates an empty, uninitialized Node.Node(java.lang.String name, java.lang.String prototype, WrappedNodeManager nmgr)
Creates a new Node with the given name.Node(java.lang.String name, java.lang.String id, java.lang.String prototype, WrappedNodeManager nmgr)
Creates a new Node with the given name.Node(java.lang.String name, java.lang.String id, java.lang.String prototype, WrappedNodeManager nmgr, long created, long lastmodified)
Constructor used to create a Node with a given name from a embedded database.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description INode
addNode(INode elem)
INode-relatedINode
addNode(INode elem, int where)
Add a node to this Node's subnodes, making the added node persistent if it hasn't been before and this Node is already persistent.void
clearCacheNode()
Reset the cache node for this node.int
contains(INode n)
Check if the given node is contained in this node's child list.long
created()
Get the node's creation timestamp.INode
createNode()
INode
createNode(int where)
INode
createNode(java.lang.String nm)
Create a new named property with a node valueINode
createNode(java.lang.String nm, int where)
Create a new unnamed child node at the given position.SubnodeList
createSubnodeList()
Create an empty subnode list.protected void
deepRemoveNode()
Delete the node from the db.void
dump()
IProperty
get(java.lang.String propname)
Get a property with the given name.boolean
getBoolean(java.lang.String propname)
Get a boolean property with the given name.Node
getCachedParent()
Get parent, using cached info if it exists.INode
getCacheNode()
Get the cache node for this node.IPathElement
getChildElement(java.lang.String name)
This implements the getChildElement() method of the IPathElement interfacejava.util.Date
getDate(java.lang.String propname)
Get a date property with the given name.DbMapping
getDbMapping()
Get the node'sDbMapping
.java.lang.String
getElementName()
Get something to identify this node within a URL.double
getFloat(java.lang.String propname)
Get a float property with the given name.protected Node
getGroupbySubnode(Node node, boolean create)
Get or create a group name for a given content node.protected Node
getGroupbySubnode(java.lang.String groupname, boolean create)
Get or create a group name for a given group name.NodeHandle
getHandle()
Get the node's handle.java.lang.String
getID()
Get the ID of this Node.long
getInteger(java.lang.String propname)
Get an integer property with the given name.java.lang.Object
getJavaObject(java.lang.String propname)
Get a Java object property with the given name.Key
getKey()
Get the node's key.java.lang.String
getName()
Return this node' name, which may or may not have some meaningINode
getNode(java.lang.String propname)
Get a node property with the given name.Node
getNonVirtualParent()
This method walks down node path to the first non-virtual node and return it.INode
getParent()
Get parent, retrieving it if necessary.IPathElement
getParentElement()
This implements the getParentElement() method of the IPathElement interfacejava.lang.String
getParentInfo()
java.lang.String
getPath()
Get the node's pathprotected Property
getProperty(java.lang.String propname)
java.util.Hashtable
getPropMap()
java.lang.String
getPrototype()
Return the node's prototype name.int
getState()
Gets this node's stateas defined in the INode interfacejava.lang.String
getString(java.lang.String propname)
Get a string property with the given name.INode
getSubnode(java.lang.String subid)
Get a named child node with the given id.INode
getSubnodeAt(int index)
Get a node at a given position.SubnodeList
getSubnodeList()
Return this Node's subnode listjava.lang.String
getSubnodeRelation()
Get the node's explicit subnode select clause if one was set, or nulljava.util.Enumeration
getSubnodes()
Enumerate through the subnodes of this node.int
hashCode()
We overwrite hashCode to make it dependant from the prototype.void
init(DbMapping dbm, java.lang.String id, java.lang.String name, java.lang.String prototype, java.util.Hashtable propMap)
Initializer used for nodes being instanced from an embedded or relational database.void
invalidate()
Mark node as invalid so it is re-fetched from the databasevoid
invalidateNode(java.lang.String key)
Check for a child mapping and evict the object specified by key from the cacheboolean
isAnonymous()
Returns true if this node is accessed by id from its aprent, false if it is accessed by nameboolean
isNullNode()
Instances of this class may be used to mark an entry in the object cache as null.boolean
isParentOf(Node n)
Check if the given node is contained in this node's child list.boolean
isRelational()
Tell whether this node is stored inside a relational db.long
lastModified()
Get the node's last modification timestamp.void
loadNodes()
Make sure the subnode index is loaded for subnodes stored in a relational data source.void
markSubnodesChanged()
Called by the transactor on registered parent nodes to mark the child index as changedint
numberOfNodes()
Count the subnodes of this node.void
persist()
Public method to make a node persistent.void
prefetchChildren(int startIndex, int length)
java.util.Enumeration
properties()
Get all properties of this node.protected void
releaseNode(Node node)
"Locally" remove a subnode from the subnodes table.boolean
remove()
Remove this node from the database.void
removeNode(INode node)
Remove the given node from this node's child nodes.protected void
set(java.lang.String propname, java.lang.Object value, int type)
Directly set a property on this nodevoid
setBoolean(java.lang.String propname, boolean value)
Set the property with the given name to the given boolean value.void
setDate(java.lang.String propname, java.util.Date value)
Set the property with the given name to the given date value.void
setDbMapping(DbMapping dbmap)
Set the node'sDbMapping
.void
setFloat(java.lang.String propname, double value)
Set the property with the given name to the given float value.void
setInteger(java.lang.String propname, long value)
Set the property with the given name to the given integer value.void
setJavaObject(java.lang.String propname, java.lang.Object value)
Set the property with the given name to the given Java object value.void
setName(java.lang.String name)
Set the node's name.void
setNode(java.lang.String propname, INode value)
Set the property with the given name to the given node value.void
setParent(Node parent)
Set this node's parent node.void
setParentHandle(NodeHandle parent)
Set this node's parent node to the node referred to by the NodeHandle.void
setPropMap(java.util.Hashtable propMap)
used by Xml deserializationvoid
setPrototype(java.lang.String proto)
Set the node's prototype name.void
setState(int s)
Sets this node's state as defined in the INode interfacevoid
setString(java.lang.String propname, java.lang.String value)
Set the property with the given name to the given string value.void
setSubnodeRelation(java.lang.String rel)
Set an explicit select clause for the node's subnodesjava.lang.String
toString()
Return a string representation for this node.void
unset(java.lang.String propname)
Remove a property.
-
-
-
Field Detail
-
parentHandle
protected NodeHandle parentHandle
-
created
protected long created
-
lastmodified
protected long lastmodified
-
anonymous
protected boolean anonymous
-
version
protected short version
-
-
Constructor Detail
-
Node
protected Node(long timestamp)
Creates an empty, uninitialized Node with the given create and modify time. This is used for null-node references in the node cache.- Parameters:
timestamp
-
-
Node
protected Node(WrappedNodeManager nmgr)
Creates an empty, uninitialized Node. The init() method must be called on the Node before it can do anything useful.
-
Node
public Node(java.lang.String name, java.lang.String id, java.lang.String prototype, WrappedNodeManager nmgr)
Creates a new Node with the given name. Used by NodeManager for creating "root nodes" outside of a Transaction context, which is why we can immediately mark it as CLEAN. Also used by embedded database to re-create an existing Node.
-
Node
public Node(java.lang.String name, java.lang.String id, java.lang.String prototype, WrappedNodeManager nmgr, long created, long lastmodified)
Constructor used to create a Node with a given name from a embedded database.
-
Node
public Node(Node home, java.lang.String propname, WrappedNodeManager nmgr, java.lang.String prototype)
Constructor used for virtual nodes.
-
Node
public Node(java.lang.String name, java.lang.String prototype, WrappedNodeManager nmgr)
Creates a new Node with the given name. This is used for ordinary transient nodes.
-
-
Method Detail
-
init
public void init(DbMapping dbm, java.lang.String id, java.lang.String name, java.lang.String prototype, java.util.Hashtable propMap)
Initializer used for nodes being instanced from an embedded or relational database.
-
setPropMap
public void setPropMap(java.util.Hashtable propMap)
used by Xml deserialization
-
markSubnodesChanged
public void markSubnodesChanged()
Called by the transactor on registered parent nodes to mark the child index as changed
-
getState
public int getState()
Gets this node's stateas defined in the INode interface
-
setState
public void setState(int s)
Sets this node's state as defined in the INode interface
-
invalidate
public void invalidate()
Mark node as invalid so it is re-fetched from the database
-
invalidateNode
public void invalidateNode(java.lang.String key)
Check for a child mapping and evict the object specified by key from the cache
-
getID
public java.lang.String getID()
Get the ID of this Node. This is the primary database key and used as part of the key for the internal node cache.
-
isAnonymous
public boolean isAnonymous()
Returns true if this node is accessed by id from its aprent, false if it is accessed by name- Specified by:
isAnonymous
in interfaceINode
-
getName
public java.lang.String getName()
Return this node' name, which may or may not have some meaning
-
getElementName
public java.lang.String getElementName()
Get something to identify this node within a URL. This is the ID for anonymous nodes and a property value for named properties.- Specified by:
getElementName
in interfaceIPathElement
-
getPath
public java.lang.String getPath()
Get the node's path
-
getPrototype
public java.lang.String getPrototype()
Return the node's prototype name.- Specified by:
getPrototype
in interfaceINode
- Specified by:
getPrototype
in interfaceIPathElement
-
setPrototype
public void setPrototype(java.lang.String proto)
Set the node's prototype name.- Specified by:
setPrototype
in interfaceINode
-
setDbMapping
public void setDbMapping(DbMapping dbmap)
Set the node'sDbMapping
.- Specified by:
setDbMapping
in interfaceINode
-
getDbMapping
public DbMapping getDbMapping()
Get the node'sDbMapping
.- Specified by:
getDbMapping
in interfaceINode
-
getKey
public Key getKey()
Get the node's key.
-
getHandle
public NodeHandle getHandle()
Get the node's handle.
-
setSubnodeRelation
public void setSubnodeRelation(java.lang.String rel)
Set an explicit select clause for the node's subnodes- Specified by:
setSubnodeRelation
in interfaceINode
-
getSubnodeRelation
public java.lang.String getSubnodeRelation()
Get the node's explicit subnode select clause if one was set, or null- Specified by:
getSubnodeRelation
in interfaceINode
-
setName
public void setName(java.lang.String name)
Set the node's name.
-
setParent
public void setParent(Node parent)
Set this node's parent node.
-
setParentHandle
public void setParentHandle(NodeHandle parent)
Set this node's parent node to the node referred to by the NodeHandle.
-
getParent
public INode getParent()
Get parent, retrieving it if necessary.
-
getCachedParent
public Node getCachedParent()
Get parent, using cached info if it exists.
-
addNode
public INode addNode(INode elem, int where)
Add a node to this Node's subnodes, making the added node persistent if it hasn't been before and this Node is already persistent.
-
createNode
public INode createNode()
- Returns:
- ...
-
createNode
public INode createNode(int where)
- Parameters:
where
- ...- Returns:
- ...
-
createNode
public INode createNode(java.lang.String nm)
Description copied from interface:INode
Create a new named property with a node value- Specified by:
createNode
in interfaceINode
- Parameters:
nm
- ...- Returns:
- ...
-
createNode
public INode createNode(java.lang.String nm, int where)
Description copied from interface:INode
Create a new unnamed child node at the given position.- Specified by:
createNode
in interfaceINode
- Parameters:
nm
- ...where
- ...- Returns:
- ...
-
getChildElement
public IPathElement getChildElement(java.lang.String name)
This implements the getChildElement() method of the IPathElement interface- Specified by:
getChildElement
in interfaceIPathElement
-
getParentElement
public IPathElement getParentElement()
This implements the getParentElement() method of the IPathElement interface- Specified by:
getParentElement
in interfaceIPathElement
-
getSubnode
public INode getSubnode(java.lang.String subid)
Get a named child node with the given id.- Specified by:
getSubnode
in interfaceINode
-
getSubnodeAt
public INode getSubnodeAt(int index)
Get a node at a given position. This causes the subnode list to be loaded in case it isn't up to date.- Specified by:
getSubnodeAt
in interfaceINode
- Parameters:
index
- the subnode index- Returns:
- the node at the given index
-
getGroupbySubnode
protected Node getGroupbySubnode(Node node, boolean create)
Get or create a group name for a given content node.- Parameters:
node
- the content nodecreate
- whether the node should be created if it doesn't exist- Returns:
- the group node, or null
-
getGroupbySubnode
protected Node getGroupbySubnode(java.lang.String groupname, boolean create)
Get or create a group name for a given group name.- Parameters:
groupname
- the group namecreate
- whether the node should be created if it doesn't exist- Returns:
- the group node, or null
-
remove
public boolean remove()
Description copied from interface:INode
Remove this node from the database.
-
removeNode
public void removeNode(INode node)
Description copied from interface:INode
Remove the given node from this node's child nodes.- Specified by:
removeNode
in interfaceINode
- Parameters:
node
- ...
-
releaseNode
protected void releaseNode(Node node)
"Locally" remove a subnode from the subnodes table. The logical stuff necessary for keeping data consistent is done inremoveNode(INode)
.
-
deepRemoveNode
protected void deepRemoveNode()
Delete the node from the db. This mainly tries to notify all nodes referring to this that it's going away. For nodes from the embedded db it also does a cascading delete, since it can tell which nodes are actual children and which are just linked in.
-
contains
public int contains(INode n)
Check if the given node is contained in this node's child list. If it is contained return its index in the list, otherwise return -1.
-
isParentOf
public boolean isParentOf(Node n)
Check if the given node is contained in this node's child list. This is similar tocontains(INode)
but does not load the child index for relational nodes.- Parameters:
n
- a node- Returns:
- true if the given node is contained in this node's child list
-
numberOfNodes
public int numberOfNodes()
Count the subnodes of this node. If they're stored in a relational data source, we may actually load their IDs in order to do this.- Specified by:
numberOfNodes
in interfaceINode
-
loadNodes
public void loadNodes()
Make sure the subnode index is loaded for subnodes stored in a relational data source. Depending on the subnode.loadmode specified in the type.properties, we'll load just the ID index or the actual nodes.
-
createSubnodeList
public SubnodeList createSubnodeList()
Create an empty subnode list.- Returns:
- List an empty List of the type used by this Node
-
prefetchChildren
public void prefetchChildren(int startIndex, int length)
- Parameters:
startIndex
- ...length
- ...- Throws:
java.lang.Exception
- ...
-
getSubnodes
public java.util.Enumeration getSubnodes()
Enumerate through the subnodes of this node.- Specified by:
getSubnodes
in interfaceINode
- Returns:
- an enumeration of this node's subnodes
-
getSubnodeList
public SubnodeList getSubnodeList()
Return this Node's subnode list- Returns:
- the subnode list
-
properties
public java.util.Enumeration properties()
Get all properties of this node.- Specified by:
properties
in interfaceINode
-
getPropMap
public java.util.Hashtable getPropMap()
- Returns:
- ...
-
get
public IProperty get(java.lang.String propname)
Description copied from interface:INode
Get a property with the given name.
-
getParentInfo
public java.lang.String getParentInfo()
- Returns:
- ...
-
getProperty
protected Property getProperty(java.lang.String propname)
- Parameters:
propname
- ...- Returns:
- ...
-
getString
public java.lang.String getString(java.lang.String propname)
Description copied from interface:INode
Get a string property with the given name.
-
getInteger
public long getInteger(java.lang.String propname)
Description copied from interface:INode
Get an integer property with the given name.- Specified by:
getInteger
in interfaceINode
- Parameters:
propname
- ...- Returns:
- ...
-
getFloat
public double getFloat(java.lang.String propname)
Description copied from interface:INode
Get a float property with the given name.
-
getDate
public java.util.Date getDate(java.lang.String propname)
Description copied from interface:INode
Get a date property with the given name.
-
getBoolean
public boolean getBoolean(java.lang.String propname)
Description copied from interface:INode
Get a boolean property with the given name.- Specified by:
getBoolean
in interfaceINode
- Parameters:
propname
- ...- Returns:
- ...
-
getNode
public INode getNode(java.lang.String propname)
Description copied from interface:INode
Get a node property with the given name.
-
getJavaObject
public java.lang.Object getJavaObject(java.lang.String propname)
Description copied from interface:INode
Get a Java object property with the given name.- Specified by:
getJavaObject
in interfaceINode
- Parameters:
propname
- ...- Returns:
- ...
-
set
protected void set(java.lang.String propname, java.lang.Object value, int type)
Directly set a property on this node- Parameters:
propname
- ...value
- ...
-
setString
public void setString(java.lang.String propname, java.lang.String value)
Description copied from interface:INode
Set the property with the given name to the given string value.
-
setInteger
public void setInteger(java.lang.String propname, long value)
Description copied from interface:INode
Set the property with the given name to the given integer value.- Specified by:
setInteger
in interfaceINode
- Parameters:
propname
- ...value
- ...
-
setFloat
public void setFloat(java.lang.String propname, double value)
Description copied from interface:INode
Set the property with the given name to the given float value.
-
setBoolean
public void setBoolean(java.lang.String propname, boolean value)
Description copied from interface:INode
Set the property with the given name to the given boolean value.- Specified by:
setBoolean
in interfaceINode
- Parameters:
propname
- ...value
- ...
-
setDate
public void setDate(java.lang.String propname, java.util.Date value)
Description copied from interface:INode
Set the property with the given name to the given date value.
-
setJavaObject
public void setJavaObject(java.lang.String propname, java.lang.Object value)
Description copied from interface:INode
Set the property with the given name to the given Java object value.- Specified by:
setJavaObject
in interfaceINode
- Parameters:
propname
- ...value
- ...
-
setNode
public void setNode(java.lang.String propname, INode value)
Description copied from interface:INode
Set the property with the given name to the given node value.
-
unset
public void unset(java.lang.String propname)
Remove a property. Note that this works only for explicitly set properties, not for those specified via property relation.
-
lastModified
public long lastModified()
Description copied from interface:INode
Get the node's last modification timestamp.- Specified by:
lastModified
in interfaceINode
- Returns:
- ...
-
created
public long created()
Description copied from interface:INode
Get the node's creation timestamp.
-
toString
public java.lang.String toString()
Return a string representation for this node. This tries to call the javascript implemented toString() if it is defined.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representing this node.
-
isRelational
public boolean isRelational()
Tell whether this node is stored inside a relational db. This doesn't mean it actually is stored in a relational db, just that it would be, if the node was persistent
-
persist
public void persist()
Public method to make a node persistent.
-
getCacheNode
public INode getCacheNode()
Get the cache node for this node. This can be used to store transient cache data per node from Javascript.- Specified by:
getCacheNode
in interfaceINode
-
clearCacheNode
public void clearCacheNode()
Reset the cache node for this node.- Specified by:
clearCacheNode
in interfaceINode
-
getNonVirtualParent
public Node getNonVirtualParent()
This method walks down node path to the first non-virtual node and return it. limit max depth to 5, since there shouldn't be more then 2 layers of virtual nodes.
-
isNullNode
public boolean isNullNode()
Instances of this class may be used to mark an entry in the object cache as null. This method tells the caller whether this is the case.
-
hashCode
public int hashCode()
We overwrite hashCode to make it dependant from the prototype. That way, when the prototype changes, the node will automatically get a new ESNode wrapper, since they're cached in a hashtable. You gotta love these hash code tricks ;-)- Overrides:
hashCode
in classjava.lang.Object
-
dump
public void dump()
-
-