use of org.structr.bolt.SessionTransaction in project structr by structr.
the class NodeWrapper method evaluateCustomQuery.
/**
* Evaluate a custom query and return result as a boolean value
*
* @param customQuery
* @param parameters
* @return
*/
public boolean evaluateCustomQuery(final String customQuery, final Map<String, Object> parameters) {
final SessionTransaction tx = db.getCurrentTransaction();
boolean result = false;
try {
result = tx.getBoolean(customQuery, parameters);
} catch (Exception ignore) {
}
return result;
}
use of org.structr.bolt.SessionTransaction in project structr by structr.
the class EntityWrapper method delete.
@Override
public void delete() throws NotInTransactionException {
assertNotStale();
final SessionTransaction tx = db.getCurrentTransaction();
final Map<String, Object> map = new HashMap<>();
map.put("id", id);
tx.set(getQueryPrefix() + " WHERE ID(n) = {id} DELETE n", map);
tx.modified(this);
stale = true;
}
use of org.structr.bolt.SessionTransaction in project structr by structr.
the class EntityWrapper method assertNotStale.
// ----- protected methods -----
protected synchronized void assertNotStale() {
if (stale) {
// invalidate caches
onRemoveFromCache();
// if a node/rel was deleted in a previous transaction but the caller keeps a
// reference to this entity, we need to make sure that the reference is fresh.
final SessionTransaction tx = db.getCurrentTransaction();
final Map<String, Object> map = new HashMap<>();
map.put("id", id);
try {
// update data
data.clear();
update(tx.getEntity(getQueryPrefix() + " WHERE ID(n) = {id} RETURN n", map).asMap());
} catch (NoSuchRecordException nex) {
throw new NotFoundException(nex);
}
stale = false;
}
}
use of org.structr.bolt.SessionTransaction in project structr by structr.
the class EntityWrapper method setProperties.
@Override
public void setProperties(final Map<String, Object> values) {
assertNotStale();
final Map<String, Object> map = new HashMap<>();
final SessionTransaction tx = db.getCurrentTransaction();
final String query = getQueryPrefix() + " WHERE ID(n) = {id} SET n += {properties}";
// overwrite a potential "id" property
map.put("id", id);
map.put("properties", values);
// execute query
tx.set(query, map);
// update data
update(values);
tx.modified(this);
}
use of org.structr.bolt.SessionTransaction in project structr by structr.
the class NodeWrapper method createRelationshipTo.
@Override
public Relationship createRelationshipTo(final Node endNode, final RelationshipType relationshipType, final Map<String, Object> properties) {
assertNotStale();
dontUseCache = true;
final SessionTransaction tx = db.getCurrentTransaction();
final Map<String, Object> map = new HashMap<>();
final NodeWrapper otherNode = (NodeWrapper) endNode;
final String tenantIdentifier = db.getTenantIdentifier();
final StringBuilder buf = new StringBuilder();
map.put("id1", id);
map.put("id2", endNode.getId());
map.put("relProperties", properties);
buf.append("MATCH (n");
if (tenantIdentifier != null) {
buf.append(":");
buf.append(tenantIdentifier);
}
buf.append("), (m");
if (tenantIdentifier != null) {
buf.append(":");
buf.append(tenantIdentifier);
}
buf.append(") WHERE ID(n) = {id1} AND ID(m) = {id2} ");
buf.append("MERGE (n)-[r:");
buf.append(relationshipType.name());
buf.append("]->(m)");
buf.append(" SET r += {relProperties} RETURN r");
final org.neo4j.driver.v1.types.Relationship rel = tx.getRelationship(buf.toString(), map);
tx.modified(this);
tx.modified(otherNode);
// clear caches
((NodeWrapper) endNode).relationshipCache.clear();
relationshipCache.clear();
return RelationshipWrapper.newInstance(db, rel);
}
Aggregations