/** * Return a ConstructorMapper using the given constructor * * @param <T> the type to map * @param constructor the constructor to be used in mapping * @return the mapper */ public static <T> RowMapper<T> of(Constructor<T> constructor) { return ConstructorMapper.of(constructor, DEFAULT_PREFIX); }
/** * Return a ConstructorMapper for the given type. * * @param <T> the type to map * @param type the mapped type * @return the mapper */ public static <T> RowMapper<T> of(Class<T> type) { return ConstructorMapper.of(type, DEFAULT_PREFIX); }
/** * Use the only declared constructor to map a class. * * @param clazz the class to find a constructor of * @param prefix a prefix for the parameter names * @return the factory */ public static RowMapperFactory factory(Class<?> clazz, String prefix) { return RowMapperFactory.of(clazz, ConstructorMapper.of(clazz, prefix)); }
/** * Use a {@code Constructor<T>} to map its declaring type. * * @param constructor the constructor to invoke * @return the factory */ public static RowMapperFactory factory(Constructor<?> constructor) { return RowMapperFactory.of(constructor.getDeclaringClass(), ConstructorMapper.of(constructor)); }
/** * Use the only declared constructor to map a class. * * @param clazz the class to find a constructor of * @return the factory */ public static RowMapperFactory factory(Class<?> clazz) { return RowMapperFactory.of(clazz, ConstructorMapper.of(clazz)); }
/** * Use a {@code Constructor<T>} to map its declaring type. * * @param constructor the constructor to invoke * @param prefix a prefix to the constructor parameter names * @return the factory */ public static RowMapperFactory factory(Constructor<?> constructor, String prefix) { return RowMapperFactory.of(constructor.getDeclaringClass(), ConstructorMapper.of(constructor, prefix)); }
@Test public void testMapOptional() { final Handle h = db.getSharedHandle(); h.execute("insert into something(intValue, name) values(1, 'Duke')"); h.execute("insert into something(intValue, name) values(null, null)"); assertThat(h.createQuery("select * from something order by id") .map(ConstructorMapper.of(OptionalBean.class)) .list()) .extracting("intValue", "name") .containsExactly( tuple(OptionalInt.of(1), Optional.of("Duke")), tuple(OptionalInt.empty(), Optional.empty())); }
/** * Return a ConstructorMapper using the given constructor * * @param <T> the type to map * @param constructor the constructor to be used in mapping * @return the mapper */ public static <T> RowMapper<T> of(Constructor<T> constructor) { return ConstructorMapper.of(constructor, DEFAULT_PREFIX); }
/** * Return a ConstructorMapper for the given type. * * @param <T> the type to map * @param type the mapped type * @return the mapper */ public static <T> RowMapper<T> of(Class<T> type) { return ConstructorMapper.of(findConstructorFor(type)); }
/** * Return a ConstructorMapper for the given type and prefix. * * @param <T> the type to map * @param type the mapped type * @param prefix the column name prefix * @return the mapper */ public static <T> RowMapper<T> of(Class<T> type, String prefix) { return ConstructorMapper.of(findConstructorFor(type), prefix); }
/** * Use a {@code Constructor<T>} to map its declaring type. * * @param constructor the constructor to invoke * @return the factory */ public static RowMapperFactory factory(Constructor<?> constructor) { return RowMapperFactory.of(constructor.getDeclaringClass(), ConstructorMapper.of(constructor)); }
/** * Use the only declared constructor to map a class. * * @param clazz the class to find a constructor of * @return the factory */ public static RowMapperFactory factory(Class<?> clazz) { return RowMapperFactory.of(clazz, ConstructorMapper.of(clazz)); }
/** * Use the only declared constructor to map a class. * * @param clazz the class to find a constructor of * @param prefix a prefix for the parameter names * @return the factory */ public static RowMapperFactory factory(Class<?> clazz, String prefix) { return RowMapperFactory.of(clazz, ConstructorMapper.of(clazz, prefix)); }
/** * Use a {@code Constructor<T>} to map its declaring type. * * @param constructor the constructor to invoke * @param prefix a prefix to the constructor parameter names * @return the factory */ public static RowMapperFactory factory(Constructor<?> constructor, String prefix) { return RowMapperFactory.of(constructor.getDeclaringClass(), ConstructorMapper.of(constructor, prefix)); }