use of org.sql2o.converters.joda.DateTimeConverter in project sql2o by aaberg.
the class Convert method fillDefaults.
private static void fillDefaults(Map<Class<?>, Converter<?>> mapToFill) {
mapToFill.put(Integer.class, new IntegerConverter(false));
mapToFill.put(int.class, new IntegerConverter(true));
mapToFill.put(Double.class, new DoubleConverter(false));
mapToFill.put(double.class, new DoubleConverter(true));
mapToFill.put(Float.class, new FloatConverter(false));
mapToFill.put(float.class, new FloatConverter(true));
mapToFill.put(Long.class, new LongConverter(false));
mapToFill.put(long.class, new LongConverter(true));
mapToFill.put(Short.class, new ShortConverter(false));
mapToFill.put(short.class, new ShortConverter(true));
mapToFill.put(Byte.class, new ByteConverter(false));
mapToFill.put(byte.class, new ByteConverter(true));
mapToFill.put(BigDecimal.class, new BigDecimalConverter());
mapToFill.put(String.class, new StringConverter());
mapToFill.put(java.util.Date.class, DateConverter.instance);
mapToFill.put(java.sql.Date.class, new AbstractDateConverter<java.sql.Date>(java.sql.Date.class) {
@Override
protected java.sql.Date fromMilliseconds(long millisecond) {
return new java.sql.Date(millisecond);
}
});
mapToFill.put(java.sql.Time.class, new AbstractDateConverter<java.sql.Time>(java.sql.Time.class) {
@Override
protected java.sql.Time fromMilliseconds(long millisecond) {
return new java.sql.Time(millisecond);
}
});
mapToFill.put(java.sql.Timestamp.class, new AbstractDateConverter<java.sql.Timestamp>(java.sql.Timestamp.class) {
@Override
protected java.sql.Timestamp fromMilliseconds(long millisecond) {
return new java.sql.Timestamp(millisecond);
}
});
BooleanConverter booleanConverter = new BooleanConverter();
mapToFill.put(Boolean.class, booleanConverter);
mapToFill.put(boolean.class, booleanConverter);
ByteArrayConverter byteArrayConverter = new ByteArrayConverter();
// it's impossible to cast Byte[].class <-> byte[].class
// and I'm too lazy to implement converter for Byte[].class
// since it's really doesn't wide-used
// otherwise someone already detect this error
// mapToFill.put(Byte[].class, byteArrayConverter);
mapToFill.put(byte[].class, byteArrayConverter);
InputStreamConverter inputStreamConverter = new InputStreamConverter();
mapToFill.put(InputStream.class, inputStreamConverter);
mapToFill.put(ByteArrayInputStream.class, inputStreamConverter);
mapToFill.put(UUID.class, new UUIDConverter());
if (FeatureDetector.isJodaTimeAvailable()) {
mapToFill.put(DateTime.class, new DateTimeConverter());
mapToFill.put(LocalTime.class, new LocalTimeConverter());
mapToFill.put(LocalDate.class, new LocalDateConverter());
}
}
use of org.sql2o.converters.joda.DateTimeConverter in project sql2o by aaberg.
the class H2Tests method testIssue155.
@Test
public void testIssue155() {
Sql2o sql2o = new Sql2o(ds, new NoQuirks(new HashMap<Class, Converter>() {
{
put(DateTime.class, new DateTimeConverter(DateTimeZone.getDefault()));
}
}));
assertThat(sql2o.getQuirks(), is(instanceOf(NoQuirks.class)));
try (Connection connection = sql2o.open()) {
int val = connection.createQuery("select 42").executeScalar(Integer.class);
assertThat(val, is(equalTo(42)));
}
}
Aggregations