* @return Table.js object with additional property named json
* @throws GameEngineException
*/
private ScriptableObject getTable(final long tableId, final long mementoId)
throws GameEngineException {
Step step = MiniProfiler.step("API.getTable");
try {
final HashMap<String, Object> hashMap = ge.persistence.get("Table",
tableId);
final ScriptableObject table = createTable();
String json = (String) hashMap.get("json");
// convert the json string to an object
Object jsonObject = ge.parse(json);
restoreTable(table, jsonObject);
Integer currentMementoId = (Integer) table.get("mementoId");
if (currentMementoId == null) {
currentMementoId = -1;
}
// if mementoId is greater then the tables mementoId
if (mementoId < currentMementoId) {
// get the mementos that are greater then mementoId
PreparedQuery mementos = getMementos(tableId, mementoId);
addMementos(table, mementos);
// redo the json attribute
json = stringify(table);
// ScriptableObject.putProperty(table, "json", json2);
}
table.put("json", table, json);
return table;
} finally {
step.close();
}
}