Search in sources :

Example 1 with NodeFactoryNeo4j3

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;
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Transaction(org.neo4j.graphdb.Transaction) NodeFactory(org.eol.globi.data.NodeFactory) Dataset(org.globalbioticinteractions.dataset.Dataset) AtomicReference(java.util.concurrent.atomic.AtomicReference) NodeFactoryNeo4j3(org.eol.globi.data.NodeFactoryNeo4j3)

Example 2 with NodeFactoryNeo4j3

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);
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) NodeFactoryNeo4j(org.eol.globi.data.NodeFactoryNeo4j) NodeFactoryNeo4j3(org.eol.globi.data.NodeFactoryNeo4j3) Test(org.junit.Test)

Aggregations

NodeFactoryNeo4j3 (org.eol.globi.data.NodeFactoryNeo4j3)2 Transaction (org.neo4j.graphdb.Transaction)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 NodeFactory (org.eol.globi.data.NodeFactory)1 NodeFactoryNeo4j (org.eol.globi.data.NodeFactoryNeo4j)1 Dataset (org.globalbioticinteractions.dataset.Dataset)1 Test (org.junit.Test)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1