Search in sources :

Example 6 with SessionTransaction

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);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SessionTransaction(org.structr.bolt.SessionTransaction)

Example 7 with SessionTransaction

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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SessionTransaction(org.structr.bolt.SessionTransaction) Label(org.structr.api.graph.Label) LinkedList(java.util.LinkedList)

Example 8 with SessionTransaction

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;
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SessionTransaction(org.structr.bolt.SessionTransaction)

Example 9 with SessionTransaction

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);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SessionTransaction(org.structr.bolt.SessionTransaction)

Example 10 with SessionTransaction

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);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SessionTransaction(org.structr.bolt.SessionTransaction)

Aggregations

SessionTransaction (org.structr.bolt.SessionTransaction)17 HashMap (java.util.HashMap)14 LinkedHashMap (java.util.LinkedHashMap)9 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 Relationship (org.structr.api.graph.Relationship)3 RelationshipRelationshipMapper (org.structr.bolt.mapper.RelationshipRelationshipMapper)3 LinkedList (java.util.LinkedList)1 NoSuchRecordException (org.neo4j.driver.v1.exceptions.NoSuchRecordException)1 NotFoundException (org.structr.api.NotFoundException)1 Label (org.structr.api.graph.Label)1