use of com.google.cloud.spanner.Type.Code in project jans by JanssenProject.
the class SpannerOperationServiceImpl method removeMutationBuilderValue.
private void removeMutationBuilderValue(WriteBuilder mutation, AttributeData attribute, StructField attributeType) throws EntryConvertationException {
ValueBinder<WriteBuilder> valueBinder = mutation.set(attributeType.getName());
Code typeCode = attributeType.getType().getCode();
if (Code.BOOL == typeCode) {
valueBinder.to((Boolean) null);
} else if (Code.DATE == typeCode) {
valueBinder.to((com.google.cloud.Date) null);
} else if (Code.TIMESTAMP == typeCode) {
valueBinder.to((com.google.cloud.Timestamp) null);
} else if (Code.INT64 == typeCode) {
valueBinder.to((Long) null);
} else if (Code.NUMERIC == typeCode) {
valueBinder.to((BigDecimal) null);
} else if (Code.STRING == typeCode) {
valueBinder.to((String) null);
} else if (Code.ARRAY == typeCode) {
Code arrayCode = attributeType.getType().getArrayElementType().getCode();
if (Code.BOOL == arrayCode) {
valueBinder.toBoolArray((boolean[]) null);
} else if (Code.DATE == arrayCode) {
valueBinder.toDateArray((List<com.google.cloud.Date>) null);
} else if (Code.TIMESTAMP == arrayCode) {
valueBinder.toTimestampArray((List<com.google.cloud.Timestamp>) null);
} else if (Code.INT64 == arrayCode) {
valueBinder.toInt64Array((long[]) null);
} else if (Code.NUMERIC == arrayCode) {
valueBinder.toNumericArray((List<BigDecimal>) null);
} else if (Code.STRING == arrayCode) {
valueBinder.toStringArray((List<String>) null);
}
} else {
throw new EntryConvertationException(String.format("Array column with name '%s' does not contain supported type '%s'", attribute.getName(), attributeType));
}
}
use of com.google.cloud.spanner.Type.Code in project jans by JanssenProject.
the class SpannerFilterConverter method isMultiValue.
protected Boolean isMultiValue(TableMapping tableMapping, String attributeName, Filter currentGenericFilter, Map<String, PropertyAnnotation> propertiesAnnotationsMap) throws SearchException {
StructField structField = getStructField(tableMapping, attributeName);
boolean hasChildTableForAttribute = tableMapping.hasChildTableForAttribute(attributeName.toLowerCase());
Code columnTypeCode = structField.getType().getCode();
if ((Code.ARRAY == columnTypeCode) || hasChildTableForAttribute) {
boolean multiValuedDetected = (Boolean.TRUE.equals(currentGenericFilter.getMultiValued()) || Boolean.TRUE.equals(determineMultiValuedByType(currentGenericFilter.getAttributeName(), propertiesAnnotationsMap)));
if (!multiValuedDetected) {
LOG.warn(String.format("Сolumn name '%s' was defined as multi valued in table/child table '%s' but detected as single value", attributeName, tableMapping.getTableName()));
}
return true;
}
return false;
}
use of com.google.cloud.spanner.Type.Code in project java-spanner-jdbc by googleapis.
the class JdbcResultSet method getTimestamp.
@Override
public Timestamp getTimestamp(int columnIndex) throws SQLException {
checkClosedAndValidRow();
boolean isNull = isNull(columnIndex);
int spannerIndex = columnIndex - 1;
Code type = spanner.getColumnType(spannerIndex).getCode();
switch(type) {
case DATE:
return isNull ? null : JdbcTypeConverter.toSqlTimestamp(spanner.getDate(spannerIndex));
case STRING:
return isNull ? null : parseTimestamp(spanner.getString(spannerIndex));
case TIMESTAMP:
return isNull ? null : JdbcTypeConverter.toSqlTimestamp(spanner.getTimestamp(spannerIndex));
case BOOL:
case FLOAT64:
case INT64:
case NUMERIC:
case PG_NUMERIC:
case BYTES:
case JSON:
case STRUCT:
case ARRAY:
default:
throw createInvalidToGetAs("timestamp", 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) throws SQLException {
checkClosedAndValidRow();
boolean isNull = isNull(columnIndex);
int spannerIndex = columnIndex - 1;
Code type = spanner.getColumnType(spannerIndex).getCode();
switch(type) {
case DATE:
return isNull ? null : JdbcTypeConverter.toSqlDate(spanner.getDate(spannerIndex));
case STRING:
return isNull ? null : parseDate(spanner.getString(spannerIndex));
case TIMESTAMP:
return isNull ? null : new Date(spanner.getTimestamp(spannerIndex).toSqlTimestamp().getTime());
case BOOL:
case FLOAT64:
case INT64:
case NUMERIC:
case PG_NUMERIC:
case BYTES:
case JSON:
case STRUCT:
case ARRAY:
default:
throw createInvalidToGetAs("date", type);
}
}
use of com.google.cloud.spanner.Type.Code in project java-spanner-jdbc by googleapis.
the class JdbcResultSet method getBoolean.
@Override
public boolean getBoolean(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 && spanner.getBoolean(spannerIndex);
case FLOAT64:
return !isNull && spanner.getDouble(spannerIndex) != 0D;
case INT64:
return !isNull && spanner.getLong(spannerIndex) != 0L;
case NUMERIC:
return !isNull && !spanner.getBigDecimal(spannerIndex).equals(BigDecimal.ZERO);
case PG_NUMERIC:
return !isNull && !spanner.getString(spannerIndex).equals("0");
case STRING:
return !isNull && Boolean.parseBoolean(spanner.getString(spannerIndex));
case BYTES:
case JSON:
case DATE:
case STRUCT:
case TIMESTAMP:
case ARRAY:
default:
throw createInvalidToGetAs("boolean", type);
}
}
Aggregations