Search in sources :

Example 11 with Code

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);
    }
}
Also used : Code(com.google.cloud.spanner.Type.Code)

Example 12 with Code

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);
    }
}
Also used : Code(com.google.cloud.spanner.Type.Code)

Example 13 with Code

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);
    }
}
Also used : Code(com.google.cloud.spanner.Type.Code)

Example 14 with Code

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);
    }
}
Also used : Code(com.google.cloud.spanner.Type.Code)

Example 15 with Code

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);
    }
}
Also used : Code(com.google.cloud.spanner.Type.Code) Date(java.sql.Date)

Aggregations

Code (com.google.cloud.spanner.Type.Code)19 StructField (com.google.cloud.spanner.Type.StructField)2 ValueWithStructField (io.jans.orm.cloud.spanner.model.ValueWithStructField)2 EntryConvertationException (io.jans.orm.exception.operation.EntryConvertationException)2 BigDecimal (java.math.BigDecimal)2 Date (java.sql.Date)2 ArrayList (java.util.ArrayList)2 WriteBuilder (com.google.cloud.spanner.Mutation.WriteBuilder)1 SpannerException (com.google.cloud.spanner.SpannerException)1 Type (com.google.cloud.spanner.Type)1 Value (com.google.cloud.spanner.Value)1 DeleteException (io.jans.orm.exception.operation.DeleteException)1 DuplicateEntryException (io.jans.orm.exception.operation.DuplicateEntryException)1 EntryNotFoundException (io.jans.orm.exception.operation.EntryNotFoundException)1 IncompatibleTypeException (io.jans.orm.exception.operation.IncompatibleTypeException)1 PersistenceException (io.jans.orm.exception.operation.PersistenceException)1 SearchException (io.jans.orm.exception.operation.SearchException)1 AttributeData (io.jans.orm.model.AttributeData)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Date (java.util.Date)1