mirror of
https://github.com/moparisthebest/JdbcMapper
synced 2024-11-21 08:35:00 -05:00
Implement UnNestArrayInList for hsqldb
This commit is contained in:
parent
30599a15fd
commit
7cc5af55fb
@ -129,6 +129,7 @@ public interface JdbcMapper extends Closeable {
|
||||
public enum DatabaseType {
|
||||
DEFAULT(null, null),
|
||||
STANDARD("numeric", "text"),
|
||||
UNNEST("numeric", "text"),
|
||||
ORACLE("ARRAY_NUM_TYPE", "ARRAY_STR_TYPE");
|
||||
|
||||
public final String arrayNumberTypeName, arrayStringTypeName;
|
||||
|
@ -1,9 +1,6 @@
|
||||
package com.moparisthebest.jdbc.codegen;
|
||||
|
||||
import com.moparisthebest.jdbc.ArrayInList;
|
||||
import com.moparisthebest.jdbc.Cleaner;
|
||||
import com.moparisthebest.jdbc.MapperException;
|
||||
import com.moparisthebest.jdbc.OracleArrayInList;
|
||||
import com.moparisthebest.jdbc.*;
|
||||
|
||||
import javax.annotation.processing.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
@ -194,6 +191,9 @@ public class JdbcMapperProcessor extends AbstractProcessor {
|
||||
case STANDARD:
|
||||
arrayInList = new ArrayInList(arrayNumberTypeName, arrayStringTypeName);
|
||||
break;
|
||||
case UNNEST:
|
||||
arrayInList = new UnNestArrayInList(arrayNumberTypeName, arrayStringTypeName);
|
||||
break;
|
||||
default:
|
||||
// no support
|
||||
arrayInList = null;
|
||||
@ -403,6 +403,11 @@ public class JdbcMapperProcessor extends AbstractProcessor {
|
||||
"(" + inColumnName + " != ANY(?))" :
|
||||
"(" + inColumnName + " = ANY(?))";
|
||||
break;
|
||||
case UNNEST:
|
||||
replacement = not ?
|
||||
"(" + inColumnName + " NOT IN(UNNEST(?)))" :
|
||||
"(" + inColumnName + " IN(UNNEST(?)))";
|
||||
break;
|
||||
default:
|
||||
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "default DatabaseType? should never happen!!", bindParam);
|
||||
return false;
|
||||
@ -749,6 +754,7 @@ public class JdbcMapperProcessor extends AbstractProcessor {
|
||||
//w.write("(Array) createArray.invoke(conn.unwrap(oracleConnection), \"");
|
||||
break;
|
||||
case STANDARD:
|
||||
case UNNEST:
|
||||
w.write("conn.createArrayOf(\"");
|
||||
break;
|
||||
default:
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.moparisthebest.jdbc;
|
||||
|
||||
/**
|
||||
* HSQLDB requires array in lists to be implemented this way:
|
||||
* https://stackoverflow.com/questions/35939489/createarrayof-string-in-hsqldb-jdbc-returns-abstractmethoderror/35964424#35964424
|
||||
*/
|
||||
public class UnNestArrayInList extends ArrayInList {
|
||||
|
||||
private static final InList instance = new UnNestArrayInList();
|
||||
|
||||
public static InList instance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public UnNestArrayInList(final String numberType, final String otherType) {
|
||||
super(numberType, otherType);
|
||||
}
|
||||
|
||||
public UnNestArrayInList() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected String columnAppend(final String columnName) {
|
||||
return "(" + columnName + " IN(UNNEST(?)))";
|
||||
}
|
||||
}
|
@ -54,12 +54,13 @@ public class QueryMapperQmDao implements QmDao {
|
||||
public static final String selectStrVal = "SELECT str_val FROM val WHERE val_no = ?";
|
||||
|
||||
private static final Collection<Class<?>> noArrayInListSupport;
|
||||
private static final Class<?> hsqlConnection;
|
||||
|
||||
static {
|
||||
Collection<Class<?>> no = new ArrayList<Class<?>>();
|
||||
for(final String connectionClassName : new String[]{
|
||||
"org.apache.derby.impl.jdbc.EmbedConnection"
|
||||
, "org.hsqldb.jdbc.JDBCConnection"
|
||||
, "org.hsqldb.jdbc.JDBCConnection" // does not support ArrayInList but *does* support UnNestArrayInList
|
||||
, "org.sqlite.jdbc3.JDBC3Connection"
|
||||
, "org.mariadb.jdbc.MariaDbConnection"
|
||||
// h2 doesn't support this with java6 either...
|
||||
@ -73,6 +74,13 @@ public class QueryMapperQmDao implements QmDao {
|
||||
// ignore
|
||||
}
|
||||
noArrayInListSupport = Collections.unmodifiableCollection(no);
|
||||
Class<?> hsql = null;
|
||||
try {
|
||||
hsql = Class.forName("org.hsqldb.jdbc.JDBCConnection");
|
||||
} catch(Exception e) {
|
||||
// ignore
|
||||
}
|
||||
hsqlConnection = hsql;
|
||||
}
|
||||
|
||||
public static boolean supportsArrayInList(final Connection conn) {
|
||||
@ -89,7 +97,17 @@ public class QueryMapperQmDao implements QmDao {
|
||||
}
|
||||
|
||||
public static InList getBestInList(final Connection conn) {
|
||||
return supportsArrayInList(conn) ? ArrayInList.instance() : BindInList.instance();
|
||||
if(supportsArrayInList(conn))
|
||||
return ArrayInList.instance();
|
||||
if(hsqlConnection != null)
|
||||
try {
|
||||
if(conn.isWrapperFor(hsqlConnection))
|
||||
return UnNestArrayInList.instance();
|
||||
} catch (SQLException e) {
|
||||
// ignore
|
||||
}
|
||||
// works for everything
|
||||
return BindInList.instance();
|
||||
}
|
||||
|
||||
protected final QueryMapper qm;
|
||||
|
Loading…
Reference in New Issue
Block a user