1

だから私はNeo4j Spatialに頭を悩ませようとしています。次のコードを書きました。

public static void main(String[] args) {
    GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase("var/geo");
    SpatialDatabaseService spatialDb = new SpatialDatabaseService(graphDb);
    EditableLayer runningLayer = (EditableLayer) spatialDb.getOrCreateLayer("running", SimplePointEncoder.class, EditableLayerImpl.class, "lon:lat");

    Node ship = null;
    try(Transaction tx = graphDb.beginTx();) {
        ship = graphDb.createNode(MyLabels.Ship);
        ship.setProperty("Name", new String("Toms Powerboat"));
        tx.success();
    }
    routeGenerator(graphDb, runningLayer, ship);
    graphDb.shutdown();
}


private static void routeGenerator(GraphDatabaseService graphDb, EditableLayer runningLayer, Node node){

    final long startTime = System.currentTimeMillis();
    try(
            Transaction tx = graphDb.beginTx();
            ){
        Coordinate start = new Coordinate(Math.random()*10, Math.random()*10);
        for(int i=0; i<200; i++){
            SpatialDatabaseRecord torecord = runningLayer.add(runningLayer.getGeometryFactory().createPoint(start));
            torecord.setProperty("Time", (System.currentTimeMillis() - startTime)*10000000);
            torecord.getGeomNode().createRelationshipTo(node, RelTypes.hasLocation);
            start = new Coordinate((start.x + 0.1), start.x+Math.random()*0.2);
        }

        tx.success();


    }
}

これは、最初に実行したときに機能するように見えますが、2 回目に実行しようとすると、次のようになります。

Exception in thread "main" java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, C:\Users\pstephens\Programming\Java\ContainSSS\var\geo
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:330)
at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:63)
at org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:92)
at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:198)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:69)
at com.bmt.contain.spatial.test.SpatialTest.main(SpatialTest.java:43)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.impl.transaction.XaDataSourceManager@349cebe0' was successfully initialized, but failed to start. Please see attached cause exception.
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:509)
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:115)
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:307)
... 5 more


Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource@46c8fa1e' was successfully initialized, but failed to start. Please see attached cause exception.
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:509)
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:115)
at org.neo4j.kernel.impl.transaction.XaDataSourceManager.start(XaDataSourceManager.java:164)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:503)
... 7 more
Caused by: org.neo4j.kernel.impl.storemigration.UpgradeNotAllowedByConfigurationException: Failed to start Neo4j with an older data store version. To enable automatic upgrade, please set configuration parameter "allow_store_upgrade=true"
at org.neo4j.kernel.impl.storemigration.ConfigMapUpgradeConfiguration.checkConfigurationAllowsAutomaticUpgrade(ConfigMapUpgradeConfiguration.java:39)
at org.neo4j.kernel.impl.storemigration.StoreUpgrader.attemptUpgrade(StoreUpgrader.java:71)
at org.neo4j.kernel.impl.nioneo.store.StoreFactory.tryToUpgradeStores(StoreFactory.java:144)
at org.neo4j.kernel.impl.nioneo.store.StoreFactory.newNeoStore(StoreFactory.java:119)
at org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource.start(NeoStoreXaDataSource.java:323)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:503)
... 10 more

したがって、これは通常、ある種のバージョン管理であることを理解しています。そのため、以下は、有効な POM からの (他の多くの中で) Maven の依存関係です。

<dependency>
  <groupId>org.neo4j</groupId>
  <artifactId>neo4j-spatial</artifactId>
  <version>0.13-neo4j-2.0.1</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.neo4j</groupId>
  <artifactId>neo4j</artifactId>
  <version>2.0.1</version>
  <scope>compile</scope>
</dependency>

PS: Java コードが SO によって解析されていない理由を理解していただければ幸いです。

4

2 に答える 2