├── neo4j-jdbc ├── src │ ├── main │ │ ├── resources │ │ │ ├── empty.txt │ │ │ ├── META-INF │ │ │ │ └── services │ │ │ │ │ └── java.sql.Driver │ │ │ └── neo4j-jdbc-driver.properties │ │ └── java │ │ │ └── org │ │ │ └── neo4j │ │ │ └── jdbc │ │ │ ├── utils │ │ │ ├── Neo4jJdbcRuntimeException.java │ │ │ ├── UncaughtExceptionLogger.java │ │ │ ├── ExceptionBuilder.java │ │ │ ├── TimeLimitedCodeBlock.java │ │ │ ├── Neo4jInvocationHandler.java │ │ │ └── PreparedStatementBuilder.java │ │ │ ├── InstanceFactory.java │ │ │ ├── Loggable.java │ │ │ ├── Neo4jConnection.java │ │ │ ├── metadata │ │ │ ├── Table.java │ │ │ └── Column.java │ │ │ ├── Wrapper.java │ │ │ ├── Neo4jParameterMetaData.java │ │ │ ├── impl │ │ │ └── ListArray.java │ │ │ └── Neo4jArray.java │ └── test │ │ ├── resources │ │ └── empty.txt │ │ └── java │ │ └── org │ │ └── neo4j │ │ └── jdbc │ │ ├── Neo4jDriverTest.java │ │ ├── Neo4jStatementTest.java │ │ ├── Neo4jParameterMetaDataTest.java │ │ ├── Neo4jConnectionTest.java │ │ ├── Neo4jCallableStatementTest.java │ │ ├── Neo4jResultSetTest.java │ │ ├── Neo4jPreparedStatementTest.java │ │ ├── utils │ │ └── Neo4jPreparedStatementBuilderTest.java │ │ └── Neo4jDataSourceTest.java ├── README.adoc └── pom.xml ├── neo4j-jdbc-bolt ├── src │ ├── test │ │ ├── resources │ │ │ └── empty.txt │ │ └── java │ │ │ └── org │ │ │ └── neo4j │ │ │ └── jdbc │ │ │ └── bolt │ │ │ ├── BoltNeo4jDatabaseMetaDataTest.java │ │ │ ├── BoltNeo4jDataSourceIT.java │ │ │ ├── SampleIT.java │ │ │ ├── BoltNeo4jResultSetTest.java │ │ │ ├── Neo4jBoltRule.java │ │ │ ├── data │ │ │ └── StatementData.java │ │ │ ├── BoltNeo4jDatabaseMetaDataIT.java │ │ │ └── SamplePT.java │ └── main │ │ ├── resources │ │ ├── META-INF │ │ │ └── services │ │ │ │ └── java.sql.Driver │ │ └── empty.txt │ │ └── java │ │ └── org │ │ └── neo4j │ │ └── jdbc │ │ └── bolt │ │ ├── BoltNeo4jParameterMetaData.java │ │ ├── BoltNeo4jConnection.java │ │ ├── BoltNeo4jDataSource.java │ │ └── BoltNeo4jCallableStatement.java ├── pom.xml └── README.adoc ├── neo4j-jdbc-examples ├── mybatis │ ├── .gitignore │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── org │ │ │ │ │ └── neo4j │ │ │ │ │ │ └── jdbc │ │ │ │ │ │ └── example │ │ │ │ │ │ └── mybatis │ │ │ │ │ │ └── mapper │ │ │ │ │ │ └── ActorMapper.xml │ │ │ │ └── database-config.xml │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── neo4j │ │ │ │ └── jdbc │ │ │ │ └── example │ │ │ │ └── mybatis │ │ │ │ ├── mapper │ │ │ │ └── ActorMapper.java │ │ │ │ ├── bean │ │ │ │ └── Actor.java │ │ │ │ └── util │ │ │ │ ├── ActorManager.java │ │ │ │ └── ConnectionFactory.java │ │ └── test │ │ │ ├── resources │ │ │ ├── bolt-database-config.xml │ │ │ └── http-database-config.xml │ │ │ └── java │ │ │ └── org │ │ │ └── neo4j │ │ │ └── jdbc │ │ │ └── example │ │ │ └── mybatis │ │ │ ├── ActorManagerBoltTestWithLocalServer.java │ │ │ ├── ActorManagerHttpTestWithLocalServer.java │ │ │ ├── ActorManagerIT.java │ │ │ └── MybatisTestUtil.java │ └── pom.xml └── pom.xml ├── docs ├── img │ ├── apoc.jdbc.png │ ├── solr-dih.png │ ├── qlik.config.png │ ├── qlik.results.png │ ├── qlik.settings.png │ ├── tableau-table.png │ ├── talend.config.png │ ├── talend.query.png │ ├── tableau-circles.png │ ├── tableau-jdbc2tde.png │ ├── tableau-bar-chart.png │ └── tableau-line-chart.png ├── spring.adoc ├── apoc.adoc ├── squirrel.adoc ├── talend.adoc ├── sqlshell.adoc ├── qlik.adoc ├── tableau.adoc ├── play.adoc ├── index.adoc ├── jasper.adoc ├── solr.adoc ├── eclipse.adoc ├── pentaho.adoc ├── birt.adoc └── matlab.adoc ├── neo4j-jdbc-http ├── src │ ├── main │ │ ├── resources │ │ │ └── META-INF │ │ │ │ └── services │ │ │ │ └── java.sql.Driver │ │ └── java │ │ │ └── org │ │ │ └── neo4j │ │ │ └── jdbc │ │ │ └── http │ │ │ ├── HttpNeo4jParameterMetaData.java │ │ │ ├── HttpNeo4jDatabaseMetaData.java │ │ │ ├── driver │ │ │ ├── Neo4jResult.java │ │ │ └── Neo4jStatement.java │ │ │ ├── HttpDriver.java │ │ │ ├── HttpNeo4jResultSetMetaData.java │ │ │ └── HttpNeo4jStatement.java │ └── test │ │ ├── resources │ │ └── data │ │ │ └── queries.csv │ │ └── java │ │ └── org │ │ └── neo4j │ │ └── jdbc │ │ └── http │ │ ├── HttpNeo4jResultSetTest.java │ │ ├── driver │ │ ├── Neo4jStatementTest.java │ │ ├── CypherExecutorTest.java │ │ └── Neo4jResponseTest.java │ │ ├── test │ │ └── Neo4jHttpITUtil.java │ │ ├── HttpNeo4jResultSetMetaDataIT.java │ │ ├── HttpNeo4jResultSetMetaDataTest.java │ │ └── HttpNeo4jResultSetIT.java ├── README.adoc └── pom.xml ├── neo4j-jdbc-idea-settings.jar ├── .travis.yml ├── docs.sh ├── .gitignore └── neo4j-jdbc-driver ├── pom.xml └── src ├── main └── java │ └── org │ └── neo4j │ └── jdbc │ └── Driver.java └── test └── java └── org └── neo4j └── jdbc └── DriverTestIT.java /neo4j-jdbc/src/main/resources/empty.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/test/resources/empty.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /neo4j-jdbc-bolt/src/test/resources/empty.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /neo4j-jdbc-examples/mybatis/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/main/resources/META-INF/services/java.sql.Driver: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/img/apoc.jdbc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larusba/neo4j-jdbc/HEAD/docs/img/apoc.jdbc.png -------------------------------------------------------------------------------- /docs/img/solr-dih.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larusba/neo4j-jdbc/HEAD/docs/img/solr-dih.png -------------------------------------------------------------------------------- /docs/img/qlik.config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larusba/neo4j-jdbc/HEAD/docs/img/qlik.config.png -------------------------------------------------------------------------------- /docs/img/qlik.results.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larusba/neo4j-jdbc/HEAD/docs/img/qlik.results.png -------------------------------------------------------------------------------- /docs/img/qlik.settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larusba/neo4j-jdbc/HEAD/docs/img/qlik.settings.png -------------------------------------------------------------------------------- /docs/img/tableau-table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larusba/neo4j-jdbc/HEAD/docs/img/tableau-table.png -------------------------------------------------------------------------------- /docs/img/talend.config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larusba/neo4j-jdbc/HEAD/docs/img/talend.config.png -------------------------------------------------------------------------------- /docs/img/talend.query.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larusba/neo4j-jdbc/HEAD/docs/img/talend.query.png -------------------------------------------------------------------------------- /neo4j-jdbc-bolt/src/main/resources/META-INF/services/java.sql.Driver: -------------------------------------------------------------------------------- 1 | org.neo4j.jdbc.bolt.BoltDriver 2 | 3 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/src/main/resources/META-INF/services/java.sql.Driver: -------------------------------------------------------------------------------- 1 | org.neo4j.jdbc.http.HttpDriver 2 | 3 | -------------------------------------------------------------------------------- /docs/img/tableau-circles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larusba/neo4j-jdbc/HEAD/docs/img/tableau-circles.png -------------------------------------------------------------------------------- /docs/img/tableau-jdbc2tde.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larusba/neo4j-jdbc/HEAD/docs/img/tableau-jdbc2tde.png -------------------------------------------------------------------------------- /neo4j-jdbc-idea-settings.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larusba/neo4j-jdbc/HEAD/neo4j-jdbc-idea-settings.jar -------------------------------------------------------------------------------- /docs/img/tableau-bar-chart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larusba/neo4j-jdbc/HEAD/docs/img/tableau-bar-chart.png -------------------------------------------------------------------------------- /docs/img/tableau-line-chart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/larusba/neo4j-jdbc/HEAD/docs/img/tableau-line-chart.png -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - oraclejdk8 5 | 6 | script: 7 | - mvn clean test 8 | #- mvn clean test -Pperformance-test 9 | 10 | branches: 11 | only: 12 | - master 13 | -------------------------------------------------------------------------------- /docs.sh: -------------------------------------------------------------------------------- 1 | asciidoctor -a env-docs -a allow-uri-read docs/index.adoc 2 | git checkout gh-pages 3 | cp docs/index.html index.html 4 | git add index.html 5 | git commit -m"docs update" 6 | git push 7 | git checkout master 8 | 9 | -------------------------------------------------------------------------------- /neo4j-jdbc/README.adoc: -------------------------------------------------------------------------------- 1 | = Neo4j JDBC Driver 2 | 3 | This is the core module of the neo4j-jdbc driver. 4 | 5 | It contains all the abstract classes implementing the java.sql interface and also the common pieces of code between the modules. 6 | -------------------------------------------------------------------------------- /neo4j-jdbc-bolt/src/main/resources/empty.txt: -------------------------------------------------------------------------------- 1 | ziotob's (secret) TODOLIST: 2 | 3 | Test databaseMetadata 4 | Test Statement closed closes ResultSet 5 | Test Statement re-executed closes ResultSet 6 | Multi-Thread test 7 | Test flattening reliability (IT) 8 | -------------------------------------------------------------------------------- /docs/spring.adoc: -------------------------------------------------------------------------------- 1 | === Spring JDBC Template 2 | 3 | Integrating with Spring JDBC is as easy as defining a datasource in your Spring config and then using it via JDBC Template. 4 | 5 | You can find an example application here: 6 | 7 | https://github.com/neo4j-examples/movies-java-spring-boot-jdbc 8 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/README.adoc: -------------------------------------------------------------------------------- 1 | = Neo4j JDBC Driver - Http 2 | 3 | This module implements the neo4j-jdbc driver with the HTTP cypher transaction endpoint. 4 | 5 | == Some enhancements 6 | 7 | * Use the streaming part of Jackson instead of POJO Binding 8 | * Manually serialize statement instead via Jackson 9 | * Reuse connection on http-client 10 | * Adding hack for product like on the previous jdbc driver 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /docs/apoc.adoc: -------------------------------------------------------------------------------- 1 | === APOC LOAD JDBC 2 | 3 | * Copy Neo4j JDBC Driver jar into `NEO4J_HOME/plugins` folder 4 | * Restart the database 5 | * Run some JDBC Queries: 6 | 7 | [source,cypher] 8 | ---- 9 | WITH ['The Matrix'] as movies 10 | CALL apoc.load.jdbcParams('jdbc:neo4j:bolt://localhost?user=neo4j,password=test','MATCH (m:Movie) WHERE m.title=? RETURN m', movies) YIELD row 11 | RETURN row 12 | ---- 13 | 14 | image::https://cloud.githubusercontent.com/assets/231657/15970058/01334dfc-2f33-11e6-8cc8-9ad9658049cd.png[] 15 | -------------------------------------------------------------------------------- /docs/squirrel.adoc: -------------------------------------------------------------------------------- 1 | === Squirrel SQL 2 | 3 | Squirrel SQL is a widely used SQL workbench that supports many databases out of the box. 4 | Adding the JDBC driver was straightforward, as was running Cypher queries and getting tabular results back. 5 | 6 | Works in general for scalar values 7 | 8 | * Configured Driver via Add Driver -> Extra ClassPath 9 | * Created New Session, 10 | * Worked but gave a warning about 2.1 incompatibility 11 | 12 | image::https://cloud.githubusercontent.com/assets/67427/15894295/67e6126e-2d85-11e6-96e5-b71a214f811b.png[] -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | !neo4j-jdbc-idea-settings.jar 9 | *.war 10 | *.ear 11 | dependency-reduced-pom.xml 12 | 13 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 14 | hs_err_pid* 15 | 16 | # Mac OSX 17 | .DS_Store 18 | 19 | # Temp di GEdit 20 | *.*~ 21 | 22 | #IntelliJ IDEA 23 | .idea/ 24 | *.iml 25 | 26 | #Eclipse 27 | .settings/ 28 | target/ 29 | .project 30 | .classpath 31 | 32 | #Neo4j 33 | **/neo4j-home/* 34 | 35 | -------------------------------------------------------------------------------- /neo4j-jdbc-examples/mybatis/src/main/resources/org/neo4j/jdbc/example/mybatis/mapper/ActorMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | -------------------------------------------------------------------------------- /docs/talend.adoc: -------------------------------------------------------------------------------- 1 | === Talend 2 | 3 | (Thanks a lot to Benoit Simard) 4 | 5 | With Talend, you can query or import your data into Neo4j using Talend JDBC Components. 6 | On the Job, you just have to add a tJDBCConnection and add the usual fields: JDBC-URL, Driver-Jar, Driver, username and password. 7 | 8 | image::img/talend.config.png[] 9 | 10 | NB: On the Advanced Settings tab, you can also configure the auto-commit, if you want it. 11 | 12 | Now, you can add some tJDBCInput to make some queries to your Neo4j databases like this : 13 | 14 | image::img/talend.query.png[] 15 | -------------------------------------------------------------------------------- /neo4j-jdbc-examples/mybatis/src/main/resources/database-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /neo4j-jdbc-examples/mybatis/src/test/resources/bolt-database-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /neo4j-jdbc-examples/mybatis/src/test/resources/http-database-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/sqlshell.adoc: -------------------------------------------------------------------------------- 1 | === SQL-Shell 2 | 3 | It's working now on the master branch (6b166ec31bdb61f76279be717aa1f30ada5c553e) 4 | 5 | * Copy Neo4j JDBC driver into `SQLSHELL_HOME/lib` folder 6 | * Edit the configuration file `SQLSHELL_HOME/sample.cfg` for : 7 | * Adding neo4j driver : 8 | 9 | ---- 10 | [drivers] 11 | neo4j = org.neo4j.jdbc.bolt.BoltDriver 12 | ---- 13 | 14 | * Adding your database 15 | 16 | ---- 17 | [db_neo4j] 18 | aliases: neo 19 | driver: neo4j 20 | url: jdbc:neo4j:bolt://localhost 21 | user: neo4j 22 | password: test 23 | ---- 24 | 25 | * Now execute `sqlshell` with the configuration file to open `neo` database : 26 | 27 | ---- 28 | $> SQLSHELL_HOME/bin/sqlshell -c SQLSHELL_HOME/sample.cfg neo 29 | ---- 30 | 31 | * Execute some queries ! 32 | 33 | image::https://cloud.githubusercontent.com/assets/231657/15985061/c8c7f33c-2fe1-11e6-90e7-fc44be9d4866.png[] 34 | -------------------------------------------------------------------------------- /docs/qlik.adoc: -------------------------------------------------------------------------------- 1 | === QlikView / Qlik Sense via TIQ JDBC Connector 2 | 3 | (Thanks a lot to Ralf Becher, TIQ Solutions) 4 | 5 | TIQ Solutions provides a commercial product to enable JDBC connectivity in QlikView and Qlik Sense. The configuration is simple. 6 | 7 | In QlikView, you can connect to Neo4j directly. In Qlik Sense you need to copy the CUSTOM CONNECT script code. 8 | 9 | image::https://cloud.githubusercontent.com/assets/6613815/17213244/d04d482a-54d3-11e6-8813-29d3d701ea2b.png[] 10 | 11 | If your Neo4j connection is established, you now can execute Cypher queries in LOAD statements (but mention the SQL prefix). The results get loaded into memory tables as usual. 12 | 13 | image::https://cloud.githubusercontent.com/assets/6613815/17213245/d04dbd14-54d3-11e6-914e-0729e02e61e9.png[] 14 | 15 | image::https://cloud.githubusercontent.com/assets/6613815/17213472/add61f14-54d4-11e6-8ed6-3792786c45c3.png[] -------------------------------------------------------------------------------- /neo4j-jdbc/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | 9 | 10 | 11 | org.neo4j 12 | neo4j-jdbc-parent 13 | 3.2.0 14 | 15 | 16 | 17 | 18 | 19 | neo4j-jdbc 20 | jar 21 | Neo4j JDBC Driver 22 | Common module for every implementation of the Neo4j JDBC Driver 23 | 24 | 25 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/main/resources/neo4j-jdbc-driver.properties: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | # Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 4 | #

5 | # This file is part of the "LARUS Integration Framework for Neo4j". 6 | #

7 | # The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | #

11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | #

13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | #

19 | # Created on 17/4/2016 20 | # 21 | # 22 | driver.name=${project.name} 23 | driver.version=${project.version} 24 | -------------------------------------------------------------------------------- /docs/tableau.adoc: -------------------------------------------------------------------------------- 1 | === Tableau via jdbc2tde 2 | 3 | (Thanks a lot to Ralf Becher, TIQ Solutions) 4 | 5 | Integration with Tableau is not that trivial as it only generates SQL. 6 | 7 | So you can either use the Tableau REST integration (which we will publish soon). 8 | 9 | image::https://cloud.githubusercontent.com/assets/6613815/17213908/ba8d8f42-54d6-11e6-9838-d0e7104d36ab.png[] 10 | 11 | Or the jdbc2tde tool from TIQ that uses JDBC queries to generate TDE files. 12 | 13 | Those can then be loaded into Tableau and visualized and interacted with in the many ways you know and love. 14 | 15 | image::https://cloud.githubusercontent.com/assets/6613815/17213907/ba8cf712-54d6-11e6-9eee-303abe164f75.png[] 16 | 17 | image::https://cloud.githubusercontent.com/assets/6613815/17213906/ba88be86-54d6-11e6-89ac-2bbf942d100c.png[] 18 | 19 | image::https://cloud.githubusercontent.com/assets/6613815/17213905/ba888ec0-54d6-11e6-8164-755ef3cb2624.png[] 20 | 21 | image::https://cloud.githubusercontent.com/assets/6613815/17213909/ba90b0f0-54d6-11e6-8d41-fd4bc5a31b18.png[] 22 | -------------------------------------------------------------------------------- /docs/play.adoc: -------------------------------------------------------------------------------- 1 | === Play Framework 2 | 3 | Taken from the https://www.playframework.com/documentation/2.5.x/JavaDatabase[Play Framework Documentation]. 4 | Enable the database plugin by adding `javaJdbc` in your build dependencies: 5 | 6 | ---- 7 | libraryDependencies += javaJdbc 8 | ---- 9 | 10 | Then you must configure a connection pool in the `conf/application.conf` file. 11 | By convention the default JDBC data source must be called default, but you can use other names for named databases, in this case we use `neo4j` 12 | 13 | ---- 14 | # Neo4j database configuration 15 | db.neo4j.driver=org.neo4j.jdbc.bolt.BoltDriver 16 | db.neo4j.url="jdbc:neo4j:bolt://localhost" 17 | ---- 18 | 19 | [source,java] 20 | ---- 21 | import javax.inject.Inject; 22 | 23 | import play.mvc.Controller; 24 | import play.db.NamedDatabase; 25 | import play.db.Database; 26 | 27 | // inject "neo4j" database instead of "default" 28 | class JavaNamedDatabase extends Controller { 29 | private Database db; 30 | 31 | @Inject 32 | public JavaNamedDatabase(@NamedDatabase("neo4j") Database db) { 33 | this.db = db; 34 | } 35 | 36 | // do whatever you need with the db 37 | } 38 | ---- 39 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/main/java/org/neo4j/jdbc/utils/Neo4jJdbcRuntimeException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 28/11/17 19 | */ 20 | package org.neo4j.jdbc.utils; 21 | 22 | /** 23 | * @author AgileLARUS 24 | * 25 | * @since 3.0.0 26 | */ 27 | public class Neo4jJdbcRuntimeException extends RuntimeException { 28 | public Neo4jJdbcRuntimeException (Throwable t) { 29 | super(t); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /neo4j-jdbc-examples/mybatis/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | 7 | 8 | 9 | org.neo4j 10 | neo4j-jdbc-examples 11 | 3.2.0 12 | 13 | 14 | 15 | 16 | 17 | neo4j-jdbc-examples-mybatis 18 | jar 19 | Neo4j JDBC Driver Example with Mybatis 20 | POM for Neo4j JDBC Driver Example with Mybatis 21 | 22 | 23 | 24 | 25 | 26 | 27 | org.mybatis 28 | mybatis 29 | 3.4.1 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/main/java/org/neo4j/jdbc/InstanceFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 4 | *

5 | * This file is part of the "LARUS Integration Framework for Neo4j". 6 | *

7 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | *

11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | *

13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *

19 | * Created on 19/4/2016 20 | * 21 | */ 22 | package org.neo4j.jdbc; 23 | 24 | /** 25 | * @author AgileLARUS 26 | * @since 3.0.0 27 | */ 28 | public class InstanceFactory { 29 | 30 | private InstanceFactory () {} 31 | 32 | public static T debug(T obj) { 33 | return obj; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/main/java/org/neo4j/jdbc/Loggable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 4 | *

5 | * This file is part of the "LARUS Integration Framework for Neo4j". 6 | *

7 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | *

11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | *

13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *

19 | * Created on 19/4/2016 20 | * 21 | */ 22 | package org.neo4j.jdbc; 23 | 24 | /** 25 | * @author AgileLARUS 26 | * @since 3.0.0 27 | */ 28 | public interface Loggable { 29 | boolean hasDebug(); 30 | 31 | void setDebug(boolean debug); 32 | 33 | void setDebugLevel(int level); 34 | 35 | int getDebugLevel(); 36 | } 37 | -------------------------------------------------------------------------------- /neo4j-jdbc-examples/mybatis/src/main/java/org/neo4j/jdbc/example/mybatis/mapper/ActorMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 4 | *

5 | * This file is part of the "LARUS Integration Framework for Neo4j". 6 | *

7 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | *

11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | *

13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *

19 | * Created on 24/4/2016 20 | * 21 | */ 22 | package org.neo4j.jdbc.example.mybatis.mapper; 23 | 24 | import org.neo4j.jdbc.example.mybatis.bean.Actor; 25 | 26 | /** 27 | * @author AgileLARUS 28 | * @since 3.0.2 29 | */ 30 | public interface ActorMapper { 31 | public Actor selectActorByBorn(int born); 32 | } 33 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/src/test/resources/data/queries.csv: -------------------------------------------------------------------------------- 1 | query;params;stat 2 | MATCH (tom {name: {name} }) RETURN tom; { "name" : "Tom Hanks" } ;true 3 | MATCH (cloudAtlas {title: { movie } }) RETURN cloudAtlas; { "movie" : "Cloud Atlas" } ;true 4 | MATCH (people:Person) WHERE people.name=~ { regex } RETURN people.name LIMIT 10; { "regex" : "Tom.*" } ;false 5 | MATCH (nineties:Movie) WHERE nineties.released > { from } AND nineties.released < { to } RETURN nineties.title; { "from" : 1990, "to" : 2000 };false 6 | MATCH (tom:Person {name: { name } } )-[:ACTED_IN]->(tomHanksMovies) RETURN tom,tomHanksMovies; { "name" : "Tom Hanks" } ;false 7 | MATCH (cloudAtlas {title: { movie } })<-[:DIRECTED]-(directors) RETURN directors.name; { "movie" : "Cloud Atlas" } ;true 8 | MATCH (tom:Person {name: { name } })-[:ACTED_IN]->(m)<-[:ACTED_IN]-(coActors) RETURN coActors.name; { "name" : "Tom Hanks" } ;false 9 | MATCH (people:Person)-[relatedTo]-(:Movie {title: { movie } }) RETURN people.name, Type(relatedTo), relatedTo; { "movie" : "Cloud Atlas" } ;true 10 | MATCH (bacon:Person {name:{kevin}})-[*1..4]-(hollywood) RETURN DISTINCT hollywood; { "kevin" : "Kevin Bacon" } ;true 11 | MATCH p=shortestPath((bacon:Person {name: { start } })-[*]-(meg:Person {name: { end } })) RETURN p; { "start" : "Kevin Bacon", "end" : "Meg Ryan" } ;true 12 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/src/test/java/org/neo4j/jdbc/http/HttpNeo4jResultSetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 19/06/16 19 | */ 20 | package org.neo4j.jdbc.http; 21 | 22 | import org.junit.Test; 23 | 24 | import java.sql.SQLException; 25 | 26 | /** 27 | * @author AgileLARUS 28 | * @since 3.0 29 | */ 30 | public class HttpNeo4jResultSetTest { 31 | 32 | @Test 33 | public void closeMultipleTimeShouldBeNOOP() throws SQLException { 34 | 35 | HttpNeo4jResultSet rs = new HttpNeo4jResultSet(null, null); 36 | 37 | rs.close(); 38 | rs.close(); 39 | rs.close(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /neo4j-jdbc-examples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | 8 | 9 | 10 | org.neo4j 11 | neo4j-jdbc-parent 12 | 3.2.0 13 | 14 | 15 | 16 | 17 | 18 | neo4j-jdbc-examples 19 | pom 20 | Neo4j JDBC Driver Examples 21 | Parent POM for Neo4j JDBC Driver Examples 22 | 23 | 24 | 25 | 26 | 27 | mybatis 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | org.neo4j 36 | neo4j-jdbc-driver 37 | 3.2.0 38 | runtime 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/src/main/java/org/neo4j/jdbc/http/HttpNeo4jParameterMetaData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 15/4/2016 19 | */ 20 | package org.neo4j.jdbc.http; 21 | 22 | import org.neo4j.jdbc.Neo4jParameterMetaData; 23 | 24 | public class HttpNeo4jParameterMetaData extends Neo4jParameterMetaData { 25 | 26 | private HttpNeo4jPreparedStatement preparedStatement; 27 | 28 | public HttpNeo4jParameterMetaData(HttpNeo4jPreparedStatement preparedStatement) { 29 | this.preparedStatement = preparedStatement; 30 | } 31 | 32 | public HttpNeo4jPreparedStatement getPreparedStatement() { 33 | return preparedStatement; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /neo4j-jdbc-bolt/src/main/java/org/neo4j/jdbc/bolt/BoltNeo4jParameterMetaData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 24/03/16 19 | */ 20 | package org.neo4j.jdbc.bolt; 21 | 22 | import org.neo4j.jdbc.Neo4jParameterMetaData; 23 | 24 | /** 25 | * @author AgileLARUS 26 | * @since 3.0.0 27 | */ 28 | public class BoltNeo4jParameterMetaData extends Neo4jParameterMetaData { 29 | 30 | private BoltNeo4jPreparedStatement preparedStatement; 31 | 32 | public BoltNeo4jParameterMetaData(BoltNeo4jPreparedStatement preparedStatement) { 33 | this.preparedStatement = preparedStatement; 34 | } 35 | 36 | public BoltNeo4jPreparedStatement getPreparedStatement() { 37 | return preparedStatement; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/src/main/java/org/neo4j/jdbc/http/HttpNeo4jDatabaseMetaData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 15/4/2016 19 | */ 20 | package org.neo4j.jdbc.http; 21 | 22 | import org.neo4j.jdbc.Neo4jDatabaseMetaData; 23 | 24 | /** 25 | * Provides metadata 26 | * 27 | * @author AgileLARUS 28 | * @since 3.0.0 29 | */ 30 | class HttpNeo4jDatabaseMetaData extends Neo4jDatabaseMetaData { 31 | 32 | public HttpNeo4jDatabaseMetaData(HttpNeo4jConnection connection) { 33 | super(connection); 34 | 35 | // compute database version 36 | if (connection != null && connection.executor != null ) { 37 | this.databaseVersion = connection.executor.getServerVersion(); 38 | } 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /neo4j-jdbc-bolt/src/main/java/org/neo4j/jdbc/bolt/BoltNeo4jConnection.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 22/12/17 19 | */ 20 | package org.neo4j.jdbc.bolt; 21 | 22 | import org.neo4j.driver.v1.Session; 23 | import org.neo4j.driver.v1.Transaction; 24 | 25 | import java.sql.Connection; 26 | 27 | /** 28 | * @author Gianmarco Laggia @ Larus B.A. 29 | * @since 3.2.0 30 | */ 31 | public interface BoltNeo4jConnection extends Connection { 32 | 33 | /** 34 | * Getter for transaction. 35 | * 36 | * @return the transaction 37 | */ 38 | Transaction getTransaction(); 39 | 40 | /** 41 | * Getter for session. 42 | * 43 | * @return the internal session 44 | */ 45 | Session getSession(); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | 9 | 10 | 11 | org.neo4j 12 | neo4j-jdbc-parent 13 | 3.2.0 14 | 15 | 16 | 17 | 18 | 19 | Neo4j JDBC Http 20 | neo4j-jdbc-http 21 | Http implementation for the Neo4j JDBC Driver 22 | 23 | 24 | 25 | 26 | 27 | 28 | org.neo4j 29 | neo4j-jdbc 30 | 31 | 32 | 33 | org.apache.httpcomponents 34 | httpclient 35 | 36 | 37 | 38 | com.fasterxml.jackson.core 39 | jackson-databind 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /neo4j-jdbc-examples/mybatis/src/main/java/org/neo4j/jdbc/example/mybatis/bean/Actor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 4 | *

5 | * This file is part of the "LARUS Integration Framework for Neo4j". 6 | *

7 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | *

11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | *

13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *

19 | * Created on 24/4/2016 20 | * 21 | */ 22 | package org.neo4j.jdbc.example.mybatis.bean; 23 | 24 | /** 25 | * @author AgileLARUS 26 | * @since 3.0.2 27 | */ 28 | public class Actor { 29 | 30 | private int nodeId; 31 | private int born; 32 | private String name; 33 | 34 | public int getNodeId() { 35 | return nodeId; 36 | } 37 | 38 | public void setNodeId(int nodeId) { 39 | this.nodeId = nodeId; 40 | } 41 | 42 | public int getBorn() { 43 | return born; 44 | } 45 | 46 | public void setBorn(int born) { 47 | this.born = born; 48 | } 49 | 50 | public String getName() { 51 | return name; 52 | } 53 | 54 | public void setName(String name) { 55 | this.name = name; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /neo4j-jdbc-bolt/src/main/java/org/neo4j/jdbc/bolt/BoltNeo4jDataSource.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 01/12/17 19 | */ 20 | package org.neo4j.jdbc.bolt; 21 | 22 | import org.neo4j.jdbc.Neo4jDataSource; 23 | 24 | import java.sql.Connection; 25 | import java.sql.DriverManager; 26 | import java.sql.SQLException; 27 | 28 | /** 29 | * @author Gianmarco Laggia @ Larus B.A. 30 | * 31 | * @since 3.2.0 32 | */ 33 | public class BoltNeo4jDataSource extends Neo4jDataSource { 34 | 35 | private static final String PROTOCOL = "bolt"; 36 | 37 | @Override public Connection getConnection() throws SQLException { 38 | return getConnection(user, password); 39 | } 40 | 41 | @Override public Connection getConnection(String username, String pass) throws SQLException { 42 | setUser(username); 43 | setPassword(pass); 44 | return DriverManager.getConnection(getUrl(PROTOCOL)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/main/java/org/neo4j/jdbc/Neo4jConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 03/02/16 19 | */ 20 | package org.neo4j.jdbc; 21 | 22 | import java.util.Properties; 23 | 24 | /** 25 | * @author AgileLARUS 26 | * @since 3.0.0 27 | */ 28 | public interface Neo4jConnection extends java.sql.Connection { 29 | 30 | /** 31 | * Get the connection url. 32 | * 33 | * @return String the connection url 34 | */ 35 | String getUrl(); 36 | 37 | /** 38 | * Get the properties for this connection. 39 | * 40 | * @return Properties the properties for this connection 41 | */ 42 | Properties getProperties(); 43 | 44 | /** 45 | * Get the user of this connection. 46 | * 47 | * @return String 48 | */ 49 | String getUserName(); 50 | 51 | /** 52 | * Get the flattening sample rows (-1 if no flattening). 53 | * 54 | * @return int 55 | */ 56 | int getFlattening(); 57 | 58 | } 59 | -------------------------------------------------------------------------------- /neo4j-jdbc-examples/mybatis/src/main/java/org/neo4j/jdbc/example/mybatis/util/ActorManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 4 | *

5 | * This file is part of the "LARUS Integration Framework for Neo4j". 6 | *

7 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | *

11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | *

13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *

19 | * Created on 24/4/2016 20 | * 21 | */ 22 | package org.neo4j.jdbc.example.mybatis.util; 23 | 24 | import org.apache.ibatis.session.SqlSession; 25 | import org.neo4j.jdbc.example.mybatis.bean.Actor; 26 | import org.neo4j.jdbc.example.mybatis.mapper.ActorMapper; 27 | 28 | /** 29 | * @author AgileLARUS 30 | * @since 3.0.2 31 | */ 32 | public class ActorManager { 33 | 34 | private ActorManager() {} 35 | 36 | public static Actor selectActorByBorn(int born) { 37 | SqlSession sqlSession = ConnectionFactory.getSqlSessionFactory() 38 | .openSession(); 39 | try { 40 | ActorMapper categoryMapper = sqlSession 41 | .getMapper(ActorMapper.class); 42 | return categoryMapper.selectActorByBorn(born); 43 | } finally { 44 | sqlSession.close(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/main/java/org/neo4j/jdbc/utils/UncaughtExceptionLogger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 02/08/16 19 | */ 20 | package org.neo4j.jdbc.utils; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | /** 26 | * @author AgileLARUS 27 | * @since 3.0.0 28 | * This class is used to intercept any exception coming from the test query used in the isValid method. 29 | */ 30 | public class UncaughtExceptionLogger implements Thread.UncaughtExceptionHandler { 31 | private List exceptions = new ArrayList<>(); 32 | 33 | @Override public void uncaughtException(Thread th, Throwable ex) { 34 | this.exceptions.add(ex); 35 | } 36 | 37 | /** 38 | * This method returns the list of exceptions eventually thrown during the execution of the related thread. 39 | * 40 | * @return An ArrayList<Throwable> of exceptions 41 | */ 42 | public List getExceptions() { 43 | return this.exceptions; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /neo4j-jdbc-bolt/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | 9 | 10 | 11 | org.neo4j 12 | neo4j-jdbc-parent 13 | 3.2.0 14 | 15 | 16 | 17 | 18 | 19 | Neo4j JDBC Bolt 20 | neo4j-jdbc-bolt 21 | Bolt implementation for the Neo4j JDBC Driver 22 | 23 | 24 | 25 | 26 | 27 | 28 | org.neo4j.driver 29 | neo4j-java-driver 30 | 31 | 32 | 33 | org.neo4j 34 | neo4j-jdbc 35 | 36 | 37 | 38 | 39 | org.openjdk.jmh 40 | jmh-core 41 | test 42 | 43 | 44 | org.openjdk.jmh 45 | jmh-generator-annprocess 46 | test 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/src/test/java/org/neo4j/jdbc/http/driver/Neo4jStatementTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 15/4/2016 19 | */ 20 | package org.neo4j.jdbc.http.driver; 21 | 22 | import com.fasterxml.jackson.databind.ObjectMapper; 23 | import org.neo4j.jdbc.http.test.Neo4jHttpUnitTestUtil; 24 | import org.junit.Test; 25 | 26 | import java.util.List; 27 | import java.util.Map; 28 | 29 | public class Neo4jStatementTest extends Neo4jHttpUnitTestUtil { 30 | 31 | @Test public void toJsonShouldSucceed() throws Exception { 32 | ObjectMapper mapper = new ObjectMapper(); 33 | 34 | // Testing with all queries into a statement 35 | Map queries = getRandomNeo4jStatementFromCSV("data/queries.csv", -1); 36 | assertCSVQueryEqual(queries.get("source"), Neo4jStatement.toJson(queries.get("object"), mapper)); 37 | 38 | // Testing with only one query 39 | queries = getRandomNeo4jStatementFromCSV("data/queries.csv", 1); 40 | assertCSVQueryEqual(queries.get("source"), Neo4jStatement.toJson(queries.get("object"), mapper)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /neo4j-jdbc-bolt/src/main/java/org/neo4j/jdbc/bolt/BoltNeo4jCallableStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 21/04/16 19 | */ 20 | package org.neo4j.jdbc.bolt; 21 | 22 | import org.neo4j.jdbc.Neo4jCallableStatement; 23 | import org.neo4j.jdbc.Neo4jConnection; 24 | 25 | import java.sql.ParameterMetaData; 26 | import java.sql.ResultSetMetaData; 27 | import java.sql.SQLException; 28 | 29 | /** 30 | * @author AgileLARUS 31 | * @since 3.0.0 32 | */ 33 | class BoltNeo4jCallableStatement extends Neo4jCallableStatement { 34 | /** 35 | * Default constructor with connection and statement. 36 | * 37 | * @param connection The JDBC connection 38 | * @param rawStatement The prepared statement 39 | */ 40 | protected BoltNeo4jCallableStatement(Neo4jConnection connection, String rawStatement) { 41 | super(connection, rawStatement); 42 | } 43 | 44 | @Override public ResultSetMetaData getMetaData() throws SQLException { 45 | return null; 46 | } 47 | 48 | @Override public ParameterMetaData getParameterMetaData() throws SQLException { 49 | return null; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /neo4j-jdbc-examples/mybatis/src/test/java/org/neo4j/jdbc/example/mybatis/ActorManagerBoltTestWithLocalServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 4 | *

5 | * This file is part of the "LARUS Integration Framework for Neo4j". 6 | *

7 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | *

11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | *

13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *

19 | * Created on 24/4/2016 20 | * 21 | */ 22 | package org.neo4j.jdbc.example.mybatis; 23 | 24 | import org.junit.Assert; 25 | import org.junit.Ignore; 26 | import org.junit.Test; 27 | import org.neo4j.jdbc.example.mybatis.bean.Actor; 28 | import org.neo4j.jdbc.example.mybatis.util.ActorManager; 29 | import org.neo4j.jdbc.example.mybatis.util.ConnectionFactory; 30 | 31 | /** 32 | * @author AgileLARUS 33 | * @since 3.0.2 34 | */ 35 | public class ActorManagerBoltTestWithLocalServer extends MybatisTestUtil { 36 | 37 | /* 38 | * Need to start a neo4j instance and load the "Movie" example graph 39 | */ 40 | @Test 41 | @Ignore 42 | public void testSelectActorBornIn1973() { 43 | ConnectionFactory.getSqlSessionFactory("bolt-database-config.xml"); 44 | 45 | Actor actor = ActorManager.selectActorByBorn(1973); 46 | Assert.assertNotNull(actor); 47 | Assert.assertEquals(1973, actor.getBorn()); 48 | Assert.assertEquals("Dave Chappelle", actor.getName()); 49 | }} 50 | -------------------------------------------------------------------------------- /neo4j-jdbc-examples/mybatis/src/test/java/org/neo4j/jdbc/example/mybatis/ActorManagerHttpTestWithLocalServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 4 | *

5 | * This file is part of the "LARUS Integration Framework for Neo4j". 6 | *

7 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | *

11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | *

13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *

19 | * Created on 24/4/2016 20 | * 21 | */ 22 | package org.neo4j.jdbc.example.mybatis; 23 | 24 | import org.junit.Assert; 25 | import org.junit.Ignore; 26 | import org.junit.Test; 27 | import org.neo4j.jdbc.example.mybatis.bean.Actor; 28 | import org.neo4j.jdbc.example.mybatis.util.ActorManager; 29 | import org.neo4j.jdbc.example.mybatis.util.ConnectionFactory; 30 | 31 | /** 32 | * @author AgileLARUS 33 | * @since 3.0.2 34 | */ 35 | public class ActorManagerHttpTestWithLocalServer extends MybatisTestUtil { 36 | 37 | /* 38 | * Need to start a neo4j instance and load the "Movie" example graph 39 | */ 40 | @Test 41 | @Ignore 42 | public void testSelectActorBornIn1973() { 43 | ConnectionFactory.getSqlSessionFactory("http-database-config.xml"); 44 | 45 | Actor actor = ActorManager.selectActorByBorn(1973); 46 | Assert.assertNotNull(actor); 47 | Assert.assertEquals(1973, actor.getBorn()); 48 | Assert.assertEquals("Dave Chappelle", actor.getName()); 49 | }} 50 | -------------------------------------------------------------------------------- /neo4j-jdbc-bolt/src/test/java/org/neo4j/jdbc/bolt/BoltNeo4jDatabaseMetaDataTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 01/03/2016 19 | */ 20 | package org.neo4j.jdbc.bolt; 21 | 22 | import org.junit.Test; 23 | import org.mockito.Mockito; 24 | import org.neo4j.jdbc.bolt.impl.BoltNeo4jConnectionImpl; 25 | 26 | import java.sql.SQLException; 27 | 28 | import static org.junit.Assert.assertEquals; 29 | 30 | /** 31 | * Neo4jDatabaseMetaData Tests class 32 | * 33 | * @author AgileLARUS 34 | * @since 3.0.0 35 | */ 36 | public class BoltNeo4jDatabaseMetaDataTest { 37 | 38 | //@Rule public ExpectedException expectedEx = ExpectedException.none(); 39 | 40 | /*------------------------------*/ 41 | /* getConnection */ 42 | /*------------------------------*/ 43 | 44 | @Test public void getConnectionShouldGetConnection() throws SQLException, NoSuchFieldException, IllegalAccessException { 45 | BoltNeo4jConnectionImpl connection = Mockito.mock(BoltNeo4jConnectionImpl.class); 46 | BoltNeo4jDatabaseMetaData boltDatabaseMetaData = new BoltNeo4jDatabaseMetaData(connection); 47 | 48 | assertEquals(connection, boltDatabaseMetaData.getConnection()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/main/java/org/neo4j/jdbc/utils/ExceptionBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 15/4/2016 19 | */ 20 | package org.neo4j.jdbc.utils; 21 | 22 | /** 23 | * An exception builder. 24 | */ 25 | public class ExceptionBuilder { 26 | 27 | private ExceptionBuilder() {} 28 | 29 | /** 30 | * An UnsupportedOperationException exception builder that retrueve it's caller to make 31 | * a not yet implemented exception with method and class name. 32 | * 33 | * @return an UnsupportedOperationException 34 | */ 35 | public static UnsupportedOperationException buildUnsupportedOperationException() { 36 | StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); 37 | if (stackTraceElements.length > 2) { 38 | StackTraceElement caller = stackTraceElements[2]; 39 | 40 | StringBuilder sb = new StringBuilder().append("Method ").append(caller.getMethodName()).append(" in class ").append(caller.getClassName()) 41 | .append(" is not yet implemented."); 42 | 43 | return new UnsupportedOperationException(sb.toString()); 44 | } else { 45 | return new UnsupportedOperationException("Not yet implemented."); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/src/test/java/org/neo4j/jdbc/http/test/Neo4jHttpITUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 15/4/2016 19 | */ 20 | package org.neo4j.jdbc.http.test; 21 | 22 | import org.junit.ClassRule; 23 | import org.junit.Rule; 24 | import org.junit.rules.ExpectedException; 25 | import org.junit.runner.RunWith; 26 | import org.junit.runners.Parameterized; 27 | import org.neo4j.harness.junit.Neo4jRule; 28 | 29 | import java.io.File; 30 | import java.util.Arrays; 31 | 32 | @RunWith(Parameterized.class) 33 | public abstract class Neo4jHttpITUtil extends Neo4jHttpUnitTestUtil { 34 | 35 | @Parameterized.Parameters 36 | public static Iterable data() { 37 | return Arrays.asList(Boolean.FALSE, Boolean.TRUE); 38 | } 39 | 40 | @Parameterized.Parameter 41 | public Boolean secureMode; 42 | 43 | @ClassRule public static Neo4jRule neo4j = new Neo4jRule() 44 | .withFixture(new File(Neo4jHttpUnitTestUtil.class.getClassLoader().getResource("data/movie.cyp").getFile())); 45 | 46 | @Rule public ExpectedException expectedEx = ExpectedException.none(); 47 | 48 | 49 | protected String getJDBCUrl() { 50 | if(secureMode) 51 | return "jdbc:neo4j:" + neo4j.httpsURI().toString(); 52 | else 53 | return "jdbc:neo4j:" + neo4j.httpURI().toString(); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/main/java/org/neo4j/jdbc/utils/TimeLimitedCodeBlock.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 28/11/17 19 | */ 20 | package org.neo4j.jdbc.utils; 21 | 22 | import java.util.concurrent.*; 23 | 24 | /** 25 | * @author AgileLARUS 26 | * 27 | * @since 3.0.0 28 | */ 29 | public class TimeLimitedCodeBlock { 30 | 31 | private TimeLimitedCodeBlock () {} 32 | 33 | /** 34 | * This method is used to run a specific Runnable for at most a timeout period of time. 35 | * If a timeout of 0 is set then no timeout will be applied. 36 | * 37 | * @param runnable The runnable to run 38 | * @param timeout The maximum time a run should last 39 | * @param timeUnit The TimeUnit unit for the timeout 40 | * @throws Neo4jJdbcRuntimeException Any exception thrown by the runnable wrapped. 41 | */ 42 | public static void runWithTimeout(final Runnable runnable, long timeout, TimeUnit timeUnit) { 43 | ExecutorService executor = Executors.newSingleThreadExecutor(); 44 | Future future = executor.submit(runnable); 45 | executor.shutdown(); 46 | try { 47 | if (timeout == 0) { 48 | future.get(); 49 | } else { 50 | future.get(timeout, timeUnit); 51 | } 52 | } 53 | catch (Exception e) { 54 | future.cancel(true); 55 | throw new Neo4jJdbcRuntimeException(e); 56 | } 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/test/java/org/neo4j/jdbc/Neo4jDriverTest.java: -------------------------------------------------------------------------------- 1 | package org.neo4j.jdbc; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | 6 | import java.sql.*; 7 | import java.sql.Connection; 8 | import java.util.Properties; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * @author mh 14 | * @since 10.06.16 15 | */ 16 | public class Neo4jDriverTest { 17 | 18 | private Neo4jDriver neo4jDriver; 19 | 20 | @Before 21 | public void setUp() throws Exception { 22 | neo4jDriver = new Neo4jDriver("http") { 23 | public Connection connect(String url, Properties info) throws SQLException { 24 | return null; 25 | } 26 | }; 27 | } 28 | 29 | @Test 30 | public void acceptsURL() throws Exception { 31 | assertTrue(neo4jDriver.acceptsURL("jdbc:neo4j:http://localhost")); 32 | assertTrue(neo4jDriver.acceptsURL("jdbc:neo4j:http://localhost:7373")); 33 | assertTrue(neo4jDriver.acceptsURL("jdbc:neo4j:http://localhost:7373?nossl")); 34 | assertTrue(neo4jDriver.acceptsURL("jdbc:neo4j:http://localhost:7373?user=neo4j")); 35 | assertTrue(neo4jDriver.acceptsURL("jdbc:neo4j:http://localhost:7373?user=neo4j,password=test")); 36 | assertFalse(neo4jDriver.acceptsURL("jdbc:mysql://localhost:3306/sakila")); 37 | assertFalse(neo4jDriver.acceptsURL("jdbc:postgresql://localhost/test")); 38 | } 39 | 40 | @Test 41 | public void parseUrlProperties() throws Exception { 42 | Properties props = new Properties(); 43 | assertEquals(props, neo4jDriver.parseUrlProperties("jdbc:neo4j:http://localhost",null)); 44 | props.setProperty("user","neo4j"); 45 | assertEquals(props, neo4jDriver.parseUrlProperties("jdbc:neo4j:http://localhost?user=neo4j",null)); 46 | props.setProperty("password","a test/paßword"); 47 | assertEquals(props, neo4jDriver.parseUrlProperties("jdbc:neo4j:http://localhost?user=neo4j&password=a%20test%2Fpa%C3%9Fword",null)); 48 | assertEquals(props, neo4jDriver.parseUrlProperties("jdbc:neo4j:http://localhost?user=neo4j,password=a%20test%2Fpa%C3%9Fword",null)); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/main/java/org/neo4j/jdbc/metadata/Table.java: -------------------------------------------------------------------------------- 1 | package org.neo4j.jdbc.metadata; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Table { 7 | private static final List COLUMN_NAMES; 8 | 9 | static { 10 | COLUMN_NAMES = new ArrayList<>(); 11 | 12 | COLUMN_NAMES.add("TABLE_CAT"); 13 | COLUMN_NAMES.add("TABLE_SCHEM"); 14 | COLUMN_NAMES.add("TABLE_NAME"); 15 | COLUMN_NAMES.add("TABLE_TYPE"); 16 | COLUMN_NAMES.add("REMARKS"); 17 | COLUMN_NAMES.add("TYPE_CAT"); 18 | COLUMN_NAMES.add("TYPE_SCHEM"); 19 | COLUMN_NAMES.add("TYPE_NAME"); 20 | COLUMN_NAMES.add("SELF_REFERENCING_COL_NAME"); 21 | COLUMN_NAMES.add("REF_GENERATION"); 22 | } 23 | 24 | private String tableName; 25 | 26 | public Table(String tableName) { 27 | this.tableName = tableName; 28 | } 29 | 30 | public static List getColumns() { 31 | return COLUMN_NAMES; 32 | } 33 | 34 | public String getTableCat() { 35 | return null; 36 | } 37 | 38 | public String getTableSchem() { 39 | return null; 40 | } 41 | 42 | public String getTableName() { 43 | return this.tableName; 44 | } 45 | 46 | public String getTableType() { 47 | return "TABLE"; 48 | } 49 | 50 | public String getRemarks() { 51 | return ":" + this.tableName + " node label"; 52 | } 53 | 54 | public String getTypeCat() { 55 | return null; 56 | } 57 | 58 | public String getTypeSchem() { 59 | return null; 60 | } 61 | 62 | public String getTypeName() { 63 | return null; 64 | } 65 | 66 | public String getSelfReferencingColName() { 67 | return null; 68 | } 69 | 70 | public String getRefGeneration() { 71 | return null; 72 | } 73 | 74 | public List toResultSetRow() { 75 | List row = new ArrayList<>(); 76 | row.add(this.getTableCat()); 77 | row.add(this.getTableSchem()); 78 | row.add(this.getTableName()); 79 | row.add(this.getTableType()); 80 | row.add(this.getRemarks()); 81 | row.add(this.getTypeCat()); 82 | row.add(this.getTypeSchem()); 83 | row.add(this.getTypeName()); 84 | row.add(this.getSelfReferencingColName()); 85 | row.add(this.getRefGeneration()); 86 | return row; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /neo4j-jdbc-bolt/src/test/java/org/neo4j/jdbc/bolt/BoltNeo4jDataSourceIT.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 01/12/17 19 | */ 20 | package org.neo4j.jdbc.bolt; 21 | 22 | import org.junit.ClassRule; 23 | import org.junit.Rule; 24 | import org.junit.Test; 25 | import org.junit.rules.ExpectedException; 26 | 27 | import java.sql.Connection; 28 | import java.sql.SQLException; 29 | import java.sql.Statement; 30 | 31 | import static org.junit.Assert.assertNotNull; 32 | import static org.junit.Assert.assertTrue; 33 | 34 | /** 35 | * @author AgileLARUS 36 | * 37 | * @since 3.0.0 38 | */ 39 | public class BoltNeo4jDataSourceIT { 40 | @Rule 41 | public ExpectedException expectedEx = ExpectedException.none(); 42 | 43 | @ClassRule 44 | public static Neo4jBoltRule neo4j = new Neo4jBoltRule(); 45 | 46 | /*------------------------------*/ 47 | /* getConnection */ 48 | /*------------------------------*/ 49 | 50 | @Test public void getConnectionShouldWork() throws SQLException { 51 | 52 | BoltNeo4jDataSource boltNeo4jDataSource = new BoltNeo4jDataSource(); 53 | boltNeo4jDataSource.setServerName(neo4j.getHost()); 54 | boltNeo4jDataSource.setPortNumber(neo4j.getPort()); 55 | 56 | Connection connection = boltNeo4jDataSource.getConnection(); 57 | assertNotNull(connection); 58 | 59 | Statement statement = connection.createStatement(); 60 | assertTrue(statement.execute("RETURN 1")); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/main/java/org/neo4j/jdbc/Wrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 09/03/16 19 | */ 20 | package org.neo4j.jdbc; 21 | 22 | import java.sql.SQLException; 23 | 24 | /** 25 | * @author AgileLARUS 26 | * @since 3.0.0 27 | */ 28 | public class Wrapper { 29 | 30 | private Wrapper() {}; 31 | 32 | @SuppressWarnings("unchecked") 33 | public static T unwrap(Class iface, Object obj) throws SQLException { 34 | if (!isWrapperFor(iface, obj.getClass())) { 35 | //Current class is not implementing the requested class 36 | throw new SQLException(); 37 | } 38 | 39 | return (T) obj; 40 | } 41 | 42 | @SuppressWarnings("rawtypes") 43 | public static boolean isWrapperFor(Class iface, Class cls) throws SQLException { 44 | if (cls.getName().equals(iface.getName())) { 45 | //iface is the cls class 46 | return true; 47 | } 48 | 49 | for (Class c : cls.getInterfaces()) { 50 | //Looking inside current class implementations 51 | if (c.getName().equals(iface.getName())) { 52 | //The cls class implements iface 53 | return true; 54 | } else if (isWrapperFor(iface, c)) { 55 | //Recursively search inside cls' interface 56 | return true; 57 | } 58 | } 59 | 60 | if (cls.getSuperclass() != null) { 61 | //Recursively search inside the cls' superclass 62 | return isWrapperFor(iface, cls.getSuperclass()); 63 | } else { 64 | //iface is not directly or indirectly implemented in cls 65 | return false; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /neo4j-jdbc-examples/mybatis/src/main/java/org/neo4j/jdbc/example/mybatis/util/ConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 4 | *

5 | * This file is part of the "LARUS Integration Framework for Neo4j". 6 | *

7 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | *

11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | *

13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *

19 | * Created on 24/4/2016 20 | * 21 | */ 22 | package org.neo4j.jdbc.example.mybatis.util; 23 | 24 | import java.io.IOException; 25 | import java.io.Reader; 26 | 27 | import org.apache.ibatis.io.Resources; 28 | import org.apache.ibatis.session.Configuration; 29 | import org.apache.ibatis.session.SqlSessionFactory; 30 | import org.apache.ibatis.session.SqlSessionFactoryBuilder; 31 | 32 | /** 33 | * @author AgileLARUS 34 | * @since 3.0.2 35 | */ 36 | public class ConnectionFactory { 37 | 38 | private static final String DATABASE_CONFIG_XML = "database-config.xml"; 39 | 40 | private static SqlSessionFactory factory; 41 | 42 | private ConnectionFactory() {} 43 | 44 | public static SqlSessionFactory getSqlSessionFactory() { 45 | return getSqlSessionFactory(DATABASE_CONFIG_XML); 46 | } 47 | 48 | public static SqlSessionFactory getSqlSessionFactory(String config) { 49 | if (factory == null) { 50 | try (Reader reader = Resources.getResourceAsReader(config)){ 51 | factory = new SqlSessionFactoryBuilder().build(reader); 52 | } catch (IOException e) { 53 | throw new RuntimeException(e); 54 | } 55 | } 56 | return factory; 57 | } 58 | 59 | public static SqlSessionFactory getSqlSessionFactory(Configuration configuration) { 60 | if (factory == null) { 61 | factory = new SqlSessionFactoryBuilder().build(configuration); 62 | } 63 | return factory; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /neo4j-jdbc-examples/mybatis/src/test/java/org/neo4j/jdbc/example/mybatis/ActorManagerIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 4 | *

5 | * This file is part of the "LARUS Integration Framework for Neo4j". 6 | *

7 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | *

11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | *

13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *

19 | * Created on 24/4/2016 20 | * 21 | */ 22 | package org.neo4j.jdbc.example.mybatis; 23 | 24 | import org.junit.Assert; 25 | import org.junit.BeforeClass; 26 | import org.junit.ClassRule; 27 | import org.junit.Test; 28 | import org.neo4j.harness.junit.Neo4jRule; 29 | import org.neo4j.jdbc.example.mybatis.bean.Actor; 30 | import org.neo4j.jdbc.example.mybatis.util.ActorManager; 31 | 32 | /** 33 | * @author AgileLARUS 34 | * @since 3.0.2 35 | */ 36 | public class ActorManagerIT extends MybatisTestUtil { 37 | 38 | @ClassRule 39 | public static Neo4jRule neo4j = new Neo4jRule(); 40 | 41 | @BeforeClass 42 | public static void setUp() { 43 | populateGraphDB(neo4j.getGraphDatabaseService()); 44 | } 45 | 46 | @Test 47 | public void testMybatisViaHttp() { 48 | buildMybatisConfiguration("http", neo4j.httpURI().getHost(), neo4j.httpURI().getPort()); 49 | Actor actor = ActorManager.selectActorByBorn(1973); 50 | Assert.assertNotNull(actor); 51 | Assert.assertEquals(1973, actor.getBorn()); 52 | Assert.assertEquals("Dave Chappelle", actor.getName()); 53 | } 54 | 55 | @Test 56 | public void testMybatisViaBolt() { 57 | buildMybatisConfiguration("bolt", neo4j.boltURI().getHost(), neo4j.boltURI().getPort()); 58 | Actor actor = ActorManager.selectActorByBorn(1973); 59 | Assert.assertNotNull(actor); 60 | Assert.assertEquals(1973, actor.getBorn()); 61 | Assert.assertEquals("Dave Chappelle", actor.getName()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /neo4j-jdbc-driver/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | 9 | 10 | 11 | org.neo4j 12 | neo4j-jdbc-parent 13 | 3.2.0 14 | 15 | 16 | 17 | 18 | 19 | Neo4j JDBC Packaging 20 | neo4j-jdbc-driver 21 | Module to package Neo4j JDBC Driver into one jar 22 | 23 | 24 | 25 | 26 | 27 | 28 | org.neo4j 29 | neo4j-jdbc-bolt 30 | 31 | 32 | org.neo4j 33 | neo4j-jdbc-http 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.apache.maven.plugins 44 | maven-shade-plugin 45 | ${maven.plugin.shade} 46 | 47 | 48 | package 49 | 50 | shade 51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /docs/index.adoc: -------------------------------------------------------------------------------- 1 | = Neo4j JDBC Driver Documentation 2 | :toc: left 3 | :toclevels: 2 4 | 5 | include::../README.adoc[] 6 | 7 | 8 | 9 | == Technical Reference 10 | 11 | === Usage Examples 12 | 13 | 14 | === The Bolt Driver 15 | 16 | The Bolt driver connects to any Neo4j 3.x database that has the binary "Bolt" transport enabled. 17 | 18 | It uses the https://github.com/neo4j/neo4j-java-driver[neo4j-java-driver] to provide the connectivity. 19 | 20 | Just provide your username and password and you can connect to Neo4j. 21 | 22 | The JDBC URL has this format: `jdbc:neo4j:bolt://host:port/?username=neo4j,password=xxxx` 23 | 24 | === The HTTP Driver 25 | 26 | The HTTP driver uses the existing (since Neo4j 2.x) transaction Cypher HTTP API, and is implemented using `Apache Commons httpclient` and `Jackson` for JSON (de)serialization. 27 | 28 | The JDBC URL has this format: `jdbc:neo4j:http://host:port/?username=neo4j,password=xxxx` 29 | 30 | === JDBC Compatibility 31 | 32 | We cover these aspects of the JDBC-APIs, everything that's not explicitely mentioned should be assumed to be not implemented: 33 | 34 | * Driver handling automatic loading and JDBC URLs 35 | * Connection, incl. autocommit and manual commit 36 | * Transactions 37 | * Statements for reads and writes 38 | * PreparedStatement for reads and writes, including parameters, both question marks `?` and named numbered parameters `{1}` 39 | * ResultSet retrieving all columns as String, Object and their native type with optional conversions 40 | 41 | == Libraries and Frameworks 42 | 43 | === Java JDBC Usage 44 | 45 | Plain JDBC usage was already shown before: 46 | 47 | include::../README.adoc[tags=mvs] 48 | 49 | include::spring.adoc[] 50 | 51 | include::play.adoc[] 52 | 53 | // TODO === Mybatis 54 | 55 | == Integration Examples with Popular Database Tools 56 | 57 | // todo list of tools here: https://github.com/neo4j-contrib/neo4j-jdbc/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3ATools%20 58 | 59 | == Reporting Tools 60 | 61 | include::jasper.adoc[] 62 | 63 | include::birt.adoc[] 64 | 65 | == Business Intelligence Tools 66 | 67 | include::qlik.adoc[] 68 | 69 | include::tableau.adoc[] 70 | 71 | == ETL Tools 72 | 73 | include::pentaho.adoc[] 74 | 75 | include::talend.adoc[] 76 | 77 | == Database Tools 78 | 79 | include::squirrel.adoc[] 80 | 81 | include::eclipse.adoc[] 82 | 83 | include::sqlshell.adoc[] 84 | 85 | include::apoc.adoc[] 86 | 87 | include::solr.adoc[] 88 | 89 | // TODO === JDBC-ODBC Bridge 90 | -------------------------------------------------------------------------------- /docs/jasper.adoc: -------------------------------------------------------------------------------- 1 | === Jasper Reports 2 | 3 | ==== Step 1: Create new Data Adapters: 4 | 5 | - Right click on *Data Adapters* and click on *Create Data Adapter* and select "Database JDBC Connection* 6 | 7 | image::https://cloud.githubusercontent.com/assets/15228280/15931473/2f81674c-2e58-11e6-9dfc-f3fed514f9fe.png[] 8 | image::https://cloud.githubusercontent.com/assets/15228280/15931644/ebf0e510-2e58-11e6-9b36-5feed0879a1c.png[] 9 | 10 | - Insert the values of *JDBC driver*: "org.neo4j.jdbc.bolt.BoltDriver" and 11 | - *JDBC Url*: `jdbc:neo4j:bolt://localhost` like the image below and 12 | - insert your *username* and *password* 13 | 14 | image::https://cloud.githubusercontent.com/assets/15228280/15931831/98ce1eb0-2e59-11e6-8a59-5c73cd09389f.png[] 15 | 16 | - Click on Driver Classpath tab then to add: 17 | 18 | image::https://cloud.githubusercontent.com/assets/15228280/15932157/e3715aee-2e5a-11e6-95be-870d636e5e2f.png[] 19 | 20 | - Add the Neo4j JDBC jar file: 21 | 22 | image::https://cloud.githubusercontent.com/assets/15228280/15932298/6a5103f2-2e5b-11e6-8574-3e4c98351789.png[] 23 | image::https://cloud.githubusercontent.com/assets/15228280/15932309/78fc6fae-2e5b-11e6-950d-62ffcea3c11e.png[] 24 | 25 | - Click on Test and you should have a *successful* message: 26 | 27 | image::https://cloud.githubusercontent.com/assets/15228280/15932369/b9e7d8be-2e5b-11e6-96ad-3d12faa6f588.png[] 28 | 29 | 30 | ==== Step 2: Retrieve Columns from Database: 31 | 32 | - Create new Jasper Report and click on DataSet and Query editor Dialog: 33 | 34 | image::https://cloud.githubusercontent.com/assets/15228280/15932739/19fadea8-2e5d-11e6-9f4f-fec9add565d5.png[] 35 | 36 | - Insert the cypher "MATCH (a)-[:ACTED_IN]->(m)<-[:DIRECTED]-(d) RETURN a.name, m.title, d.name;" then click on Read Field: 37 | 38 | image::https://cloud.githubusercontent.com/assets/15228280/15932873/aca6f0de-2e5d-11e6-832a-a2388c3f1527.png[] 39 | 40 | - You can check data retrieve clicking on Data preview tab then Refresh Preview Data: 41 | 42 | image::https://cloud.githubusercontent.com/assets/15228280/15932940/f432a70e-2e5d-11e6-82a0-51344894468d.png[] 43 | 44 | ==== Step 3: Prepare Report and create document: 45 | 46 | image::https://cloud.githubusercontent.com/assets/15228280/15932984/23a5c2d2-2e5e-11e6-93ec-7f22dd4cc7f5.png[] 47 | 48 | image::https://cloud.githubusercontent.com/assets/15228280/15932994/2d1b40e4-2e5e-11e6-8301-b0886b118787.png[] 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/main/java/org/neo4j/jdbc/utils/Neo4jInvocationHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 22/12/17 19 | */ 20 | package org.neo4j.jdbc.utils; 21 | 22 | import java.lang.reflect.InvocationHandler; 23 | import java.lang.reflect.InvocationTargetException; 24 | import java.lang.reflect.Method; 25 | import java.util.HashMap; 26 | import java.util.Map; 27 | import java.util.logging.Logger; 28 | 29 | /** 30 | * @author Gianmarco Laggia @ Larus B.A. 31 | * @since 3.2.0 32 | */ 33 | public class Neo4jInvocationHandler implements InvocationHandler { 34 | 35 | private static final Logger LOGGER = Logger.getLogger(Neo4jInvocationHandler.class.getName()); 36 | 37 | private final Map methods = new HashMap<>(); 38 | 39 | private Object target; 40 | private boolean debug; 41 | 42 | public Neo4jInvocationHandler(Object target, boolean debug) { 43 | this.target = target; 44 | this.debug = debug; 45 | 46 | for (Method method : target.getClass().getMethods()) { 47 | String key = getUniqueKeyFromMethod(method); 48 | this.methods.put(key, method); 49 | } 50 | } 51 | 52 | @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 53 | try { 54 | Object result = methods.get(getUniqueKeyFromMethod(method)).invoke(target, args); 55 | 56 | if (debug) { 57 | LOGGER.info("[" + target.getClass().getCanonicalName() + "] " + method.getName()); 58 | } 59 | 60 | return result; 61 | } catch (InvocationTargetException e) { 62 | throw e.getCause(); 63 | } 64 | } 65 | 66 | private String getUniqueKeyFromMethod(Method method) { 67 | String key = method.getName() + "_"; 68 | for(Class type : method.getParameterTypes()) { 69 | key += type.getCanonicalName() + "_"; 70 | } 71 | return key; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/main/java/org/neo4j/jdbc/utils/PreparedStatementBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 25/03/16 19 | */ 20 | package org.neo4j.jdbc.utils; 21 | 22 | import java.util.regex.Matcher; 23 | import java.util.regex.Pattern; 24 | 25 | /** 26 | * This class contains static methods used to process a raw statement and create a valid string to be used as preparedStatement in neo4j 27 | * 28 | * @author AgileLARUS 29 | * @since 3.0.0 30 | */ 31 | public class PreparedStatementBuilder { 32 | 33 | private PreparedStatementBuilder() {} 34 | 35 | /** 36 | * This method return a String that is the original raw string with all valid placeholders replaced with neo4j curly brackets notation for parameters. 37 | *
38 | * i.e. MATCH n RETURN n WHERE n.name = ? is transformed in MATCH n RETURN n WHERE n.name = {1} 39 | * 40 | * @param raw The string to be translated. 41 | * @return The string with the placeholders replaced. 42 | */ 43 | public static String replacePlaceholders(String raw) { 44 | int index = 1; 45 | String digested = raw; 46 | 47 | String regex = "\\?(?=[^\"]*(?:\"[^\"]*\"[^\"]*)*$)"; 48 | Matcher matcher = Pattern.compile(regex).matcher(digested); 49 | 50 | while (matcher.find()) { 51 | digested = digested.replaceFirst(regex, "{" + index + "}"); 52 | index++; 53 | } 54 | 55 | return digested; 56 | } 57 | 58 | /** 59 | * Given a string (statement) it counts all valid placeholders 60 | * 61 | * @param raw The string of the statement 62 | * @return The number of all valid placeholders 63 | */ 64 | public static int namedParameterCount(String raw) { 65 | int max = 0; 66 | String regex = "\\{\\s*`?\\s*(\\d+)\\s*`?\\s*\\}(?=[^\"]*(\"[^\"]*\"[^\"]*)*$)"; 67 | Matcher matcher = Pattern.compile(regex).matcher(raw); 68 | while (matcher.find()) { 69 | max = Math.max(Integer.parseInt(matcher.group(1)),max); 70 | } 71 | return max; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /neo4j-jdbc-bolt/src/test/java/org/neo4j/jdbc/bolt/SampleIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 23/02/16 19 | */ 20 | package org.neo4j.jdbc.bolt; 21 | 22 | import org.junit.Rule; 23 | import org.junit.Test; 24 | import org.neo4j.driver.v1.*; 25 | import org.neo4j.driver.v1.Driver; 26 | 27 | import java.sql.*; 28 | import java.sql.Statement; 29 | 30 | import static org.junit.Assert.*; 31 | import static org.neo4j.driver.v1.Config.build; 32 | 33 | /** 34 | * @author Stefan Armbruster 35 | */ 36 | public class SampleIT { 37 | 38 | @Rule public Neo4jBoltRule neo4j = new Neo4jBoltRule(); // here we're firing up neo4j with bolt enabled 39 | 40 | @Test public void shouldSimpleServerTestSucceed() throws Exception { 41 | 42 | // if we want to have raw access to neo4j instance, e.g. for populating the DB upfront: 43 | neo4j.getGraphDatabase().execute("create ( )"); 44 | 45 | //Creating config without SSL 46 | Config.ConfigBuilder builder = build(); 47 | builder.withoutEncryption(); 48 | Config config = builder.toConfig(); 49 | 50 | // hitting the DB with a bolt request 51 | Driver driver = GraphDatabase.driver(neo4j.getBoltUrl(), config); // defaults to localhost:7687 52 | Session session = driver.session(); 53 | StatementResult rs = session.run("match (n) RETURN count(n)"); 54 | session.close(); 55 | driver.close(); 56 | } 57 | 58 | @Test public void exampleTestInMemory() throws ClassNotFoundException, SQLException { 59 | neo4j.getGraphDatabase().execute("create (:User{name:\"testUser\"})"); 60 | 61 | // Connect 62 | Connection con = DriverManager.getConnection("jdbc:neo4j:" + neo4j.getBoltUrl() + "?nossl"); 63 | 64 | // Querying 65 | try (Statement stmt = con.createStatement()) { 66 | ResultSet rs = stmt.executeQuery("MATCH (n:User) RETURN n.name"); 67 | assertTrue(rs.next()); 68 | assertEquals("testUser", rs.getString("n.name")); 69 | assertFalse(rs.next()); 70 | } 71 | con.close(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/src/main/java/org/neo4j/jdbc/http/driver/Neo4jResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 15/4/2016 19 | */ 20 | package org.neo4j.jdbc.http.driver; 21 | 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | /** 26 | * A POJO that store a Neo4j query result that match the cypher endpoint. 27 | */ 28 | @SuppressWarnings({"rawtypes", "unchecked"}) 29 | public class Neo4jResult { 30 | 31 | /** 32 | * List of columns. 33 | */ 34 | private List columns; 35 | 36 | /** 37 | * List of data row. 38 | */ 39 | private List rows; 40 | 41 | /** 42 | * List fof stats 43 | */ 44 | private Map stats; 45 | 46 | /** 47 | * Constructor. 48 | * 49 | * @param map JSON Map 50 | */ 51 | public Neo4jResult(Map map) { 52 | this.columns = (List) map.get("columns"); 53 | this.rows = (List) map.get("data"); 54 | 55 | if (map.containsKey("stats")) { 56 | this.stats = (Map) map.get("stats"); 57 | } 58 | } 59 | 60 | /** 61 | * @return the column names in the result 62 | */ 63 | public List getColumns() { 64 | return columns; 65 | } 66 | 67 | /** 68 | * @return the rows in the result set 69 | */ 70 | public List getRows() { 71 | return rows; 72 | } 73 | 74 | /** 75 | * @return the statistics for the statement 76 | */ 77 | public Map getStats() { 78 | return stats; 79 | } 80 | 81 | /** 82 | * Compute updated elements number. 83 | * 84 | * @return the number of updated elements 85 | */ 86 | public int getUpdateCount() { 87 | int updated = 0; 88 | if (this.stats != null && (boolean) this.stats.get("contains_updates")) { 89 | updated += ((Long) stats.get("nodes_created")).intValue(); 90 | updated += ((Long) stats.get("nodes_deleted")).intValue(); 91 | updated += ((Long) stats.get("relationships_created")).intValue(); 92 | updated += ((Long) stats.get("relationship_deleted")).intValue(); 93 | } 94 | return updated; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/main/java/org/neo4j/jdbc/Neo4jParameterMetaData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 03/02/16 19 | */ 20 | package org.neo4j.jdbc; 21 | 22 | import org.neo4j.jdbc.utils.ExceptionBuilder; 23 | 24 | import java.sql.SQLException; 25 | 26 | /** 27 | * @author AgileLARUS 28 | * @since 3.0.0 29 | */ 30 | public abstract class Neo4jParameterMetaData implements java.sql.ParameterMetaData { 31 | 32 | @Override public int getParameterCount() throws SQLException { 33 | throw ExceptionBuilder.buildUnsupportedOperationException(); 34 | } 35 | 36 | @Override public int isNullable(int param) throws SQLException { 37 | throw ExceptionBuilder.buildUnsupportedOperationException(); 38 | } 39 | 40 | @Override public boolean isSigned(int param) throws SQLException { 41 | throw ExceptionBuilder.buildUnsupportedOperationException(); 42 | } 43 | 44 | @Override public int getPrecision(int param) throws SQLException { 45 | throw ExceptionBuilder.buildUnsupportedOperationException(); 46 | } 47 | 48 | @Override public int getScale(int param) throws SQLException { 49 | throw ExceptionBuilder.buildUnsupportedOperationException(); 50 | } 51 | 52 | @Override public int getParameterType(int param) throws SQLException { 53 | throw ExceptionBuilder.buildUnsupportedOperationException(); 54 | } 55 | 56 | @Override public String getParameterTypeName(int param) throws SQLException { 57 | throw ExceptionBuilder.buildUnsupportedOperationException(); 58 | } 59 | 60 | @Override public String getParameterClassName(int param) throws SQLException { 61 | throw ExceptionBuilder.buildUnsupportedOperationException(); 62 | } 63 | 64 | @Override public int getParameterMode(int param) throws SQLException { 65 | throw ExceptionBuilder.buildUnsupportedOperationException(); 66 | } 67 | 68 | @Override public T unwrap(Class iface) throws SQLException { 69 | return Wrapper.unwrap(iface, this); 70 | } 71 | 72 | @Override public boolean isWrapperFor(Class iface) throws SQLException { 73 | return Wrapper.isWrapperFor(iface, this.getClass()); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/src/main/java/org/neo4j/jdbc/http/HttpDriver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 15/4/2016 19 | */ 20 | package org.neo4j.jdbc.http; 21 | 22 | import org.neo4j.jdbc.Neo4jDriver; 23 | import org.neo4j.jdbc.InstanceFactory; 24 | 25 | import java.net.MalformedURLException; 26 | import java.net.URL; 27 | import java.sql.Connection; 28 | import java.sql.DriverManager; 29 | import java.sql.SQLException; 30 | import java.util.Properties; 31 | 32 | /** 33 | * JDBC Driver class for the HTTP connector. 34 | */ 35 | public class HttpDriver extends Neo4jDriver { 36 | 37 | public static final String JDBC_HTTP_PREFIX = "http(s)*"; 38 | 39 | static { 40 | try { 41 | HttpDriver driver = new HttpDriver(); 42 | DriverManager.registerDriver(driver); 43 | } catch (SQLException e) { 44 | throw new ExceptionInInitializerError(e); 45 | } 46 | } 47 | 48 | /** 49 | * Default constructor. 50 | * 51 | * @throws SQLException sqlexception 52 | */ 53 | public HttpDriver() throws SQLException { 54 | super(JDBC_HTTP_PREFIX); 55 | } 56 | 57 | @Override public Connection connect(String url, Properties params) throws SQLException { 58 | Connection connection = null; 59 | try { 60 | if (acceptsURL(url)) { 61 | URL neo4jUrl = new URL(url.replace("jdbc:neo4j:", "").replaceAll("^(" + JDBC_HTTP_PREFIX + ":)([^/])", "$1//$2")); 62 | Properties props = parseUrlProperties(url, params); 63 | String host = neo4jUrl.getHost(); 64 | Boolean secure = Boolean.FALSE; 65 | // default port for http 66 | int port = 7474; 67 | // default port for https 68 | if ("https".equals(neo4jUrl.getProtocol())) { 69 | port = 7473; 70 | secure = Boolean.TRUE; 71 | } 72 | // if a port a specified, we take it 73 | if (neo4jUrl.getPort() > 0) { 74 | port = neo4jUrl.getPort(); 75 | } 76 | connection = InstanceFactory.debug(new HttpNeo4jConnection(host, port, secure, props, url)); 77 | } 78 | } catch (MalformedURLException e) { 79 | throw new SQLException(e); 80 | } 81 | 82 | return connection; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /neo4j-jdbc-examples/mybatis/src/test/java/org/neo4j/jdbc/example/mybatis/MybatisTestUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 4 | *

5 | * This file is part of the "LARUS Integration Framework for Neo4j". 6 | *

7 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | *

11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | *

13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *

19 | * Created on 24/4/2016 20 | * 21 | */ 22 | package org.neo4j.jdbc.example.mybatis; 23 | 24 | import javax.sql.DataSource; 25 | 26 | import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; 27 | import org.apache.ibatis.mapping.Environment; 28 | import org.apache.ibatis.session.Configuration; 29 | import org.apache.ibatis.transaction.TransactionFactory; 30 | import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; 31 | import org.neo4j.graphdb.GraphDatabaseService; 32 | import org.neo4j.graphdb.Label; 33 | import org.neo4j.graphdb.Node; 34 | import org.neo4j.graphdb.Transaction; 35 | import org.neo4j.jdbc.example.mybatis.mapper.ActorMapper; 36 | import org.neo4j.jdbc.example.mybatis.util.ConnectionFactory; 37 | 38 | /** 39 | * @author AgileLARUS 40 | * @since 3.0.2 41 | */ 42 | public class MybatisTestUtil { 43 | 44 | public enum TestLabels implements Label { 45 | Person 46 | } 47 | 48 | protected static void populateGraphDB(GraphDatabaseService graphDatabaseService) { 49 | try (Transaction tx = graphDatabaseService.beginTx()) { 50 | Node node = graphDatabaseService.createNode(TestLabels.Person); 51 | node.setProperty("name", "Dave Chappelle"); 52 | node.setProperty("born", 1973); 53 | tx.success(); 54 | } 55 | } 56 | 57 | protected void buildMybatisConfiguration(String protocol, String host, int port) { 58 | DataSource dataSource = new UnpooledDataSource("org.neo4j.jdbc.Driver", "jdbc:neo4j:" + protocol + "://" + host + ":" + port + "?nossl", null); 59 | TransactionFactory transactionFactory = new JdbcTransactionFactory(); 60 | Environment environment = new Environment("development", transactionFactory, dataSource); 61 | 62 | Configuration configuration = new Configuration(environment); 63 | configuration.getMapperRegistry().addMapper(ActorMapper.class); 64 | configuration.addLoadedResource("org/neo4j/jdbc/example/mybatis/mapper/ActorMapper.xml"); 65 | 66 | ConnectionFactory.getSqlSessionFactory(configuration); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /docs/solr.adoc: -------------------------------------------------------------------------------- 1 | === Apache SolR 2 | 3 | ==== Description 4 | 5 | You can index your Neo4j database directly into SolR with the help of SolR `Data Import Handler` (DIH) feature and the neo4j jdbc driver. 6 | This article is just on how to make the glue the two component via the JDBC driver. 7 | 8 | If you want to learn how SolR works with its DIH feature, please refer to thoses documentations : 9 | * https://wiki.apache.org/solr/DataImportHandler 10 | * https://cwiki.apache.org/confluence/display/solr/Uploading+Structured+Data+Store+Data+with+the+Data+Import+Handler 11 | 12 | ==== How-to 13 | 14 | Download the lastest release of SolR (for example : http://apache.crihan.fr/dist/lucene/solr/6.1.0/solr-6.1.0.tgz) 15 | 16 | ---- 17 | $>cd /tmp 18 | $> wget http://apache.crihan.fr/dist/lucene/solr/6.1.0/solr-6.1.0.tgz 19 | ---- 20 | 21 | Extract it to a folder (reference as SOLR_HOME) 22 | 23 | ---- 24 | $> tar xzvf solr-6.1.0.tgz -C SOLR_HOME 25 | ---- 26 | 27 | Copy the folder `SOLR_HOME/example/example-DIH/solr/solr` to `SOLR_HOME/server/solr/neo4j`. 28 | This will create a new SolR core called `neo4j` with all DIH feautres enabled. 29 | 30 | ---- 31 | $> cp -rf SOLR_HOME/example/example-DIH/solr/solr SOLR_HOME/server/solr/neo4j 32 | ---- 33 | 34 | Copy The Neo4j JDBC Driver jar into folder `SOLR_HOME/server/solr/neo4j/lib` (create the folder of it doesn't exist). 35 | 36 | ---- 37 | $> mkdir SOLR_HOME/server/solr/neo4j/lib 38 | $> cp neo4j-jdbc-driver-3.0.1-SNAPSHOT.jar SOLR_HOME/solr/server/solr/neo4j/lib/ 39 | ---- 40 | 41 | Edit the file `SOLR_HOME/server/solr/neo4j/config/solrconfig.xml` to add `lib` folder by adding this line : 42 | 43 | ---- 44 | 45 | ---- 46 | 47 | We will configure SolR DIH feature by editing the file `SOLR_HOME/server/solr/neo4j/config/solr-data-config.xml`. 48 | Just replace its content by this one (don't forget to replace the jdbc url, login password by yours): 49 | 50 | ---- 51 | 52 | 53 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | ---- 70 | 71 | Start SolR server : 72 | 73 | ---- 74 | $> SOLR_HOME/bin/solr start 75 | ---- 76 | 77 | Open your browser at this url, http://localhost:8983/solr/#/neo4j/dataimport//dataimport , and click on the `Execute` button. 78 | A click on the `refresh status` allow you to see the status of the indexation. 79 | 80 | image::./img/solr-dih.png[] 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/src/test/java/org/neo4j/jdbc/http/driver/CypherExecutorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 15/4/2016 19 | */ 20 | package org.neo4j.jdbc.http.driver; 21 | 22 | import org.neo4j.jdbc.http.test.Neo4jHttpUnitTestUtil; 23 | import org.junit.After; 24 | import org.junit.Assert; 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | 28 | import java.io.IOException; 29 | import java.sql.SQLException; 30 | import java.util.Arrays; 31 | import java.util.List; 32 | import java.util.Properties; 33 | import java.util.Random; 34 | 35 | public class CypherExecutorTest extends Neo4jHttpUnitTestUtil { 36 | 37 | private CypherExecutor executor; 38 | 39 | @Before public void before() throws IOException, SQLException { 40 | String host = "azertyuiop"; 41 | Integer port = 1234; 42 | Properties properties = new Properties(); 43 | this.executor = new CypherExecutor(host, port, false, properties); 44 | } 45 | 46 | @Test public void getTransactionIdShouldReturnCorrectId() { 47 | Random idGenerator = new Random(); 48 | for (Integer i = 1; i < 100; i++) { 49 | Integer id = idGenerator.nextInt(); 50 | Integer returnId = executor.getTransactionId(executor.transactionUrl + "/" + id); 51 | Assert.assertEquals(id, returnId); 52 | } 53 | } 54 | 55 | @Test public void getTransactionIdShouldReturnNegativeId() { 56 | List urls = Arrays.asList("", "http://localhost1234:1234/db/data", executor.transactionUrl, executor.transactionUrl + "/commit"); 57 | for (String url : urls) { 58 | Integer returnId = executor.getTransactionId(url); 59 | Assert.assertTrue(returnId < 0); 60 | } 61 | } 62 | 63 | @Test public void executeQueryOnDownServerShouldFail() throws Exception { 64 | expectedEx.expect(SQLException.class); 65 | 66 | List queries = getRandomNeo4jStatementFromCSV("data/queries.csv", 1).get("object"); 67 | executor.executeQueries(queries); 68 | } 69 | 70 | @Test public void executeEmptyQueryShouldFail() throws Exception { 71 | expectedEx.expect(SQLException.class); 72 | executor.executeQuery(new Neo4jStatement("", null, null)); 73 | } 74 | 75 | @After public void after() throws SQLException { 76 | executor.close(); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /neo4j-jdbc-bolt/src/test/java/org/neo4j/jdbc/bolt/BoltNeo4jResultSetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 04/03/16 19 | */ 20 | package org.neo4j.jdbc.bolt; 21 | 22 | import org.neo4j.jdbc.bolt.data.ResultSetData; 23 | import org.junit.BeforeClass; 24 | import org.junit.Rule; 25 | import org.junit.Test; 26 | import org.junit.rules.ExpectedException; 27 | import org.neo4j.driver.v1.StatementResult; 28 | 29 | import java.sql.ResultSet; 30 | import java.sql.SQLException; 31 | 32 | import static org.junit.Assert.assertFalse; 33 | import static org.junit.Assert.assertTrue; 34 | 35 | /** 36 | * @author AgileLARUS 37 | * @since 3.0.0 38 | */ 39 | public class BoltNeo4jResultSetTest { 40 | 41 | @Rule public ExpectedException expectedEx = ExpectedException.none(); 42 | 43 | @BeforeClass public static void initialize() { 44 | ResultSetData.initialize(); 45 | } 46 | 47 | /*------------------------------*/ 48 | /* isClosed */ 49 | /*------------------------------*/ 50 | 51 | @Test public void isClosedReturnFalseWhenConnectionOpen() throws SQLException { 52 | StatementResult StatementResult = ResultSetData 53 | .buildResultCursor(ResultSetData.KEYS_RECORD_LIST_MORE_ELEMENTS, ResultSetData.RECORD_LIST_MORE_ELEMENTS); 54 | ResultSet resultSet = BoltNeo4jResultSet.newInstance(false, null, StatementResult); 55 | 56 | assertFalse(resultSet.isClosed()); 57 | } 58 | 59 | //this method depends on the close() method 60 | @Test public void isClosedReturnTrueWhenConnectionClosed() throws SQLException { 61 | StatementResult StatementResult = ResultSetData 62 | .buildResultCursor(ResultSetData.KEYS_RECORD_LIST_MORE_ELEMENTS, ResultSetData.RECORD_LIST_MORE_ELEMENTS); 63 | ResultSet resultSet = BoltNeo4jResultSet.newInstance(false, null, StatementResult); 64 | 65 | resultSet.close(); 66 | assertTrue(resultSet.isClosed()); 67 | } 68 | 69 | /*------------------------------*/ 70 | /* close */ 71 | /*------------------------------*/ 72 | 73 | @Test public void closeShouldThrowExceptionIfIteratorIsNull() throws SQLException { 74 | expectedEx.expect(SQLException.class); 75 | ResultSet resultSet = BoltNeo4jResultSet.newInstance(false, null, null); 76 | 77 | resultSet.close(); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /neo4j-jdbc-bolt/src/test/java/org/neo4j/jdbc/bolt/Neo4jBoltRule.java: -------------------------------------------------------------------------------- 1 | package org.neo4j.jdbc.bolt; 2 | 3 | import org.junit.rules.TestRule; 4 | import org.junit.runner.Description; 5 | import org.junit.runners.model.Statement; 6 | import org.neo4j.graphdb.GraphDatabaseService; 7 | import org.neo4j.graphdb.config.Setting; 8 | import org.neo4j.graphdb.factory.GraphDatabaseSettings; 9 | import org.neo4j.test.TestGraphDatabaseFactory; 10 | 11 | import java.io.IOException; 12 | import java.net.InetSocketAddress; 13 | import java.net.ServerSocket; 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | import org.neo4j.kernel.configuration.BoltConnector; 17 | 18 | import static org.neo4j.graphdb.factory.GraphDatabaseSettings.BoltConnector.EncryptionLevel.DISABLED; 19 | 20 | /** 21 | * provide an embedded in-memory Neo4j instance with bolt enabled 22 | * the port number is dynamically scanned 23 | * 24 | * @author Stefan Armbruster 25 | */ 26 | public class Neo4jBoltRule implements TestRule { 27 | 28 | private String hostAndPort; 29 | private GraphDatabaseService graphDatabase; 30 | private String host; 31 | private int port; 32 | private final boolean requireAuth; 33 | 34 | public Neo4jBoltRule() { 35 | this(false); 36 | } 37 | 38 | public Neo4jBoltRule(boolean requireAuth) { 39 | this.requireAuth = requireAuth; 40 | } 41 | 42 | @Override public Statement apply(final Statement statement, Description description) { 43 | return new Statement() { 44 | 45 | @Override public void evaluate() throws Throwable { 46 | Map, String> settings = new HashMap<>(); 47 | BoltConnector boltConnector = new BoltConnector(); 48 | settings.put(boltConnector.enabled, "true"); 49 | settings.put(boltConnector.type, GraphDatabaseSettings.Connector.ConnectorType.BOLT.name()); 50 | settings.put(boltConnector.encryption_level, DISABLED.name()); 51 | settings.put(GraphDatabaseSettings.auth_enabled, Boolean.toString(requireAuth)); 52 | InetSocketAddress inetAddr = new InetSocketAddress("localhost", getFreePort()); 53 | host = inetAddr.getHostName(); 54 | port = inetAddr.getPort(); 55 | hostAndPort = String.format("%s:%d", inetAddr.getHostName(), inetAddr.getPort()); 56 | settings.put(boltConnector.listen_address, hostAndPort); 57 | graphDatabase = new TestGraphDatabaseFactory().newImpermanentDatabase(settings); 58 | try { 59 | statement.evaluate(); 60 | } finally { 61 | graphDatabase.shutdown(); 62 | } 63 | } 64 | }; 65 | } 66 | 67 | public String getBoltUrl() { 68 | return String.format("bolt://%s", hostAndPort); 69 | } 70 | 71 | public GraphDatabaseService getGraphDatabase() { 72 | return graphDatabase; 73 | } 74 | 75 | public int getPort() { 76 | return port; 77 | } 78 | 79 | public String getHost() { 80 | return host; 81 | } 82 | 83 | private int getFreePort() throws IOException { 84 | try (ServerSocket socket = new ServerSocket(0)) { 85 | socket.setReuseAddress(true); 86 | return socket.getLocalPort(); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /docs/eclipse.adoc: -------------------------------------------------------------------------------- 1 | === Eclipse Database Tools 2 | 3 | ==== Step 1: Create a new connection profile 4 | 5 | * Open the *Database Developement* perspective: 6 | 7 | image::https://cloud.githubusercontent.com/assets/6613815/15891647/ee537ca2-2d75-11e6-9bcb-fbc1e89d987c.png[] 8 | 9 | image::https://cloud.githubusercontent.com/assets/6613815/15891652/ee58c356-2d75-11e6-9f5e-6bc6df75bdaf.png[] 10 | 11 | * Click on the icon *New Connection Profile*: 12 | 13 | image::https://cloud.githubusercontent.com/assets/6613815/15891651/ee556c1a-2d75-11e6-9aea-3fdcc7256ec5.png[] 14 | 15 | * Choose *Generic JDBC* (and optionally type "Neo4j 3.0 JDBC Bolt Driver" in "name" and "description" fields. Then click *Next*: 16 | 17 | image::https://cloud.githubusercontent.com/assets/6613815/15891650/ee55612a-2d75-11e6-908d-910d39dc15b1.png[] 18 | 19 | ==== Step 2: Create a new driver definition 20 | 21 | * Click on the icon *New Driver Definition*: 22 | 23 | image::https://cloud.githubusercontent.com/assets/6613815/15891649/ee5531fa-2d75-11e6-95d8-06f7747178bc.png[] 24 | 25 | * Choose "Generic JDBC Driver" in folder *Name/Type* (and optionally re-type "Neo4j 3.0 JDBC Bolt Driver" in the "Driver Name" field): 26 | 27 | image::https://cloud.githubusercontent.com/assets/6613815/15891648/ee549466-2d75-11e6-97ef-3c0c0b0a5d71.png[] 28 | 29 | * In Folder *JAR List*, click *Add JAR/Zip* and choose the new *Neo4j JDBC Bolt Driver*: 30 | 31 | image::https://cloud.githubusercontent.com/assets/6613815/15891653/ee692e58-2d75-11e6-94db-64a462195ea8.png[] 32 | 33 | * In Folder *Properties* choose the *Driver Class*" by clicking the icon *[..]*: 34 | 35 | image::https://cloud.githubusercontent.com/assets/6613815/15891654/ee6aded8-2d75-11e6-8344-2b0a96a418c9.png[] 36 | 37 | * Choose *org.neo4j.jdbc.bolt.BoltDriver* as the Driver class: 38 | 39 | image::https://cloud.githubusercontent.com/assets/6613815/15891658/ee7043f0-2d75-11e6-97ba-efb1f3835a4c.png[] 40 | 41 | * Set the *Connection URL* to "jdbc:neo4j:bolt://localhost" and the *User ID* to "neo4j", then click *OK*: 42 | 43 | image::https://cloud.githubusercontent.com/assets/6613815/15891656/ee6bf35e-2d75-11e6-901a-29396d251fb7.png[] 44 | 45 | * Set the *Password* and click *Test Connection*: 46 | 47 | image::https://cloud.githubusercontent.com/assets/6613815/15891655/ee6b4bfc-2d75-11e6-9903-419c28499517.png[] 48 | 49 | * You should get *Ping Succeeded!* message (with your database online). Click *OK* and then *Finish*: 50 | 51 | image::https://cloud.githubusercontent.com/assets/6613815/15891657/ee6e9154-2d75-11e6-97a4-5b5185369407.png[] 52 | 53 | ==== Step 3: Test the connection (match and create) 54 | 55 | * Open an *SQL Scrapbook* and execute your statement (i.e. `match (n) return n`): 56 | 57 | image::https://cloud.githubusercontent.com/assets/6613815/15891659/ee7ec150-2d75-11e6-8643-8b040fb588bb.png[] 58 | 59 | * Create statements should work as well: 60 | 61 | image::https://cloud.githubusercontent.com/assets/6613815/15891660/ee81b3ba-2d75-11e6-8232-b6044e855252.png[] 62 | 63 | as you can see on the neo4j browser: 64 | 65 | image::https://cloud.githubusercontent.com/assets/6613815/15891661/ee830f3a-2d75-11e6-9d1f-9b50aac21cb6.png[] 66 | 67 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/test/java/org/neo4j/jdbc/Neo4jStatementTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 09/03/16 19 | */ 20 | package org.neo4j.jdbc; 21 | 22 | import org.junit.Rule; 23 | import org.junit.Test; 24 | import org.junit.rules.ExpectedException; 25 | import org.mockito.Mockito; 26 | 27 | import java.sql.SQLException; 28 | 29 | import static org.junit.Assert.*; 30 | import static org.mockito.Mockito.mock; 31 | 32 | /** 33 | * @author AgileLARUS 34 | * @since 3.0.0 35 | */ 36 | public class Neo4jStatementTest { 37 | 38 | @Rule public ExpectedException expectedEx = ExpectedException.none(); 39 | 40 | /*------------------------------*/ 41 | /* isWrapperFor */ 42 | /*------------------------------*/ 43 | 44 | @Test public void isWrapperForShouldReturnTrue() throws SQLException { 45 | Neo4jStatement statement = mock(Neo4jStatement.class, Mockito.CALLS_REAL_METHODS); 46 | 47 | assertTrue(statement.isWrapperFor(Neo4jStatement.class)); 48 | assertTrue(statement.isWrapperFor(java.sql.Statement.class)); 49 | assertTrue(statement.isWrapperFor(java.sql.Wrapper.class)); 50 | assertTrue(statement.isWrapperFor(AutoCloseable.class)); 51 | } 52 | 53 | @Test public void isWrapperForShouldReturnFalse() throws SQLException { 54 | Neo4jStatement statement = mock(Neo4jStatement.class, Mockito.CALLS_REAL_METHODS); 55 | 56 | assertFalse(statement.isWrapperFor(Neo4jParameterMetaData.class)); 57 | assertFalse(statement.isWrapperFor(java.sql.Driver.class)); 58 | assertFalse(statement.isWrapperFor(javax.sql.DataSource.class)); 59 | assertFalse(statement.isWrapperFor(java.sql.ResultSet.class)); 60 | } 61 | 62 | /*------------------------------*/ 63 | /* unwrap */ 64 | /*------------------------------*/ 65 | 66 | @Test public void unwrapShouldReturnCorrectClass() throws SQLException { 67 | Neo4jStatement statement = mock(Neo4jStatement.class, Mockito.CALLS_REAL_METHODS); 68 | 69 | assertNotNull(statement.unwrap(Neo4jStatement.class)); 70 | assertNotNull(statement.unwrap(java.sql.Statement.class)); 71 | assertNotNull(statement.unwrap(java.sql.Wrapper.class)); 72 | assertNotNull(statement.unwrap(AutoCloseable.class)); 73 | } 74 | 75 | @Test public void unwrapShouldThrowException() throws SQLException { 76 | expectedEx.expect(SQLException.class); 77 | 78 | Neo4jStatement statement = mock(Neo4jStatement.class, Mockito.CALLS_REAL_METHODS); 79 | 80 | statement.unwrap(Neo4jResultSet.class); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /neo4j-jdbc-bolt/src/test/java/org/neo4j/jdbc/bolt/data/StatementData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 19/02/16 19 | */ 20 | package org.neo4j.jdbc.bolt.data; 21 | 22 | /** 23 | * @author AgileLARUS 24 | * @since 3.0.0 25 | */ 26 | public class StatementData { 27 | public static String STATEMENT_MATCH_ALL = "MATCH (n) RETURN n;"; 28 | public static String STATEMENT_MATCH_ALL_STRING = "MATCH (n:User) RETURN n.name;"; 29 | public static String STATEMENT_MATCH_NODES = "MATCH (n:User) RETURN n;"; 30 | public static String STATEMENT_MATCH_NODES_MORE = "MATCH (n:User)-[]->(s:Session) RETURN n, s;"; 31 | public static String STATEMENT_MATCH_MISC = "MATCH (n:User) RETURN n, n.name;"; 32 | public static String STATEMENT_MATCH_RELATIONS = "MATCH ()-[r:CONNECTED_IN]-() RETURN r;"; 33 | public static String STATEMENT_MATCH_NODES_RELATIONS = "MATCH (n:User)-[r:CONNECTED_IN]->(s:Session) RETURN n, r, s"; 34 | public static String STATEMENT_CREATE = "CREATE (n:User {name:\"test\"});"; 35 | public static String STATEMENT_CREATE_REV = "MATCH (n:User {name:\"test\"}) DELETE n;"; 36 | public static String STATEMENT_CREATE_TWO_PROPERTIES = "CREATE (n:User {name:\"test\", surname:\"testAgain\"});"; 37 | public static String STATEMENT_CREATE_TWO_PROPERTIES_REV = "MATCH (n:USer {name:\"test\", surname:\"testAgain\"}) DETACH DELETE n;"; 38 | public static String STATEMENT_MATCH_ALL_STRING_PARAMETRIC = "MATCH (n) WHERE n.name = ? RETURN n.surname;"; 39 | public static String STATEMENT_MATCH_ALL_STRING_PARAMETRIC_NAMED = "MATCH (n) WHERE n.name = {1} RETURN n.surname;"; 40 | public static String STATEMENT_CREATE_OTHER_TYPE_AND_RELATIONS = "MATCH (n:User) CREATE (n)-[:CONNECTED_IN {date:1459248821051}]->(:Session {status:true});"; 41 | public static String STATEMENT_CREATE_OTHER_TYPE_AND_RELATIONS_REV = "MATCH (s:Session) DETACH DELETE s;"; 42 | public static String STATEMENT_CREATE_TWO_PROPERTIES_PARAMETRIC = "CREATE (n:User {name:?, surname:?});"; 43 | public static String STATEMENT_CREATE_TWO_PROPERTIES_PARAMETRIC_REV = "MATCH (n:User {name:?, surname:?}) DETACH DELETE n;"; 44 | public static String STATEMENT_CLEAR_DB = "MATCH (n) DETACH DELETE n;"; 45 | public static String STATEMENT_COUNT_NODES = "MATCH (n) RETURN count(n) AS total;"; 46 | } 47 | -------------------------------------------------------------------------------- /neo4j-jdbc-bolt/src/test/java/org/neo4j/jdbc/bolt/BoltNeo4jDatabaseMetaDataIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 4 | *

5 | * This file is part of the "LARUS Integration Framework for Neo4j". 6 | *

7 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | *

11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | *

13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *

19 | * Created on 17/4/2016 20 | * 21 | */ 22 | package org.neo4j.jdbc.bolt; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.junit.Assert.assertNotEquals; 26 | import static org.junit.Assert.assertNotNull; 27 | import static org.junit.Assert.assertTrue; 28 | 29 | import java.sql.Connection; 30 | import java.sql.DriverManager; 31 | import java.sql.ResultSet; 32 | import java.sql.SQLException; 33 | import java.sql.Statement; 34 | 35 | import org.junit.Rule; 36 | import org.junit.Test; 37 | 38 | /** 39 | * Neo4jDatabaseMetaData IT Tests class 40 | */ 41 | public class BoltNeo4jDatabaseMetaDataIT { 42 | 43 | @Rule public Neo4jBoltRule neo4j = new Neo4jBoltRule(); 44 | 45 | @Test public void getDatabaseVersionShouldBeOK() throws SQLException, NoSuchFieldException, IllegalAccessException { 46 | Connection connection = DriverManager.getConnection("jdbc:neo4j:" + neo4j.getBoltUrl() + "?nossl","user","password"); 47 | 48 | assertNotNull(connection.getMetaData().getDatabaseProductVersion()); 49 | assertNotEquals(-1, connection.getMetaData().getDatabaseMajorVersion()); 50 | assertNotEquals(-1, connection.getMetaData().getDatabaseMajorVersion()); 51 | assertEquals("user", connection.getMetaData().getUserName()); 52 | 53 | connection.close(); 54 | } 55 | 56 | @Test public void getDatabaseLabelsShouldBeOK() throws SQLException, NoSuchFieldException, IllegalAccessException { 57 | Connection connection = DriverManager.getConnection("jdbc:neo4j:" + neo4j.getBoltUrl() + "?nossl","user","password"); 58 | 59 | try (Statement statement = connection.createStatement()) { 60 | statement.execute("create (a:A {one:1, two:2})"); 61 | statement.execute("create (b:B {three:3, four:4})"); 62 | } 63 | 64 | ResultSet labels = connection.getMetaData().getTables(null, null, null, null); 65 | 66 | assertNotNull(labels); 67 | assertTrue(labels.next()); 68 | assertEquals("A", labels.getString("TABLE_NAME")); 69 | assertTrue(labels.next()); 70 | assertEquals("B", labels.getString("TABLE_NAME")); 71 | assertTrue(!labels.next()); 72 | 73 | connection.close(); 74 | } 75 | 76 | @Test public void classShouldWorkIfTransactionIsAlreadyOpened() throws SQLException { 77 | Connection connection = DriverManager.getConnection("jdbc:neo4j:" + neo4j.getBoltUrl() + "?nossl","user","password"); 78 | connection.setAutoCommit(false); 79 | connection.getMetaData(); 80 | 81 | connection.close(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/test/java/org/neo4j/jdbc/Neo4jParameterMetaDataTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 09/03/16 19 | */ 20 | package org.neo4j.jdbc; 21 | 22 | import org.junit.Rule; 23 | import org.junit.Test; 24 | import org.junit.rules.ExpectedException; 25 | import org.mockito.Mockito; 26 | 27 | import java.sql.SQLException; 28 | 29 | import static org.junit.Assert.*; 30 | import static org.mockito.Mockito.mock; 31 | 32 | /** 33 | * @author AgileLARUS 34 | * @since 3.0.0 35 | */ 36 | public class Neo4jParameterMetaDataTest { 37 | 38 | @Rule public ExpectedException expectedEx = ExpectedException.none(); 39 | 40 | /*------------------------------*/ 41 | /* isWrapperFor */ 42 | /*------------------------------*/ 43 | 44 | @Test public void isWrapperForShouldReturnTrue() throws SQLException { 45 | Neo4jParameterMetaData parameterMetaData = mock(Neo4jParameterMetaData.class, Mockito.CALLS_REAL_METHODS); 46 | 47 | assertTrue(parameterMetaData.isWrapperFor(Neo4jParameterMetaData.class)); 48 | assertTrue(parameterMetaData.isWrapperFor(java.sql.ParameterMetaData.class)); 49 | assertTrue(parameterMetaData.isWrapperFor(java.sql.Wrapper.class)); 50 | } 51 | 52 | @Test public void isWrapperForShouldReturnFalse() throws SQLException { 53 | Neo4jParameterMetaData parameterMetaData = mock(Neo4jParameterMetaData.class, Mockito.CALLS_REAL_METHODS); 54 | 55 | assertFalse(parameterMetaData.isWrapperFor(Neo4jResultSet.class)); 56 | assertFalse(parameterMetaData.isWrapperFor(java.sql.Driver.class)); 57 | assertFalse(parameterMetaData.isWrapperFor(Neo4jResultSet.class)); 58 | assertFalse(parameterMetaData.isWrapperFor(java.sql.ResultSet.class)); 59 | } 60 | 61 | /*------------------------------*/ 62 | /* unwrap */ 63 | /*------------------------------*/ 64 | 65 | @Test public void unwrapShouldReturnCorrectClass() throws SQLException { 66 | Neo4jParameterMetaData parameterMetaData = mock(Neo4jParameterMetaData.class, Mockito.CALLS_REAL_METHODS); 67 | 68 | assertNotNull(parameterMetaData.unwrap(Neo4jParameterMetaData.class)); 69 | assertNotNull(parameterMetaData.unwrap(java.sql.ParameterMetaData.class)); 70 | assertNotNull(parameterMetaData.unwrap(java.sql.Wrapper.class)); 71 | } 72 | 73 | @Test public void unwrapShouldThrowException() throws SQLException { 74 | expectedEx.expect(SQLException.class); 75 | 76 | Neo4jParameterMetaData parameterMetaData = mock(Neo4jParameterMetaData.class, Mockito.CALLS_REAL_METHODS); 77 | 78 | parameterMetaData.unwrap(Neo4jResultSet.class); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/test/java/org/neo4j/jdbc/Neo4jConnectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 09/03/16 19 | */ 20 | package org.neo4j.jdbc; 21 | 22 | import org.junit.Rule; 23 | import org.junit.Test; 24 | import org.junit.rules.ExpectedException; 25 | import org.mockito.Mockito; 26 | import org.neo4j.jdbc.impl.Neo4jConnectionImpl; 27 | 28 | import java.sql.SQLException; 29 | 30 | import static org.junit.Assert.*; 31 | import static org.mockito.Mockito.mock; 32 | 33 | /** 34 | * @author AgileLARUS 35 | * @since 3.0.0 36 | */ 37 | public class Neo4jConnectionTest { 38 | 39 | @Rule public ExpectedException expectedEx = ExpectedException.none(); 40 | 41 | /*------------------------------*/ 42 | /* isWrapperFor */ 43 | /*------------------------------*/ 44 | 45 | @Test public void isWrapperForShouldReturnTrue() throws SQLException { 46 | Neo4jConnection connection = mock(Neo4jConnectionImpl.class, Mockito.CALLS_REAL_METHODS); 47 | 48 | assertTrue(connection.isWrapperFor(Neo4jConnection.class)); 49 | assertTrue(connection.isWrapperFor(java.sql.Connection.class)); 50 | assertTrue(connection.isWrapperFor(java.sql.Wrapper.class)); 51 | assertTrue(connection.isWrapperFor(java.lang.AutoCloseable.class)); 52 | } 53 | 54 | @Test public void isWrapperForShouldReturnFalse() throws SQLException { 55 | Neo4jConnection connection = mock(Neo4jConnectionImpl.class, Mockito.CALLS_REAL_METHODS); 56 | 57 | assertFalse(connection.isWrapperFor(Neo4jStatement.class)); 58 | assertFalse(connection.isWrapperFor(java.sql.Driver.class)); 59 | assertFalse(connection.isWrapperFor(Neo4jResultSet.class)); 60 | assertFalse(connection.isWrapperFor(java.sql.ResultSet.class)); 61 | } 62 | 63 | /*------------------------------*/ 64 | /* unwrap */ 65 | /*------------------------------*/ 66 | 67 | @Test public void unwrapShouldReturnCorrectClass() throws SQLException { 68 | Neo4jConnection connection = mock(Neo4jConnectionImpl.class, Mockito.CALLS_REAL_METHODS); 69 | 70 | assertNotNull(connection.unwrap(Neo4jConnection.class)); 71 | assertNotNull(connection.unwrap(java.sql.Connection.class)); 72 | assertNotNull(connection.unwrap(java.sql.Wrapper.class)); 73 | assertNotNull(connection.unwrap(java.lang.AutoCloseable.class)); 74 | } 75 | 76 | @Test public void unwrapShouldThrowException() throws SQLException { 77 | expectedEx.expect(SQLException.class); 78 | 79 | Neo4jConnection connection = mock(Neo4jConnectionImpl.class, Mockito.CALLS_REAL_METHODS); 80 | 81 | connection.unwrap(Neo4jStatement.class); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/src/test/java/org/neo4j/jdbc/http/HttpNeo4jResultSetMetaDataIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 4 | *

5 | * This file is part of the "LARUS Integration Framework for Neo4j". 6 | *

7 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | *

11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | *

13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *

19 | * Created on 25/4/2016 20 | * 21 | */ 22 | 23 | package org.neo4j.jdbc.http; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | 27 | import java.sql.Array; 28 | import java.sql.Connection; 29 | import java.sql.DriverManager; 30 | import java.sql.ResultSet; 31 | import java.sql.ResultSetMetaData; 32 | import java.sql.SQLException; 33 | import java.sql.Statement; 34 | import java.sql.Types; 35 | import java.util.Map; 36 | 37 | import org.junit.Test; 38 | import org.neo4j.jdbc.http.test.Neo4jHttpITUtil; 39 | 40 | /** 41 | * @author AgileLARUS 42 | * @since 3.0.2 43 | */ 44 | public class HttpNeo4jResultSetMetaDataIT extends Neo4jHttpITUtil { 45 | 46 | @Test 47 | public void getColumnClassNameShouldSucceed() throws SQLException { 48 | Connection con = DriverManager.getConnection(getJDBCUrl()); 49 | 50 | try (Statement stmt = con.createStatement()) { 51 | stmt.execute("CREATE (n:User {name:\"test\", surname:\"testAgain\"})"); 52 | } 53 | 54 | try (Statement stmt = con.createStatement()) { 55 | ResultSet rs = stmt.executeQuery("MATCH (n:User) return 'a',1,1.0,[1,2,3],{a:1},null,n,n.name"); 56 | 57 | while (rs.next()) { 58 | ResultSetMetaData rsm = rs.getMetaData(); 59 | 60 | assertEquals(Types.VARCHAR, rsm.getColumnType(1)); 61 | assertEquals(String.class.getName(), rsm.getColumnClassName(1)); 62 | 63 | assertEquals(Types.INTEGER, rsm.getColumnType(2)); 64 | assertEquals(Long.class.getName(), rsm.getColumnClassName(2)); 65 | 66 | assertEquals(Types.FLOAT, rsm.getColumnType(3)); 67 | assertEquals(Double.class.getName(), rsm.getColumnClassName(3)); 68 | 69 | assertEquals(Types.ARRAY, rsm.getColumnType(4)); 70 | assertEquals(Array.class.getName(), rsm.getColumnClassName(4)); 71 | 72 | assertEquals(Types.JAVA_OBJECT, rsm.getColumnType(5)); 73 | assertEquals(Map.class.getName(), rsm.getColumnClassName(5)); 74 | 75 | assertEquals(Types.NULL, rsm.getColumnType(6)); 76 | assertEquals(null, rsm.getColumnClassName(6)); 77 | 78 | assertEquals(Types.JAVA_OBJECT, rsm.getColumnType(7)); 79 | assertEquals(Map.class.getName(), rsm.getColumnClassName(7)); 80 | 81 | assertEquals(Types.VARCHAR, rsm.getColumnType(8)); 82 | assertEquals(String.class.getName(), rsm.getColumnClassName(8)); 83 | } 84 | } 85 | finally { 86 | try (Statement stmt = con.createStatement()) { 87 | stmt.execute("MATCH (n:User), (s:Session) DETACH DELETE n, s"); 88 | } 89 | 90 | con.close(); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /neo4j-jdbc-driver/src/main/java/org/neo4j/jdbc/Driver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 4 | *

5 | * This file is part of the "LARUS Integration Framework for Neo4j". 6 | *

7 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | *

11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | *

13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *

19 | * Created on 19/4/2016 20 | * 21 | */ 22 | 23 | package org.neo4j.jdbc; 24 | 25 | import org.neo4j.jdbc.bolt.BoltDriver; 26 | import org.neo4j.jdbc.http.HttpDriver; 27 | 28 | import java.lang.reflect.Constructor; 29 | import java.sql.Connection; 30 | import java.sql.SQLException; 31 | import java.util.HashMap; 32 | import java.util.Map; 33 | import java.util.Objects; 34 | import java.util.Properties; 35 | 36 | public class Driver extends Neo4jDriver { 37 | 38 | /** 39 | * Prefix/class hashMap of all available Driver. 40 | */ 41 | @SuppressWarnings({ "rawtypes", "serial" }) 42 | private static final Map DRIVERS = new HashMap<>(); 43 | 44 | static { 45 | DRIVERS.put(BoltDriver.JDBC_BOLT_PREFIX, BoltDriver.class); 46 | DRIVERS.put(HttpDriver.JDBC_HTTP_PREFIX, HttpDriver.class); 47 | } 48 | 49 | /** 50 | * Default constructor. 51 | * @throws SQLException sqlexception 52 | */ 53 | public Driver() throws SQLException { 54 | super(null); 55 | } 56 | 57 | @Override public Connection connect(String url, Properties info) throws SQLException { 58 | Connection connection = null; 59 | if(!Objects.isNull(getDriver(url))) { 60 | connection = getDriver(url).connect(url, info); 61 | } 62 | return connection; 63 | } 64 | 65 | /** 66 | * Retrieve the corresponding driver from the JDBC url. 67 | * @param url The JDBC url 68 | * @return The driver 69 | */ 70 | @SuppressWarnings({ "rawtypes", "unchecked" }) 71 | private Neo4jDriver getDriver(String url) throws SQLException { 72 | Neo4jDriver driver = null; 73 | 74 | if (url == null) { 75 | throw new SQLException("null is not a valid url"); 76 | } 77 | 78 | // We search the driver prefix from the url 79 | if (url.startsWith(JDBC_PREFIX)) { 80 | String[] pieces = url.split(":"); 81 | if (pieces.length > 3) { 82 | String prefix = pieces[2]; 83 | 84 | // We look into driver map is it known 85 | driver = getDriverForPrefix(prefix); 86 | } 87 | } 88 | return driver; 89 | } 90 | 91 | private Neo4jDriver getDriverForPrefix(String prefix) throws SQLException { 92 | Neo4jDriver driver = null; 93 | try { 94 | for (Map.Entry entry : DRIVERS.entrySet()) { 95 | if (prefix.matches(entry.getKey())) { 96 | Constructor constructor = entry.getValue().getDeclaredConstructor(); 97 | driver = (Neo4jDriver) constructor.newInstance(); 98 | } 99 | } 100 | } catch (Exception e) { 101 | throw new SQLException(e); 102 | } 103 | return driver; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/test/java/org/neo4j/jdbc/Neo4jCallableStatementTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 09/03/16 19 | */ 20 | package org.neo4j.jdbc; 21 | 22 | import org.junit.Rule; 23 | import org.junit.Test; 24 | import org.junit.rules.ExpectedException; 25 | import org.mockito.Mockito; 26 | 27 | import java.sql.SQLException; 28 | 29 | import static org.junit.Assert.*; 30 | import static org.mockito.Mockito.mock; 31 | 32 | /** 33 | * @author AgileLARUS 34 | * @since 3.0.0 35 | */ 36 | public class Neo4jCallableStatementTest { 37 | 38 | @Rule public ExpectedException expectedEx = ExpectedException.none(); 39 | 40 | /*------------------------------*/ 41 | /* isWrapperFor */ 42 | /*------------------------------*/ 43 | 44 | @Test public void isWrapperForShouldReturnTrue() throws SQLException { 45 | Neo4jCallableStatement callableStatement = mock(Neo4jCallableStatement.class, Mockito.CALLS_REAL_METHODS); 46 | 47 | assertTrue(callableStatement.isWrapperFor(Neo4jCallableStatement.class)); 48 | assertTrue(callableStatement.isWrapperFor(java.sql.Statement.class)); 49 | assertTrue(callableStatement.isWrapperFor(java.sql.CallableStatement.class)); 50 | assertTrue(callableStatement.isWrapperFor(java.sql.PreparedStatement.class)); 51 | assertTrue(callableStatement.isWrapperFor(java.sql.Wrapper.class)); 52 | } 53 | 54 | @Test public void isWrapperForShouldReturnFalse() throws SQLException { 55 | Neo4jCallableStatement callableStatement = mock(Neo4jCallableStatement.class, Mockito.CALLS_REAL_METHODS); 56 | 57 | assertFalse(callableStatement.isWrapperFor(Neo4jResultSet.class)); 58 | assertFalse(callableStatement.isWrapperFor(java.sql.Driver.class)); 59 | assertFalse(callableStatement.isWrapperFor(Neo4jResultSet.class)); 60 | assertFalse(callableStatement.isWrapperFor(java.sql.ResultSet.class)); 61 | } 62 | 63 | /*------------------------------*/ 64 | /* unwrap */ 65 | /*------------------------------*/ 66 | 67 | @Test public void unwrapShouldReturnCorrectClass() throws SQLException { 68 | Neo4jCallableStatement callableStatement = mock(Neo4jCallableStatement.class, Mockito.CALLS_REAL_METHODS); 69 | 70 | assertNotNull(callableStatement.unwrap(Neo4jCallableStatement.class)); 71 | assertNotNull(callableStatement.unwrap(java.sql.Statement.class)); 72 | assertNotNull(callableStatement.unwrap(java.sql.CallableStatement.class)); 73 | assertNotNull(callableStatement.unwrap(java.sql.PreparedStatement.class)); 74 | assertNotNull(callableStatement.unwrap(java.sql.Wrapper.class)); 75 | } 76 | 77 | @Test public void unwrapShouldThrowException() throws SQLException { 78 | expectedEx.expect(SQLException.class); 79 | 80 | Neo4jCallableStatement callableStatement = mock(Neo4jCallableStatement.class, Mockito.CALLS_REAL_METHODS); 81 | 82 | callableStatement.unwrap(Neo4jResultSet.class); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/src/main/java/org/neo4j/jdbc/http/HttpNeo4jResultSetMetaData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 15/4/2016 19 | */ 20 | package org.neo4j.jdbc.http; 21 | 22 | import org.neo4j.jdbc.Neo4jResultSetMetaData; 23 | import org.neo4j.jdbc.http.driver.Neo4jResult; 24 | 25 | import java.sql.Array; 26 | import java.sql.SQLException; 27 | import java.sql.Types; 28 | import java.util.HashMap; 29 | import java.util.List; 30 | import java.util.Map; 31 | 32 | public class HttpNeo4jResultSetMetaData extends Neo4jResultSetMetaData { 33 | 34 | private Neo4jResult result; 35 | 36 | private static final Map CLASSES_ASSOCIATIONS = new HashMap<>(); 37 | private static final Map TYPES_ASSOCIATIONS = new HashMap<>(); 38 | 39 | static { 40 | CLASSES_ASSOCIATIONS.put(String.class, String.class); 41 | CLASSES_ASSOCIATIONS.put(Integer.class, Long.class); 42 | CLASSES_ASSOCIATIONS.put(Long.class, Long.class); 43 | CLASSES_ASSOCIATIONS.put(Boolean.class, Boolean.class); 44 | CLASSES_ASSOCIATIONS.put(Float.class, Double.class); 45 | CLASSES_ASSOCIATIONS.put(Double.class, Double.class); 46 | CLASSES_ASSOCIATIONS.put(Map.class, Map.class); 47 | CLASSES_ASSOCIATIONS.put(List.class, Array.class); 48 | 49 | TYPES_ASSOCIATIONS.put(String.class, Types.VARCHAR); 50 | TYPES_ASSOCIATIONS.put(Integer.class, Types.INTEGER); 51 | TYPES_ASSOCIATIONS.put(Long.class, Types.INTEGER); 52 | TYPES_ASSOCIATIONS.put(Boolean.class, Types.BOOLEAN); 53 | TYPES_ASSOCIATIONS.put(Float.class, Types.FLOAT); 54 | TYPES_ASSOCIATIONS.put(Double.class, Types.FLOAT); 55 | TYPES_ASSOCIATIONS.put(Map.class, Types.JAVA_OBJECT); 56 | TYPES_ASSOCIATIONS.put(List.class, Types.ARRAY); 57 | } 58 | 59 | /** 60 | * Default constructor. 61 | */ 62 | HttpNeo4jResultSetMetaData(Neo4jResult result) { 63 | super(result.getColumns()); 64 | this.result = result; 65 | } 66 | 67 | @SuppressWarnings("unchecked") @Override public int getColumnType(int column) throws SQLException { 68 | final Object object = ((List) this.result.getRows().get(0).get("row")).get(column - 1); 69 | 70 | if (object == null) { 71 | return Types.NULL; 72 | } 73 | for (Map.Entry entry : TYPES_ASSOCIATIONS.entrySet()) { 74 | if (entry.getKey().isInstance(object)) { 75 | return entry.getValue(); 76 | } 77 | } 78 | 79 | return Types.JAVA_OBJECT; 80 | } 81 | 82 | @SuppressWarnings("unchecked") @Override public String getColumnClassName(int column) throws SQLException { 83 | final Object object = ((List) this.result.getRows().get(0).get("row")).get(column - 1); 84 | 85 | if (object == null) { 86 | return null; 87 | } 88 | for (Map.Entry entry : CLASSES_ASSOCIATIONS.entrySet()) { 89 | if (entry.getKey().isInstance(object)) { 90 | return entry.getValue().getName(); 91 | } 92 | } 93 | return Object.class.getName(); 94 | } 95 | } 96 | 97 | -------------------------------------------------------------------------------- /docs/pentaho.adoc: -------------------------------------------------------------------------------- 1 | === Pentaho 2 | 3 | ==== Step 1: Create database connections: 4 | 5 | Right click on *Database connections* and click on *New* 6 | 7 | image::https://cloud.githubusercontent.com/assets/15228280/16164582/463fc1f8-34df-11e6-9dac-f62def4311e2.png[] 8 | 9 | Insert the connection parameters for source database the press *Test* button to check the connection: 10 | 11 | image::https://cloud.githubusercontent.com/assets/15228280/16164800/74c1b7d8-34e0-11e6-8478-7952686766c4.png[] 12 | image::https://cloud.githubusercontent.com/assets/15228280/16164811/846c3d84-34e0-11e6-947b-e5e617800c3b.png[] 13 | 14 | As before, select a new *Database connections* and insert neo4j connection parameters, set: 15 | 16 | - *Connection Type*: *Generic database* 17 | - *Custom Connection URL*: "jdbc:neo4j:bolt://localhost:7687" 18 | - *Custom Driver Class Name*: "org.neo4j.jdbc.Driver" 19 | - Login and password: 20 | 21 | image::https://cloud.githubusercontent.com/assets/15228280/16164984/8a6df4b0-34e1-11e6-84a7-3ea9cd024529.png[] 22 | 23 | image::https://cloud.githubusercontent.com/assets/15228280/16226524/2263fbc6-37ac-11e6-9a8d-bdf8c78d96bf.png[] 24 | 25 | Then press to Test button to check the connection: 26 | 27 | image::https://cloud.githubusercontent.com/assets/15228280/16226531/2989eaa0-37ac-11e6-8ca7-cd5c50786a5d.png[] 28 | 29 | ==== Step 2: Create Steps and Hops: 30 | 31 | - From Design select input and click on table input top insert the source table: 32 | 33 | image::https://cloud.githubusercontent.com/assets/15228280/16165147/95f20bfe-34e2-11e6-9ce0-c5999027c07d.png[] 34 | image::https://cloud.githubusercontent.com/assets/15228280/16165152/9934f0a6-34e2-11e6-97b4-c1c49c276ccf.png[] 35 | 36 | - From Scripting click on Execute SQL script: 37 | 38 | image::https://cloud.githubusercontent.com/assets/15228280/16165229/0fd68062-34e3-11e6-8272-562f06b4b93f.png[] 39 | image::https://cloud.githubusercontent.com/assets/15228280/16165242/1e7ad190-34e3-11e6-8fb7-beda60ee391b.png[] 40 | 41 | - Double click on table input. Select the source database Connection and write query to extract data the press *Preview* button to check query: 42 | 43 | image::https://cloud.githubusercontent.com/assets/15228280/16165314/73469a7e-34e3-11e6-8f77-7c8db5bbcec9.png[] 44 | image::https://cloud.githubusercontent.com/assets/15228280/16165326/7dee0dae-34e3-11e6-8e89-457a8c5aa36c.png[] 45 | 46 | - Double click on *Hops*, select as *From step* the table input and as *to step* the Execute SQL Script: 47 | 48 | image::https://cloud.githubusercontent.com/assets/15228280/16165553/d82771f6-34e4-11e6-85c8-07a65fe14e6f.png[] 49 | image::https://cloud.githubusercontent.com/assets/15228280/16165559/dd56b24a-34e4-11e6-88da-d0ab1fd8e008.png[] 50 | 51 | - Now your Hop is complete! 52 | 53 | image::https://cloud.githubusercontent.com/assets/15228280/16165607/247b2e12-34e5-11e6-8a31-2e4329c04f1a.png[] 54 | 55 | - Double click on *Execute SQL script*. Click on *Get Fields* to retrive the column from source database. Write the cypher to create nodes and relationship: 56 | 57 | image::https://cloud.githubusercontent.com/assets/15228280/16226545/32ef7a56-37ac-11e6-9e58-433ed6444b0a.png[] 58 | 59 | ==== Step 3: Run the job 60 | 61 | - Click on run this transformation or job and wait until finished: 62 | 63 | image::https://cloud.githubusercontent.com/assets/15228280/16165728/eefac170-34e5-11e6-83d3-7f4faa4c7745.png[] 64 | image::https://cloud.githubusercontent.com/assets/15228280/16165730/f1156e06-34e5-11e6-99b1-5d2d37b9737e.png[] 65 | image::https://cloud.githubusercontent.com/assets/15228280/16165732/f39b13d8-34e5-11e6-8d16-869345f82dd5.png[] 66 | 67 | - If all ok, you should have like this: 68 | 69 | image::https://cloud.githubusercontent.com/assets/15228280/16165816/813e5e2a-34e6-11e6-81cf-5492c664c041.png[] 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/test/java/org/neo4j/jdbc/Neo4jResultSetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 09/03/16 19 | */ 20 | package org.neo4j.jdbc; 21 | 22 | import org.junit.Rule; 23 | import org.junit.Test; 24 | import org.junit.rules.ExpectedException; 25 | import org.mockito.Mockito; 26 | 27 | import java.sql.SQLException; 28 | 29 | import static org.junit.Assert.*; 30 | import static org.mockito.Mockito.mock; 31 | 32 | /** 33 | * @author AgileLARUS 34 | * @since 3.0.0 35 | */ 36 | public class Neo4jResultSetTest { 37 | 38 | @Rule public ExpectedException expectedEx = ExpectedException.none(); 39 | 40 | /*------------------------------*/ 41 | /* isWrapperFor */ 42 | /*------------------------------*/ 43 | 44 | @Test public void isWrapperForShouldReturnTrue() throws SQLException { 45 | Neo4jResultSet resultSet = mock(Neo4jResultSet.class, Mockito.CALLS_REAL_METHODS); 46 | 47 | assertTrue(resultSet.isWrapperFor(Neo4jResultSet.class)); 48 | assertTrue(resultSet.isWrapperFor(java.sql.ResultSet.class)); 49 | assertTrue(resultSet.isWrapperFor(java.sql.Wrapper.class)); 50 | assertTrue(resultSet.isWrapperFor(java.lang.AutoCloseable.class)); 51 | } 52 | 53 | @Test public void isWrapperForShouldReturnFalse() throws SQLException { 54 | Neo4jResultSet resultSet = mock(Neo4jResultSet.class, Mockito.CALLS_REAL_METHODS); 55 | 56 | assertFalse(resultSet.isWrapperFor(Neo4jStatement.class)); 57 | assertFalse(resultSet.isWrapperFor(java.sql.Driver.class)); 58 | assertFalse(resultSet.isWrapperFor(java.sql.Statement.class)); 59 | assertFalse(resultSet.isWrapperFor(java.sql.ResultSetMetaData.class)); 60 | } 61 | 62 | /*------------------------------*/ 63 | /* unwrap */ 64 | /*------------------------------*/ 65 | 66 | @Test public void unwrapShouldReturnCorrectClass() throws SQLException { 67 | Neo4jResultSet resultSet = mock(Neo4jResultSet.class, Mockito.CALLS_REAL_METHODS); 68 | 69 | assertNotNull(resultSet.unwrap(Neo4jResultSet.class)); 70 | assertNotNull(resultSet.unwrap(java.sql.ResultSet.class)); 71 | assertNotNull(resultSet.unwrap(java.sql.Wrapper.class)); 72 | assertNotNull(resultSet.unwrap(java.lang.AutoCloseable.class)); 73 | } 74 | 75 | @Test public void unwrapShouldThrowException() throws SQLException { 76 | expectedEx.expect(SQLException.class); 77 | 78 | Neo4jResultSet resultSet = mock(Neo4jResultSet.class, Mockito.CALLS_REAL_METHODS); 79 | 80 | resultSet.unwrap(Neo4jStatement.class); 81 | } 82 | 83 | /*-----------------------------*/ 84 | /* warning */ 85 | /*-----------------------------*/ 86 | @Test public void getWarningsShouldReturnNull() throws SQLException { 87 | Neo4jResultSet resultSet = mock(Neo4jResultSet.class, Mockito.CALLS_REAL_METHODS); 88 | assertNull(resultSet.getWarnings()); 89 | } 90 | 91 | @Test public void clearWarningsShouldNotThrowException() throws SQLException { 92 | Neo4jResultSet resultSet = mock(Neo4jResultSet.class, Mockito.CALLS_REAL_METHODS); 93 | resultSet.clearWarnings(); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /neo4j-jdbc-bolt/README.adoc: -------------------------------------------------------------------------------- 1 | = Neo4j JDBC Driver - Bolt 2 | 3 | This module implements the neo4j-jdbc driver with the BOLT protocol. 4 | 5 | This module is a JDBC-way wrapper of the https://github.com/neo4j/neo4j-java-driver[Neo4j-java] driver currently implementing an alpha 6 | version of the BOLT protocol for Java. 7 | 8 | == Special wrapping for neo4j nodes relationships and paths. == 9 | 10 | Even if you can access each value in a `ResultSet` with multiple type-specific method, you might want to get a whole _node_, _relationship_ or _path_. 11 | 12 | This *can't* be done by default with JDBC standard methods, to allow this usage we re-invented the use of `getObject(*)` method. 13 | 14 | If the object you are trying to get is an `*instanceof* InternalNode` (thus being a neo4j Node) it will be returned wrapped in a `Map`. This map will contain all the object's properties where their names (`String`) are the keys. It will also contains two default values mapped as "`_id`", representing neo4j internal identity ID and "`_labels`", a `Collection` of all the labels of that node. 15 | 16 | If the object is instead an `*instanceof* InternalRelationship` (thus being a neo4j Relationship) it will be also returned as a `Map`. This map will contain all the object's properties and the four default: "`_id`" the _internal_ neo4j ID, "`_type`" that is the _type_ of the relationship, "`_startId`" that is the _internal_ neo4j Node ID where the relation starts from, "`_endId`" that is the _internal_ neo4j Node ID where the relation ends. 17 | 18 | If the object is instead an `*instanceof* InternalPath` (thus being a neo4j Path) it will be also returned as an `ArrayList>`. this list will contain an alternation of Node and Relationship converted following the below two lines' specifications. 19 | 20 | IMPORTANT: You can't get an `InternalNode` or `InternalRelationship` directly `InternalPath` 21 | 22 | When the object is not recognized as one of the two specified it is treated as a standard object and returned _directly_. 23 | 24 | == Bolt module specific URL parameters == 25 | 26 | When using the jdbc Bolt module you will be able to specify dedicated parameters, here is a list of them: 27 | 28 | ==== Trust Strategy ==== 29 | 30 | When creating using the driver with a DriverManager with: 31 | ---- 32 | DriverManager.getConnection(NEO4J_JDBC_BOLT_URL, PROPERTIES); 33 | ---- 34 | 35 | you can use the property `trust.strategy`, a string value of your choice among the `Config.TrustStrategy.Strategy` enum values. 36 | When a file is required you *must* add the `trusted.certificate.file` property that *must* be a valid `java.util.File` object. 37 | 38 | ==== Flatten ==== 39 | When a ResultSet is flattened it explodes the returned columns (ONLY if they are ALL nodes and relationships) adding virtual columns with id, labels, type and entity specific fields. 40 | 41 | You can enable such behaviour just by adding ?flatten=x to your url connection where x possible values are: 42 | 43 | * -1: the entire resultSet is fetched (may slow down the performances with big resultSets) for retrieving nodes and relationships structure (useful if you're retrieving results with lots of different properties) 44 | 45 | * N > 0: the specified number of rows are fetched for retrieving specific properties 46 | 47 | Example: 48 | Given a :User node connected to :Attributes nodes like (:Attribute {age:20})< -[:AGED]-(:User {username:"username"})-[FULL_NAME]- >(:Attribute {full_name:"Name Surname"}) 49 | 50 | with the query: 51 | 52 | MATCH (u:User)--(a:Attribute) RETURN u, a; 53 | 54 | you will have only the columns (u, a) with flattening disabled; 55 | 56 | with flatten=1 you will have u, u.id, u.labels, u.username, a, a.id, a.type, a.age 57 | 58 | with flatten=-1 you will have u, u.id, u.labels, u.username, a, a.id, a.type, a.age, a.full_name 59 | -------------------------------------------------------------------------------- /docs/birt.adoc: -------------------------------------------------------------------------------- 1 | === Eclipse BIRT 2 | 3 | . Start a new "Report project" under "Report design" perspective 4 | + 5 | image::https://cloud.githubusercontent.com/assets/13695124/16531592/82aa4d36-3fcd-11e6-8865-17d044d34743.png[] 6 | 7 | . Select the project's name 8 | + 9 | image::https://cloud.githubusercontent.com/assets/13695124/16531611/9ffe01d4-3fcd-11e6-8e45-c9f3841a8436.png[] 10 | 11 | . Create a new report (File->New->Report) and give it a name 12 | + 13 | image::https://cloud.githubusercontent.com/assets/13695124/16531682/e9dce37e-3fcd-11e6-84c4-83c3e7547b46.png[] 14 | 15 | . Choose your template 16 | + 17 | image::https://cloud.githubusercontent.com/assets/13695124/16531712/04240596-3fce-11e6-9e97-b8e611e48a44.png[] 18 | 19 | . Create a new Datasource by right clicking "Data sources" -> New Data Source and choose the second option 20 | + 21 | image::https://cloud.githubusercontent.com/assets/13695124/16531815/79956734-3fce-11e6-8141-5777f15399e9.png[] 22 | 23 | . Create a new Connection profile store (click new on both windows) 24 | + 25 | image::https://cloud.githubusercontent.com/assets/13695124/16531873/cf2ad59e-3fce-11e6-911c-999f8b6f2cd0.png[] 26 | 27 | . Choose "BIRTH JDBC Data Source" and give it a name 28 | + 29 | image::https://cloud.githubusercontent.com/assets/13695124/16531895/f0ec6904-3fce-11e6-88c8-5be6e62ed8bd.png[] 30 | 31 | . Load your jdbc jar by clicking "Manage Drivers" and select "Add" 32 | + 33 | image::https://cloud.githubusercontent.com/assets/13695124/16531929/2d32090a-3fcf-11e6-893d-ed4ccef968c4.png[] 34 | 35 | . Choose your dirver location and press OK 36 | + 37 | image::https://cloud.githubusercontent.com/assets/13695124/16531945/3fce59f6-3fcf-11e6-9fe7-f7ecca4716db.png[] 38 | 39 | . Fill the driver connection parameters 40 | + 41 | image::https://cloud.githubusercontent.com/assets/13695124/16531965/59d8e352-3fcf-11e6-8458-5faf8fea540f.png[] 42 | 43 | . Click "Next" and "Finish" and choose the newly created connection profile store 44 | + 45 | image::https://cloud.githubusercontent.com/assets/13695124/16532005/85f3630e-3fcf-11e6-9521-902bc61e5d8b.png[] 46 | 47 | . Click "Next" and "Finish" and the Data Source should be created 48 | + 49 | image::https://cloud.githubusercontent.com/assets/13695124/16532102/06b6a280-3fd0-11e6-88e7-0d6f8bc79928.png[] 50 | 51 | . Create a new Dataset (right click Data Sets -> New Data Set) and choose Next 52 | + 53 | image::https://cloud.githubusercontent.com/assets/13695124/16532142/4521c4d2-3fd0-11e6-8fae-bb3e0aee3e4f.png[] 54 | 55 | . Type the query you want to create your Dataset with and click Finish 56 | + 57 | image::https://cloud.githubusercontent.com/assets/13695124/16532158/698c4a36-3fd0-11e6-8ef1-2126cad983a1.png[] 58 | 59 | . A new Window will appear showing the columns available with your query 60 | + 61 | image::https://cloud.githubusercontent.com/assets/13695124/16532173/83925a2e-3fd0-11e6-9e92-cd8276a24c41.png[] 62 | 63 | . You can also preview the results 64 | + 65 | image::https://cloud.githubusercontent.com/assets/13695124/16532199/9ffde6ec-3fd0-11e6-9d32-ecb0ab797e7e.png[] 66 | 67 | . Close this window and create a new Table element (Right click the document -> Insert -> Table) 68 | + 69 | image::https://cloud.githubusercontent.com/assets/13695124/16532646/848ca81e-3fd3-11e6-9f85-aeed3f4e0092.png[] 70 | 71 | . Choose 4 columns and click Finish 72 | + 73 | image::https://cloud.githubusercontent.com/assets/13695124/16533601/44c07b28-3fda-11e6-8273-a4b4c0d55545.png[] 74 | 75 | . Fill the table with the following data (drag and drop the datasource colums in the right position) 76 | + 77 | image::https://cloud.githubusercontent.com/assets/13695124/16533694/edf3b98a-3fda-11e6-9d80-f4026e036770.png[] 78 | 79 | . To export the report click Run -> View report -> As PDF 80 | + 81 | image::https://cloud.githubusercontent.com/assets/13695124/16533721/181e062a-3fdb-11e6-89eb-3a14c959e53b.png[] 82 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/src/main/java/org/neo4j/jdbc/http/driver/Neo4jStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 15/4/2016 19 | */ 20 | package org.neo4j.jdbc.http.driver; 21 | 22 | import com.fasterxml.jackson.core.JsonProcessingException; 23 | import com.fasterxml.jackson.databind.ObjectMapper; 24 | 25 | import java.sql.SQLException; 26 | import java.util.HashMap; 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | /** 31 | * A POJO to store a cypher query that match the cypher request endpoint. 32 | */ 33 | public class Neo4jStatement { 34 | 35 | /** 36 | * Cypher query. 37 | */ 38 | public final String statement; 39 | 40 | /** 41 | * Params of the cypher query. 42 | */ 43 | public final Map parameters; 44 | 45 | /** 46 | * Do we need to include stats with the query ? 47 | */ 48 | public final Boolean includeStats; 49 | 50 | /** 51 | * Default constructor. 52 | * 53 | * @param statement Cypher query 54 | * @param parameters List of named params for the cypher query 55 | * @param includeStats Do we need to include stats 56 | * @throws SQLException sqlexception 57 | */ 58 | public Neo4jStatement(String statement, Map parameters, Boolean includeStats) throws SQLException { 59 | if (statement != null && !"".equals(statement)) { 60 | this.statement = statement; 61 | } else { 62 | throw new SQLException("Creating a NULL query"); 63 | } 64 | if (parameters != null) { 65 | this.parameters = parameters; 66 | } else { 67 | this.parameters = new HashMap<>(); 68 | } 69 | if (includeStats != null) { 70 | this.includeStats = includeStats; 71 | } else { 72 | this.includeStats = Boolean.FALSE; 73 | } 74 | } 75 | 76 | /** 77 | * Escape method for cypher queries. 78 | * 79 | * @param query Cypher query 80 | * @return ... 81 | */ 82 | public static String escapeQuery(String query) { 83 | return query.replace('\"', '\'').replace('\n', ' '); 84 | } 85 | 86 | /** 87 | * Convert the list of query to a JSON compatible with Neo4j endpoint. 88 | * 89 | * @param queries List of cypher queries. 90 | * @param mapper mapper 91 | * @return The JSON string that correspond to the body of the API call 92 | * @throws SQLException sqlexception 93 | */ 94 | public static String toJson(List queries, ObjectMapper mapper) throws SQLException { 95 | StringBuilder sb = new StringBuilder(); 96 | try { 97 | sb.append("{\"statements\":"); 98 | sb.append(mapper.writeValueAsString(queries)); 99 | sb.append("}"); 100 | 101 | } catch (JsonProcessingException e) { 102 | throw new SQLException("Can't convert Cypher statement(s) into JSON", e); 103 | } 104 | return sb.toString(); 105 | } 106 | 107 | /** 108 | * Getter for Statements. 109 | * We escape the string for the API. 110 | * 111 | * @return the statement 112 | */ 113 | public String getStatement() { 114 | return escapeQuery(statement); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/main/java/org/neo4j/jdbc/impl/ListArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 30/03/16 19 | */ 20 | package org.neo4j.jdbc.impl; 21 | 22 | import org.neo4j.jdbc.Neo4jArray; 23 | 24 | import java.sql.SQLException; 25 | import java.sql.Types; 26 | import java.util.List; 27 | import java.util.Objects; 28 | 29 | /** 30 | * @author AgileLARUS 31 | * @since 3.0.0 32 | */ 33 | public class ListArray extends Neo4jArray { 34 | 35 | private List list; 36 | private int type; 37 | private static final String TYPE_NOT_SUPPORTED = "Type %s not supported"; 38 | 39 | 40 | public ListArray(List list, int type) { 41 | this.list = list; 42 | this.type = type; 43 | } 44 | 45 | @Override public String getBaseTypeName() throws SQLException { 46 | String name; 47 | 48 | if (!TYPES_SUPPORTED.contains(this.type)) { 49 | throw new SQLException(String.format(TYPE_NOT_SUPPORTED, this.type)); 50 | } 51 | 52 | switch (this.type) { 53 | case Types.VARCHAR: 54 | name = "VARCHAR"; 55 | break; 56 | case Types.INTEGER: 57 | name = "INTEGER"; 58 | break; 59 | case Types.BOOLEAN: 60 | name = "BOOLEAN"; 61 | break; 62 | case Types.DOUBLE: 63 | name = "DOUBLE"; 64 | break; 65 | case Types.JAVA_OBJECT: 66 | name = "JAVA_OBJECT"; 67 | break; 68 | default: 69 | throw new SQLException(String.format(TYPE_NOT_SUPPORTED, this.type)); 70 | } 71 | 72 | return name; 73 | } 74 | 75 | @Override public int getBaseType() throws SQLException { 76 | if (!TYPES_SUPPORTED.contains(this.type)) { 77 | throw new SQLException(String.format(TYPE_NOT_SUPPORTED, this.type)); 78 | } 79 | return this.type; 80 | } 81 | 82 | @Override public Object getArray() throws SQLException { 83 | if(!TYPES_SUPPORTED.contains(this.type)) { 84 | throw new SQLException(String.format(TYPE_NOT_SUPPORTED, this.type)); 85 | } 86 | Object result; 87 | 88 | try { 89 | switch (this.type) { 90 | case Types.VARCHAR: 91 | result = this.list.toArray(new String[this.list.size()]); 92 | break; 93 | case Types.INTEGER: 94 | result = this.list.toArray(new Long[this.list.size()]); 95 | break; 96 | case Types.BOOLEAN: 97 | result = this.list.toArray(new Boolean[this.list.size()]); 98 | break; 99 | case Types.DOUBLE: 100 | result = this.list.toArray(new Double[this.list.size()]); 101 | break; 102 | case Types.JAVA_OBJECT: 103 | result = this.list.toArray(new Object[this.list.size()]); 104 | break; 105 | default: 106 | throw new SQLException(String.format(TYPE_NOT_SUPPORTED, this.type)); 107 | } 108 | } catch (ArrayStoreException e){ 109 | throw new SQLException(e); 110 | } 111 | 112 | return result; 113 | } 114 | 115 | @Override public boolean equals(Object o){ 116 | return o instanceof ListArray && this.list.equals(((ListArray)o).list); 117 | } 118 | 119 | @Override public int hashCode() { 120 | return Objects.hash(list, type); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/src/test/java/org/neo4j/jdbc/http/HttpNeo4jResultSetMetaDataTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 29/11/17 19 | */ 20 | package org.neo4j.jdbc.http; 21 | 22 | import org.junit.Before; 23 | import org.junit.Test; 24 | import org.neo4j.jdbc.http.driver.Neo4jResult; 25 | 26 | import java.sql.SQLException; 27 | import java.sql.Types; 28 | import java.util.ArrayList; 29 | import java.util.HashMap; 30 | import java.util.List; 31 | import java.util.Map; 32 | 33 | import static org.junit.Assert.assertEquals; 34 | import static org.powermock.api.mockito.PowerMockito.mock; 35 | import static org.powermock.api.mockito.PowerMockito.when; 36 | 37 | /** 38 | * @author AgileLARUS 39 | * 40 | * @since 3.0.0 41 | */ 42 | public class HttpNeo4jResultSetMetaDataTest { 43 | 44 | HttpNeo4jResultSetMetaData httpResultSetMetadata; 45 | 46 | @Before 47 | public void setUp() { 48 | List rows = new ArrayList<>(); 49 | Map map = new HashMap<>(); 50 | List row = new ArrayList<>(); 51 | 52 | row.add(null); 53 | row.add("string"); 54 | row.add(1); 55 | row.add(1L); 56 | row.add(true); 57 | row.add(1.2); 58 | row.add(1.2F); 59 | row.add(new HashMap<>()); 60 | row.add(new ArrayList()); 61 | 62 | map.put("row", row); 63 | 64 | rows.add(map); 65 | 66 | Neo4jResult result = mock(Neo4jResult.class); 67 | when(result.getRows()).thenReturn(rows); 68 | this.httpResultSetMetadata = new HttpNeo4jResultSetMetaData(result); 69 | } 70 | @Test 71 | public void getColumnClassNameShouldReturnTheCorrectValue() throws SQLException { 72 | assertEquals(null, this.httpResultSetMetadata.getColumnClassName(1)); 73 | assertEquals("java.lang.String", this.httpResultSetMetadata.getColumnClassName(2)); 74 | assertEquals("java.lang.Long", this.httpResultSetMetadata.getColumnClassName(3)); 75 | assertEquals("java.lang.Long", this.httpResultSetMetadata.getColumnClassName(4)); 76 | assertEquals("java.lang.Boolean", this.httpResultSetMetadata.getColumnClassName(5)); 77 | assertEquals("java.lang.Double", this.httpResultSetMetadata.getColumnClassName(6)); 78 | assertEquals("java.lang.Double", this.httpResultSetMetadata.getColumnClassName(7)); 79 | assertEquals("java.util.Map", this.httpResultSetMetadata.getColumnClassName(8)); 80 | assertEquals("java.sql.Array", this.httpResultSetMetadata.getColumnClassName(9)); 81 | } 82 | @Test 83 | public void getColumnTypeShouldReturnTheCorrectValue() throws SQLException { 84 | assertEquals(Types.NULL, this.httpResultSetMetadata.getColumnType(1)); 85 | assertEquals(Types.VARCHAR, this.httpResultSetMetadata.getColumnType(2)); 86 | assertEquals(Types.INTEGER, this.httpResultSetMetadata.getColumnType(3)); 87 | assertEquals(Types.INTEGER, this.httpResultSetMetadata.getColumnType(4)); 88 | assertEquals(Types.BOOLEAN, this.httpResultSetMetadata.getColumnType(5)); 89 | assertEquals(Types.FLOAT, this.httpResultSetMetadata.getColumnType(6)); 90 | assertEquals(Types.FLOAT, this.httpResultSetMetadata.getColumnType(7)); 91 | assertEquals(Types.JAVA_OBJECT, this.httpResultSetMetadata.getColumnType(8)); 92 | assertEquals(Types.ARRAY, this.httpResultSetMetadata.getColumnType(9)); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/src/test/java/org/neo4j/jdbc/http/HttpNeo4jResultSetIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 4 | *

5 | * This file is part of the "LARUS Integration Framework for Neo4j". 6 | *

7 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | *

11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | *

13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *

19 | * Created on 25/4/2016 20 | * 21 | */ 22 | 23 | package org.neo4j.jdbc.http; 24 | 25 | import org.neo4j.jdbc.http.test.Neo4jHttpITUtil; 26 | import org.junit.Test; 27 | 28 | import java.sql.*; 29 | 30 | import static org.junit.Assert.assertEquals; 31 | import static org.junit.Assert.assertFalse; 32 | import static org.junit.Assert.assertTrue; 33 | 34 | /* 35 | * Created by bsimard on 25/04/16. 36 | */ 37 | public class HttpNeo4jResultSetIT extends Neo4jHttpITUtil { 38 | 39 | @Test 40 | public void paramConversionShouldWork() throws SQLException { 41 | Connection connection = DriverManager.getConnection(getJDBCUrl()); 42 | Statement statement = connection.createStatement(); 43 | ResultSet rs = statement.executeQuery("CREATE (n:TestParamConvertionShouldWork_" + secureMode.toString() + " { string:\"AZERTYUIOP\", bool:true, float:3.14, integer:7, array:[1,2,3,4]}) RETURN n, n.string, n.bool, n.float, n.integer, n.array, n.nop"); 44 | 45 | assertEquals(statement, rs.getStatement()); 46 | assertTrue(rs.next()); 47 | 48 | // Testing string 49 | assertEquals("AZERTYUIOP", rs.getString("n.string")); 50 | assertEquals("AZERTYUIOP", rs.getString(2)); 51 | 52 | // Testing bool 53 | assertEquals(true, rs.getBoolean("n.bool")); 54 | assertEquals(true, rs.getBoolean(3)); 55 | 56 | // Testing float / double 57 | assertEquals("Float conversion failed", 3.14f, rs.getFloat("n.float"),0); 58 | assertEquals("Float conversion failed", 3.14f, rs.getFloat(4),0); 59 | assertEquals("Double conversion failed", 3.14d, rs.getDouble("n.float"),0); 60 | assertEquals("Double conversion failed", 3.14d, rs.getDouble(4),0); 61 | 62 | // Testing integer, long 63 | assertEquals("Integer conversion failed",7, rs.getInt("n.integer")); 64 | assertEquals("Integer conversion failed", 7, rs.getInt(5)); 65 | assertEquals("Long conversion failed", Long.valueOf("7").longValue(), rs.getLong("n.integer")); 66 | assertEquals("Long conversion failed", Long.valueOf("7").longValue(), rs.getLong(5)); 67 | assertEquals("Short conversion failed", Short.valueOf("7").shortValue(), rs.getShort("n.integer")); 68 | assertEquals("Short conversion failed", Short.valueOf("7").shortValue(), rs.getShort(5)); 69 | 70 | // Testing array 71 | //assertEquals(7, rs.getArray("n.array")); 72 | //assertEquals(7, rs.getInt(6)); 73 | 74 | // Testing object 75 | 76 | // Testing null 77 | assertEquals("Null for string", null, rs.getString("n.nop")); 78 | assertTrue(rs.wasNull()); 79 | assertEquals("Null for boolean", false, rs.getBoolean("n.nop")); 80 | assertTrue(rs.wasNull()); 81 | assertEquals("Null for float", 0f, rs.getFloat("n.nop"),0); 82 | assertTrue(rs.wasNull()); 83 | assertEquals("Null for double", 0d, rs.getDouble("n.nop"),0); 84 | assertTrue(rs.wasNull()); 85 | assertEquals("Null for long", 0, rs.getLong("n.nop")); 86 | assertTrue(rs.wasNull()); 87 | assertEquals("Null for integer", 0, rs.getInt("n.nop")); 88 | assertTrue(rs.wasNull()); 89 | assertEquals("Null for short", 0, rs.getShort("n.nop")); 90 | assertTrue(rs.wasNull()); 91 | 92 | assertFalse(rs.next()); 93 | connection.close(); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/test/java/org/neo4j/jdbc/Neo4jPreparedStatementTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 09/03/16 19 | */ 20 | package org.neo4j.jdbc; 21 | 22 | import org.junit.Rule; 23 | import org.junit.Test; 24 | import org.junit.rules.ExpectedException; 25 | import org.mockito.Mockito; 26 | 27 | import java.sql.SQLException; 28 | 29 | import static org.junit.Assert.*; 30 | import static org.mockito.Mockito.mock; 31 | 32 | /** 33 | * @author AgileLARUS 34 | * @since 3.0.0 35 | */ 36 | public class Neo4jPreparedStatementTest { 37 | 38 | @Rule public ExpectedException expectedEx = ExpectedException.none(); 39 | 40 | /*------------------------------*/ 41 | /* isWrapperFor */ 42 | /*------------------------------*/ 43 | 44 | @Test public void isWrapperForShouldReturnTrue() throws SQLException { 45 | Neo4jPreparedStatement preparedStatement = mock(Neo4jPreparedStatement.class, Mockito.CALLS_REAL_METHODS); 46 | 47 | assertTrue(preparedStatement.isWrapperFor(Neo4jPreparedStatement.class)); 48 | assertTrue(preparedStatement.isWrapperFor(java.sql.Statement.class)); 49 | assertTrue(preparedStatement.isWrapperFor(java.sql.PreparedStatement.class)); 50 | assertTrue(preparedStatement.isWrapperFor(java.sql.Wrapper.class)); 51 | assertTrue(preparedStatement.isWrapperFor(java.lang.AutoCloseable.class)); 52 | } 53 | 54 | @Test public void isWrapperForShouldReturnFalse() throws SQLException { 55 | Neo4jPreparedStatement preparedStatement = mock(Neo4jPreparedStatement.class, Mockito.CALLS_REAL_METHODS); 56 | 57 | assertFalse(preparedStatement.isWrapperFor(Neo4jResultSet.class)); 58 | assertFalse(preparedStatement.isWrapperFor(java.sql.Driver.class)); 59 | assertFalse(preparedStatement.isWrapperFor(Neo4jResultSet.class)); 60 | assertFalse(preparedStatement.isWrapperFor(java.sql.ResultSet.class)); 61 | } 62 | 63 | /*------------------------------*/ 64 | /* unwrap */ 65 | /*------------------------------*/ 66 | 67 | @Test public void unwrapShouldReturnCorrectClass() throws SQLException { 68 | Neo4jPreparedStatement preparedStatement = mock(Neo4jPreparedStatement.class, Mockito.CALLS_REAL_METHODS); 69 | 70 | assertNotNull(preparedStatement.unwrap(Neo4jPreparedStatement.class)); 71 | assertNotNull(preparedStatement.unwrap(java.sql.Statement.class)); 72 | assertNotNull(preparedStatement.unwrap(java.sql.PreparedStatement.class)); 73 | assertNotNull(preparedStatement.unwrap(java.sql.Wrapper.class)); 74 | assertNotNull(preparedStatement.unwrap(java.lang.AutoCloseable.class)); 75 | } 76 | 77 | @Test public void unwrapShouldThrowException() throws SQLException { 78 | expectedEx.expect(SQLException.class); 79 | 80 | Neo4jPreparedStatement preparedStatement = mock(Neo4jPreparedStatement.class, Mockito.CALLS_REAL_METHODS); 81 | 82 | preparedStatement.unwrap(Neo4jResultSet.class); 83 | } 84 | 85 | /*------------------------------*/ 86 | /* addBatch */ 87 | /*------------------------------*/ 88 | 89 | @Test public void addBatchShouldThrowException() throws SQLException { 90 | expectedEx.expect(SQLException.class); 91 | 92 | Neo4jPreparedStatement stmt = Mockito.mock(Neo4jPreparedStatement.class, Mockito.CALLS_REAL_METHODS); 93 | 94 | stmt.addBatch(""); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/src/test/java/org/neo4j/jdbc/http/driver/Neo4jResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 15/4/2016 19 | */ 20 | package org.neo4j.jdbc.http.driver; 21 | 22 | import com.fasterxml.jackson.databind.ObjectMapper; 23 | import org.neo4j.jdbc.http.test.Neo4jHttpUnitTestUtil; 24 | import org.apache.http.HttpResponse; 25 | import org.apache.http.ProtocolVersion; 26 | import org.apache.http.entity.StringEntity; 27 | import org.apache.http.message.BasicHttpResponse; 28 | import org.apache.http.message.BasicStatusLine; 29 | import org.junit.Assert; 30 | import org.junit.Test; 31 | 32 | import java.io.UnsupportedEncodingException; 33 | import java.sql.SQLException; 34 | 35 | public class Neo4jResponseTest extends Neo4jHttpUnitTestUtil { 36 | 37 | @Test public void hasErrorShoudlReturnFalse() throws SQLException { 38 | Neo4jResponse response = generateNeo4jResponse(Boolean.FALSE); 39 | Assert.assertFalse(response.hasErrors()); 40 | } 41 | 42 | @Test public void hasErrorShoudlReturnTrue() throws SQLException { 43 | Neo4jResponse response = generateNeo4jResponse(Boolean.TRUE); 44 | Assert.assertTrue(response.hasErrors()); 45 | } 46 | 47 | @Test public void displayErrorShouldSucceed() throws SQLException { 48 | // Without errors 49 | Neo4jResponse response = generateNeo4jResponse(Boolean.FALSE); 50 | Assert.assertEquals(0, response.displayErrors().length()); 51 | 52 | // With errors 53 | response = generateNeo4jResponse(Boolean.TRUE); 54 | Assert.assertTrue(response.displayErrors().length() > 0); 55 | } 56 | 57 | /** 58 | * Create a response object. 59 | * 60 | * @return 61 | */ 62 | private Neo4jResponse generateNeo4jResponse(Boolean withErrors) throws SQLException { 63 | String body = ""; 64 | if (withErrors) { 65 | body = "{\n" + 66 | " \"results\" : [ ],\n" + 67 | " \"errors\" : [ {\n" + 68 | " \"code\" : \"Neo.ClientError.Statement.InvalidSyntax\",\n" + 69 | " \"message\" : \"Invalid input 'T': expected (line 1, column 1 (offset: 0))\\n\\\"This is not a valid Cypher Statement.\\\"\\n ^\"\n" 70 | + 71 | " } ]\n" + 72 | "}"; 73 | } else { 74 | body = "{\n" + 75 | " \"results\" : [ {\n" + 76 | " \"columns\" : [ \"id(n)\" ],\n" + 77 | " \"data\" : [ {\n" + 78 | " \"row\" : [ 74 ],\n" + 79 | " \"meta\" : [ null ]\n" + 80 | " } ]\n" + 81 | " }, {\n" + 82 | " \"columns\" : [ \"n\" ],\n" + 83 | " \"data\" : [ {\n" + 84 | " \"row\" : [ {\n" + 85 | " \"name\" : \"My Node\"\n" + 86 | " } ],\n" + 87 | " \"meta\" : [ {\n" + 88 | " \"id\" : 75,\n" + 89 | " \"type\" : \"node\",\n" + 90 | " \"deleted\" : false\n" + 91 | " } ]\n" + 92 | " } ]\n" + 93 | " } ],\n" + 94 | " \"errors\" : [ ]\n" + 95 | "}"; 96 | } 97 | Neo4jResponse mock = new Neo4jResponse(mockHttpResponse(200, body), new ObjectMapper()); 98 | return mock; 99 | } 100 | 101 | /** 102 | * Mock an HttpResponse. 103 | */ 104 | private HttpResponse mockHttpResponse(int code, String body) { 105 | HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), code, "")); 106 | response.setStatusCode(code); 107 | try { 108 | response.setEntity(new StringEntity(body)); 109 | } catch (UnsupportedEncodingException e) { 110 | throw new IllegalArgumentException(e); 111 | } 112 | return response; 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/test/java/org/neo4j/jdbc/utils/Neo4jPreparedStatementBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 25/03/16 19 | */ 20 | package org.neo4j.jdbc.utils; 21 | 22 | import org.junit.Test; 23 | 24 | import static org.neo4j.jdbc.utils.PreparedStatementBuilder.replacePlaceholders; 25 | import static org.junit.Assert.assertEquals; 26 | 27 | /** 28 | * @author AgileLARUS 29 | * @since 3.0.0 30 | */ 31 | public class Neo4jPreparedStatementBuilderTest { 32 | 33 | @Test public void replacePlaceholderShouldReturnSameStatementIfNoPlaceholders() { 34 | String raw = "MATCH statement RETURN same WHERE thereAreNoPlaceholders"; 35 | assertEquals(raw, replacePlaceholders(raw)); 36 | } 37 | 38 | @Test public void replacePlaceholderShouldReplaceQuestionMarksByDefaultWithOrderedCurlyBraces() { 39 | String raw = "MATCH statement RETURN same WHERE thereIsAPlaceholder = ?"; 40 | assertEquals("MATCH statement RETURN same WHERE thereIsAPlaceholder = {1}", replacePlaceholders(raw)); 41 | } 42 | 43 | @Test public void replacePlaceholderShouldReplaceQuestionMarksByDefaultWithOrderedCurlyBracesMultiple() { 44 | String raw = "MATCH statement RETURN same WHERE thereIsAPlaceholder = ? AND another = ?"; 45 | assertEquals("MATCH statement RETURN same WHERE thereIsAPlaceholder = {1} AND another = {2}", replacePlaceholders(raw)); 46 | } 47 | 48 | @Test public void replacePlaceholderShouldReplaceQuestionMarksByDefaultWithOrderedCurlyBracesMultipleNotInStrings() { 49 | String raw = "MATCH statement RETURN same WHERE thisIs = \"a string ?\" AND thereIsAPlaceholder = ? AND another = ? AND notInString = \"shall I replace this?\""; 50 | assertEquals( 51 | "MATCH statement RETURN same WHERE thisIs = \"a string ?\" AND thereIsAPlaceholder = {1} AND another = {2} AND notInString = \"shall I replace this?\"", 52 | replacePlaceholders(raw)); 53 | } 54 | 55 | @Test public void replacePlaceholderShouldReplaceQuestionMarksMultiline() { 56 | String raw = "MATCH statement RETURN same WHERE thereIsAPlaceholder = ? \nAND newLinePar = ?"; 57 | assertEquals("MATCH statement RETURN same WHERE thereIsAPlaceholder = {1} \nAND newLinePar = {2}", replacePlaceholders(raw)); 58 | } 59 | 60 | @Test public void replacePlaceholderShouldReplaceQuestionMarksWithOrderedCurlyBracesNotInQuotesAndNotCommentedMultilineMulti() { 61 | String raw = "MATCH statement RETURN same WHERE thisIs = \"a string ?\"\n" + 62 | "AND thereIsAPlaceholder = ?\n" + 63 | "AND another = ?"; 64 | assertEquals("MATCH statement RETURN same WHERE thisIs = \"a string ?\"\nAND thereIsAPlaceholder = {1}\nAND another = {2}", replacePlaceholders(raw)); 65 | } 66 | 67 | @Test public void placeholdersCountShouldCountCorrectlyIfNoPlaceholdersArePresent() { 68 | String raw = "MATCH n RETURN n"; 69 | assertEquals(0, PreparedStatementBuilder.namedParameterCount(raw)); 70 | } 71 | 72 | @Test public void placeholdersCountShouldCountCorrectlyIfOneLine() { 73 | String raw = "MATCH n RETURN n WHERE param = {1}"; 74 | assertEquals(1, PreparedStatementBuilder.namedParameterCount(raw)); 75 | } 76 | 77 | @Test public void placeholdersCountShouldCountCorrectlyIfOneLineString() { 78 | String raw = "MATCH n RETURN n WHERE param = {1} AND paramString = \"string{2}\""; 79 | assertEquals(1, PreparedStatementBuilder.namedParameterCount(raw)); 80 | } 81 | 82 | @Test public void placeholdersCountShouldCountCorrectlyIfOneLineStringMultiline() { 83 | String raw = "MATCH n RETURN n WHERE param = {2} AND paramString = \"string{3}\"\n" + "AND param2 = {1}"; 84 | assertEquals(2, PreparedStatementBuilder.namedParameterCount(raw)); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /neo4j-jdbc-http/src/main/java/org/neo4j/jdbc/http/HttpNeo4jStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 15/4/2016 19 | */ 20 | package org.neo4j.jdbc.http; 21 | 22 | import org.neo4j.jdbc.Loggable; 23 | import org.neo4j.jdbc.Neo4jStatement; 24 | import org.neo4j.jdbc.http.driver.Neo4jResponse; 25 | 26 | import java.sql.BatchUpdateException; 27 | import java.sql.ResultSet; 28 | import java.sql.SQLException; 29 | import java.util.ArrayList; 30 | import java.util.HashMap; 31 | import java.util.List; 32 | import java.util.Map; 33 | 34 | public class HttpNeo4jStatement extends Neo4jStatement implements Loggable { 35 | 36 | public HttpNeo4jStatement(HttpNeo4jConnection httpConnection) { 37 | super(httpConnection); 38 | batchStatements = new ArrayList<>(); 39 | } 40 | 41 | @Override public ResultSet executeQuery(String cypher) throws SQLException { 42 | this.execute(cypher); 43 | return currentResultSet; 44 | } 45 | 46 | @Override public int executeUpdate(String cypher) throws SQLException { 47 | this.execute(cypher); 48 | return currentUpdateCount; 49 | } 50 | 51 | @Override public boolean execute(String cypher) throws SQLException { 52 | checkClosed(); 53 | 54 | // execute the query 55 | Neo4jResponse response = ((HttpNeo4jConnection) getConnection()).executeQuery(cypher, null, Boolean.TRUE); 56 | 57 | if (response.hasErrors()) { 58 | throw new SQLException(response.displayErrors()); 59 | } 60 | 61 | // Parse stats 62 | this.currentUpdateCount = response.getFirstResult().getUpdateCount(); 63 | 64 | // Parse response data 65 | boolean hasResultSets = response.hasResultSets(); 66 | 67 | this.currentResultSet = hasResultSets ? new HttpNeo4jResultSet(this,response.getFirstResult()) : null; 68 | 69 | return hasResultSets; 70 | } 71 | 72 | @Override public int getResultSetConcurrency() throws SQLException { 73 | return ResultSet.CONCUR_READ_ONLY; 74 | } 75 | 76 | @Override public int getResultSetType() throws SQLException { 77 | return ResultSet.TYPE_FORWARD_ONLY; 78 | } 79 | 80 | @Override public int getResultSetHoldability() throws SQLException { 81 | return ResultSet.CLOSE_CURSORS_AT_COMMIT; 82 | } 83 | 84 | /*-------------------*/ 85 | /* Batch */ 86 | /*-------------------*/ 87 | 88 | @Override public int[] executeBatch() throws SQLException { 89 | this.checkClosed(); 90 | 91 | // execute batch queries 92 | List> parameters = new ArrayList<>(); 93 | for (int i = 0; i < batchStatements.size(); i++) { 94 | parameters.add(new HashMap()); 95 | } 96 | Neo4jResponse response = ((HttpNeo4jConnection) getConnection()).executeQueries(batchStatements, parameters, Boolean.TRUE); 97 | 98 | // proceed the result 99 | int[] result = new int[response.getResults().size()]; 100 | for (int i = 0; i < response.getResults().size(); i++) { 101 | result[i] = response.getResults().get(i).getUpdateCount(); 102 | } 103 | 104 | // we check if there is some error into the response => batch exception 105 | if (response.getErrors() != null && response.getErrors().size() > 0) { 106 | throw new BatchUpdateException(result, response.getErrors().get(0).getCause()); 107 | } 108 | // if no exception and we don't have the same cardiniality between queries & result => batch exception 109 | if (response.getResults().size() != batchStatements.size()) { 110 | throw new BatchUpdateException("Result size doesn't match queries size", result); 111 | } 112 | 113 | return result; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/test/java/org/neo4j/jdbc/Neo4jDataSourceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 09/03/16 19 | */ 20 | package org.neo4j.jdbc; 21 | 22 | import org.junit.Before; 23 | import org.junit.Rule; 24 | import org.junit.Test; 25 | import org.junit.rules.ExpectedException; 26 | import org.mockito.Mockito; 27 | 28 | import java.sql.SQLException; 29 | 30 | import static org.junit.Assert.*; 31 | import static org.mockito.Mockito.mock; 32 | 33 | /** 34 | * @author AgileLARUS 35 | * @since 3.0.0 36 | */ 37 | public class Neo4jDataSourceTest { 38 | 39 | @Rule public ExpectedException expectedEx = ExpectedException.none(); 40 | 41 | private Neo4jDataSource dataSource; 42 | 43 | @Before public void setUp() { 44 | this.dataSource = mock(Neo4jDataSource.class, Mockito.CALLS_REAL_METHODS); 45 | this.dataSource.setServerName("localhost"); //a protected non static non final variable is not initialized in a mock. 46 | } 47 | 48 | /*------------------------------*/ 49 | /* isWrapperFor */ 50 | /*------------------------------*/ 51 | 52 | @Test public void isWrapperForShouldReturnTrue() throws SQLException { 53 | assertTrue(this.dataSource.isWrapperFor(Neo4jDataSource.class)); 54 | assertTrue(this.dataSource.isWrapperFor(javax.sql.DataSource.class)); 55 | assertTrue(this.dataSource.isWrapperFor(javax.sql.CommonDataSource.class)); 56 | assertTrue(this.dataSource.isWrapperFor(java.sql.Wrapper.class)); 57 | } 58 | 59 | @Test public void isWrapperForShouldReturnFalse() throws SQLException { 60 | assertFalse(this.dataSource.isWrapperFor(Neo4jResultSet.class)); 61 | assertFalse(this.dataSource.isWrapperFor(java.sql.Driver.class)); 62 | assertFalse(this.dataSource.isWrapperFor(Neo4jResultSet.class)); 63 | assertFalse(this.dataSource.isWrapperFor(java.sql.ResultSet.class)); 64 | } 65 | 66 | /*------------------------------*/ 67 | /* unwrap */ 68 | /*------------------------------*/ 69 | 70 | @Test public void unwrapShouldReturnCorrectClass() throws SQLException { 71 | assertNotNull(this.dataSource.unwrap(Neo4jDataSource.class)); 72 | assertNotNull(this.dataSource.unwrap(javax.sql.DataSource.class)); 73 | assertNotNull(this.dataSource.unwrap(javax.sql.CommonDataSource.class)); 74 | assertNotNull(this.dataSource.unwrap(java.sql.Wrapper.class)); 75 | } 76 | 77 | @Test public void unwrapShouldThrowException() throws SQLException { 78 | expectedEx.expect(SQLException.class); 79 | 80 | this.dataSource.unwrap(Neo4jResultSet.class); 81 | } 82 | 83 | /*------------------------------*/ 84 | /* getURL */ 85 | /*------------------------------*/ 86 | @Test public void getUrlTest() throws SQLException { 87 | this.dataSource.setIsSsl(false); 88 | this.dataSource.setUser("test"); 89 | 90 | assertEquals("jdbc:neo4j:bolt://localhost?nossl,user=test", this.dataSource.getUrl("bolt")); 91 | 92 | this.dataSource.setIsSsl(true); 93 | assertEquals("jdbc:neo4j:bolt://localhost?user=test", this.dataSource.getUrl("bolt")); 94 | 95 | this.dataSource.setPassword("password"); 96 | this.dataSource.setIsSsl(false); 97 | assertEquals("jdbc:neo4j:bolt://localhost?nossl,user=test,password=password", this.dataSource.getUrl("bolt")); 98 | assertEquals("jdbc:neo4j:http://localhost?nossl,user=test,password=password", this.dataSource.getUrl("http")); 99 | 100 | this.dataSource.setPortNumber(7687); 101 | assertEquals("jdbc:neo4j:bolt://localhost:7687?nossl,user=test,password=password", this.dataSource.getUrl("bolt")); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/main/java/org/neo4j/jdbc/Neo4jArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 30/03/16 19 | */ 20 | package org.neo4j.jdbc; 21 | 22 | import java.sql.ResultSet; 23 | import java.sql.SQLException; 24 | import java.sql.SQLFeatureNotSupportedException; 25 | import java.sql.Types; 26 | import java.util.Arrays; 27 | import java.util.List; 28 | import java.util.Map; 29 | 30 | /** 31 | * @author AgileLARUS 32 | * @since 3.0.0 33 | */ 34 | public abstract class Neo4jArray implements java.sql.Array { 35 | 36 | protected static final List TYPES_SUPPORTED = Arrays.asList(Types.VARCHAR, Types.INTEGER, Types.BOOLEAN, Types.DOUBLE, Types.JAVA_OBJECT); 37 | protected static final List TYPES_UNSUPPORTED = Arrays 38 | .asList(Types.ARRAY, Types.BIGINT, Types.BINARY, Types.BIT, Types.BLOB, Types.CHAR, Types.CLOB, Types.DATALINK, Types.DATE, Types.DECIMAL, 39 | Types.DISTINCT, Types.FLOAT, Types.LONGNVARCHAR, Types.LONGVARBINARY, Types.NCHAR, Types.NCLOB, Types.NUMERIC, Types.NVARCHAR, Types.OTHER, 40 | Types.REAL, Types.REF, /*Types.REF_CURSOR,*/ Types.ROWID, Types.SMALLINT, Types.SQLXML, Types.STRUCT, Types.TIME, /*Types.TIME_WITH_TIMEZONE,*/ 41 | Types.TIMESTAMP, /*Types.TIMESTAMP_WITH_TIMEZONE,*/ Types.TINYINT, Types.VARBINARY); 42 | 43 | private static final String NOT_SUPPORTED = "Feature not supported"; 44 | 45 | @Override public String getBaseTypeName() throws SQLException { 46 | throw new SQLFeatureNotSupportedException(NOT_SUPPORTED); 47 | } 48 | 49 | @Override public int getBaseType() throws SQLException { 50 | throw new SQLFeatureNotSupportedException(NOT_SUPPORTED); 51 | } 52 | 53 | @Override public Object getArray() throws SQLException { 54 | throw new SQLFeatureNotSupportedException(NOT_SUPPORTED); 55 | } 56 | 57 | @Override public Object getArray(Map> map) throws SQLException { 58 | throw new SQLFeatureNotSupportedException(NOT_SUPPORTED); 59 | } 60 | 61 | @Override public Object getArray(long index, int count) throws SQLException { 62 | throw new SQLFeatureNotSupportedException(NOT_SUPPORTED); 63 | } 64 | 65 | @Override public Object getArray(long index, int count, Map> map) throws SQLException { 66 | throw new SQLFeatureNotSupportedException(NOT_SUPPORTED); 67 | } 68 | 69 | @Override public java.sql.ResultSet getResultSet() throws SQLException { 70 | throw new SQLFeatureNotSupportedException(NOT_SUPPORTED); 71 | } 72 | 73 | @Override public ResultSet getResultSet(Map> map) throws SQLException { 74 | throw new SQLFeatureNotSupportedException(NOT_SUPPORTED); 75 | } 76 | 77 | @Override public ResultSet getResultSet(long index, int count) throws SQLException { 78 | throw new SQLFeatureNotSupportedException(NOT_SUPPORTED); 79 | } 80 | 81 | @Override public ResultSet getResultSet(long index, int count, Map> map) throws SQLException { 82 | throw new SQLFeatureNotSupportedException(NOT_SUPPORTED); 83 | } 84 | 85 | @Override public void free() throws SQLException { 86 | throw new SQLFeatureNotSupportedException(NOT_SUPPORTED); 87 | } 88 | 89 | public static int getObjectType(Object obj){ 90 | int type; 91 | 92 | if(obj instanceof String){ 93 | type = Types.VARCHAR; 94 | } else if(obj instanceof Long){ 95 | type = Types.INTEGER; 96 | } else if(obj instanceof Boolean) { 97 | type = Types.BOOLEAN; 98 | } else if(obj instanceof Double){ 99 | type = Types.DOUBLE; 100 | } else { 101 | type = Types.JAVA_OBJECT; 102 | } 103 | 104 | return type; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /neo4j-jdbc-driver/src/test/java/org/neo4j/jdbc/DriverTestIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 4 | *

5 | * This file is part of the "LARUS Integration Framework for Neo4j". 6 | *

7 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | *

11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | *

13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | *

19 | * Created on 23/4/2016 20 | * 21 | */ 22 | 23 | package org.neo4j.jdbc; 24 | 25 | import java.sql.Connection; 26 | import java.sql.DriverManager; 27 | import java.sql.SQLException; 28 | import java.util.Properties; 29 | 30 | import org.junit.Assert; 31 | import org.junit.ClassRule; 32 | import org.junit.Rule; 33 | import org.junit.Test; 34 | import org.junit.rules.ExpectedException; 35 | import org.neo4j.harness.junit.Neo4jRule; 36 | import org.neo4j.jdbc.bolt.BoltNeo4jConnection; 37 | import org.neo4j.jdbc.bolt.impl.BoltNeo4jConnectionImpl; 38 | import org.neo4j.jdbc.http.HttpNeo4jConnection; 39 | 40 | import static org.mockito.Matchers.anyString; 41 | import static org.mockito.Mockito.*; 42 | 43 | public class DriverTestIT { 44 | 45 | @Rule public ExpectedException expectedEx = ExpectedException.none(); 46 | 47 | @ClassRule public static Neo4jRule neo4j = new Neo4jRule(); 48 | 49 | @Test public void shouldReturnAHttpConnection() throws SQLException { 50 | Driver driver = new Driver(); 51 | Connection connection = driver.connect("jdbc:neo4j:http://localhost:7474", new Properties()); 52 | Assert.assertTrue(connection instanceof HttpNeo4jConnection); 53 | } 54 | @Test public void shouldReturnAHttpConnection2() throws SQLException { 55 | Driver driver = new Driver(); 56 | Connection connection = driver.connect("jdbc:neo4j:http:localhost:7474", new Properties()); 57 | Assert.assertTrue(connection instanceof HttpNeo4jConnection); 58 | } 59 | 60 | @Test public void shouldReturnAHttpsConnection() throws SQLException { 61 | Driver driver = new Driver(); 62 | Connection connection = driver.connect("jdbc:neo4j:https://localhost", new Properties()); 63 | Assert.assertTrue(connection instanceof HttpNeo4jConnection); 64 | } 65 | 66 | @Test public void shouldReturnABoltConnection() throws Exception { 67 | Driver driver = new Driver(); 68 | Connection connection = driver.connect("jdbc:neo4j:" + neo4j.boltURI() + "/?nossl", new Properties()); 69 | Assert.assertTrue(connection instanceof BoltNeo4jConnection); 70 | } 71 | 72 | @Test public void shouldReturnNullWithBadUrl() throws SQLException { 73 | Driver driver = new Driver(); 74 | Connection connection = driver.connect("jdbc:mysql:localhost", new Properties()); 75 | Assert.assertNull(connection); 76 | } 77 | 78 | @Test public void shouldReturnNullWithUrlThatContainsOnlyJDBC() throws SQLException { 79 | // The driver can't understand that url so should returns a null connection 80 | Driver driver = new Driver(); 81 | Connection connection = driver.connect("jdbc:", new Properties()); 82 | Assert.assertNull(connection); 83 | } 84 | 85 | @Test public void shouldReturnNullWithEmptyUrl() throws SQLException { 86 | // The driver can't understand that url so should returns a null connection 87 | Driver driver = new Driver(); 88 | Connection connection = driver.connect("", new Properties()); 89 | Assert.assertNull(connection); 90 | } 91 | 92 | @Test public void shouldCallTheNextDriverWhenNonNeo4jUrl() throws SQLException { 93 | Driver driver = new Driver(); 94 | DriverManager.registerDriver(driver); 95 | java.sql.Driver mysqlDriver = mock(java.sql.Driver.class); 96 | Connection mockConnection = mock(Connection.class); 97 | when(mysqlDriver.connect(anyString(), any(Properties.class))).thenReturn(mockConnection); 98 | DriverManager.registerDriver(mysqlDriver); 99 | 100 | DriverManager.getConnection("jdbc:mysql:localhost"); 101 | 102 | verify(mysqlDriver, times(1)).connect(anyString(), any(Properties.class)); 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /docs/matlab.adoc: -------------------------------------------------------------------------------- 1 | = Combining Matlab with Neo4j 2 | 3 | == Setup 4 | 5 | === Download and Install Neo4j 6 | 7 | image::http://i.imgur.com/JqEqrlS.png[width=400,float=right] 8 | 9 | Go to http://neo4j.com/download and download, install and start neo4j 3.3.1. 10 | 11 | After providing the initial password, choose a new password, you'll need it later. 12 | 13 | Type into the command-line at the top: `:play movies`, click the big block of text which is then copied into the command-line and hit the triangular "Run" button (or press Ctrl-Enter). 14 | 15 | The data is inserted and should be visualized. 16 | 17 | === Get JDBC Driver 18 | 19 | Download the Neo4j jdbc driver from neo4j-contrib/neo4j-jdbc GitHub releases 20 | Need the older version b/c MATLAB still runs on Java 7 21 | 22 | ---- 23 | curl -O "$HOME/Documents/MATLAB/neo4j-jdbc-driver-3.1.0.jar" https://github.com/neo4j-contrib/neo4j-jdbc/releases/download/3.1.0/neo4j-jdbc-driver-3.1.0.jar 24 | ---- 25 | 26 | === Add the jar to the class pah via javaaddpath 27 | 28 | ---- 29 | javaaddpath([matlabroot,'/neo4j-jdbc-driver-3.1.0.jar']) 30 | ---- 31 | 32 | and check that the dynamic path contains the jar 33 | 34 | ---- 35 | javaclasspath 36 | ---- 37 | 38 | === Test Connection 39 | 40 | image::https://user-images.githubusercontent.com/12963831/34491711-d06858e2-efe4-11e7-96de-941f4ac06844.png[width=400,float=right] 41 | 42 | .Open Connection 43 | ---- 44 | conn = database('','neo4j','test','org.neo4j.jdbc.BoltNeo4jDriver','jdbc:neo4j:bolt://localhost:7687') 45 | ---- 46 | 47 | .Fetch Total Node Count 48 | ---- 49 | curs = exec(conn,'MATCH (n) RETURN count(*)') 50 | curs = fetch(curs); 51 | curs.Data 52 | close(curs) 53 | ---- 54 | 55 | .Output 56 | ---- 57 | ans = 58 | 59 | '102671' 60 | ---- 61 | 62 | .Fetch Movies 63 | ---- 64 | curs = exec(conn,'MATCH (n:Movie) RETURN n.title, n.released, n.tagline') 65 | curs = fetch(curs).Data 66 | curs.Data 67 | close(curs) 68 | ---- 69 | 70 | .Output 71 | ---- 72 | ans = 73 | 74 | 'The Matrix' '1999' 'Welcome to the Real World' 75 | 'The Matrix Reloaded' '2003' 'Free your mind' 76 | 'The Matrix Revolutions' '2003' 'Everything that has a beginni…' 77 | 'The Devil's Advocate' '1997' 'Evil has its winning ways' 78 | 'A Few Good Men' '1992' 'In the heart of the nation's …' 79 | 'Top Gun' '1986' 'I feel the need, the need for…' 80 | 'Jerry Maguire' '2000' 'The rest of his life begins n…' 81 | .... 82 | ---- 83 | 84 | .Close Connection 85 | ---- 86 | close(conn) 87 | ---- 88 | 89 | == Resources 90 | 91 | === Matlab & JDBC 92 | 93 | * http://www.mathworks.com/help/matlab/matlab_external/bringing-java-classes-and-methods-into-matlab-workspace.html[Bring Java Classes into MATLAB Workspace (javaclasspath.txt)] 94 | 95 | * http://www.mathworks.com/help/database/ug/configure-your-driver-and-data-source.html[donfiguring a driver and a data source] 96 | * http://www.mathworks.com/help/database/run-sql-query.html[Running a SQL Query: API Overview] 97 | * http://www.mathworks.com/help/database/ug/database.html[`database()` function to connect to a jdbc/odbc database] 98 | * http://www.mathworks.com/help/database/ug/exec.html[`exec()` function to run sql statements] 99 | 100 | * http://www.mathworks.com/help/database/ug/runsqlscript.html[`runsqlscript()` database function to run scripts from files] 101 | 102 | * http://www.mathworks.com/help/database/ug/configure-data-sources-and-connect-to-databases.html[Configure Data Sources and Connect to Databases] 103 | * http://www.mathworks.com/help/database/ug/choosing-between-odbc-and-jdbc-drivers.html[Choosing Between ODBC and JDBC Drivers] 104 | * http://www.mathworks.com/help/database/ug/other-odbc-or-jdbc-compliant-databases.html[Other ODBC- or JDBC-Compliant Databases] 105 | * http://www.mathworks.com/help/database/open-and-close-database-connection.html[open and close database connections] 106 | * http://www.mathworks.com/help/database/ug/oracle-jdbc-windows.html[Oracle JDBC for Windows] 107 | 108 | * http://www.mathworks.com/help/database/ug/connect-to-a-database.html[Overview: Connecting to a Database] 109 | * http://www.mathworks.com/help/database/ug/database-explorer.html[Working with Database Explorer] 110 | 111 | * http://www.mathworks.com/matlabcentral/answers/32618-connecting-to-mysql-using-jdbc 112 | * http://www.mathworks.com/matlabcentral/answers/166006-connect-using-jdbc-driver-to-neo4j[Original Question from 2014] -------------------------------------------------------------------------------- /neo4j-jdbc-bolt/src/test/java/org/neo4j/jdbc/bolt/SamplePT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 LARUS Business Automation [http://www.larus-ba.it] 3 | *

4 | * This file is part of the "LARUS Integration Framework for Neo4j". 5 | *

6 | * The "LARUS Integration Framework for Neo4j" is licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | *

10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | *

12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | *

18 | * Created on 14/03/16 19 | */ 20 | package org.neo4j.jdbc.bolt; 21 | 22 | import org.junit.Test; 23 | import org.mockito.Mockito; 24 | import org.neo4j.driver.v1.AuthTokens; 25 | import org.neo4j.driver.v1.GraphDatabase; 26 | import org.neo4j.driver.v1.Session; 27 | import org.openjdk.jmh.annotations.*; 28 | import org.openjdk.jmh.infra.Blackhole; 29 | import org.openjdk.jmh.runner.Runner; 30 | import org.openjdk.jmh.runner.options.Options; 31 | import org.openjdk.jmh.runner.options.OptionsBuilder; 32 | import org.openjdk.jmh.runner.options.TimeValue; 33 | 34 | import java.io.IOException; 35 | import java.io.PrintStream; 36 | import java.sql.*; 37 | import java.util.concurrent.TimeUnit; 38 | 39 | /** 40 | * @author AgileLARUS 41 | * @since 3.0.0 42 | */ 43 | public class SamplePT { 44 | 45 | @Test public void launchBenchmark() throws Exception { 46 | 47 | Connection conn = DriverManager.getConnection("jdbc:neo4j:bolt://localhost:7687?user=neo4j,password=test"); 48 | Statement stmt = conn.createStatement(); 49 | ResultSet rs = stmt.executeQuery("MATCH (n) RETURN n"); 50 | if (rs.next()) { 51 | throw new Exception("Database localhost:7687 is not empty"); 52 | } 53 | for (int i = 0; i < 100; i++) { 54 | stmt.executeQuery("CREATE (:A {prop:" + (int) (Math.random() * 100) + "})" + (Math.random() * 10 > 5 ? 55 | "-[:X]->(:B {prop:'" + (int) (Math.random() * 100) + "'})" : 56 | "")); 57 | } 58 | stmt.executeQuery("CREATE (:C)"); 59 | stmt.executeQuery("MATCH (b:B), (c:C) MERGE (c)<-[:Y]-(b)"); 60 | stmt.close(); 61 | conn.close(); 62 | 63 | // @formatter:off 64 | Options opt = new OptionsBuilder() 65 | .include(this.getClass().getName() + ".*") 66 | .mode(Mode.AverageTime) 67 | .timeUnit(TimeUnit.MICROSECONDS) 68 | //Warmup 69 | .warmupTime(TimeValue.seconds(1)) 70 | .warmupIterations(10) 71 | //Measurement 72 | .measurementTime(TimeValue.seconds(1)) 73 | .measurementIterations(10) 74 | .threads(1) 75 | .forks(2) 76 | .shouldFailOnError(true) 77 | //.shouldDoGC(true) 78 | //.jvmArgs("-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining") 79 | //.addProfiler(WinPerfAsmProfiler.class) 80 | .build(); 81 | 82 | new Runner(opt).run(); 83 | } 84 | 85 | @State(Scope.Thread) public static class Data { 86 | @Setup public static void initialize() throws ClassNotFoundException, SQLException, IOException { 87 | } 88 | 89 | public String query = "MATCH (n) RETURN n"; 90 | } 91 | 92 | @Benchmark public void testSimpleQueryJDBC(Data data, Blackhole bh) throws ClassNotFoundException, SQLException { 93 | Connection conn = DriverManager.getConnection("jdbc:neo4j:bolt://localhost:7687?user=neo4j,password=test"); 94 | Statement stmt = conn.createStatement(); 95 | bh.consume(stmt.executeQuery(data.query)); 96 | stmt.close(); 97 | conn.close(); 98 | } 99 | 100 | @Benchmark public void testSimpleQueryBoltDriver(Data data, Blackhole bh) { 101 | org.neo4j.driver.v1.Driver driver = GraphDatabase.driver("bolt://localhost:7687", AuthTokens.basic("neo4j", "test")); 102 | 103 | Session session = driver.session(); 104 | 105 | bh.consume(session.run(data.query)); 106 | 107 | session.close(); 108 | } 109 | 110 | @Benchmark public void testSimpleQueryWithDebugJDBC(Data data, Blackhole bh) throws SQLException { 111 | System.setOut(Mockito.mock(PrintStream.class)); 112 | Connection conn = DriverManager.getConnection("jdbc:neo4j:bolt://localhost:7687?user=neo4j,password=test,debug"); 113 | Statement stmt = conn.createStatement(); 114 | bh.consume(stmt.executeQuery(data.query)); 115 | stmt.close(); 116 | conn.close(); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /neo4j-jdbc/src/main/java/org/neo4j/jdbc/metadata/Column.java: -------------------------------------------------------------------------------- 1 | package org.neo4j.jdbc.metadata; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Column { 7 | private static final List COLUMN_NAMES; 8 | 9 | static { 10 | COLUMN_NAMES = new ArrayList<>(); 11 | 12 | COLUMN_NAMES.add("TABLE_CAT"); 13 | COLUMN_NAMES.add("TABLE_SCHEM"); 14 | COLUMN_NAMES.add("TABLE_NAME"); 15 | COLUMN_NAMES.add("COLUMN_NAME"); 16 | COLUMN_NAMES.add("DATA_TYPE"); 17 | COLUMN_NAMES.add("TYPE_NAME"); 18 | COLUMN_NAMES.add("COLUMN_SIZE"); 19 | COLUMN_NAMES.add("BUFFER_LENGTH"); 20 | COLUMN_NAMES.add("DECIMAL_DIGITS"); 21 | COLUMN_NAMES.add("NUM_PREC_RADIX"); 22 | COLUMN_NAMES.add("NULLABLE"); 23 | COLUMN_NAMES.add("REMARKS"); 24 | COLUMN_NAMES.add("COLUMN_DEF"); 25 | COLUMN_NAMES.add("SQL_DATA_TYPE"); 26 | COLUMN_NAMES.add("SQL_DATETIME_SUB"); 27 | COLUMN_NAMES.add("CHAR_OCTET_LENGTH"); 28 | COLUMN_NAMES.add("ORDINAL_POSITION"); 29 | COLUMN_NAMES.add("IS_NULLABLE"); 30 | COLUMN_NAMES.add("SCOPE_CATALOG"); 31 | COLUMN_NAMES.add("SCOPE_SCHEMA"); 32 | COLUMN_NAMES.add("SCOPE_TABLE"); 33 | COLUMN_NAMES.add("SOURCE_DATA_TYPE"); 34 | COLUMN_NAMES.add("IS_AUTOINCREMENT"); 35 | COLUMN_NAMES.add("IS_GENERATEDCOLUMN"); 36 | } 37 | 38 | private String tableName; 39 | private String columnName; 40 | private int columnsPosition; 41 | 42 | public Column(String tableName, String columnName, int columnsPosition) { 43 | this.tableName = tableName; 44 | this.columnName = columnName; 45 | this.columnsPosition = columnsPosition; 46 | } 47 | 48 | public static List getColumns() { 49 | return COLUMN_NAMES; 50 | } 51 | 52 | public String getTableCat() { 53 | return null; 54 | } 55 | 56 | public String getTableSchem() { 57 | return null; 58 | } 59 | 60 | public String getTableName() { 61 | return this.tableName; 62 | } 63 | 64 | public String getColumnName() { 65 | return this.columnName; 66 | } 67 | 68 | public String getDataType() { 69 | return null; 70 | } 71 | 72 | public String getTypeName() { 73 | return null; 74 | } 75 | 76 | public String getColumnSize() { 77 | return null; 78 | } 79 | 80 | public String getBufferLength() { 81 | return null; 82 | } 83 | 84 | public String getDecimalDigits() { 85 | return null; 86 | } 87 | 88 | public String getNumPrecRadix() { 89 | return null; 90 | } 91 | 92 | public String getNullable() { 93 | return "columnNoNulls"; 94 | } 95 | 96 | public String getRemarks() { 97 | return this.columnName + " node property for label :" + this.tableName; 98 | } 99 | 100 | public String getColumnDef() { 101 | return null; 102 | } 103 | 104 | public String getSqlDataType() { 105 | return null; 106 | } 107 | 108 | public String getSqlDatetimeSub() { 109 | return null; 110 | } 111 | 112 | public String getCharOctetLength() { 113 | return "0"; 114 | } 115 | 116 | public int getOrdinalPosition() { 117 | return this.columnsPosition; 118 | } 119 | 120 | public String getIsNullable() { 121 | return "NO"; 122 | } 123 | 124 | public String getScopeCatalog() { 125 | return null; 126 | } 127 | 128 | public String getScopeSchema() { 129 | return null; 130 | } 131 | 132 | public String getScopeTable() { 133 | return null; 134 | } 135 | 136 | public String getSourceDataType() { 137 | return null; 138 | } 139 | 140 | public String getIsAutoincrement() { 141 | return "NO"; 142 | } 143 | 144 | public String getIsGeneratedcolumn() { 145 | return "NO"; 146 | } 147 | 148 | public List toResultSetRow() { 149 | List row = new ArrayList<>(); 150 | row.add(this.getTableCat()); 151 | row.add(this.getTableSchem()); 152 | row.add(this.getTableName()); 153 | row.add(this.getColumnName()); 154 | row.add(this.getDataType()); 155 | row.add(this.getTypeName()); 156 | row.add(this.getColumnSize()); 157 | row.add(this.getBufferLength()); 158 | row.add(this.getDecimalDigits()); 159 | row.add(this.getNumPrecRadix()); 160 | row.add(this.getNullable()); 161 | row.add(this.getRemarks()); 162 | row.add(this.getColumnDef()); 163 | row.add(this.getSqlDataType()); 164 | row.add(this.getSqlDatetimeSub()); 165 | row.add(this.getCharOctetLength()); 166 | row.add(this.getOrdinalPosition()); 167 | row.add(this.getIsNullable()); 168 | row.add(this.getScopeCatalog()); 169 | row.add(this.getScopeSchema()); 170 | row.add(this.getScopeTable()); 171 | row.add(this.getSourceDataType()); 172 | row.add(this.getIsAutoincrement()); 173 | row.add(this.getIsGeneratedcolumn()); 174 | return row; 175 | } 176 | } 177 | --------------------------------------------------------------------------------