/** * 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); }
/** * 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 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); }
/** * 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 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; }