#1186 - ENH: Support using TableValues / Array for select prop in (?) queries

Use Postgres Array ANY and ALL without select unnest
This commit is contained in:
rob bygrave committed 2017-10-31 22:09:35 +13:00
1 parent 5bccdccbd6
commit 1e1c518641
34 files changed
+157 -117

No files matched your search

@@ -10,10 +10,10 @@ import io.ebeaninternal.server.type.ScalarType;
public class H2MultiValueBind extends AbstractMultiValueBind {
@Override
public String getInExpression(ScalarType<?> type, int size) {
public String getInExpression(boolean not, ScalarType<?> type, int size) {
String arrayType = getArrayType(type.getJdbcType());
if (arrayType == null) {
return super.getInExpression(type, size);
return super.getInExpression(not, type, size);
} else {
StringBuilder sb = new StringBuilder(50);
sb.append(" in (select * from table(x ").append(arrayType).append(" = ?)) ");
@@ -55,8 +55,11 @@ public class MultiValueBind {
/**
* Appends the 'in' expression to the request. Must add leading & trailing space!
*/
public String getInExpression(ScalarType<?> type, int size) {
public String getInExpression(boolean not, ScalarType<?> type, int size) {
StringBuilder sb = new StringBuilder();
if (not) {
sb.append(" not");
}
sb.append(" in (?");
for (int i = 1; i < size; i++) {
sb.append(", ").append("?");
@@ -4,31 +4,22 @@ import io.ebean.config.dbplatform.ExtraDbTypes;
import io.ebeaninternal.server.type.ScalarType;
/**
* Multi value binder that uses Postgres Array and unnest.
*
* @author Roland Praml, FOCONIS AG
* Multi value binder that uses Postgres Array.
*/
public class PostgresMultiValueBind extends AbstractMultiValueBind {
@Override
public String getInExpression(ScalarType<?> type, int size) {
public String getInExpression(boolean not, ScalarType<?> type, int size) {
int dbType = type.getJdbcType();
if (dbType == ExtraDbTypes.UUID) {
return " in (select(unnest(?))::uuid) ";
return (not) ? " != all(?::uuid[])" : " = any(?::uuid[])";
}
String arrayType = getArrayType(dbType);
if (arrayType == null) {
return super.getInExpression(type, size);
return super.getInExpression(not, type, size);
} else {
return " in (select(unnest(?))) ";
return (not) ? " != all(?)" : " = any(?)";
}
}
@Override
protected String getArrayType(int dbType) {
if (dbType == ExtraDbTypes.UUID) {
return "uuid";
}
return super.getArrayType(dbType);
}
}