Handle ByteEnums. Not actually tested.
This commit is contained in:
@@ -20,9 +20,12 @@
|
|||||||
|
|
||||||
package com.samskivert.depot.impl;
|
package com.samskivert.depot.impl;
|
||||||
|
|
||||||
|
import java.sql.Array;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import com.samskivert.depot.ByteEnum;
|
||||||
import com.samskivert.depot.DatabaseException;
|
import com.samskivert.depot.DatabaseException;
|
||||||
import com.samskivert.depot.expression.ValueExp;
|
import com.samskivert.depot.expression.ValueExp;
|
||||||
import com.samskivert.depot.operator.Conditionals.In;
|
import com.samskivert.depot.operator.Conditionals.In;
|
||||||
@@ -45,19 +48,31 @@ public class PostgreSQL4Builder extends PostgreSQLBuilder
|
|||||||
_builder.append(" = any (?)");
|
_builder.append(" = any (?)");
|
||||||
_bindables.add(new Bindable() {
|
_bindables.add(new Bindable() {
|
||||||
public void doBind (Connection conn, PreparedStatement stmt, int argIdx)
|
public void doBind (Connection conn, PreparedStatement stmt, int argIdx)
|
||||||
throws Exception {
|
throws Exception
|
||||||
stmt.setObject(argIdx, conn.createArrayOf(getElementType(values[0]),
|
{
|
||||||
(Object[])values));
|
stmt.setObject(argIdx, createArray(conn, values));
|
||||||
}
|
}
|
||||||
protected String getElementType (Object value) {
|
protected Array createArray (Connection conn, Object[] values)
|
||||||
if (value instanceof Integer) {
|
throws SQLException
|
||||||
return "integer";
|
{
|
||||||
} else if (value instanceof String) {
|
String type;
|
||||||
return "varchar";
|
Object testValue = values[0];
|
||||||
|
if (testValue instanceof Integer) {
|
||||||
|
type = "integer";
|
||||||
|
} else if (testValue instanceof String) {
|
||||||
|
type = "varchar";
|
||||||
|
} else if (testValue instanceof ByteEnum) {
|
||||||
|
Byte[] bytes = new Byte[values.length];
|
||||||
|
for (int ii = 0; ii < bytes.length; ii ++) {
|
||||||
|
bytes[ii] = ((ByteEnum) values[ii]).toByte();
|
||||||
|
}
|
||||||
|
values = bytes;
|
||||||
|
type = "smallint"; // tinyint is in the spec, but PG doesn't recognize?
|
||||||
} else {
|
} else {
|
||||||
throw new DatabaseException(
|
throw new DatabaseException(
|
||||||
"Don't know how to make Postgres array for " + value.getClass());
|
"Don't know how to make Postgres array for " + testValue.getClass());
|
||||||
}
|
}
|
||||||
|
return conn.createArrayOf(type, values);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user