use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class ImportToolTest method shouldSkipDuplicateNodesIfToldTo.
@Test
public void shouldSkipDuplicateNodesIfToldTo() throws Exception {
// GIVEN
List<String> nodeIds = asList("a", "b", "c", "d", "e", "f", "a", "g");
Configuration config = Configuration.COMMAS;
File nodeHeaderFile = nodeHeader(config);
File nodeData1 = nodeData(false, config, nodeIds, lines(0, 4));
File nodeData2 = nodeData(false, config, nodeIds, lines(4, nodeIds.size()));
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--skip-duplicate-nodes", "--nodes", nodeHeaderFile.getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData1.getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData2.getAbsolutePath());
// THEN
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
// there should not be duplicates of any node
Iterator<Node> nodes = db.getAllNodes().iterator();
Iterator<String> expectedIds = FilteringIterator.noDuplicates(nodeIds.iterator());
while (expectedIds.hasNext()) {
assertTrue(nodes.hasNext());
assertEquals(expectedIds.next(), nodes.next().getProperty("id"));
}
assertFalse(nodes.hasNext());
// also all nodes in the label index should exist
for (int i = 0; i < MAX_LABEL_ID; i++) {
Label label = Label.label(labelName(i));
try (ResourceIterator<Node> nodesByLabel = db.findNodes(label)) {
while (nodesByLabel.hasNext()) {
assertTrue(nodesByLabel.next().hasLabel(label));
}
}
}
tx.success();
} finally {
db.shutdown();
}
}
use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class GraphDbStructureGuide method showRelCounts.
private void showRelCounts(ReadOperations read, DbStructureVisitor visitor) {
// all wildcards
noSide(read, visitor, WILDCARD_REL_TYPE, ANY_RELATIONSHIP_TYPE);
// one label only
for (Label label : db.getAllLabels()) {
int labelId = read.labelGetForName(label.name());
leftSide(read, visitor, label, labelId, WILDCARD_REL_TYPE, ANY_RELATIONSHIP_TYPE);
rightSide(read, visitor, label, labelId, WILDCARD_REL_TYPE, ANY_RELATIONSHIP_TYPE);
}
// fixed rel type
for (RelationshipType relType : db.getAllRelationshipTypes()) {
int relTypeId = read.relationshipTypeGetForName(relType.name());
noSide(read, visitor, relType, relTypeId);
for (Label label : db.getAllLabels()) {
int labelId = read.labelGetForName(label.name());
// wildcard on right
leftSide(read, visitor, label, labelId, relType, relTypeId);
// wildcard on left
rightSide(read, visitor, label, labelId, relType, relTypeId);
}
}
}
use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class NodeProxyTest method createDropNodeLongArrayProperty.
@Test
public void createDropNodeLongArrayProperty() {
Label markerLabel = Label.label("marker");
String testPropertyKey = "testProperty";
byte[] propertyValue = RandomUtils.nextBytes(1024);
try (Transaction tx = db.beginTx()) {
Node node = db.createNode(markerLabel);
node.setProperty(testPropertyKey, propertyValue);
tx.success();
}
try (Transaction tx = db.beginTx()) {
Node node = Iterators.single(db.findNodes(markerLabel));
assertArrayEquals(propertyValue, (byte[]) node.getProperty(testPropertyKey));
tx.success();
}
try (Transaction tx = db.beginTx()) {
Node node = Iterators.single(db.findNodes(markerLabel));
node.removeProperty(testPropertyKey);
tx.success();
}
try (Transaction tx = db.beginTx()) {
Node node = Iterators.single(db.findNodes(markerLabel));
assertFalse(node.hasProperty(testPropertyKey));
tx.success();
}
}
use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class RelationshipProxyTest method createDropRelationshipLongStringProperty.
@Test
public void createDropRelationshipLongStringProperty() {
Label markerLabel = DynamicLabel.label("marker");
String testPropertyKey = "testProperty";
String propertyValue = RandomStringUtils.randomAscii(255);
try (Transaction tx = db.beginTx()) {
Node start = db.createNode(markerLabel);
Node end = db.createNode(markerLabel);
Relationship relationship = start.createRelationshipTo(end, withName("type"));
relationship.setProperty(testPropertyKey, propertyValue);
tx.success();
}
try (Transaction tx = db.beginTx()) {
Relationship relationship = db.getRelationshipById(0);
assertEquals(propertyValue, relationship.getProperty(testPropertyKey));
tx.success();
}
try (Transaction tx = db.beginTx()) {
Relationship relationship = db.getRelationshipById(0);
relationship.removeProperty(testPropertyKey);
tx.success();
}
try (Transaction tx = db.beginTx()) {
Relationship relationship = db.getRelationshipById(0);
assertFalse(relationship.hasProperty(testPropertyKey));
tx.success();
}
}
use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class ManyMergesStressTest method shouldWorkFine.
@Test
public void shouldWorkFine() throws Throwable {
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
GraphDatabaseQueryService graph = new GraphDatabaseCypherService(db);
Label person = Label.label("Person");
try (Transaction tx = db.beginTx()) {
// THIS USED TO CAUSE OUT OF FILE HANDLES
// (maybe look at: http://stackoverflow.com/questions/6210348/too-many-open-files-error-on-lucene)
db.schema().indexFor(person).on("id").create();
// THIS SHOULD ALSO WORK
db.schema().constraintFor(person).assertPropertyIsUnique("id").create();
tx.success();
}
try (Transaction tx = db.beginTx()) {
db.schema().indexFor(person).on("name").create();
tx.success();
}
try (Transaction tx = db.beginTx()) {
db.schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
tx.success();
}
for (int count = 0; count < TRIES; count++) {
Pair<String, String> stringPair = getRandomName();
String ident = stringPair.first();
String name = stringPair.other();
String id = Long.toString(Math.abs(random.nextLong()));
String query = format("MERGE (%s:Person {id: %s}) ON CREATE SET %s.name = \"%s\";", ident, id, ident, name);
try (InternalTransaction tx = graph.beginTransaction(KernelTransaction.Type.implicit, SecurityContext.AUTH_DISABLED)) {
Result result = db.execute(query);
result.close();
tx.success();
}
}
}
Aggregations