use of org.eol.globi.data.NodeFactoryNeo4j3 in project eol-globi-data by jhpoelen.
the class NodeFactoryFactoryTransactingOnDatasetNeo4j3 method create.
@Override
public NodeFactory create(GraphDatabaseService service) {
GraphDatabaseService graphService = graphServiceFactory.getGraphService();
try (Transaction tx = graphService.beginTx()) {
NodeFactory nodeFactory = new NodeFactoryNeo4j3(graphService) {
final AtomicReference<Transaction> tx = new AtomicReference<>();
final AtomicBoolean closing = new AtomicBoolean(false);
@Override
public Dataset getOrCreateDataset(Dataset dataset) {
if (closing.get()) {
throw new IllegalStateException("cannot create a dataset on closing node factory");
} else {
Transaction transaction = tx.get();
if (transaction != null) {
transaction.success();
transaction.close();
}
tx.set(graphServiceFactory.getGraphService().beginTx());
}
return super.getOrCreateDataset(dataset);
}
@Override
public void close() {
closing.set(true);
Transaction lastTx = tx.getAndSet(null);
if (lastTx != null) {
lastTx.success();
lastTx.close();
}
}
};
tx.success();
return nodeFactory;
}
}
use of org.eol.globi.data.NodeFactoryNeo4j3 in project eol-globi-data by jhpoelen.
the class NodeFactoryTest method doSingleImportNeo4j3.
@Test
public void doSingleImportNeo4j3() throws StudyImporterException {
try (Transaction tx = getGraphDb().beginTx()) {
NodeFactoryNeo4j3.initSchema(getGraphDb());
tx.success();
}
NodeFactoryNeo4j factory = new NodeFactoryNeo4j3(getGraphDb());
try (Transaction tx = getGraphDb().beginTx()) {
assertGraphDBImportNativeIndexes(factory);
}
}
Aggregations