From 2d13a76c883121695e14bfbb7f6d76990cde0c5a Mon Sep 17 00:00:00 2001 From: gongxin Date: Mon, 2 Sep 2019 22:37:14 +0800 Subject: [PATCH 1/3] fix transaction isolation level check bug --- .../main/java/org/neo4j/jdbc/impl/Neo4jConnectionImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neo4j-jdbc/src/main/java/org/neo4j/jdbc/impl/Neo4jConnectionImpl.java b/neo4j-jdbc/src/main/java/org/neo4j/jdbc/impl/Neo4jConnectionImpl.java index 7b19fdf2..c4e4afc5 100644 --- a/neo4j-jdbc/src/main/java/org/neo4j/jdbc/impl/Neo4jConnectionImpl.java +++ b/neo4j-jdbc/src/main/java/org/neo4j/jdbc/impl/Neo4jConnectionImpl.java @@ -229,7 +229,7 @@ protected void checkTypeParams(int resultSetType) throws SQLException { */ protected void checkTransactionIsolation(int level) throws SQLException { // @formatter:off - int[] invalid = { + Integer[] invalid = { TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, @@ -238,7 +238,7 @@ protected void checkTransactionIsolation(int level) throws SQLException { }; if(!Arrays.asList(invalid).contains(level)){ - throw new SQLException(); + throw new SQLException("Unsupported isolation level"); } // @formatter:on } From 105ac5b5a2b5e053533aebeb0460be869a8cd596 Mon Sep 17 00:00:00 2001 From: gongxin Date: Mon, 2 Sep 2019 23:18:10 +0800 Subject: [PATCH 2/3] bug of travis CI --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 91a3716b..9e1288ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,5 @@ jdk: script: - mvn clean test +dist: trusty #- mvn clean test -Pperformance-test From f50418cae6d4edb6ce29fce6bb67142aa11aa495 Mon Sep 17 00:00:00 2001 From: gongxin Date: Tue, 3 Sep 2019 01:09:35 +0800 Subject: [PATCH 3/3] Add some test case --- .../neo4j/jdbc/impl/Neo4jConnectionImpl.java | 2 + .../jdbc/impl/Neo4jConnectionImplTest.java | 102 ++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 neo4j-jdbc/src/test/java/org/neo4j/jdbc/impl/Neo4jConnectionImplTest.java diff --git a/neo4j-jdbc/src/main/java/org/neo4j/jdbc/impl/Neo4jConnectionImpl.java b/neo4j-jdbc/src/main/java/org/neo4j/jdbc/impl/Neo4jConnectionImpl.java index c4e4afc5..51d40c0a 100644 --- a/neo4j-jdbc/src/main/java/org/neo4j/jdbc/impl/Neo4jConnectionImpl.java +++ b/neo4j-jdbc/src/main/java/org/neo4j/jdbc/impl/Neo4jConnectionImpl.java @@ -75,6 +75,8 @@ protected Neo4jConnectionImpl(Properties properties, String url, int defaultHold this.holdability = defaultHoldability; } + Neo4jConnectionImpl() {} + public static boolean hasDebug(Properties properties) { return "true".equalsIgnoreCase(properties.getProperty("debug", "false")); } diff --git a/neo4j-jdbc/src/test/java/org/neo4j/jdbc/impl/Neo4jConnectionImplTest.java b/neo4j-jdbc/src/test/java/org/neo4j/jdbc/impl/Neo4jConnectionImplTest.java new file mode 100644 index 00000000..59ff59c5 --- /dev/null +++ b/neo4j-jdbc/src/test/java/org/neo4j/jdbc/impl/Neo4jConnectionImplTest.java @@ -0,0 +1,102 @@ +package org.neo4j.jdbc.impl; + +import org.junit.Test; + +import java.sql.DatabaseMetaData; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.Statement; + +import static org.junit.Assert.fail; + +/** + * @description + * @time 创建时间:2019/9/3 0:44 + * @param + * @author xin.gong + */ +public class Neo4jConnectionImplTest { + + Neo4jConnectionImpl neo4jConnection = new Neo4jConnectionImpl(){ + @Override public Statement createStatement() throws SQLException { + return null; + } + + @Override public PreparedStatement prepareStatement(String sql) throws SQLException { + return null; + } + + @Override public void setAutoCommit(boolean autoCommit) throws SQLException { + + } + + @Override public boolean getAutoCommit() throws SQLException { + return false; + } + + @Override public void commit() throws SQLException { + + } + + @Override public void rollback() throws SQLException { + + } + + @Override public void close() throws SQLException { + + } + + @Override public boolean isClosed() throws SQLException { + return false; + } + + @Override public DatabaseMetaData getMetaData() throws SQLException { + return null; + } + + @Override public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { + return null; + } + + @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) + throws SQLException { + return null; + } + + @Override public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + return null; + } + + @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + return null; + } + + @Override public boolean isValid(int timeout) throws SQLException { + return false; + } + }; + @Test public void checkTransactionIsolationShouldReturnNothing() { + Integer[] levels = {0, 1, 2, 4, 8}; + for (int level : levels) { + try { + neo4jConnection.checkTransactionIsolation(level); + } catch (SQLException e) { + fail(); + } + } + } + + @Test public void checkTransactionIsolationShouldThrowExceptionWhenInputErrorLevel() { + Integer[] levels = {3, 5, 7, 9}; + for (int level : levels) { + try { + neo4jConnection.checkTransactionIsolation(level); + fail(); + } catch (SQLException e) { + // OK + } + } + } +}