Search in sources :

Example 1 with Entity

use of org.neo4j.driver.v1.types.Entity 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;
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SessionTransaction(org.structr.bolt.SessionTransaction) NotFoundException(org.structr.api.NotFoundException) NoSuchRecordException(org.neo4j.driver.v1.exceptions.NoSuchRecordException)

Example 2 with Entity

use of org.neo4j.driver.v1.types.Entity in project cypher-for-gremlin by opencypher.

the class GremlinCypherValueConverter method toCypherPath.

@SuppressWarnings("unchecked")
private static Value toCypherPath(List p) {
    boolean isNode = true;
    Entity[] objects = new Entity[p.size()];
    for (int i = 0; i < p.size(); i++) {
        if (isNode) {
            objects[i] = toCypherNode((Map<?, ?>) p.get(i));
        } else {
            objects[i] = toCypherRelationship((Map<?, ?>) p.get(i));
        }
        isNode = !isNode;
    }
    return new InternalPath(objects).asValue();
}
Also used : Entity(org.neo4j.driver.v1.types.Entity) InternalPath(org.neo4j.driver.internal.InternalPath) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Entity

use of org.neo4j.driver.v1.types.Entity in project structr by structr.

the class SessionTransaction method close.

@Override
public void close() {
    if (!success) {
        // be sure that they contain the correct values after a rollback.
        for (final EntityWrapper entity : modifiedEntities) {
            entity.stale();
        }
    } else {
        // so that the relationship caches are rebuilt.
        for (final EntityWrapper entity : modifiedEntities) {
            entity.clearCaches();
        }
    }
    // mark this transaction as closed BEFORE trying to actually close it
    // so that it is closed in case of a failure
    closed = true;
    try {
        tx.close();
        session.close();
    } catch (TransientException tex) {
        // transient exceptions can be retried
        throw new RetryException(tex);
    } finally {
        // so that the relationship caches are rebuilt.
        for (final EntityWrapper entity : modifiedEntities) {
            entity.onClose();
        }
        // make sure that the resources are freed
        if (session.isOpen()) {
            session.close();
        }
    }
}
Also used : TransientException(org.neo4j.driver.v1.exceptions.TransientException) EntityWrapper(org.structr.bolt.wrapper.EntityWrapper) RetryException(org.structr.api.RetryException)

Aggregations

HashMap (java.util.HashMap)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 InternalPath (org.neo4j.driver.internal.InternalPath)1 NoSuchRecordException (org.neo4j.driver.v1.exceptions.NoSuchRecordException)1 TransientException (org.neo4j.driver.v1.exceptions.TransientException)1 Entity (org.neo4j.driver.v1.types.Entity)1 NotFoundException (org.structr.api.NotFoundException)1 RetryException (org.structr.api.RetryException)1 SessionTransaction (org.structr.bolt.SessionTransaction)1 EntityWrapper (org.structr.bolt.wrapper.EntityWrapper)1