Skip to content

Commit

Permalink
Add Oracle 18 flavour
Browse files Browse the repository at this point in the history
  • Loading branch information
mprins committed May 15, 2020
1 parent 3a26872 commit 942ba52
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -66,13 +67,20 @@ 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;
if (oracle11) {
geomToJdbc = new Oracle11JdbcConverter(oc);
}else if(oracle12){
geomToJdbc = new Oracle12JdbcConverter(oc);
}else if(oracle18){
geomToJdbc = new Oracle18JdbcConverter(oc);
} else {
geomToJdbc = new OracleJdbcConverter(oc);
}
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/nl/b3p/loader/jdbc/Oracle11JdbcConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
26 changes: 26 additions & 0 deletions src/main/java/nl/b3p/loader/jdbc/Oracle18JdbcConverter.java
Original file line number Diff line number Diff line change
@@ -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;
* <em>can only be used to increase the value of the sequence, not decrease.</em>
*
* @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);
}
}
4 changes: 4 additions & 0 deletions src/main/java/nl/b3p/loader/jdbc/OracleJdbcConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/oracle.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 942ba52

Please sign in to comment.