@Test public void getUnconvertedValueReturnsArrayOfStructureBeansWhenDestinationTypeIsArray() { tableMapping = new TableMapping(TestStructureBean[].class, TestStructureBean.class, "sapName", "javaName", structureMapping, null); List<Map<String, Integer>> tableMap = new ArrayList<>(); tableMap.add(singletonMap("sapField", 1)); tableMap.add(singletonMap("sapField", 2)); Object value = tableMapping.getUnconvertedValueToJava(tableMap, new ConverterCache()); assertThat(value).isInstanceOf(TestStructureBean[].class); TestStructureBean[] structureBeans = (TestStructureBean[]) value; assertThat(structureBeans).hasSize(2); assertThat(structureBeans[0].javaField).isEqualTo(1); assertThat(structureBeans[1].javaField).isEqualTo(2); }
@Override public Object getUnconvertedValueToJava(final Object fieldMapCollection, final ConverterCache converterCache) { if (!hasConverter()) { @SuppressWarnings({"unchecked"}) Class<? extends Collection<Object>> destinationType = (Class<? extends Collection<Object>>) getDestinationType(); Collection<Object> collection = newCollectionInstance(destinationType); Collection<Map<String, Object>> rows; if (fieldMapCollection instanceof ResultSet) { try { rows = resultSetToArrayList((ResultSet) fieldMapCollection); } catch (SQLException e) { throw new InternalHiberSapException("Could not convert ResultSet"); } } else { rows = castToCollectionOfMaps(fieldMapCollection); } if (rows != null) { for (Map<String, Object> tableMap : rows) { Object elementBean = getComponentParameter().mapToJava(tableMap, converterCache); collection.add(elementBean); } } if (getFieldType().isArray()) { return ReflectionHelper.newArrayFromCollection(collection, getAssociatedType()); } else { return collection; } } else { throw new InternalHiberSapException( "This method should only be called by the framework " + "when the corresponding table field has a converter attached" ); } }
TableMapping extends ParameterMapping { @Override public Object getUnconvertedValueToJava(final Object fieldMapCollection, final ConverterCache converterCache) { if (!hasConverter()) { @SuppressWarnings({"unchecked"}) Class<? extends Collection<Object>> destinationType = (Class<? extends Collection<Object>>) getDestinationType(); Collection<Object> collection = newCollectionInstance(destinationType); Collection<Map<String, Object>> rows; if (fieldMapCollection instanceof ResultSet) { try { rows = resultSetToArrayList((ResultSet) fieldMapCollection); } catch (SQLException e) { throw new InternalHiberSapException("Could not convert ResultSet"); } } else { rows = castToCollectionOfMaps(fieldMapCollection); } if (rows != null) { for (Map<String, Object> tableMap : rows) { Object elementBean = getComponentParameter().mapToJava(tableMap, converterCache); collection.add(elementBean); } } if (getFieldType().isArray()) { return ReflectionHelper.newArrayFromCollection(collection, getAssociatedType()); } else { return collection; } } else { throw new InternalHiberSapException( "This method should only be called by the framework " + "when the corresponding table field has a converter attached" ); } } }
TableMapping extends ParameterMapping { @Override public Object getUnconvertedValueToJava(final Object fieldMapCollection, final ConverterCache converterCache) { if (!hasConverter()) { @SuppressWarnings({"unchecked"}) Class<? extends Collection<Object>> destinationType = (Class<? extends Collection<Object>>) getDestinationType(); Collection<Object> collection = newCollectionInstance(destinationType); Collection<Map<String, Object>> rows; if (fieldMapCollection instanceof ResultSet) { try { rows = resultSetToArrayList((ResultSet) fieldMapCollection); } catch (SQLException e) { throw new InternalHiberSapException("Could not convert ResultSet"); } } else { rows = castToCollectionOfMaps(fieldMapCollection); } if (rows != null) { for (Map<String, Object> tableMap : rows) { Object elementBean = getComponentParameter().mapToJava(tableMap, converterCache); collection.add(elementBean); } } if (getFieldType().isArray()) { return ReflectionHelper.newArrayFromCollection(collection, getAssociatedType()); } else { return collection; } } else { throw new InternalHiberSapException( "This method should only be called by the framework " + "when the corresponding table field has a converter attached" ); } } TableMapping(final Class<?> fieldType,
                        final Class<?> associatedType,
                        final String sapName,
                        final String javaName,
                        final StructureMapping componentParameter,
                        final Class<? extends Converter<?, ?>> converterClass); }
TableMapping extends ParameterMapping { @Override public Object getUnconvertedValueToJava(final Object fieldMapCollection, final ConverterCache converterCache) { if (!hasConverter()) { @SuppressWarnings({"unchecked"}) Class<? extends Collection<Object>> destinationType = (Class<? extends Collection<Object>>) getDestinationType(); Collection<Object> collection = newCollectionInstance(destinationType); Collection<Map<String, Object>> rows; if (fieldMapCollection instanceof ResultSet) { try { rows = resultSetToArrayList((ResultSet) fieldMapCollection); } catch (SQLException e) { throw new InternalHiberSapException("Could not convert ResultSet"); } } else { rows = castToCollectionOfMaps(fieldMapCollection); } if (rows != null) { for (Map<String, Object> tableMap : rows) { Object elementBean = getComponentParameter().mapToJava(tableMap, converterCache); collection.add(elementBean); } } if (getFieldType().isArray()) { return ReflectionHelper.newArrayFromCollection(collection, getAssociatedType()); } else { return collection; } } else { throw new InternalHiberSapException( "This method should only be called by the framework " + "when the corresponding table field has a converter attached" ); } } TableMapping(final Class<?> fieldType,
                        final Class<?> associatedType,
                        final String sapName,
                        final String javaName,
                        final StructureMapping componentParameter,
                        final Class<? extends Converter<?, ?>> converterClass); Class<?> getDestinationType(); StructureMapping getComponentParameter(); Class<?> getFieldType(); @Override ParamType getParamType(); @Override Object getUnconvertedValueToJava(final Object fieldMapCollection, final ConverterCache converterCache); @Override @Generated("") boolean equals(final Object o); @Override @Generated("") int hashCode(); }
TableMapping extends ParameterMapping { @Override public Object getUnconvertedValueToJava(final Object fieldMapCollection, final ConverterCache converterCache) { if (!hasConverter()) { @SuppressWarnings({"unchecked"}) Class<? extends Collection<Object>> destinationType = (Class<? extends Collection<Object>>) getDestinationType(); Collection<Object> collection = newCollectionInstance(destinationType); Collection<Map<String, Object>> rows; if (fieldMapCollection instanceof ResultSet) { try { rows = resultSetToArrayList((ResultSet) fieldMapCollection); } catch (SQLException e) { throw new InternalHiberSapException("Could not convert ResultSet"); } } else { rows = castToCollectionOfMaps(fieldMapCollection); } if (rows != null) { for (Map<String, Object> tableMap : rows) { Object elementBean = getComponentParameter().mapToJava(tableMap, converterCache); collection.add(elementBean); } } if (getFieldType().isArray()) { return ReflectionHelper.newArrayFromCollection(collection, getAssociatedType()); } else { return collection; } } else { throw new InternalHiberSapException( "This method should only be called by the framework " + "when the corresponding table field has a converter attached" ); } } TableMapping(final Class<?> fieldType,
                        final Class<?> associatedType,
                        final String sapName,
                        final String javaName,
                        final StructureMapping componentParameter,
                        final Class<? extends Converter<?, ?>> converterClass); Class<?> getDestinationType(); StructureMapping getComponentParameter(); Class<?> getFieldType(); @Override ParamType getParamType(); @Override Object getUnconvertedValueToJava(final Object fieldMapCollection, final ConverterCache converterCache); @Override @Generated("") boolean equals(final Object o); @Override @Generated("") int hashCode();  }