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");
}
}
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");
}
}
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");
}
}
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);
}
}
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;
}
}
Aggregations