use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class BatchInsertTest method shouldNotAllowCreationOfUniquenessConstraintAndIndexOnSameLabelAndProperty.
@Test
public void shouldNotAllowCreationOfUniquenessConstraintAndIndexOnSameLabelAndProperty() throws Exception {
// Given
Label label = label("Person1-" + denseNodeThreshold);
String property = "name";
BatchInserter inserter = globalInserter;
// When
inserter.createDeferredConstraint(label).assertPropertyIsUnique(property).create();
try {
inserter.createDeferredSchemaIndex(label).on(property).create();
fail("Exception expected");
} catch (ConstraintViolationException e) {
// Then
assertEquals("Index for given {label;property} already exists", e.getMessage());
}
}
use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class BatchInsertTest method uniquenessConstraintShouldBeCheckedOnBatchInserterShutdownAndFailIfViolated.
@Test
public void uniquenessConstraintShouldBeCheckedOnBatchInserterShutdownAndFailIfViolated() throws Exception {
// Given
Label label = label("Foo");
String property = "Bar";
String value = "Baz";
BatchInserter inserter = newBatchInserter();
// When
inserter.createDeferredConstraint(label).assertPropertyIsUnique(property).create();
inserter.createNode(Collections.<String, Object>singletonMap(property, value), label);
inserter.createNode(Collections.<String, Object>singletonMap(property, value), label);
// Then
try {
inserter.shutdown();
fail("Node that violates uniqueness constraint was created by batch inserter");
} catch (RuntimeException ex) {
// good
assertEquals(new IndexEntryConflictException(0, 1, value), ex.getCause());
}
}
use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class TestLuceneIndex method queryIndexWithSortByNumericAfterSamePropertyUpdate.
@Test
public void queryIndexWithSortByNumericAfterSamePropertyUpdate() {
Index<Node> index = nodeIndex(stringMap());
commitTx();
String numericProperty = "PRODUCT_ID";
Label updatableIndexesProperty = Label.label("updatableIndexes");
try (Transaction transaction = graphDb.beginTx()) {
for (int i = 0; i < 15; i++) {
Node node = graphDb.createNode(updatableIndexesProperty);
node.setProperty(numericProperty, i);
index.add(node, numericProperty, new ValueContext(i).indexNumeric());
}
transaction.success();
}
doubleNumericPropertyValueForAllNodesWithLabel(index, numericProperty, updatableIndexesProperty);
queryAndSortNodesByNumericProperty(index, numericProperty, i -> i * 2);
}
use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class TestLuceneIndex method queryIndexWithSortByStringAfterSamePropertyUpdate.
@Test
public void queryIndexWithSortByStringAfterSamePropertyUpdate() {
Index<Node> index = nodeIndex(stringMap());
commitTx();
String nameProperty = "NODE_NAME";
Label heroes = Label.label("heroes");
String[] names = new String[] { "Fry", "Leela", "Bender", "Amy", "Hubert", "Calculon" };
try (Transaction transaction = graphDb.beginTx()) {
for (String name : names) {
Node node = graphDb.createNode(heroes);
node.setProperty(nameProperty, name);
index.add(node, nameProperty, name);
}
transaction.success();
}
try (Transaction transaction = graphDb.beginTx()) {
ResourceIterator<Node> nodes = graphDb.findNodes(heroes);
nodes.stream().forEach(node -> {
node.setProperty(nameProperty, "junior " + node.getProperty(nameProperty));
index.remove(node, nameProperty);
index.add(node, nameProperty, node.getProperty(nameProperty));
});
transaction.success();
}
String[] sortedNames = new String[] { "junior Leela", "junior Hubert", "junior Fry", "junior Calculon", "junior Bender", "junior Amy" };
queryAndSortNodesByStringProperty(index, nameProperty, sortedNames);
}
use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class TestLuceneIndex method queryIndexWithSortByNumericAfterOtherPropertyUpdate.
@Test
public void queryIndexWithSortByNumericAfterOtherPropertyUpdate() {
Index<Node> index = nodeIndex();
commitTx();
String yearProperty = "year";
String priceProperty = "price";
Label nodeLabel = Label.label("priceyNodes");
try (Transaction transaction = graphDb.beginTx()) {
for (int i = 0; i < 15; i++) {
Node node = graphDb.createNode(nodeLabel);
node.setProperty(yearProperty, i);
node.setProperty(priceProperty, i);
index.add(node, yearProperty, new ValueContext(i).indexNumeric());
index.add(node, priceProperty, new ValueContext(i).indexNumeric());
}
transaction.success();
}
doubleNumericPropertyValueForAllNodesWithLabel(index, priceProperty, nodeLabel);
queryAndSortNodesByNumericProperty(index, yearProperty);
queryAndSortNodesByNumericProperty(index, priceProperty, (value) -> value * 2);
}
Aggregations