public FieldMapperColumnDefinition<K> addGetter(Getter<?, ?> getter) { return add(new GetterProperty(getter)); } public FieldMapperColumnDefinition<K> addGetterFactory(GetterFactory<?, K> getterFactory) {
public FieldMapperColumnDefinition<K> addGetter(Getter<?, ?> getter) { return add(new GetterProperty(getter)); } public FieldMapperColumnDefinition<K> addGetterFactory(GetterFactory<?, K> getterFactory) {
public FieldMapperColumnDefinition<K> addGetterFactory(GetterFactory<?, K> getterFactory) { return add(new GetterFactoryProperty(getterFactory)); } public FieldMapperColumnDefinition<K> addFieldMapper(FieldMapper<?, ?> mapper){
public FieldMapperColumnDefinition<K> addGetterFactory(GetterFactory<?, K> getterFactory) { return add(new GetterFactoryProperty(getterFactory)); } public FieldMapperColumnDefinition<K> addFieldMapper(FieldMapper<?, ?> mapper){
public FieldMapperColumnDefinition<K> addFieldMapper(FieldMapper<?, ?> mapper){ return add(new FieldMapperProperty(mapper)); }
public FieldMapperColumnDefinition<K> addFieldMapper(FieldMapper<?, ?> mapper){ return add(new FieldMapperProperty(mapper)); }
public B addColumn(K key, Object... properties) { return addColumn(key, FieldMapperColumnDefinition.<K>identity().add(properties)); }
public B addColumn(K key, Object... properties) { return addColumn(key, FieldMapperColumnDefinition.<K>identity().add(properties)); }
/** * Create a new DSL object identical to the current one but with the specified property added. * @param column the property name * @param property the property properties * @return the new DSL */ @SuppressWarnings("unchecked") public CsvWriterDSL<T> column(String column, Object... property) { Column[] newColumns = Arrays.copyOf(columns, columns.length + 1); FieldMapperColumnDefinition<CsvColumnKey> columnDefinition = FieldMapperColumnDefinition.<CsvColumnKey>identity().add(property); newColumns[columns.length] = new Column(column, columnDefinition); return newColumnMapDSL(classMeta, newColumns, mapperConfig, cellWriter, skipHeaders); }
/** * Create a new DSL object identical to the current one but with the specified property added. * @param column the property name * @param property the property properties * @return the new DSL */ @SuppressWarnings("unchecked") public CsvWriterDSL<T> column(String column, Object... property) { Column[] newColumns = Arrays.copyOf(columns, columns.length + 1); FieldMapperColumnDefinition<CsvColumnKey> columnDefinition = FieldMapperColumnDefinition.<CsvColumnKey>identity().add(property); newColumns[columns.length] = new Column(column, columnDefinition); return newColumnMapDSL(classMeta, newColumns, mapperConfig, cellWriter, skipHeaders); }
/** * Create a new DSL object identical to the current one but with the specified property instead of the default ones. * @param column the property name * @param property the property properties * @return the new DSL */ @SuppressWarnings("unchecked") public CsvWriterDSL<T> column(String column, Object... property) { Column[] newColumns = new Column[1]; FieldMapperColumnDefinition<CsvColumnKey> columnDefinition = FieldMapperColumnDefinition.<CsvColumnKey>identity().add(property); newColumns[0] = new Column(column, columnDefinition); return newColumnMapDSL(classMeta, newColumns, mapperConfig, cellWriter, skipHeaders); }
/** * Create a new DSL object identical to the current one but with the specified property instead of the default ones. * @param column the property name * @param property the property properties * @return the new DSL */ @SuppressWarnings("unchecked") public CsvWriterDSL<T> column(String column, Object... property) { Column[] newColumns = new Column[1]; FieldMapperColumnDefinition<CsvColumnKey> columnDefinition = FieldMapperColumnDefinition.<CsvColumnKey>identity().add(property); newColumns[0] = new Column(column, columnDefinition); return newColumnMapDSL(classMeta, newColumns, mapperConfig, cellWriter, skipHeaders); }
@Override public FieldMapperColumnDefinition<SampleFieldKey> getColumnDefinition(SampleFieldKey key) { if (key.getName().equals("email")) { return FieldMapperColumnDefinition.<SampleFieldKey>identity().add(MandatoryProperty.class); } return FieldMapperColumnDefinition.<SampleFieldKey>identity(); }
private MapperConfig<SampleFieldKey, Object[]> mapperConfig() { FieldMapperColumnDefinitionProviderImpl<SampleFieldKey> provider = new FieldMapperColumnDefinitionProviderImpl<SampleFieldKey>(); provider.addColumnDefinition("benchmark", FieldMapperColumnDefinition.<SampleFieldKey>identity().add(new SetterProperty(SETTER)).add(new GetterProperty(GETTER))); return MapperConfig.<SampleFieldKey, Object[]>fieldMapperConfig().columnDefinitions(provider); } }
@Test public void testBigInteger() throws Exception { BigDecimal bg = new BigDecimal("314"); when(resultSet.getBigDecimal(1)).thenReturn(bg); Getter<ResultSet, BigInteger> getter = factory.newGetter(BigInteger.class, key(Types.DECIMAL), IDENTITY.properties()); assertEquals(bg.toBigInteger(), getter.get(resultSet)); reset(resultSet); when(resultSet.getBigDecimal(1)).thenReturn(null); assertNull(getter.get(resultSet)); reset(resultSet); getter = factory.newGetter(BigInteger.class, key(Types.VARCHAR), IDENTITY.properties()); when(resultSet.getString(1)).thenReturn("314"); assertEquals(bg.toBigInteger(), getter.get(resultSet)); reset(resultSet); when(resultSet.getString(1)).thenReturn(null); assertNull(getter.get(resultSet)); reset(resultSet); getter = factory.newGetter(BigInteger.class, key(Types.DECIMAL), IDENTITY.add(SqlTypeColumnProperty.of(Types.VARCHAR)).properties()); when(resultSet.getString(1)).thenReturn("314"); assertEquals(bg.toBigInteger(), getter.get(resultSet)); reset(resultSet); when(resultSet.getString(1)).thenReturn(null); assertNull(getter.get(resultSet)); }
@Test public void testBigDecimal() throws Exception { BigDecimal bg = new BigDecimal("3.14"); when(resultSet.getBigDecimal(1)).thenReturn(bg); Getter<ResultSet, BigDecimal> getter = factory.newGetter(BigDecimal.class, key(Types.DECIMAL), IDENTITY.properties()); assertEquals(bg, getter.get(resultSet)); reset(resultSet); when(resultSet.getBigDecimal(1)).thenReturn(null); assertNull(getter.get(resultSet)); reset(resultSet); getter = factory.newGetter(BigDecimal.class, key(Types.VARCHAR), IDENTITY.properties()); when(resultSet.getString(1)).thenReturn("3.14"); assertEquals(bg, getter.get(resultSet)); reset(resultSet); when(resultSet.getString(1)).thenReturn(null); assertNull(getter.get(resultSet)); reset(resultSet); getter = factory.newGetter(BigDecimal.class, key(Types.DECIMAL), IDENTITY.add(SqlTypeColumnProperty.of(Types.VARCHAR)).properties()); when(resultSet.getString(1)).thenReturn("3.14"); assertEquals(bg, getter.get(resultSet)); reset(resultSet); when(resultSet.getString(1)).thenReturn(null); assertNull(getter.get(resultSet)); }
@Test public void testColumnDefinition() { MapperFactory mapperFactory = new MapperFactory(); Object prop1 = new Object(); Object prop2 = new Object(); mapperFactory.addColumnDefinition("mykey", FieldMapperColumnDefinition.<SampleFieldKey>identity().add(prop1)); Assert.assertArrayEquals(new Object[] {prop1}, mapperFactory.columnDefinitions().getColumnDefinition(new SampleFieldKey("mykey", 0)).properties()); mapperFactory.addColumnDefinition(new Predicate<SampleFieldKey>() { @Override public boolean test(SampleFieldKey sampleFieldKey) { return sampleFieldKey.getIndex() < 1; } }, FieldMapperColumnDefinition.<SampleFieldKey>identity().add(prop2)); Assert.assertArrayEquals(new Object[] {prop2, prop1}, mapperFactory.columnDefinitions().getColumnDefinition(new SampleFieldKey("mykey", 0)).properties()); Assert.assertArrayEquals(new Object[] {prop1}, mapperFactory.columnDefinitions().getColumnDefinition(new SampleFieldKey("mykey", 1)).properties()); }
@Test public void test576OptionalProperty() { final ClassMeta<DbObject> classMeta = ReflectionService.newInstance().getClassMeta(DbObject.class); PropertyMappingsBuilder<DbObject, SampleFieldKey> builder = PropertyMappingsBuilder.of( classMeta, MapperConfig.<SampleFieldKey, Object[]>fieldMapperConfig(), CONSTANT_PREDICATE); FieldMapperColumnDefinition<SampleFieldKey> columnDefinition = FieldMapperColumnDefinition.<SampleFieldKey>identity().add(OptionalProperty.INSTANCE); PropertyMapping<DbObject, Object, SampleFieldKey> pName = builder.addProperty(new SampleFieldKey("name", 0), columnDefinition); assertEquals("name", pName.getPropertyMeta().getPath()); PropertyMapping<DbObject, Object, SampleFieldKey> pNotThere = builder.addProperty(new SampleFieldKey("not_there", 0), columnDefinition); assertNull(pNotThere); builder = PropertyMappingsBuilder.of( classMeta, MapperConfig.<SampleFieldKey, Object[]>fieldMapperConfig(), CONSTANT_PREDICATE); PropertyMapping<DbObject, Object, SampleFieldKey> pNotThere1 = builder.addProperty(new SampleFieldKey("not_there", 0), columnDefinition); assertEquals("{this}", pNotThere1.getPropertyMeta().getPath()); PropertyMapping<DbObject, Object, SampleFieldKey> pName1 = builder.addProperty(new SampleFieldKey("name", 0), columnDefinition); assertEquals("name", pName1.getPropertyMeta().getPath()); assertNull(builder.currentProperties().get(0)); }