Search in sources :

Example 1 with LocalTimeConverter

use of org.sql2o.converters.joda.LocalTimeConverter 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());
    }
}
Also used : DateTime(org.joda.time.DateTime) LocalTime(org.joda.time.LocalTime) LocalDateConverter(org.sql2o.converters.joda.LocalDateConverter) LocalTimeConverter(org.sql2o.converters.joda.LocalTimeConverter) LocalDate(org.joda.time.LocalDate) DateTimeConverter(org.sql2o.converters.joda.DateTimeConverter)

Aggregations

DateTime (org.joda.time.DateTime)1 LocalDate (org.joda.time.LocalDate)1 LocalTime (org.joda.time.LocalTime)1 DateTimeConverter (org.sql2o.converters.joda.DateTimeConverter)1 LocalDateConverter (org.sql2o.converters.joda.LocalDateConverter)1 LocalTimeConverter (org.sql2o.converters.joda.LocalTimeConverter)1