use of org.h2.engine.SessionInterface in project h2database by h2database.
the class DataType method convertToValue1.
private static Value convertToValue1(SessionInterface session, Object x, int type) {
if (x == null) {
return ValueNull.INSTANCE;
}
if (type == Value.JAVA_OBJECT) {
return ValueJavaObject.getNoCopy(x, null, session.getDataHandler());
}
if (x instanceof String) {
return ValueString.get((String) x);
} else if (x instanceof Value) {
return (Value) x;
} else if (x instanceof Long) {
return ValueLong.get(((Long) x).longValue());
} else if (x instanceof Integer) {
return ValueInt.get(((Integer) x).intValue());
} else if (x instanceof BigInteger) {
return ValueDecimal.get(new BigDecimal((BigInteger) x));
} else if (x instanceof BigDecimal) {
return ValueDecimal.get((BigDecimal) x);
} else if (x instanceof Boolean) {
return ValueBoolean.get(((Boolean) x).booleanValue());
} else if (x instanceof Byte) {
return ValueByte.get(((Byte) x).byteValue());
} else if (x instanceof Short) {
return ValueShort.get(((Short) x).shortValue());
} else if (x instanceof Float) {
return ValueFloat.get(((Float) x).floatValue());
} else if (x instanceof Double) {
return ValueDouble.get(((Double) x).doubleValue());
} else if (x instanceof byte[]) {
return ValueBytes.get((byte[]) x);
} else if (x instanceof Date) {
return ValueDate.get((Date) x);
} else if (x instanceof Time) {
return ValueTime.get((Time) x);
} else if (x instanceof Timestamp) {
return ValueTimestamp.get((Timestamp) x);
} else if (x instanceof java.util.Date) {
return ValueTimestamp.fromMillis(((java.util.Date) x).getTime());
} else if (x instanceof java.io.Reader) {
Reader r = new BufferedReader((java.io.Reader) x);
return session.getDataHandler().getLobStorage().createClob(r, -1);
} else if (x instanceof java.sql.Clob) {
try {
java.sql.Clob clob = (java.sql.Clob) x;
Reader r = new BufferedReader(clob.getCharacterStream());
return session.getDataHandler().getLobStorage().createClob(r, clob.length());
} catch (SQLException e) {
throw DbException.convert(e);
}
} else if (x instanceof java.io.InputStream) {
return session.getDataHandler().getLobStorage().createBlob((java.io.InputStream) x, -1);
} else if (x instanceof java.sql.Blob) {
try {
java.sql.Blob blob = (java.sql.Blob) x;
return session.getDataHandler().getLobStorage().createBlob(blob.getBinaryStream(), blob.length());
} catch (SQLException e) {
throw DbException.convert(e);
}
} else if (x instanceof java.sql.Array) {
java.sql.Array array = (java.sql.Array) x;
try {
return convertToValue(session, array.getArray(), Value.ARRAY);
} catch (SQLException e) {
throw DbException.convert(e);
}
} else if (x instanceof ResultSet) {
if (x instanceof SimpleResultSet) {
return ValueResultSet.get((ResultSet) x);
}
return ValueResultSet.getCopy((ResultSet) x, Integer.MAX_VALUE);
} else if (x instanceof UUID) {
return ValueUuid.get((UUID) x);
}
Class<?> clazz = x.getClass();
if (x instanceof Object[]) {
// (a.getClass().isArray());
// (a.getClass().getComponentType().isPrimitive());
Object[] o = (Object[]) x;
int len = o.length;
Value[] v = new Value[len];
for (int i = 0; i < len; i++) {
v[i] = convertToValue(session, o[i], type);
}
return ValueArray.get(clazz.getComponentType(), v);
} else if (x instanceof Character) {
return ValueStringFixed.get(((Character) x).toString());
} else if (isGeometry(x)) {
return ValueGeometry.getFromGeometry(x);
} else if (clazz == LocalDateTimeUtils.LOCAL_DATE) {
return LocalDateTimeUtils.localDateToDateValue(x);
} else if (clazz == LocalDateTimeUtils.LOCAL_TIME) {
return LocalDateTimeUtils.localTimeToTimeValue(x);
} else if (clazz == LocalDateTimeUtils.LOCAL_DATE_TIME) {
return LocalDateTimeUtils.localDateTimeToValue(x);
} else if (clazz == LocalDateTimeUtils.INSTANT) {
return LocalDateTimeUtils.instantToValue(x);
} else if (clazz == LocalDateTimeUtils.OFFSET_DATE_TIME) {
return LocalDateTimeUtils.offsetDateTimeToValue(x);
} else if (x instanceof TimestampWithTimeZone) {
return ValueTimestampTimeZone.get((TimestampWithTimeZone) x);
} else {
if (JdbcUtils.customDataTypesHandler != null) {
return JdbcUtils.customDataTypesHandler.getValue(type, x, session.getDataHandler());
}
return ValueJavaObject.getNoCopy(x, null, session.getDataHandler());
}
}
use of org.h2.engine.SessionInterface in project h2database by h2database.
the class JdbcDatabaseMetaData method hasSynonyms.
private boolean hasSynonyms() {
Boolean hasSynonyms = this.hasSynonyms;
if (hasSynonyms == null) {
SessionInterface si = conn.getSession();
if (si instanceof SessionRemote) {
SessionRemote sr = (SessionRemote) si;
int clientVersion = sr.getClientVersion();
if (clientVersion >= Constants.TCP_PROTOCOL_VERSION_17) {
hasSynonyms = true;
} else if (clientVersion <= Constants.TCP_PROTOCOL_VERSION_15) {
hasSynonyms = false;
} else {
// 1.4.194-1.4.196
CommandInterface c = sr.prepareCommand("CALL H2VERSION()", Integer.MAX_VALUE);
ResultInterface result = c.executeQuery(0, false);
result.next();
String s = result.currentRow()[0].getString();
result.close();
hasSynonyms = "1.4.196".equals(s);
}
} else {
hasSynonyms = true;
}
this.hasSynonyms = hasSynonyms;
}
return hasSynonyms;
}
use of org.h2.engine.SessionInterface in project h2database by h2database.
the class JdbcStatement method checkClosed.
/**
* INTERNAL.
* Check if the statement is closed.
*
* @param write if the next operation is possibly writing
* @return true if a reconnect was required
* @throws DbException if it is closed
*/
protected boolean checkClosed(boolean write) {
if (conn == null) {
throw DbException.get(ErrorCode.OBJECT_CLOSED);
}
conn.checkClosed(write);
SessionInterface s = conn.getSession();
if (s != session) {
session = s;
trace = session.getTrace();
return true;
}
return false;
}
Aggregations