List<Property<?>> properties = entry.getValue(); Map<Property<?>, Property<?>> aliasMap = aliasedPropertiesMap.get(tableModelName); constructVisitor(tableModelName.modelClass, tableModelName.tableName, result, properties, aliasMap);
@Override public Void visitString(Property<String> property, T dst, ViewModel src) { Property<String> toSet = getPropertyToSet(property); if (src.containsValue(property)) { dst.set(toSet, src.get(property)); } return null; }
public List<AbstractModel> mapToSourceModels() { List<AbstractModel> result = new ArrayList<>(); TableMappingVisitors visitors = getTableMappingVisitors(); if (visitors != null) { Set<Map.Entry<Class<? extends AbstractModel>, Map<String, TableModelMappingVisitor<?>>>> allMappings = visitors.allMappings(); for (Map.Entry<Class<? extends AbstractModel>, Map<String, TableModelMappingVisitor<?>>> entry : allMappings) { try { Class<? extends AbstractModel> cls = entry.getKey(); Map<String, TableModelMappingVisitor<?>> clsMappers = entry.getValue(); for (String table : clsMappers.keySet()) { result.add(mapToModel(cls.newInstance(), table)); } } catch (Exception e) { throw new RuntimeException(e); } } } return result; }
/** * Extracts the properties in this ViewModel that originated from the specified model class and reads them into the * destination model object * <br> * Note: if the backing query for your ViewModel joins on the same table multiple times with different aliases, * you should instead use {@link #mapToModel(AbstractModel, SqlTable)} and pass the aliased table object as the * second argument * * @param dst the destination model object * @return the destination model object */ public <T extends AbstractModel> T mapToModel(T dst) { return mapToModel(dst, (String) null); }
public <T extends AbstractModel> T mapToModel(T dst, String tableAlias) { TableMappingVisitors visitors = getTableMappingVisitors(); if (visitors != null) { @SuppressWarnings("unchecked") TableModelMappingVisitor<T> mapper = visitors.get((Class<T>) dst.getClass(), tableAlias); if (mapper != null) { return mapper.map(this, dst); } } return dst; }
/** * Extracts the properties in this ViewModel that originated from the specified model class for the given table * alias and reads them into the destination model object * * @param dst the destination model object * @param tableAlias the table alias for which you want to extract values. If you only join on a given table * once without aliasing it, this would simply be e.g. Model.TABLE. * @return the destination model object */ public <T extends AbstractModel> T mapToModel(T dst, SqlTable<?> tableAlias) { return mapToModel(dst, tableAlias.getName()); }
public <T extends AbstractModel> T mapToModel(T dst, String tableAlias) { TableMappingVisitors visitors = getTableMappingVisitors(); if (visitors != null) { @SuppressWarnings("unchecked") TableModelMappingVisitor<T> mapper = visitors.get((Class<T>) dst.getClass(), tableAlias); if (mapper != null) { return mapper.map(this, dst); } } return dst; }
@Override public Void visitInteger(Property<Integer> property, T dst, ViewModel src) { Property<Integer> toSet = getPropertyToSet(property); if (src.containsValue(property)) { dst.set(toSet, src.get(property)); } return null; }
public List<AbstractModel> mapToSourceModels() { List<AbstractModel> result = new ArrayList<>(); TableMappingVisitors visitors = getTableMappingVisitors(); if (visitors != null) { Set<Map.Entry<Class<? extends AbstractModel>, Map<String, TableModelMappingVisitor<?>>>> allMappings = visitors.allMappings(); for (Map.Entry<Class<? extends AbstractModel>, Map<String, TableModelMappingVisitor<?>>> entry : allMappings) { try { Class<? extends AbstractModel> cls = entry.getKey(); Map<String, TableModelMappingVisitor<?>> clsMappers = entry.getValue(); for (String table : clsMappers.keySet()) { result.add(mapToModel(cls.newInstance(), table)); } } catch (Exception e) { throw new RuntimeException(e); } } } return result; }
/** * Extracts the properties in this ViewModel that originated from the specified model class and reads them into the * destination model object * <br> * Note: if the backing query for your ViewModel joins on the same table multiple times with different aliases, * you should instead use {@link #mapToModel(AbstractModel, SqlTable)} and pass the aliased table object as the * second argument * * @param dst the destination model object * @return the destination model object */ public <T extends AbstractModel> T mapToModel(T dst) { return mapToModel(dst, (String) null); }
List<Property<?>> properties = entry.getValue(); Map<Property<?>, Property<?>> aliasMap = aliasedPropertiesMap.get(tableModelName); constructVisitor(tableModelName.modelClass, tableModelName.tableName, result, properties, aliasMap);
@Override public Void visitLong(Property<Long> property, T dst, ViewModel src) { Property<Long> toSet = getPropertyToSet(property); if (src.containsValue(property)) { dst.set(toSet, src.get(property)); } return null; }
/** * Extracts the properties in this ViewModel that originated from the specified model class for the given table * alias and reads them into the destination model object * * @param dst the destination model object * @param tableAlias the table alias for which you want to extract values. If you only join on a given table * once without aliasing it, this would simply be e.g. Model.TABLE. * @return the destination model object */ public <T extends AbstractModel> T mapToModel(T dst, SqlTable<?> tableAlias) { return mapToModel(dst, tableAlias.getName()); }
@Override public Void visitDouble(Property<Double> property, T dst, ViewModel src) { Property<Double> toSet = getPropertyToSet(property); if (src.containsValue(property)) { dst.set(toSet, src.get(property)); } return null; }
@Override public Void visitBoolean(Property<Boolean> property, T dst, ViewModel src) { Property<Boolean> toSet = getPropertyToSet(property); if (src.containsValue(property)) { dst.set(toSet, src.get(property)); } return null; }
@Override public Void visitBlob(Property<byte[]> property, T dst, ViewModel src) { Property<byte[]> toSet = getPropertyToSet(property); if (src.containsValue(property)) { dst.set(toSet, src.get(property)); } return null; }
@Override public Void visitLong(Property<Long> property, T dst, ViewModel src) { Property<Long> toSet = getPropertyToSet(property); if (src.containsValue(property)) { dst.set(toSet, src.get(property)); } return null; }
@Override public Void visitBoolean(Property<Boolean> property, T dst, ViewModel src) { Property<Boolean> toSet = getPropertyToSet(property); if (src.containsValue(property)) { dst.set(toSet, src.get(property)); } return null; }
@Override public Void visitDouble(Property<Double> property, T dst, ViewModel src) { Property<Double> toSet = getPropertyToSet(property); if (src.containsValue(property)) { dst.set(toSet, src.get(property)); } return null; }
@Override public Void visitString(Property<String> property, T dst, ViewModel src) { Property<String> toSet = getPropertyToSet(property); if (src.containsValue(property)) { dst.set(toSet, src.get(property)); } return null; }