use of org.structr.bolt.SessionTransaction in project structr by structr.
the class NodeWrapper method addLabel.
@Override
public void addLabel(final Label label) {
assertNotStale();
final SessionTransaction tx = db.getCurrentTransaction();
final Map<String, Object> map = new HashMap<>();
final String tenantIdentifier = db.getTenantIdentifier();
map.put("id", id);
tx.set("MATCH (n" + (tenantIdentifier != null ? ":" + tenantIdentifier : "") + ") WHERE ID(n) = {id} SET n :" + label.name(), map);
tx.modified(this);
}
use of org.structr.bolt.SessionTransaction in project structr by structr.
the class NodeWrapper method getLabels.
@Override
public Iterable<Label> getLabels() {
assertNotStale();
final SessionTransaction tx = db.getCurrentTransaction();
final Map<String, Object> map = new HashMap<>();
final List<Label> result = new LinkedList<>();
final String tenantIdentifier = db.getTenantIdentifier();
map.put("id", id);
// execute query
for (final String label : tx.getStrings("MATCH (n" + (tenantIdentifier != null ? ":" + tenantIdentifier : "") + ") WHERE ID(n) = {id} RETURN LABELS(n)", map)) {
result.add(db.forName(Label.class, label));
}
return result;
}
use of org.structr.bolt.SessionTransaction in project structr by structr.
the class NodeWrapper method newInstance.
public static NodeWrapper newInstance(final BoltDatabaseService db, final long id) {
synchronized (nodeCache) {
NodeWrapper wrapper = nodeCache.get(id);
if (wrapper == null) {
final SessionTransaction tx = db.getCurrentTransaction();
final Map<String, Object> map = new HashMap<>();
final String tenantIdentifier = db.getTenantIdentifier();
map.put("id", id);
wrapper = new NodeWrapper(db, tx.getNode("MATCH (n" + (tenantIdentifier != null ? ":" + tenantIdentifier : "") + ") WHERE ID(n) = {id} RETURN n", map));
nodeCache.put(id, wrapper);
}
return wrapper;
}
}
use of org.structr.bolt.SessionTransaction in project structr by structr.
the class EntityWrapper method setProperty.
@Override
public void setProperty(final String key, final Object value) {
assertNotStale();
final SessionTransaction tx = db.getCurrentTransaction();
// only update values if actually different from what is stored
if (differentValue(key, value)) {
final Map<String, Object> map = new HashMap<>();
final String query = getQueryPrefix() + " WHERE ID(n) = {id} SET n.`" + key + "` = {value}";
map.put("id", id);
map.put("value", value);
// update entity handle
tx.set(query, map);
// update data
update(key, value);
}
// mark node as modified
tx.modified(this);
}
use of org.structr.bolt.SessionTransaction in project structr by structr.
the class EntityWrapper method removeProperty.
@Override
public void removeProperty(String key) {
assertNotStale();
final SessionTransaction tx = db.getCurrentTransaction();
final Map<String, Object> map = new HashMap<>();
final String query = getQueryPrefix() + " WHERE ID(n) = {id} SET n.`" + key + "` = Null";
map.put("id", id);
// execute query
tx.set(query, map);
// remove key from data
data.remove(key);
tx.modified(this);
}
Aggregations