use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class TestRelationship method testRelGetProperties.
@Test
public void testRelGetProperties() {
Integer int1 = new Integer(1);
Integer int2 = new Integer(2);
String string = new String("3");
Node node1 = getGraphDb().createNode();
Node node2 = getGraphDb().createNode();
Relationship rel1 = node1.createRelationshipTo(node2, MyRelTypes.TEST);
try {
rel1.getProperty(key1);
fail("get non existing property din't throw exception");
} catch (NotFoundException e) {
// OK
}
try {
rel1.getProperty(null);
fail("get of null key din't throw exception");
} catch (IllegalArgumentException e) {
// OK
}
assertTrue(!rel1.hasProperty(key1));
assertTrue(!rel1.hasProperty(null));
rel1.setProperty(key1, int1);
rel1.setProperty(key2, int2);
rel1.setProperty(key3, string);
assertTrue(rel1.hasProperty(key1));
assertTrue(rel1.hasProperty(key2));
assertTrue(rel1.hasProperty(key3));
Map<String, Object> properties = rel1.getAllProperties();
assertTrue(properties.get(key1).equals(int1));
assertTrue(properties.get(key2).equals(int2));
assertTrue(properties.get(key3).equals(string));
properties = rel1.getProperties(key1, key2);
assertTrue(properties.get(key1).equals(int1));
assertTrue(properties.get(key2).equals(int2));
assertFalse(properties.containsKey(key3));
properties = node1.getProperties();
assertTrue(properties.isEmpty());
try {
String[] names = null;
node1.getProperties(names);
fail();
} catch (NullPointerException e) {
// Ok
}
try {
String[] names = new String[] { null };
node1.getProperties(names);
fail();
} catch (NullPointerException e) {
// Ok
}
try {
rel1.removeProperty(key3);
} catch (NotFoundException e) {
fail("Remove of property failed.");
}
assertTrue(!rel1.hasProperty(key3));
assertTrue(!rel1.hasProperty(null));
rel1.delete();
node2.delete();
node1.delete();
}
use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class TestProperties method addAndRemovePropertiesWithinOneTransaction2.
@Test
public void addAndRemovePropertiesWithinOneTransaction2() throws Exception {
Node node = getGraphDb().createNode();
node.setProperty("foo", "bar");
newTransaction();
node.setProperty("foo2", "bar");
node.removeProperty("foo");
newTransaction();
try {
node.getProperty("foo");
fail("property should not exist");
} catch (NotFoundException e) {
// good
}
}
use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class NeoStoresIT method shouldWriteOutThePropertyRecordBeforeReferencingItFromANodeRecord.
@Test
public void shouldWriteOutThePropertyRecordBeforeReferencingItFromANodeRecord() throws Throwable {
Race race = new Race();
long[] latestNodeId = new long[1];
AtomicLong writes = new AtomicLong();
AtomicLong reads = new AtomicLong();
long endTime = currentTimeMillis() + SECONDS.toMillis(2);
race.withEndCondition(() -> (writes.get() > 100 && reads.get() > 10_000) || currentTimeMillis() > endTime);
race.addContestant(() -> {
try (Transaction tx = db.beginTx()) {
Node node = db.createNode();
latestNodeId[0] = node.getId();
node.setProperty("largeProperty", LONG_STRING_VALUE);
tx.success();
}
writes.incrementAndGet();
});
race.addContestant(() -> {
try (Transaction tx = db.getGraphDatabaseAPI().beginTx()) {
Node node = db.getGraphDatabaseAPI().getNodeById(latestNodeId[0]);
for (String propertyKey : node.getPropertyKeys()) {
node.getProperty(propertyKey);
}
tx.success();
} catch (NotFoundException e) {
if (Exceptions.contains(e, InvalidRecordException.class)) {
throw e;
}
}
reads.incrementAndGet();
});
race.go();
}
use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class RelationshipProxy method setProperty.
@Override
public void setProperty(String key, Object value) {
try (Statement statement = actions.statement()) {
int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName(key);
statement.dataWriteOperations().relationshipSetProperty(getId(), Property.property(propertyKeyId, value));
} catch (IllegalArgumentException e) {
// Trying to set an illegal value is a critical error - fail this transaction
actions.failTransaction();
throw e;
} catch (EntityNotFoundException e) {
throw new NotFoundException(e);
} catch (IllegalTokenNameException e) {
// TODO: Maybe throw more context-specific error than just IllegalArgument
throw new IllegalArgumentException(e);
} catch (InvalidTransactionTypeKernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
} catch (AutoIndexingKernelException e) {
throw new IllegalStateException("Auto indexing encountered a failure while setting property: " + e.getMessage(), e);
}
}
use of org.neo4j.graphdb.NotFoundException in project neo4j by neo4j.
the class RelationshipProxy method getProperty.
@Override
public Object getProperty(String key) {
if (null == key) {
throw new IllegalArgumentException("(null) property key is not allowed");
}
try (Statement statement = actions.statement()) {
try {
int propertyId = statement.readOperations().propertyKeyGetForName(key);
if (propertyId == KeyReadOperations.NO_SUCH_PROPERTY_KEY) {
throw new NotFoundException(String.format("No such property, '%s'.", key));
}
Object value = statement.readOperations().relationshipGetProperty(getId(), propertyId);
if (value == null) {
throw new PropertyNotFoundException(propertyId, EntityType.RELATIONSHIP, getId());
}
return value;
} catch (EntityNotFoundException | PropertyNotFoundException e) {
throw new NotFoundException(e.getUserMessage(new StatementTokenNameLookup(statement.readOperations())), e);
}
}
}
Aggregations