diff --git a/src/main/java/nl/b3p/loader/jdbc/GeometryJdbcConverter.java b/src/main/java/nl/b3p/loader/jdbc/GeometryJdbcConverter.java index 7b77b592..65cb7ba1 100644 --- a/src/main/java/nl/b3p/loader/jdbc/GeometryJdbcConverter.java +++ b/src/main/java/nl/b3p/loader/jdbc/GeometryJdbcConverter.java @@ -120,7 +120,7 @@ static public Object convertToSQLObject(String stringValue, ColumnMetadata cm, * @return SQL statement specific for the flavour of database */ public String getUpdateSequenceSQL(String seqName, long nextVal) { - // supported for postgres, ms sql, hsqldb, (18+) oracle + // supported for postgres, ms sql, hsqldb return String.format("ALTER SEQUENCE %s RESTART WITH %d", seqName , nextVal); } diff --git a/src/main/java/nl/b3p/loader/jdbc/GeometryJdbcConverterFactory.java b/src/main/java/nl/b3p/loader/jdbc/GeometryJdbcConverterFactory.java index 4f2ea1d4..0e9abdfc 100644 --- a/src/main/java/nl/b3p/loader/jdbc/GeometryJdbcConverterFactory.java +++ b/src/main/java/nl/b3p/loader/jdbc/GeometryJdbcConverterFactory.java @@ -56,6 +56,7 @@ public static GeometryJdbcConverter getGeometryJdbcConverter(Connection conn) { } else if (databaseProductName.contains("Oracle")) { boolean oracle11 = false; boolean oracle12 = false; + boolean oracle18 = false; try { oracle11 = (conn.getMetaData().getDatabaseMajorVersion() == 11); } catch (SQLException ex) { @@ -66,6 +67,11 @@ public static GeometryJdbcConverter getGeometryJdbcConverter(Connection conn) { } catch (SQLException ex) { LOG.warn("Uitlezen database versie is mislukt.", ex); } + try { + oracle18 = (conn.getMetaData().getDatabaseMajorVersion() == 18); + } catch (SQLException ex) { + LOG.warn("Uitlezen database versie is mislukt.", ex); + } try { OracleConnection oc = OracleConnectionUnwrapper.unwrap(conn); OracleJdbcConverter geomToJdbc; @@ -73,6 +79,8 @@ public static GeometryJdbcConverter getGeometryJdbcConverter(Connection conn) { geomToJdbc = new Oracle11JdbcConverter(oc); }else if(oracle12){ geomToJdbc = new Oracle12JdbcConverter(oc); + }else if(oracle18){ + geomToJdbc = new Oracle18JdbcConverter(oc); } else { geomToJdbc = new OracleJdbcConverter(oc); } diff --git a/src/main/java/nl/b3p/loader/jdbc/Oracle11JdbcConverter.java b/src/main/java/nl/b3p/loader/jdbc/Oracle11JdbcConverter.java index 4a609aef..acfd606b 100644 --- a/src/main/java/nl/b3p/loader/jdbc/Oracle11JdbcConverter.java +++ b/src/main/java/nl/b3p/loader/jdbc/Oracle11JdbcConverter.java @@ -64,8 +64,4 @@ public StringBuilder buildLimitSql(StringBuilder sql, int limit) { return sql; } - - public String getUpdateSequenceSQL(String seqName, long nextVal){ - throw new UnsupportedOperationException("Not supported."); - } } diff --git a/src/main/java/nl/b3p/loader/jdbc/Oracle18JdbcConverter.java b/src/main/java/nl/b3p/loader/jdbc/Oracle18JdbcConverter.java new file mode 100644 index 00000000..f6981e09 --- /dev/null +++ b/src/main/java/nl/b3p/loader/jdbc/Oracle18JdbcConverter.java @@ -0,0 +1,26 @@ +package nl.b3p.loader.jdbc; + +import oracle.jdbc.OracleConnection; + +import java.sql.SQLException; + +public class Oracle18JdbcConverter extends Oracle12JdbcConverter { + + public Oracle18JdbcConverter(OracleConnection oc) throws SQLException { + super(oc); + } + + /** + * Gets a statement to use in a prepared statement to restart a sequence. + * This assumes no other interactions are going on with the sequence; + * can only be used to increase the value of the sequence, not decrease. + * + * @param seqName name of sequence + * @return SQL statement specific for the flavour of database + */ + @Override + public String getUpdateSequenceSQL(String seqName, long nextVal) { + // zie: https://rogertroller.com/2018/02/20/oracle-18c-alter-sequence-restart/ + return String.format("ALTER SEQUENCE %s RESTART START WITH %d",seqName, nextVal); + } +} diff --git a/src/main/java/nl/b3p/loader/jdbc/OracleJdbcConverter.java b/src/main/java/nl/b3p/loader/jdbc/OracleJdbcConverter.java index 49669350..87235819 100644 --- a/src/main/java/nl/b3p/loader/jdbc/OracleJdbcConverter.java +++ b/src/main/java/nl/b3p/loader/jdbc/OracleJdbcConverter.java @@ -171,4 +171,8 @@ public String getSelectNextValueFromSequenceSQL(String seqName) { public Geometry convertToJTSGeometryObject(Object nativeObj) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } + + public String getUpdateSequenceSQL(String seqName, long nextVal){ + throw new UnsupportedOperationException("Not supported."); + } } diff --git a/src/test/java/nl/b3p/loader/jdbc/RestartSequenceIntegrationTest.java b/src/test/java/nl/b3p/loader/jdbc/RestartSequenceIntegrationTest.java index 43d6fb18..150d79b1 100644 --- a/src/test/java/nl/b3p/loader/jdbc/RestartSequenceIntegrationTest.java +++ b/src/test/java/nl/b3p/loader/jdbc/RestartSequenceIntegrationTest.java @@ -14,7 +14,6 @@ import java.sql.SQLException; import static junit.framework.TestCase.assertEquals; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** @@ -42,7 +41,9 @@ public void testRestartSequence() throws SQLException { int updated = run.update(c, converter.getUpdateSequenceSQL( params.getProperty("staging.sequence.name", "testing_seq"), 99999) ); - if (converter instanceof Oracle12JdbcConverter ){ + if (converter instanceof Oracle18JdbcConverter) { + assertEquals("expected 0 rows to be updated", 0, updated); + } else if (converter instanceof Oracle12JdbcConverter) { assertEquals("expected 1 rows to be updated", 1, updated); } else { assertEquals("expected 0 rows to be updated", 0, updated); diff --git a/src/test/resources/oracle.properties b/src/test/resources/oracle.properties index 62888329..f4ef923f 100644 --- a/src/test/resources/oracle.properties +++ b/src/test/resources/oracle.properties @@ -1,6 +1,6 @@ # evt. override met een local.oracle.properties dbtype=oracle staging.jdbc.driverClassName=oracle.jdbc.OracleDriver -staging.jdbc.url=jdbc:oracle:thin:@192.168.1.16:15210:XE +staging.jdbc.url=jdbc:oracle:thin:@192.168.1.26:15210:XE staging.user=jenkins_staging staging.passwd=jenkins_staging