Search in sources :

Example 1 with NotFoundException

use of org.structr.api.NotFoundException in project structr by structr.

the class CypherTest method test03DeleteDirectly.

@Test
public void test03DeleteDirectly() {
    try {
        final TestOne testOne = createTestNode(TestOne.class);
        final TestSix testSix = createTestNode(TestSix.class);
        SixOneOneToOne rel = null;
        assertNotNull(testOne);
        assertNotNull(testSix);
        try (final Tx tx = app.tx()) {
            rel = app.create(testSix, testOne, SixOneOneToOne.class);
            tx.success();
        }
        assertNotNull(rel);
        try (final Tx tx = app.tx()) {
            testOne.getRelationships().iterator().next().getRelationship().delete();
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            rel.getUuid();
            fail("Accessing a deleted relationship should thow an exception.");
            tx.success();
        } catch (NotFoundException nfex) {
            assertNotNull(nfex.getMessage());
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) NotFoundException(org.structr.api.NotFoundException) TestOne(org.structr.core.entity.TestOne) SixOneOneToOne(org.structr.core.entity.SixOneOneToOne) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 2 with NotFoundException

use of org.structr.api.NotFoundException in project structr by structr.

the class CypherTest method test01DeleteAfterLookupWithCypherInTransaction.

@Test
public void test01DeleteAfterLookupWithCypherInTransaction() {
    try {
        final TestSix testSix = this.createTestNode(TestSix.class);
        final TestOne testOne = this.createTestNode(TestOne.class);
        SixOneOneToOne rel = null;
        assertNotNull(testSix);
        assertNotNull(testOne);
        try (final Tx tx = app.tx()) {
            rel = app.create(testSix, testOne, SixOneOneToOne.class);
            tx.success();
        }
        assertNotNull(rel);
        DatabaseService graphDb = app.command(GraphDatabaseCommand.class).execute();
        try (final Tx tx = app.tx()) {
            NativeResult<Relationship> result = graphDb.execute("MATCH (n)<-[r:ONE_TO_ONE]-() RETURN r");
            final Iterator<Relationship> rels = result.columnAs("r");
            assertTrue(rels.hasNext());
            rels.next().delete();
            tx.success();
        }
        try (final Tx tx = app.tx()) {
            rel.getUuid();
            fail("Accessing a deleted relationship should thow an exception.");
            tx.success();
        } catch (NotFoundException iex) {
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Relationship(org.structr.api.graph.Relationship) NotFoundException(org.structr.api.NotFoundException) TestOne(org.structr.core.entity.TestOne) DatabaseService(org.structr.api.DatabaseService) SixOneOneToOne(org.structr.core.entity.SixOneOneToOne) GraphDatabaseCommand(org.structr.core.graph.GraphDatabaseCommand) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 3 with NotFoundException

use of org.structr.api.NotFoundException in project structr by structr.

the class CypherTest method test05RollbackDelete.

@Test
public void test05RollbackDelete() {
    try {
        final TestOne testOne = createTestNode(TestOne.class);
        final TestSix testSix = createTestNode(TestSix.class);
        String relId = null;
        SixOneOneToOne rel = null;
        assertNotNull(testOne);
        assertNotNull(testSix);
        try (final Tx tx = app.tx()) {
            rel = app.create(testSix, testOne, SixOneOneToOne.class);
            relId = rel.getUuid();
            tx.success();
        }
        assertNotNull(rel);
        try (final Tx tx = app.tx()) {
            // do not commit transaction
            testOne.getRelationships().iterator().next().getRelationship().delete();
        }
        try (final Tx tx = app.tx()) {
            assertEquals("UUID of relationship should be readable after rollback", relId, rel.getUuid());
            tx.success();
        } catch (NotFoundException iex) {
        }
    } catch (FrameworkException ex) {
        logger.error(ex.toString());
        fail("Unexpected exception");
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) NotFoundException(org.structr.api.NotFoundException) TestOne(org.structr.core.entity.TestOne) SixOneOneToOne(org.structr.core.entity.SixOneOneToOne) TestSix(org.structr.core.entity.TestSix) Test(org.junit.Test)

Example 4 with NotFoundException

use of org.structr.api.NotFoundException in project structr by structr.

the class SessionTransaction method getStrings.

public QueryResult<String> getStrings(final String statement, final Map<String, Object> map) {
    final long t0 = System.currentTimeMillis();
    try {
        final StatementResult result = tx.run(statement, map);
        final Record record = result.next();
        final Value value = record.get(0);
        return new QueryResult<String>() {

            @Override
            public void close() {
                result.consume();
            }

            @Override
            public Iterator<String> iterator() {
                return value.asList(Values.ofString()).iterator();
            }
        };
    } catch (TransientException tex) {
        closed = true;
        throw new RetryException(tex);
    } catch (NoSuchRecordException nex) {
        throw new NotFoundException(nex);
    } catch (ServiceUnavailableException ex) {
        throw new NetworkException(ex.getMessage(), ex);
    } finally {
        logQuery(statement, map, t0);
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) QueryResult(org.structr.api.QueryResult) TransientException(org.neo4j.driver.v1.exceptions.TransientException) Value(org.neo4j.driver.v1.Value) NotFoundException(org.structr.api.NotFoundException) Record(org.neo4j.driver.v1.Record) ServiceUnavailableException(org.neo4j.driver.v1.exceptions.ServiceUnavailableException) RetryException(org.structr.api.RetryException) NetworkException(org.structr.api.NetworkException) NoSuchRecordException(org.neo4j.driver.v1.exceptions.NoSuchRecordException)

Example 5 with NotFoundException

use of org.structr.api.NotFoundException 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)

Aggregations

NotFoundException (org.structr.api.NotFoundException)11 Tx (org.structr.core.graph.Tx)6 Test (org.junit.Test)5 FrameworkException (org.structr.common.error.FrameworkException)5 SixOneOneToOne (org.structr.core.entity.SixOneOneToOne)5 TestOne (org.structr.core.entity.TestOne)5 TestSix (org.structr.core.entity.TestSix)5 GraphObject (org.structr.core.GraphObject)4 LinkedHashSet (java.util.LinkedHashSet)2 NoSuchRecordException (org.neo4j.driver.v1.exceptions.NoSuchRecordException)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Record (org.neo4j.driver.v1.Record)1 StatementResult (org.neo4j.driver.v1.StatementResult)1 Value (org.neo4j.driver.v1.Value)1 ServiceUnavailableException (org.neo4j.driver.v1.exceptions.ServiceUnavailableException)1 TransientException (org.neo4j.driver.v1.exceptions.TransientException)1 DatabaseService (org.structr.api.DatabaseService)1 NetworkException (org.structr.api.NetworkException)1