2015-04-29 12:03:35 -04:00
|
|
|
package com.moparisthebest.jdbc;
|
|
|
|
|
2018-05-20 12:51:37 -04:00
|
|
|
import com.moparisthebest.jdbc.codegen.JdbcMapper;
|
|
|
|
|
2015-04-29 12:03:35 -04:00
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.sql.Array;
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.SQLException;
|
2018-05-23 23:41:19 -04:00
|
|
|
|
|
|
|
import static com.moparisthebest.jdbc.OptimalInList.oracleConnection;
|
2015-04-29 12:03:35 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by mopar on 4/29/15.
|
|
|
|
*/
|
|
|
|
public class OracleArrayInList extends ArrayInList {
|
|
|
|
|
|
|
|
private static final InList instance = new OracleArrayInList();
|
|
|
|
|
|
|
|
public static InList instance() {
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Method createArray;
|
|
|
|
|
|
|
|
static {
|
2018-05-23 23:41:19 -04:00
|
|
|
Method ca = null;
|
|
|
|
if(oracleConnection != null)
|
|
|
|
try {
|
|
|
|
ca = oracleConnection.getDeclaredMethod("createOracleArray", String.class, Object.class);
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
2015-04-29 12:03:35 -04:00
|
|
|
createArray = ca;
|
|
|
|
}
|
|
|
|
|
2018-03-06 01:04:44 -05:00
|
|
|
public OracleArrayInList(final String numberType, final String otherType) {
|
|
|
|
super(numberType, otherType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public OracleArrayInList() {
|
2018-05-20 12:51:37 -04:00
|
|
|
this(JdbcMapper.DatabaseType.ORACLE.arrayNumberTypeName, JdbcMapper.DatabaseType.ORACLE.arrayStringTypeName);
|
2015-04-29 12:03:35 -04:00
|
|
|
}
|
|
|
|
|
2018-05-22 23:09:57 -04:00
|
|
|
protected String columnAppendIn(final String columnName) {
|
2015-05-01 09:45:51 -04:00
|
|
|
return "(" + columnName + " IN(select column_value from table(?)))";
|
2015-04-29 12:03:35 -04:00
|
|
|
}
|
|
|
|
|
2018-05-22 23:09:57 -04:00
|
|
|
protected String columnAppendNotIn(final String columnName) {
|
|
|
|
return "(" + columnName + " NOT IN(select column_value from table(?)))";
|
|
|
|
}
|
|
|
|
|
2018-03-06 01:04:44 -05:00
|
|
|
public Array toArray(final Connection conn, final String typeName, final Object[] elements) throws SQLException {
|
|
|
|
//return conn.unwrap(oracle.jdbc.OracleConnection.class).createOracleArray(typeName, elements);
|
2015-04-29 12:03:35 -04:00
|
|
|
try {
|
2018-03-06 01:04:44 -05:00
|
|
|
return (Array) createArray.invoke(conn.unwrap(oracleConnection), typeName, elements);
|
2015-04-29 12:03:35 -04:00
|
|
|
} catch (SQLException e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new RuntimeException(e); // should never happen, but if it does don't hide it
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|