Search in sources :

Example 1 with SessionInterface

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());
    }
}
Also used : SimpleResultSet(org.h2.tools.SimpleResultSet) SQLException(java.sql.SQLException) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) Time(java.sql.Time) Timestamp(java.sql.Timestamp) Array(java.sql.Array) TimestampWithTimeZone(org.h2.api.TimestampWithTimeZone) SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet) UUID(java.util.UUID) Clob(java.sql.Clob) JdbcBlob(org.h2.jdbc.JdbcBlob) Blob(java.sql.Blob) InputStream(java.io.InputStream) BigDecimal(java.math.BigDecimal) Date(java.sql.Date) BigInteger(java.math.BigInteger) Array(java.sql.Array) JdbcArray(org.h2.jdbc.JdbcArray) BufferedReader(java.io.BufferedReader) BigInteger(java.math.BigInteger) JdbcClob(org.h2.jdbc.JdbcClob) Clob(java.sql.Clob) Blob(java.sql.Blob)

Example 2 with SessionInterface

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;
}
Also used : SessionRemote(org.h2.engine.SessionRemote) ResultInterface(org.h2.result.ResultInterface) SessionInterface(org.h2.engine.SessionInterface) CommandInterface(org.h2.command.CommandInterface)

Example 3 with SessionInterface

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;
}
Also used : SessionInterface(org.h2.engine.SessionInterface)

Aggregations

SessionInterface (org.h2.engine.SessionInterface)2 BufferedReader (java.io.BufferedReader)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 Array (java.sql.Array)1 Blob (java.sql.Blob)1 Clob (java.sql.Clob)1 Date (java.sql.Date)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Time (java.sql.Time)1 Timestamp (java.sql.Timestamp)1 UUID (java.util.UUID)1 TimestampWithTimeZone (org.h2.api.TimestampWithTimeZone)1 CommandInterface (org.h2.command.CommandInterface)1 SessionRemote (org.h2.engine.SessionRemote)1 JdbcArray (org.h2.jdbc.JdbcArray)1 JdbcBlob (org.h2.jdbc.JdbcBlob)1