mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-17 22:56:28 +00:00
#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:
1 parent
5bccdccbd6
commit
1e1c518641
34 files changed
+157
-117
No files matched your search
@@ -229,9 +229,9 @@ public class Binder {
|
||||
/**
|
||||
* Return the SQL in clause taking into account Multi-value support.
|
||||
*/
|
||||
public String getInExpression(Object[] bindValues) {
|
||||
public String getInExpression(boolean not, Object[] bindValues) {
|
||||
ScalarType<?> type = getScalarType(bindValues[0].getClass());
|
||||
return multiValueBind.getInExpression(type, bindValues.length);
|
||||
return multiValueBind.getInExpression(not, type, bindValues.length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user