From d8149e0bee4ef2b69dd286c57bf2459d1947e440 Mon Sep 17 00:00:00 2001 From: hns Date: Fri, 21 Dec 2007 16:37:25 +0000 Subject: [PATCH] * Implement new HOpObject isPersistent() and isTransient() methods. --- src/helma/scripting/rhino/HopObject.java | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/helma/scripting/rhino/HopObject.java b/src/helma/scripting/rhino/HopObject.java index 42dbd598..029a7f33 100644 --- a/src/helma/scripting/rhino/HopObject.java +++ b/src/helma/scripting/rhino/HopObject.java @@ -668,6 +668,36 @@ public class HopObject extends ScriptableObject implements Wrapper, PropertyReco return true; } + /** + * Check whether the wrapped Node is persistent. + * This also returns true if the Node is being inserted in the database, + * or it has been in database and is in the proces of being deleted. + * @return true if the the wrapped Node has a valid database id. + */ + public boolean jsFunction_isPersistent() { + if (!(node instanceof helma.objectmodel.db.Node)) { + return false; + } + checkNode(); + int nodeState = node.getState(); + return nodeState != INode.TRANSIENT; + } + + /** + * Check whether the wrapped Node is transient. + * This also returns false if the Node is being inserted in the database, + * or it has been in database and is in the proces of being deleted. + * @return true if the the wrapped Node is not stored in a database. + */ + public boolean jsFunction_isTransient() { + if (!(node instanceof helma.objectmodel.db.Node)) { + return true; + } + checkNode(); + int nodeState = node.getState(); + return nodeState == INode.TRANSIENT; + } + /** * Check if node is contained in the subnode collection. * Return its index position if it is, and -1 otherwise.