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

This commit is contained in:
rob bygrave committed 2017-10-31 02:53:20 +13:00
1 parent 89dac3820b
commit 6e62b72fb9
43 files changed
+756 -131

No files matched your search

@@ -5,6 +5,7 @@ import io.ebeaninternal.api.BindParams;
import io.ebeaninternal.server.core.DbExpressionHandler;
import io.ebeaninternal.server.core.Message;
import io.ebeaninternal.server.core.timezone.DataTimeZone;
import io.ebeaninternal.server.persist.platform.MultiValueBind;
import io.ebeaninternal.server.type.DataBind;
import io.ebeaninternal.server.type.ScalarType;
import io.ebeaninternal.server.type.TypeManager;
@@ -19,6 +20,7 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
@@ -38,17 +40,20 @@ public class Binder {
private final DataTimeZone dataTimeZone;
private final MultiValueBind multiValueBind;
/**
* Set the PreparedStatement with which to bind variables to.
*/
public Binder(TypeManager typeManager, int asOfBindCount, boolean asOfStandardsBased,
DbExpressionHandler dbExpressionHandler, DataTimeZone dataTimeZone) {
DbExpressionHandler dbExpressionHandler, DataTimeZone dataTimeZone, MultiValueBind multiValueBind) {
this.typeManager = typeManager;
this.asOfBindCount = asOfBindCount;
this.asOfStandardsBased = asOfStandardsBased;
this.dbExpressionHandler = dbExpressionHandler;
this.dataTimeZone = dataTimeZone;
this.multiValueBind = multiValueBind;
}
/**
@@ -168,6 +173,26 @@ public class Binder {
}
}
/**
* Return true if MultiValue binding is supported for the given type.
*/
public boolean isMultiValueSupported(Class<?> cls) {
try {
ScalarType<?> scalarType = getScalarType(cls);
return multiValueBind.isTypeSupported(scalarType.getJdbcType());
} catch (PersistenceException e) {
return false;
}
}
private ScalarType<?> getScalarType(Class<?> clazz) {
ScalarType<?> type = typeManager.getScalarType(clazz);
if (type == null) {
throw new PersistenceException("No ScalarType registered for " + clazz);
}
return type;
}
/**
* Bind an Object with unknown data type.
*/
@@ -178,15 +203,19 @@ public class Binder {
bindObject(dataBind, null, Types.OTHER);
return null;
} else if (value instanceof MultiValueWrapper) {
MultiValueWrapper wrapper = (MultiValueWrapper) value;
Collection<?> values = wrapper.getValues();
ScalarType<?> type = getScalarType(wrapper.getType());
int dbType = type.getJdbcType();
// let the multiValueBind decide what to do with the value
multiValueBind.bindMultiValues(dataBind, values, type, one -> bindObject(dataBind, one, dbType));
return values;
} else {
ScalarType<?> type = typeManager.getScalarType(value.getClass());
if (type == null) {
// the type is not registered with the TypeManager.
String msg = "No ScalarType registered for " + value.getClass();
throw new PersistenceException(msg);
} else if (!type.isJdbcNative()) {
ScalarType<?> type = getScalarType(value.getClass());
if (!type.isJdbcNative()) {
// convert to a JDBC native type
value = type.toJdbcType(value);
}
@@ -197,6 +226,14 @@ public class Binder {
}
}
/**
* Return the SQL in clause taking into account Multi-value support.
*/
public String getInExpression(Object[] bindValues) {
ScalarType<?> type = getScalarType(bindValues[0].getClass());
return multiValueBind.getInExpression(type, bindValues.length);
}
/**
* bind a single value.
* <p>