1

編集: 問題は、start が呼び出されても、https://github.com/ttiurani/neo4j-uuid/blob/master/src/main/java/org/neo4j/extension/uuid/UUIDTransactionEventHandler.javaがアクティブになっていることです。バージョン 2.0.0-M03 の空のデータベースに対してのみ (1.9.2 では呼び出されません)、ノードが作成された場合でも data.createdNodes() は空のイテレータを返します。そのため、トランザクション イベント ハンドラの登録にはまだ問題があるようです。この問題は PluginLifecycle とは何の関係もないため、これを解決済みとしてマークします。ここに新しい質問を投稿しました。

オリジナル:

組み込みサーバーでカスタム PluginLifecycle 実装を使用するように Neo4j を取得しようとしています。何らかの理由で、Neo4j は実装のコンストラクターを 2 回呼び出しますが、start() メソッドを呼び出しません。カスタム PluginLifecycle 実装は次のとおりです。

https://github.com/ttiurani/neo4j-uuid/blob/master/src/main/java/org/neo4j/extension/uuid/UUIDPluginLifecycle.java

テストプロジェクトは次のとおりです。

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>example</groupId>
  <artifactId>neo4j-embedded-pluginlifecycle-test</artifactId>
  <packaging>jar</packaging>
  <name>Neo4j Embedded PluginLifecycle Implementation Test</name>
  <version>1.0</version>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <neo4j.version>2.0.0-M03</neo4j.version>
  </properties>

  <repositories>
    <repository>
      <id>neo4j-public-repository</id>
      <url>http://m2.neo4j.org</url>
    </repository>
    <repository>
      <id>oss-sonatype-snapshots</id>
      <name>OSS Sonatype Snapshots</name>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
  </repositories>

  <dependencies>
    <!-- Neo4j graph database -->
    <dependency>
      <groupId>org.extendedmind</groupId>
      <artifactId>neo4j-uuid</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>org.neo4j</groupId>
      <artifactId>server-api</artifactId>
      <version>${neo4j.version}</version>
    </dependency>
    <dependency>
      <groupId>org.neo4j.app</groupId>
      <artifactId>neo4j-server</artifactId>
      <version>${neo4j.version}</version>
      <type>jar</type>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.neo4j.app</groupId>
      <artifactId>neo4j-server</artifactId>
      <classifier>static-web</classifier>
      <version>${neo4j.version}</version>
    </dependency>    

    <!-- JUnit -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <archive>
            <addMavenDescriptor>false</addMavenDescriptor>
          </archive>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

src/test/java/example/PluginLifecycleTest.java:

package example;

import org.junit.Test;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.kernel.GraphDatabaseAPI;
import org.neo4j.server.WrappingNeoServerBootstrapper;
import org.neo4j.server.configuration.Configurator;
import org.neo4j.server.configuration.ServerConfigurator;

public class PluginLifecycleTest{

  @Test
  public void shouldCreateUUIDToNewNode()
  {
        GraphDatabaseAPI graphdb = (GraphDatabaseAPI) new GraphDatabaseFactory()
                .newEmbeddedDatabaseBuilder( "/tmp/neo4j-test" )
                .newGraphDatabase();
        new UUIDPluginLifecycle().start(graphdb, null);

        ServerConfigurator config;
        config = new ServerConfigurator( graphdb );
        config.configuration().setProperty(
            Configurator.THIRD_PARTY_PACKAGES_KEY, "org.neo4j.extension.uuid=/uuid");
          config.configuration().setProperty(
            Configurator.WEBSERVER_PORT_PROPERTY_KEY, 7473);

        WrappingNeoServerBootstrapper srv = new WrappingNeoServerBootstrapper( graphdb, config );
        srv.start();

        Transaction tx = graphdb.beginTx();
        Node node = graphdb.createNode();
        node.setProperty("test", "test");
        long id = node.getId();
        tx.success();

        tx = graphdb.beginTx();
        node = graphdb.getNodeById(id);
        node.getProperty("test");
        // New nodes should have a "uuid" property
        node.getProperty("uuid");
        tx.success();

        srv.stop();
  }
}

何らかの理由で、これは「org.neo4j.graphdb.NotFoundException: org.neo4j.kernel.api.exceptions.PropertyKeyNotFoundException: プロパティ キー 'uuid' が見つかりません」というエラーで機能しません。1.9.2 で試しましたが、問題は解決しません。

それを機能させるために他に何かする必要がありますか?

4

1 に答える 1