2016-10-26 5 views
0

をArrayListのインスタンスを渡す。これは、私の場合では、MySQLを介してデータを取得し、ArrayListオブジェクトに保存しています、私は、JUnitテストで私のプログラムを実行しています、サイファー・クエリに同じオブジェクトが必要です`パブリッククラスDummyTest {checkMysqlConnection(上記のコードでのNeo4jのJUnitのためのコンフィギュレーションおよびCYPHERクエリで

@Test 
@Rollback(true) 
public void checkMysqlConnection() { 
    Connection connection = null; 
    ResultSet tableDatasRsult = null; 
    try { 
     Class.forName("com.mysql.jdbc.Driver"); 
     Properties properties = new Properties(); 
     properties.setProperty("user", "root"); 
     properties.setProperty("password", "root"); 
     String url = "127.0.0.1:3306/unicity"; 
     connection = DriverManager.getConnection("jdbc:mysql://" + url, properties); 
     Assert.assertNotNull(connection); 
     String sqlq = "select DIST_ID,PV_DATE,POST_DATE from odh"; 
     PreparedStatement preparedStatement = connection.prepareStatement(sqlq); 
     tableDatasRsult = preparedStatement.executeQuery(); 
     ArrayList<OdhDO> odhDOs = new ArrayList<>(); 
     while (tableDatasRsult.next()) { 
      OdhDO odhDO = new OdhDO(); 
      odhDO.setDistId(tableDatasRsult.getLong("DIST_ID")); 
      odhDO.setPvDate(tableDatasRsult.getString("PV_DATE")); 
      odhDO.setPostDate(tableDatasRsult.getString("POST_DATE")); 
      odhDOs.add(odhDO); 

      Map<String, Object> params = new HashMap<>(); 
      params.put(odhDO.getDistId().toString(), odhDO); 
      System.out.println(params); 

     } 

    } catch (ClassNotFoundException e) { 
     System.out.println("MySql Driver Class Not Found Exception"); 
     e.printStackTrace(); 
    } catch (SQLException e) { 
     System.out.println("Sql Exception"); 
     e.printStackTrace(); 
    } finally { 
     try { 
      connection.close(); 
     } catch (SQLException e) { 
      e.printStackTrace(); 
     } 
    } 

} 

@Test 
@Rollback(true) 

public void checkneo4jConnection(){ 

    String URL= "http://localhost:7474"; 
    Configuration configuration = new Configuration(); 
    configuration.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver").setURI(URL).setCredentials("neo4j", "admin"); 


    String cypher = "MATCH (Distributor) WHERE Distributor.DISTID IN {odhDOs} RETURN Distributor";  
    Map<String, Object> params = new HashMap<>(); 
    List<String> odhDOs = new ArrayList<>(); 
    params.put("odhDOs", odhDOs); 

    //add some names to the names list 
    //params.put(key, value) 

    }` 

)iはデータを取得し、のArrayList odhDOs =新しいArrayListを<にこのデータを保存している方法>()オブジェクト、iが必要サイファークエリでこのArraylistインスタンスを渡しますが、このクラスとhからneo4jを設定して接続する方法はわかりませんクエリ内にこのarraylistインスタンスを渡すことができます "MATCH(Distributor)WHERE Distributor.DISTID IN {odhDOs} RETURN Distributor" neo4jを使用したjunitの設定と、cypherクエリで配列インスタンスを渡す方法をお手伝いしてください事前に..thanks ...

+0

あなたは 'Distributor'がで注釈さというクラスを持っていますかNeo4j-OGMのドキュメントにある '@ NodeEntity'? https://github.com/neo4j/neo4j-ogm – digx1

+0

はいディストリビュータークラスはOGMごとに –

答えて

0

あなたはOGM reference guideにマニュアルに従って適切にすべてを設定している場合、このような何かが動作するはずです:

@Test 
public void checkneo4jConnection(){ 

    Configuration configuration = new Configuration(); 
    configuration.driverConfiguration() 
     .setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver") 
     .setURI("http://localhost:7474") 
     .setCredentials("neo4j", "admin"); 


    SessionFactory sessionFactory = new SessionFactory(configuration, "package.where.your.distributor.class.is"); 

    Session session = sessionFactory.openSession(); 

    String cypher = "MATCH (Distributor) WHERE Distributor.DISTID IN {odhDOs} RETURN Distributor";  
    Map<String, Object> params = new HashMap<>(); 
    params.put("odhDOs", Arrays.asList(new String[] {"odhDO1", "odhDO2"}); 

    // NOTE: If more than one result use session.query(). 
    //  If just one, use session.queryForObject() 
    Iterable<Distributor> distributors = session.query(Distributor.class, cypher, params); 

    for (Distributor distributor: distributors) { 
     System.out.println(distributor.getDISTID()); 
    } 
} 
+0

ありがとう、私はこれをうまくやった –

関連する問題