package io.ebeaninternal.server.persist.platform;
import io.ebean.config.dbplatform.ExtraDbTypes;
import io.ebean.core.type.ScalarType;
import io.ebeaninternal.server.type.DataBind;
import java.sql.SQLException;
import java.util.Collection;
import static java.sql.Types.BIGINT;
import static java.sql.Types.BIT;
import static java.sql.Types.BOOLEAN;
import static java.sql.Types.CHAR;
import static java.sql.Types.DATE;
import static java.sql.Types.DECIMAL;
import static java.sql.Types.DOUBLE;
import static java.sql.Types.FLOAT;
import static java.sql.Types.INTEGER;
import static java.sql.Types.NCHAR;
import static java.sql.Types.NUMERIC;
import static java.sql.Types.NVARCHAR;
import static java.sql.Types.REAL;
import static java.sql.Types.SMALLINT;
import static java.sql.Types.TIMESTAMP;
import static java.sql.Types.TIMESTAMP_WITH_TIMEZONE;
import static java.sql.Types.TIME_WITH_TIMEZONE;
import static java.sql.Types.TINYINT;
import static java.sql.Types.VARCHAR;
abstract class AbstractMultiValueBind extends MultiValueBind {
@Override
public boolean isSupported() {
return true;
}
@Override
public boolean isTypeSupported(int jdbcType) {
return getArrayType(jdbcType) != null;
}
@Override
public void bindMultiValues(DataBind dataBind, Collection<?> values, ScalarType<?> type, BindOne bindOne) throws SQLException {
String arrayType = getArrayType(type.getJdbcType());
if (arrayType == null) {
super.bindMultiValues(dataBind, values, type, bindOne);
} else {
dataBind.setArray(arrayType, toArray(values, type));
}
}
String getArrayType(int dbType) {
switch(dbType) {
case TINYINT:
case SMALLINT:
case INTEGER:
case BIGINT:
case DECIMAL:
case NUMERIC:
return "bigint";
case REAL:
case FLOAT:
case DOUBLE:
return "float";
case BIT:
case BOOLEAN:
return "bit";
case DATE:
return "date";
case TIMESTAMP:
case TIME_WITH_TIMEZONE:
case TIMESTAMP_WITH_TIMEZONE:
return "timestamp";
case CHAR:
case VARCHAR:
case NCHAR:
case NVARCHAR:
case ExtraDbTypes.UUID:
case ExtraDbTypes.INET:
return "varchar";
default:
return null;
}
}
}