Added global getById() function which allows to retrieve any persistent HopObject
by type name and id.
This commit is contained in:
parent
c93316078c
commit
7aa8a8ac87
1 changed files with 22 additions and 1 deletions
|
@ -65,7 +65,7 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
||||||
"authenticate", "createSkin", "format", "encode",
|
"authenticate", "createSkin", "format", "encode",
|
||||||
"encodeXml", "encodeForm", "stripTags", "formatParagraphs",
|
"encodeXml", "encodeForm", "stripTags", "formatParagraphs",
|
||||||
"getXmlDocument", "getHtmlDocument", "seal",
|
"getXmlDocument", "getHtmlDocument", "seal",
|
||||||
"getDBConnection", "getURL", "write", "writeln"
|
"getDBConnection", "getURL", "write", "writeln", "getById"
|
||||||
};
|
};
|
||||||
|
|
||||||
defineFunctionProperties(globalFuncs, GlobalObject.class, 0);
|
defineFunctionProperties(globalFuncs, GlobalObject.class, 0);
|
||||||
|
@ -96,6 +96,27 @@ public class GlobalObject extends ImporterTopLevel implements PropertyRecorder {
|
||||||
super.put(name, start, value);
|
super.put(name, start, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve any persistent HopObject by type name and id.
|
||||||
|
*
|
||||||
|
* @param type the prototype name
|
||||||
|
* @param id the id
|
||||||
|
* @return the HopObject or null if it doesn't exist
|
||||||
|
*/
|
||||||
|
public Object getById(String type, String id) {
|
||||||
|
DbMapping dbmap = app.getDbMapping(type);
|
||||||
|
if (dbmap == null)
|
||||||
|
return null;
|
||||||
|
Object node = null;
|
||||||
|
try {
|
||||||
|
DbKey key = new DbKey(dbmap, id);
|
||||||
|
node = app.getNodeManager().getNode(key);
|
||||||
|
} catch (Exception x) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return node == null ? null : Context.toObject(node, this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue