use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class PropertyExistenceConstraintsIT method createLabelUniquenessPropertyConstraint.
private ConstraintDefinition createLabelUniquenessPropertyConstraint(String labelName, String propertyKey) {
try (Transaction tx = graphdb().beginTx()) {
ConstraintDefinition constraintDefinition = graphdb().schema().constraintFor(label(labelName)).assertPropertyIsUnique(propertyKey).create();
tx.success();
return constraintDefinition;
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class LegacyIndexTest method createRelationshipLegacyIndexWithSingleRelationship.
private static void createRelationshipLegacyIndexWithSingleRelationship(GraphDatabaseService db, String indexName) {
try (Transaction tx = db.beginTx()) {
Relationship relationship = db.createNode().createRelationshipTo(db.createNode(), TYPE);
Index<Relationship> relationshipIndexIndex = db.index().forRelationships(indexName);
relationshipIndexIndex.add(relationship, "key", System.currentTimeMillis());
tx.success();
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class AutoIndexOperationsTest method shouldNotSeeDeletedRelationshipWhenQueryingWithStartAndEndNode.
@Test
public void shouldNotSeeDeletedRelationshipWhenQueryingWithStartAndEndNode() {
RelationshipType type = MyRelTypes.TEST;
long startId;
long endId;
Relationship rel;
try (Transaction tx = db.beginTx()) {
Node start = db.createNode();
Node end = db.createNode();
startId = start.getId();
endId = end.getId();
rel = start.createRelationshipTo(end, type);
rel.setProperty("Type", type.name());
tx.success();
}
try (Transaction tx = db.beginTx()) {
ReadableRelationshipIndex autoRelationshipIndex = db.index().getRelationshipAutoIndexer().getAutoIndex();
Node start = db.getNodeById(startId);
Node end = db.getNodeById(endId);
IndexHits<Relationship> hits = autoRelationshipIndex.get("Type", type.name(), start, end);
assertEquals(1, count(hits));
assertEquals(1, hits.size());
rel.delete();
autoRelationshipIndex = db.index().getRelationshipAutoIndexer().getAutoIndex();
hits = autoRelationshipIndex.get("Type", type.name(), start, end);
assertEquals(0, count(hits));
assertEquals(0, hits.size());
tx.success();
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class BatchInsertionIT method shouldIndexNodesWithMultipleLabels.
@Test
public void shouldIndexNodesWithMultipleLabels() throws Exception {
// Given
File path = new File(dbRule.getStoreDirAbsolutePath());
BatchInserter inserter = BatchInserters.inserter(path, fileSystemRule.get());
inserter.createNode(map("name", "Bob"), label("User"), label("Admin"));
inserter.createDeferredSchemaIndex(label("User")).on("name").create();
inserter.createDeferredSchemaIndex(label("Admin")).on("name").create();
// When
inserter.shutdown();
// Then
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
assertThat(count(db.findNodes(label("User"), "name", "Bob")), equalTo(1L));
assertThat(count(db.findNodes(label("Admin"), "name", "Bob")), equalTo(1L));
} finally {
db.shutdown();
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class IndexCreationTest method verifyThatIndexCreationTransactionIsTheFirstOne.
private void verifyThatIndexCreationTransactionIsTheFirstOne() throws Exception {
PhysicalLogFile pLogFile = db.getDependencyResolver().resolveDependency(PhysicalLogFile.class);
long version = db.getDependencyResolver().resolveDependency(LogVersionRepository.class).getCurrentLogVersion();
db.getDependencyResolver().resolveDependency(LogRotation.class).rotateLogFile();
db.getDependencyResolver().resolveDependency(CheckPointer.class).forceCheckPoint(new SimpleTriggerInfo("test"));
ReadableLogChannel logChannel = pLogFile.getReader(LogPosition.start(version));
final AtomicBoolean success = new AtomicBoolean(false);
try (IOCursor<LogEntry> cursor = new LogEntryCursor(new VersionAwareLogEntryReader<>(), logChannel)) {
List<StorageCommand> commandsInFirstEntry = new ArrayList<>();
boolean startFound = false;
while (cursor.next()) {
LogEntry entry = cursor.get();
if (entry instanceof LogEntryStart) {
if (startFound) {
throw new IllegalArgumentException("More than one start entry");
}
startFound = true;
}
if (startFound && entry instanceof LogEntryCommand) {
commandsInFirstEntry.add(entry.<LogEntryCommand>as().getXaCommand());
}
if (entry instanceof LogEntryCommit) {
// The first COMMIT
assertTrue(startFound);
assertFalse("Index creation transaction wasn't the first one", commandsInFirstEntry.isEmpty());
List<StorageCommand> createCommands = Iterators.asList(new FilteringIterator<>(commandsInFirstEntry.iterator(), item -> item instanceof IndexDefineCommand));
assertEquals(1, createCommands.size());
success.set(true);
break;
}
}
}
assertTrue("Didn't find any commit record in log " + version, success.get());
}
Aggregations