@Test public void testTimestampPrecision() { Timestamp value = new Timestamp(1234); value.setNanos(56789); Timestamp corrected = (Timestamp)ODataTypeManager.rationalizePrecision(0, null, value); assertEquals(0, corrected.getNanos()); corrected = (Timestamp)ODataTypeManager.rationalizePrecision(5, null, value); assertEquals(50000, corrected.getNanos()); corrected = (Timestamp)ODataTypeManager.rationalizePrecision(8, null, value); assertEquals(56780, corrected.getNanos()); }
public static Object rationalizePrecision(Integer precision, Integer scale, Object value) { if (precision == null) { return value; } if (value instanceof BigDecimal) { BigDecimal bigDecimalValue = (BigDecimal)value; final int digits = bigDecimalValue.scale() >= 0 ? Math.max(bigDecimalValue.precision(), bigDecimalValue.scale()) : bigDecimalValue.precision() - bigDecimalValue.scale(); if (bigDecimalValue.scale() > (scale == null ? 0 : scale) || (digits > precision)) { BigDecimal newBigDecimal = bigDecimalValue.setScale(Math.min(digits > precision ? bigDecimalValue.scale() - digits + precision : bigDecimalValue.scale(), scale == null ? 0 : scale), RoundingMode.HALF_UP); if (newBigDecimal.compareTo(bigDecimalValue) == 0) { bigDecimalValue = newBigDecimal; } } return bigDecimalValue; } else if (value instanceof Timestamp) { if (precision < 9) { Timestamp timestamp = (Timestamp)value; int nanos = timestamp.getNanos(); long mask = (long)Math.pow(10, 9-precision); long adjusted = (nanos / mask) * mask; if (adjusted != nanos) { Timestamp result = new Timestamp(timestamp.getTime()); result.setNanos((int)adjusted); return result; } } } return value; }
ODataTypeManager { public static Object rationalizePrecision(Integer precision, Integer scale, Object value) { if (precision == null) { return value; } if (value instanceof BigDecimal) { BigDecimal bigDecimalValue = (BigDecimal)value; final int digits = bigDecimalValue.scale() >= 0 ? Math.max(bigDecimalValue.precision(), bigDecimalValue.scale()) : bigDecimalValue.precision() - bigDecimalValue.scale(); if (bigDecimalValue.scale() > (scale == null ? 0 : scale) || (digits > precision)) { BigDecimal newBigDecimal = bigDecimalValue.setScale(Math.min(digits > precision ? bigDecimalValue.scale() - digits + precision : bigDecimalValue.scale(), scale == null ? 0 : scale), RoundingMode.HALF_UP); if (newBigDecimal.compareTo(bigDecimalValue) == 0) { bigDecimalValue = newBigDecimal; } } return bigDecimalValue; } else if (value instanceof Timestamp) { if (precision < 9) { Timestamp timestamp = (Timestamp)value; int nanos = timestamp.getNanos(); long mask = (long)Math.pow(10, 9-precision); long adjusted = (nanos / mask) * mask; if (adjusted != nanos) { Timestamp result = new Timestamp(timestamp.getTime()); result.setNanos((int)adjusted); return result; } } } return value; } }
ODataTypeManager { public static Object rationalizePrecision(Integer precision, Integer scale, Object value) { if (precision == null) { return value; } if (value instanceof BigDecimal) { BigDecimal bigDecimalValue = (BigDecimal)value; final int digits = bigDecimalValue.scale() >= 0 ? Math.max(bigDecimalValue.precision(), bigDecimalValue.scale()) : bigDecimalValue.precision() - bigDecimalValue.scale(); if (bigDecimalValue.scale() > (scale == null ? 0 : scale) || (digits > precision)) { BigDecimal newBigDecimal = bigDecimalValue.setScale(Math.min(digits > precision ? bigDecimalValue.scale() - digits + precision : bigDecimalValue.scale(), scale == null ? 0 : scale), RoundingMode.HALF_UP); if (newBigDecimal.compareTo(bigDecimalValue) == 0) { bigDecimalValue = newBigDecimal; } } return bigDecimalValue; } else if (value instanceof Timestamp) { if (precision < 9) { Timestamp timestamp = (Timestamp)value; int nanos = timestamp.getNanos(); long mask = (long)Math.pow(10, 9-precision); long adjusted = (nanos / mask) * mask; if (adjusted != nanos) { Timestamp result = new Timestamp(timestamp.getTime()); result.setNanos((int)adjusted); return result; } } } return value; }  }
ODataTypeManager { public static Object rationalizePrecision(Integer precision, Integer scale, Object value) { if (precision == null) { return value; } if (value instanceof BigDecimal) { BigDecimal bigDecimalValue = (BigDecimal)value; final int digits = bigDecimalValue.scale() >= 0 ? Math.max(bigDecimalValue.precision(), bigDecimalValue.scale()) : bigDecimalValue.precision() - bigDecimalValue.scale(); if (bigDecimalValue.scale() > (scale == null ? 0 : scale) || (digits > precision)) { BigDecimal newBigDecimal = bigDecimalValue.setScale(Math.min(digits > precision ? bigDecimalValue.scale() - digits + precision : bigDecimalValue.scale(), scale == null ? 0 : scale), RoundingMode.HALF_UP); if (newBigDecimal.compareTo(bigDecimalValue) == 0) { bigDecimalValue = newBigDecimal; } } return bigDecimalValue; } else if (value instanceof Timestamp) { if (precision < 9) { Timestamp timestamp = (Timestamp)value; int nanos = timestamp.getNanos(); long mask = (long)Math.pow(10, 9-precision); long adjusted = (nanos / mask) * mask; if (adjusted != nanos) { Timestamp result = new Timestamp(timestamp.getTime()); result.setNanos((int)adjusted); return result; } } } return value; }  static String teiidType(SingletonPrimitiveType odataType, boolean array); static String teiidType(String odataType, boolean array); static EdmPrimitiveTypeKind odataType(Class<?> teiidRuntimeTypeClass); static EdmPrimitiveTypeKind odataType(BaseColumn c); static EdmPrimitiveTypeKind odataType(String teiidRuntimeType); static Object convertToTeiidRuntimeType(Class<?> type, Object value, String odataType, String srid); static Object convertByteArrayToTeiidRuntimeType(final Class<?> type, final byte[] contents,
            final String odataType, String srid); static Object parseLiteral(EdmParameter edmParameter, Class<?> runtimeType, String value); static Object parseLiteral(EdmProperty edmProperty, Class<?> runtimeType, String value); static Object parseLiteral(String odataType, String value); static Object rationalizePrecision(Integer precision, Integer scale, Object value); static Geospatial convertToODataValue(InputStream wkb, boolean includesSrid); static String convertToODataURIValue(Object val, String odataType); }
ODataTypeManager { public static Object rationalizePrecision(Integer precision, Integer scale, Object value) { if (precision == null) { return value; } if (value instanceof BigDecimal) { BigDecimal bigDecimalValue = (BigDecimal)value; final int digits = bigDecimalValue.scale() >= 0 ? Math.max(bigDecimalValue.precision(), bigDecimalValue.scale()) : bigDecimalValue.precision() - bigDecimalValue.scale(); if (bigDecimalValue.scale() > (scale == null ? 0 : scale) || (digits > precision)) { BigDecimal newBigDecimal = bigDecimalValue.setScale(Math.min(digits > precision ? bigDecimalValue.scale() - digits + precision : bigDecimalValue.scale(), scale == null ? 0 : scale), RoundingMode.HALF_UP); if (newBigDecimal.compareTo(bigDecimalValue) == 0) { bigDecimalValue = newBigDecimal; } } return bigDecimalValue; } else if (value instanceof Timestamp) { if (precision < 9) { Timestamp timestamp = (Timestamp)value; int nanos = timestamp.getNanos(); long mask = (long)Math.pow(10, 9-precision); long adjusted = (nanos / mask) * mask; if (adjusted != nanos) { Timestamp result = new Timestamp(timestamp.getTime()); result.setNanos((int)adjusted); return result; } } } return value; }  static String teiidType(SingletonPrimitiveType odataType, boolean array); static String teiidType(String odataType, boolean array); static EdmPrimitiveTypeKind odataType(Class<?> teiidRuntimeTypeClass); static EdmPrimitiveTypeKind odataType(BaseColumn c); static EdmPrimitiveTypeKind odataType(String teiidRuntimeType); static Object convertToTeiidRuntimeType(Class<?> type, Object value, String odataType, String srid); static Object convertByteArrayToTeiidRuntimeType(final Class<?> type, final byte[] contents,
            final String odataType, String srid); static Object parseLiteral(EdmParameter edmParameter, Class<?> runtimeType, String value); static Object parseLiteral(EdmProperty edmProperty, Class<?> runtimeType, String value); static Object parseLiteral(String odataType, String value); static Object rationalizePrecision(Integer precision, Integer scale, Object value); static Geospatial convertToODataValue(InputStream wkb, boolean includesSrid); static String convertToODataURIValue(Object val, String odataType);  }