private void processPolymorphicChildren(OneToManyPolymorphicAssociation association) { if (delegate.isEmpty()) {//no need to process children if no models selected. return; } MetaModel childMetaModel = metaModelOf(association.getTargetClass()); Map<Object, List<Model>> childrenByParentId = new HashMap<>(); List<Object> ids = collect(metaModel.getIdName()); StringBuilder query = new StringBuilder().append("parent_id IN ("); appendQuestions(query, ids.size()); query.append(") AND parent_type = '").append(association.getTypeLabel()).append('\''); for (Model child : new LazyList<>(query.toString(), childMetaModel, ids.toArray()).orderBy(childMetaModel.getIdName())) { if (childrenByParentId.get(child.get("parent_id")) == null) { childrenByParentId.put(child.get("parent_id"), new SuperLazyList<>()); } childrenByParentId.get(child.get("parent_id")).add(child); } for (T parent : delegate) { List<Model> children = childrenByParentId.get(parent.getId()); if (children != null) { parent.setChildren(childMetaModel.getModelClass(), children); } else { parent.setChildren(childMetaModel.getModelClass(), new SuperLazyList<>()); } } }
private void processChildren(OneToManyAssociation association) { if(delegate.isEmpty()){//no need to process children if no models selected. return; } final MetaModel childMetaModel = metaModelOf(association.getTargetClass()); final String fkName = association.getFkName(); final Map<Object, List<Model>> childrenByParentId = new HashMap<>(); List<Object> ids = collect(metaModel.getIdName()); StringBuilder query = new StringBuilder().append(fkName).append(" IN ("); appendQuestions(query, ids.size()); query.append(')'); for (Model child : new LazyList<>(query.toString(), childMetaModel, ids.toArray()).orderBy(childMetaModel.getIdName())) { if(childrenByParentId.get(child.get(fkName)) == null){ childrenByParentId.put(child.get(fkName), new SuperLazyList<>()); } childrenByParentId.get(child.get(fkName)).add(child); } for(T parent : delegate){ List<Model> children = childrenByParentId.get(parent.getId()); if(children != null){ parent.setChildren(childMetaModel.getModelClass(), children); } else { parent.setChildren(childMetaModel.getModelClass(), new SuperLazyList<>()); } } }
private void processManyToMany(Many2ManyAssociation association) { if(delegate.isEmpty()){//no need to process other if no models selected. return; } final MetaModel childMetaModel = metaModelOf(association.getTargetClass()); final Map<Object, List<Model>> childrenByParentId = new HashMap<>(); List<Object> ids = collect(metaModel.getIdName()); List<Map> childResults = new DB(childMetaModel.getDbName()).findAll(childMetaModel.getDialect().selectManyToManyAssociation( association, "the_parent_record_id", ids.size()), ids.toArray()); for(Map res: childResults){ Model child = ModelDelegate.instance(res, childMetaModel); Object parentId = res.get("the_parent_record_id"); if(childrenByParentId.get(parentId) == null){ childrenByParentId.put(parentId, new SuperLazyList<>()); } childrenByParentId.get(parentId).add(child); } for(T parent : delegate){ List<Model> children = childrenByParentId.get(parent.getId()); if (children != null) { parent.setChildren(childMetaModel.getModelClass(), children); } else { parent.setChildren(childMetaModel.getModelClass(), new SuperLazyList<>()); } } }
private void processPolymorphicChildren(OneToManyPolymorphicAssociation association) { if (delegate.isEmpty()) {//no need to process children if no models selected. return; } MetaModel childMetaModel = Registry.instance().getMetaModel(association.getTarget()); Map<Object, List<Model>> childrenByParentId = new HashMap<Object, List<Model>>(); List<Object> ids = collect(metaModel.getIdName()); StringBuilder query = new StringBuilder().append("parent_id IN ("); appendQuestions(query, ids.size()); query.append(") AND parent_type = '").append(association.getTypeLabel()).append('\''); for (Model child : new LazyList<Model>(query.toString(), childMetaModel, ids.toArray()).orderBy(childMetaModel.getIdName())) { if (childrenByParentId.get(child.get("parent_id")) == null) { childrenByParentId.put(child.get("parent_id"), new SuperLazyList<Model>()); } childrenByParentId.get(child.get("parent_id")).add(child); } for (T parent : delegate) { List<Model> children = childrenByParentId.get(parent.getId()); if (children != null) { parent.setChildren(childMetaModel.getModelClass(), children); } } }
private void processChildren(OneToManyAssociation association) { if(delegate.isEmpty()){//no need to process children if no models selected. return; } final MetaModel childMetaModel = Registry.instance().getMetaModel(association.getTarget()); final String fkName = association.getFkName(); final Map<Object, List<Model>> childrenByParentId = new HashMap<Object, List<Model>>(); List<Object> ids = collect(metaModel.getIdName()); StringBuilder query = new StringBuilder().append(fkName).append(" IN ("); appendQuestions(query, ids.size()); query.append(')'); for (Model child : new LazyList<Model>(query.toString(), childMetaModel, ids.toArray()).orderBy(childMetaModel.getIdName())) { if(childrenByParentId.get(child.get(fkName)) == null){ childrenByParentId.put(child.get(fkName), new SuperLazyList<Model>()); } childrenByParentId.get(child.get(fkName)).add(child); } for(T parent : delegate){ List<Model> children = childrenByParentId.get(parent.getId()); if(children != null){ parent.setChildren(childMetaModel.getModelClass(), children); } } }
private void processPolymorphicChildren(OneToManyPolymorphicAssociation association) { if (delegate.isEmpty()) {//no need to process children if no models selected. return; } MetaModel childMetaModel = metaModelOf(association.getTargetClass()); Map<Object, List<Model>> childrenByParentId = new HashMap<>(); List<Object> ids = collect(metaModel.getIdName()); StringBuilder query = new StringBuilder().append("parent_id IN ("); appendQuestions(query, ids.size()); query.append(") AND parent_type = '").append(association.getTypeLabel()).append('\''); for (Model child : new LazyList<>(query.toString(), childMetaModel, ids.toArray()).orderBy(childMetaModel.getIdName())) { if (childrenByParentId.get(child.get("parent_id")) == null) { childrenByParentId.put(child.get("parent_id"), new SuperLazyList<>()); } childrenByParentId.get(child.get("parent_id")).add(child); } for (T parent : delegate) { List<Model> children = childrenByParentId.get(parent.getId()); if (children != null) { parent.setChildren(childMetaModel.getModelClass(), children); } else { parent.setChildren(childMetaModel.getModelClass(), new SuperLazyList<>()); } } }
private void processChildren(OneToManyAssociation association) { if(delegate.isEmpty()){//no need to process children if no models selected. return; } final MetaModel childMetaModel = metaModelOf(association.getTargetClass()); final String fkName = association.getFkName(); final Map<Object, List<Model>> childrenByParentId = new HashMap<>(); List<Object> ids = collect(metaModel.getIdName()); StringBuilder query = new StringBuilder().append(fkName).append(" IN ("); appendQuestions(query, ids.size()); query.append(')'); for (Model child : new LazyList<>(query.toString(), childMetaModel, ids.toArray()).orderBy(childMetaModel.getIdName())) { if(childrenByParentId.get(child.get(fkName)) == null){ childrenByParentId.put(child.get(fkName), new SuperLazyList<>()); } childrenByParentId.get(child.get(fkName)).add(child); } for(T parent : delegate){ List<Model> children = childrenByParentId.get(parent.getId()); if(children != null){ parent.setChildren(childMetaModel.getModelClass(), children); } else { parent.setChildren(childMetaModel.getModelClass(), new SuperLazyList<>()); } } }
private void processManyToMany(Many2ManyAssociation association) { if(delegate.isEmpty()){//no need to process other if no models selected. return; } final MetaModel childMetaModel = metaModelOf(association.getTargetClass()); final Map<Object, List<Model>> childrenByParentId = new HashMap<>(); List<Object> ids = collect(metaModel.getIdName()); List<Map> childResults = new DB(childMetaModel.getDbName()).findAll(childMetaModel.getDialect().selectManyToManyAssociation( association, "the_parent_record_id", ids.size()), ids.toArray()); for(Map res: childResults){ Model child = ModelDelegate.instance(res, childMetaModel); Object parentId = res.get("the_parent_record_id"); if(childrenByParentId.get(parentId) == null){ childrenByParentId.put(parentId, new SuperLazyList<>()); } childrenByParentId.get(parentId).add(child); } for(T parent : delegate){ List<Model> children = childrenByParentId.get(parent.getId()); if (children != null) { parent.setChildren(childMetaModel.getModelClass(), children); } else { parent.setChildren(childMetaModel.getModelClass(), new SuperLazyList<>()); } } }
private void processManyToMany(Many2ManyAssociation association) { if(delegate.isEmpty()){//no need to process other if no models selected. return; } final MetaModel childMetaModel = Registry.instance().getMetaModel(association.getTarget()); final Map<Object, List<Model>> childrenByParentId = new HashMap<Object, List<Model>>(); List<Object> ids = collect(metaModel.getIdName()); List<Map> childResults = new DB(childMetaModel.getDbName()).findAll(childMetaModel.getDialect().selectManyToManyAssociation( association, "the_parent_record_id", ids.size()), ids.toArray()); for(Map res: childResults){ Model child = ModelDelegate.instance(res, childMetaModel); Object parentId = res.get("the_parent_record_id"); if(childrenByParentId.get(parentId) == null){ childrenByParentId.put(parentId, new SuperLazyList<Model>()); } childrenByParentId.get(parentId).add(child); } for(T parent : delegate){ List<Model> children = childrenByParentId.get(parent.getId()); if (children != null) { parent.setChildren(childMetaModel.getModelClass(), children); } } }