use of com.google.cloud.spanner.Type.Code in project java-spanner-jdbc by googleapis.
the class JdbcResultSet method getTime.
@Override
public Time getTime(int columnIndex) throws SQLException {
checkClosedAndValidRow();
boolean isNull = isNull(columnIndex);
int spannerIndex = columnIndex - 1;
Code type = spanner.getColumnType(spannerIndex).getCode();
switch(type) {
case STRING:
return isNull ? null : parseTime(spanner.getString(spannerIndex));
case TIMESTAMP:
return isNull ? null : JdbcTypeConverter.toSqlTime(spanner.getTimestamp(spannerIndex));
case BOOL:
case DATE:
case FLOAT64:
case INT64:
case NUMERIC:
case PG_NUMERIC:
case BYTES:
case JSON:
case STRUCT:
case ARRAY:
default:
throw createInvalidToGetAs("time", type);
}
}
use of com.google.cloud.spanner.Type.Code in project java-spanner-jdbc by googleapis.
the class JdbcResultSet method getInt.
@Override
public int getInt(int columnIndex) throws SQLException {
checkClosedAndValidRow();
boolean isNull = isNull(columnIndex);
int spannerIndex = columnIndex - 1;
Code type = spanner.getColumnType(spannerIndex).getCode();
switch(type) {
case BOOL:
return isNull ? 0 : (spanner.getBoolean(spannerIndex) ? 1 : 0);
case FLOAT64:
return isNull ? 0 : checkedCastToInt(Double.valueOf(spanner.getDouble(spannerIndex)).longValue());
case INT64:
return isNull ? 0 : checkedCastToInt(spanner.getLong(spannerIndex));
case NUMERIC:
return isNull ? 0 : checkedCastToInt(spanner.getBigDecimal(spannerIndex));
case PG_NUMERIC:
return isNull ? 0 : checkedCastToInt(parseBigDecimal(spanner.getString(spannerIndex)).toBigInteger());
case STRING:
return isNull ? 0 : checkedCastToInt(parseLong(spanner.getString(spannerIndex)));
case BYTES:
case JSON:
case DATE:
case STRUCT:
case TIMESTAMP:
case ARRAY:
default:
throw createInvalidToGetAs("int", type);
}
}
use of com.google.cloud.spanner.Type.Code in project java-spanner-jdbc by googleapis.
the class JdbcResultSet method getTime.
@Override
public Time getTime(int columnIndex, Calendar cal) throws SQLException {
checkClosedAndValidRow();
boolean isNull = isNull(columnIndex);
int spannerIndex = columnIndex - 1;
Code type = spanner.getColumnType(spannerIndex).getCode();
switch(type) {
case STRING:
return isNull ? null : parseTime(spanner.getString(spannerIndex), cal);
case TIMESTAMP:
return isNull ? null : JdbcTypeConverter.toSqlTime(spanner.getTimestamp(spannerIndex), cal);
case BOOL:
case DATE:
case FLOAT64:
case INT64:
case NUMERIC:
case BYTES:
case JSON:
case STRUCT:
case ARRAY:
default:
throw createInvalidToGetAs("time", type);
}
}
use of com.google.cloud.spanner.Type.Code in project java-spanner-jdbc by googleapis.
the class JdbcResultSet method getByte.
@Override
public byte getByte(int columnIndex) throws SQLException {
checkClosedAndValidRow();
boolean isNull = isNull(columnIndex);
int spannerIndex = columnIndex - 1;
Code type = spanner.getColumnType(spannerIndex).getCode();
switch(type) {
case BOOL:
return isNull ? (byte) 0 : (spanner.getBoolean(spannerIndex) ? (byte) 1 : 0);
case FLOAT64:
return isNull ? (byte) 0 : checkedCastToByte(Double.valueOf(spanner.getDouble(spannerIndex)).longValue());
case INT64:
return isNull ? (byte) 0 : checkedCastToByte(spanner.getLong(spannerIndex));
case NUMERIC:
return isNull ? (byte) 0 : checkedCastToByte(spanner.getBigDecimal(spannerIndex));
case PG_NUMERIC:
return isNull ? (byte) 0 : checkedCastToByte(parseBigDecimal(spanner.getString(spannerIndex)).toBigInteger());
case STRING:
return isNull ? (byte) 0 : checkedCastToByte(parseLong(spanner.getString(spannerIndex)));
case BYTES:
case JSON:
case DATE:
case STRUCT:
case TIMESTAMP:
case ARRAY:
default:
throw createInvalidToGetAs("byte", type);
}
}
use of com.google.cloud.spanner.Type.Code in project java-spanner-jdbc by googleapis.
the class JdbcResultSet method getDate.
@Override
public Date getDate(int columnIndex, Calendar cal) throws SQLException {
checkClosedAndValidRow();
if (isNull(columnIndex)) {
return null;
}
int spannerIndex = columnIndex - 1;
Code type = spanner.getColumnType(spannerIndex).getCode();
switch(type) {
case DATE:
return JdbcTypeConverter.toSqlDate(spanner.getDate(spannerIndex), cal);
case STRING:
return parseDate(spanner.getString(spannerIndex), cal);
case TIMESTAMP:
return new Date(JdbcTypeConverter.getAsSqlTimestamp(spanner.getTimestamp(spannerIndex), cal).getTime());
case BOOL:
case FLOAT64:
case INT64:
case NUMERIC:
case BYTES:
case JSON:
case STRUCT:
case ARRAY:
default:
throw createInvalidToGetAs("date", type);
}
}
Aggregations