@Alias("jsonArrayHandler") @MappedTypes({List.class}) @MappedJdbcTypes({JdbcType.VARCHAR, JdbcType.CLOB}) @Slf4j
public void register(Class<?> typeHandlerClass) { boolean mappedTypeFound = false; MappedTypes mappedTypes = typeHandlerClass.getAnnotation(MappedTypes.class); if (mappedTypes != null) { for (Class<?> javaTypeClass : mappedTypes.value()) { register(javaTypeClass, typeHandlerClass); mappedTypeFound = true; } } if (!mappedTypeFound) { register(getInstance(null, typeHandlerClass)); } }
@Alias("jsonMapHandler") @MappedTypes({Map.class}) @MappedJdbcTypes({JdbcType.VARCHAR, JdbcType.CLOB}) @Slf4j
public void register(Class<?> typeHandlerClass) { boolean mappedTypeFound = false; MappedTypes mappedTypes = typeHandlerClass.getAnnotation(MappedTypes.class); if (mappedTypes != null) { for (Class<?> javaTypeClass : mappedTypes.value()) { register(javaTypeClass, typeHandlerClass); mappedTypeFound = true; } } if (!mappedTypeFound) { register(getInstance(null, typeHandlerClass)); } }
@Alias("jsonSetHandler") @MappedTypes({Set.class}) @MappedJdbcTypes({JdbcType.VARCHAR, JdbcType.CLOB}) @Slf4j
@SuppressWarnings("unchecked") public <T> void register(TypeHandler<T> typeHandler) { boolean mappedTypeFound = false; MappedTypes mappedTypes = typeHandler.getClass().getAnnotation(MappedTypes.class); if (mappedTypes != null) { for (Class<?> handledType : mappedTypes.value()) { register(handledType, typeHandler); mappedTypeFound = true; } } // @since 3.1.0 - try to auto-discover the mapped type if (!mappedTypeFound && typeHandler instanceof TypeReference) { try { TypeReference<T> typeReference = (TypeReference<T>) typeHandler; register(typeReference.getRawType(), typeHandler); mappedTypeFound = true; } catch (Throwable t) { // maybe users define the TypeReference with a different type and are not assignable, so just ignore it } } if (!mappedTypeFound) { register((Class<T>) null, typeHandler); } }
/** * Map PostgreSQL array of boolean to java Boolean[] array. */ @MappedTypes(Boolean[].class) public class ArrayBooleanTypeHandler extends ArrayTypeHandler<Boolean[]> { private static final Boolean[] EMPTY = new Boolean[0]; @Override protected Boolean[] empty() { return EMPTY; } @Override protected String getDbTypeName(Connection connection) throws SQLException { // Now support only PostgreSQL types return "boolean"; } }
@SuppressWarnings("unchecked") public <T> void register(TypeHandler<T> typeHandler) { boolean mappedTypeFound = false; MappedTypes mappedTypes = typeHandler.getClass().getAnnotation(MappedTypes.class); if (mappedTypes != null) { for (Class<?> handledType : mappedTypes.value()) { register(handledType, typeHandler); mappedTypeFound = true; } } // @since 3.1.0 - try to auto-discover the mapped type if (!mappedTypeFound && typeHandler instanceof TypeReference) { try { TypeReference<T> typeReference = (TypeReference<T>) typeHandler; register(typeReference.getRawType(), typeHandler); mappedTypeFound = true; } catch (Throwable t) { // maybe users define the TypeReference with a different type and are not assignable, so just ignore it } } if (!mappedTypeFound) { register((Class<T>) null, typeHandler); } }
/** * Map PostgreSQL array of longs(int8) to java Long[] array. */ @MappedTypes(Long[].class) public class ArrayLongTypeHandler extends ArrayTypeHandler<Long[]> { private static final Long[] EMPTY = new Long[0]; @Override protected Long[] empty() { return EMPTY; } @Override protected String getDbTypeName(Connection connection) { // Now support only PostgreSQL types return "bigint"; } }
/** * Map PostgreSQL array of integers(int4) to java Integer[] array. */ @MappedTypes(Integer[].class) public class ArrayIntegerTypeHandler extends ArrayTypeHandler<Integer[]> { private static final Integer[] EMPTY = new Integer[0]; @Override protected Integer[] empty() { return EMPTY; } @Override protected String getDbTypeName(Connection connection) { // Now support only PostgreSQL types return "int4"; } }
/** * Map PostgreSQL array of doubles to java Double[] array. */ @MappedTypes(Double[].class) public class ArrayDoubleTypeHandler extends ArrayTypeHandler<Double[]> { private static final Double[] EMPTY = new Double[0]; @Override protected Double[] empty() { return EMPTY; } @Override protected String getDbTypeName(Connection connection) { // Now support only PostgreSQL types return "float8"; } }
/** * Multi dimensional array handler. * * PostgreSQL require that such arrays must be as matrix - all rows must have same amount of elements. */ @MappedTypes(String[][].class) public class ArrayString2dTypeHandler extends ArrayTypeHandler<String[][]> { private static final String[][] EMPTY = new String[0][0]; @Override protected String getDbTypeName(Connection connection) throws SQLException { String db = connection.getMetaData().getDatabaseProductName(); return ArrayStringTypeHandler.getTypeForDb(db); } @Override protected String[][] empty() { return EMPTY; } }
@MappedTypes(String[].class) public class ArrayStringTypeHandler extends ArrayTypeHandler<String[]> {
@MappedTypes(LocalTime.class) public class LocalTimeTypeHandler extends BaseTypeHandler<LocalTime> {
@MappedTypes(LocalDate.class) public class LocalDateTypeHandler extends BaseTypeHandler<LocalDate> {
@MappedTypes({JsonType.class, List.class, Map.class}) public class JsonTypeHandler extends BaseTypeHandler<Object> {
@MappedTypes(Instant.class) public class InstantTypeHandler extends BaseTypeHandler<Instant> {
@MappedTypes({ IId.class, IdFactory.IdString.class }) public class IdTypeHandler extends BaseTypeHandler<Object> {
@MappedTypes(LocalDateTime.class) public class LocalDateTimeTypeHandler extends BaseTypeHandler<LocalDateTime> {
@MappedTypes(LocalTime.class) public class LocalTimeTypeHandler implements TypeHandler