use of org.h2.jdbc.JdbcBlob in project h2database by h2database.
the class JdbcConnection method createBlob.
/**
* Create a new empty Blob object.
*
* @return the object
*/
@Override
public Blob createBlob() throws SQLException {
try {
int id = getNextId(TraceObject.BLOB);
debugCodeAssign("Blob", TraceObject.BLOB, id, "createClob()");
checkClosedForWrite();
try {
Value v = session.getDataHandler().getLobStorage().createBlob(new ByteArrayInputStream(Utils.EMPTY_BYTES), 0);
synchronized (session) {
session.addTemporaryLob(v);
}
return new JdbcBlob(this, v, id);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
use of org.h2.jdbc.JdbcBlob in project h2database by h2database.
the class JdbcResultSet method getBlob.
/**
* Returns the value of the specified column as a Blob.
*
* @param columnIndex (1,2,...)
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
@Override
public Blob getBlob(int columnIndex) throws SQLException {
try {
int id = getNextId(TraceObject.BLOB);
if (isDebugEnabled()) {
debugCodeAssign("Blob", TraceObject.BLOB, id, "getBlob(" + columnIndex + ")");
}
Value v = get(columnIndex);
return v == ValueNull.INSTANCE ? null : new JdbcBlob(conn, v, id);
} catch (Exception e) {
throw logAndConvert(e);
}
}
use of org.h2.jdbc.JdbcBlob in project h2database by h2database.
the class JdbcResultSet method getBlob.
/**
* Returns the value of the specified column as a Blob.
*
* @param columnLabel the column label
* @return the value
* @throws SQLException if the column is not found or if the result set is
* closed
*/
@Override
public Blob getBlob(String columnLabel) throws SQLException {
try {
int id = getNextId(TraceObject.BLOB);
if (isDebugEnabled()) {
debugCodeAssign("Blob", TraceObject.BLOB, id, "getBlob(" + quote(columnLabel) + ")");
}
Value v = get(columnLabel);
return v == ValueNull.INSTANCE ? null : new JdbcBlob(conn, v, id);
} catch (Exception e) {
throw logAndConvert(e);
}
}
use of org.h2.jdbc.JdbcBlob in project h2database by h2database.
the class JdbcResultSet method extractObjectOfType.
private <T> T extractObjectOfType(Class<T> type, Value value) throws SQLException {
if (value == ValueNull.INSTANCE) {
return null;
}
if (type == BigDecimal.class) {
return type.cast(value.getBigDecimal());
} else if (type == BigInteger.class) {
return type.cast(value.getBigDecimal().toBigInteger());
} else if (type == String.class) {
return type.cast(value.getString());
} else if (type == Boolean.class) {
return type.cast(value.getBoolean());
} else if (type == Byte.class) {
return type.cast(value.getByte());
} else if (type == Short.class) {
return type.cast(value.getShort());
} else if (type == Integer.class) {
return type.cast(value.getInt());
} else if (type == Long.class) {
return type.cast(value.getLong());
} else if (type == Float.class) {
return type.cast(value.getFloat());
} else if (type == Double.class) {
return type.cast(value.getDouble());
} else if (type == Date.class) {
return type.cast(value.getDate());
} else if (type == Time.class) {
return type.cast(value.getTime());
} else if (type == Timestamp.class) {
return type.cast(value.getTimestamp());
} else if (type == java.util.Date.class) {
return type.cast(new java.util.Date(value.getTimestamp().getTime()));
} else if (type == Calendar.class) {
Calendar calendar = DateTimeUtils.createGregorianCalendar();
calendar.setTime(value.getTimestamp());
return type.cast(calendar);
} else if (type == UUID.class) {
return type.cast(value.getObject());
} else if (type == byte[].class) {
return type.cast(value.getBytes());
} else if (type == java.sql.Array.class) {
int id = getNextId(TraceObject.ARRAY);
return type.cast(value == ValueNull.INSTANCE ? null : new JdbcArray(conn, value, id));
} else if (type == Blob.class) {
int id = getNextId(TraceObject.BLOB);
return type.cast(value == ValueNull.INSTANCE ? null : new JdbcBlob(conn, value, id));
} else if (type == Clob.class) {
int id = getNextId(TraceObject.CLOB);
return type.cast(value == ValueNull.INSTANCE ? null : new JdbcClob(conn, value, id));
} else if (type == TimestampWithTimeZone.class) {
return type.cast(value.getObject());
} else if (DataType.isGeometryClass(type)) {
return type.cast(value.getObject());
} else if (type == LocalDateTimeUtils.LOCAL_DATE) {
return type.cast(LocalDateTimeUtils.valueToLocalDate(value));
} else if (type == LocalDateTimeUtils.LOCAL_TIME) {
return type.cast(LocalDateTimeUtils.valueToLocalTime(value));
} else if (type == LocalDateTimeUtils.LOCAL_DATE_TIME) {
return type.cast(LocalDateTimeUtils.valueToLocalDateTime(value));
} else if (type == LocalDateTimeUtils.INSTANT) {
return type.cast(LocalDateTimeUtils.valueToInstant(value));
} else if (type == LocalDateTimeUtils.OFFSET_DATE_TIME) {
return type.cast(LocalDateTimeUtils.valueToOffsetDateTime(value));
} else {
throw unsupported(type.getName());
}
}
Aggregations