use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class Inserter method getIndex.
private static Index<Node> getIndex(GraphDatabaseService db) {
try (Transaction transaction = db.beginTx()) {
Index<Node> index = db.index().forNodes("myIndex");
transaction.success();
return index;
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class TestLuceneBatchInsert method testFulltext.
@Test
public void testFulltext() {
BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProviderNewImpl(inserter);
String name = "users";
BatchInserterIndex index = provider.nodeIndex(name, stringMap("type", "fulltext"));
long id1 = inserter.createNode(null);
index.add(id1, map("name", "Mattias Persson", "email", "something@somewhere", "something", "bad"));
long id2 = inserter.createNode(null);
index.add(id2, map("name", "Lars PerssoN"));
index.flush();
assertContains(index.get("name", "Mattias Persson"), id1);
assertContains(index.query("name", "mattias"), id1);
assertContains(index.query("name", "bla"));
assertContains(index.query("name", "persson"), id1, id2);
assertContains(index.query("email", "*@*"), id1);
assertContains(index.get("something", "bad"), id1);
long id3 = inserter.createNode(null);
index.add(id3, map("name", new String[] { "What Ever", "Anything" }));
index.flush();
assertContains(index.get("name", "What Ever"), id3);
assertContains(index.get("name", "Anything"), id3);
provider.shutdown();
switchToGraphDatabaseService();
try (Transaction transaction = db.beginTx()) {
Index<Node> dbIndex = db.index().forNodes(name);
Node node1 = db.getNodeById(id1);
Node node2 = db.getNodeById(id2);
assertContains(dbIndex.query("name", "persson"), node1, node2);
transaction.success();
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class Fixtures method applyTo.
public void applyTo(InProcessServerControls controls) {
GraphDatabaseService db = controls.graph();
for (String fixtureStatement : fixtureStatements) {
try (Transaction tx = db.beginTx()) {
db.execute(fixtureStatement);
tx.success();
}
}
for (Function<GraphDatabaseService, Void> fixtureFunction : fixtureFunctions) {
fixtureFunction.apply(db);
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class InProcessBuilderTest method shouldRunBuilderOnExistingStoreDir.
@Test
public void shouldRunBuilderOnExistingStoreDir() throws Exception {
// When
// create graph db with one node upfront
Path dir = Files.createTempDirectory(getClass().getSimpleName() + "_shouldRunBuilderOnExistingStorageDir");
File storeDir = Config.embeddedDefaults(stringMap(DatabaseManagementSystemSettings.data_directory.name(), dir.toString())).get(DatabaseManagementSystemSettings.database_path);
try {
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
try {
db.execute("create ()");
} finally {
db.shutdown();
}
try (ServerControls server = getTestServerBuilder(testDir.directory()).copyFrom(dir.toFile()).newServer()) {
// Then
try (Transaction tx = server.graph().beginTx()) {
ResourceIterable<Node> allNodes = Iterables.asResourceIterable(server.graph().getAllNodes());
assertTrue(Iterables.count(allNodes) > 0);
// When: create another node
server.graph().createNode();
tx.success();
}
}
// Then: we still only have one node since the server is supposed to work on a copy
db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
try {
try (Transaction tx = db.beginTx()) {
assertEquals(1, Iterables.count(db.getAllNodes()));
tx.success();
}
} finally {
db.shutdown();
}
} finally {
FileUtils.forceDelete(dir.toFile());
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class GraphDbHelper method setRelationshipProperties.
public void setRelationshipProperties(long relationshipId, Map<String, Object> properties) {
try (Transaction tx = database.getGraph().beginTransaction(implicit, AnonymousContext.writeToken())) {
Relationship relationship = database.getGraph().getRelationshipById(relationshipId);
for (Map.Entry<String, Object> propertyEntry : properties.entrySet()) {
relationship.setProperty(propertyEntry.getKey(), propertyEntry.getValue());
}
tx.success();
}
}
Aggregations