#1640 Additionally add expression eq and in support for Inet and Postgres any

This commit is contained in:
rob bygrave committed 2019-02-24 15:29:07 +13:00
1 parent 2e496c9e1e
commit e5f98f1b7a
7 files changed
+85 -7

No files matched your search

@@ -9,6 +9,7 @@ import io.ebeaninternal.server.expression.platform.DbExpressionHandler;
import io.ebeaninternal.server.persist.platform.MultiValueBind;
import io.ebeaninternal.server.type.DataBind;
import io.ebeaninternal.server.type.DataReader;
import io.ebeaninternal.server.type.PostgresHelper;
import io.ebeaninternal.server.type.RsetDataReader;
import io.ebeaninternal.server.type.ScalarType;
import io.ebeaninternal.server.type.TypeManager;
@@ -374,6 +375,11 @@ public class Binder {
b.setObject(data);
break;
case DbPlatformType.INET:
// data is always a String at this point
b.setObject(PostgresHelper.asInet(data.toString()));
break;
case java.sql.Types.OTHER:
b.setObject(data, dataType);
break;
@@ -82,8 +82,8 @@ abstract class AbstractMultiValueBind extends MultiValueBind {
//case NCLOB:
case NCHAR:
case NVARCHAR:
return "varchar";
case ExtraDbTypes.UUID: // Db Native UUID
case ExtraDbTypes.UUID: // Postgres cast to uuid[]
case ExtraDbTypes.INET: // Postgres cast to inet[]
return "varchar";
default:
@@ -14,6 +14,9 @@ public class PostgresMultiValueBind extends AbstractMultiValueBind {
if (dbType == ExtraDbTypes.UUID) {
return (not) ? " != all(?::uuid[])" : " = any(?::uuid[])";
}
if (dbType == ExtraDbTypes.INET) {
return (not) ? " != all(?::inet[])" : " = any(?::inet[])";
}
String arrayType = getArrayType(dbType);
if (arrayType == null) {
return super.getInExpression(not, type, size);
@@ -39,6 +39,8 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.URI;
import java.net.URL;
@@ -977,9 +979,9 @@ public final class DefaultTypeManager implements TypeManager {
}
if (offlineMigrationGeneration || (postgres && !config.getPlatformConfig().isDatabaseInetAddressVarchar())) {
addType(InetAddress.class, new ScalarTypeInetAddressPostgres());
addInetAddressType(new ScalarTypeInetAddressPostgres());
} else {
addType(InetAddress.class, new ScalarTypeInetAddress());
addInetAddressType(new ScalarTypeInetAddress());
}
if (offlineMigrationGeneration || postgres) {
@@ -1077,4 +1079,10 @@ public final class DefaultTypeManager implements TypeManager {
nativeMap.put(Types.TIMESTAMP, timestampType);
}
private void addInetAddressType(ScalarType scalarType) {
addType(InetAddress.class, scalarType);
addType(Inet4Address.class, scalarType);
addType(Inet6Address.class, scalarType);
}
}
@@ -11,8 +11,8 @@ import java.sql.Types;
*/
public abstract class ScalarTypeInet extends ScalarTypeBaseVarchar<Inet> {
ScalarTypeInet() {
super(Inet.class, false, ExtraDbTypes.INET);
ScalarTypeInet(int jdbcType) {
super(Inet.class, false, jdbcType);
}
@Override
@@ -43,6 +43,10 @@ public abstract class ScalarTypeInet extends ScalarTypeBaseVarchar<Inet> {
*/
public static class Varchar extends ScalarTypeInet {
Varchar() {
super(Types.VARCHAR);
}
@Override
public void bind(DataBind b, Inet value) throws SQLException {
if (value == null) {
@@ -58,6 +62,10 @@ public abstract class ScalarTypeInet extends ScalarTypeBaseVarchar<Inet> {
*/
public static class Postgres extends ScalarTypeInet {
Postgres() {
super(ExtraDbTypes.INET);
}
@Override
public void bind(DataBind b, Inet value) throws SQLException {
if (value == null) {