private void processParent(BelongsToAssociation association) { if (delegate.isEmpty()) { // no need to process parents if no models selected. return; } //need to remove duplicates because more than one child can belong to the same parent. Set<Object> distinctParentIds = collectDistinct(association.getFkName()); distinctParentIds.remove(null); // remove null parent id if (distinctParentIds.isEmpty()) { return; } final MetaModel parentMetaModel = metaModelOf(association.getTargetClass()); final Map<Object, Model> parentById = new HashMap<>(); StringBuilder query = new StringBuilder().append(parentMetaModel.getIdName()).append(" IN ("); appendQuestions(query, distinctParentIds.size()); query.append(')'); for (Model parent : new LazyList<>(query.toString(), parentMetaModel, distinctParentIds.toArray())) { parentById.put(parent.getId(), parent); } //now that we have the parents in the has, we need to distribute them into list of children that are //stored in the delegate. for (Model child : delegate) { // parent could be null, which is fine child.setCachedParent(parentById.get(child.get(association.getFkName()))); } }
/** * @author Evan Leonard */ private void processPolymorphicParent(BelongsToPolymorphicAssociation association) { if (delegate.isEmpty()) { // no need to process children if no models selected. return; } //need to remove duplicates because more than one child can belong to the same parent. Set<Object> distinctParentIds = collectDistinct("parent_id", "parent_type", association.getParentClassName()); distinctParentIds.remove(null); // remove null parent id if (distinctParentIds.isEmpty()) { return; } final MetaModel parentMetaModel = metaModelOf(association.getTargetClass()); final Map<Object, Model> parentById = new HashMap<>(); StringBuilder query = new StringBuilder().append(parentMetaModel.getIdName()).append(" IN ("); appendQuestions(query, distinctParentIds.size()); query.append(')'); for (Model parent : new LazyList<>(query.toString(), parentMetaModel, distinctParentIds.toArray())) { parentById.put(association.getParentClassName() + ":" + parent.getId(), parent); } //now that we have the parents in the has, we need to distribute them into list of children that are //stored in the delegate. for (Model child : delegate) { // parent could be null, which is fine child.setCachedParent(parentById.get(association.getParentClassName() + ":" + child.get("parent_id"))); } }
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 processParent(BelongsToAssociation association) { if (delegate.isEmpty()) { // no need to process parents if no models selected. return; } //need to remove duplicates because more than one child can belong to the same parent. Set<Object> distinctParentIds = collectDistinct(association.getFkName()); distinctParentIds.remove(null); // remove null parent id if (distinctParentIds.isEmpty()) { return; } final MetaModel parentMetaModel = metaModelOf(association.getTargetClass()); final Map<Object, Model> parentById = new HashMap<>(); StringBuilder query = new StringBuilder().append(parentMetaModel.getIdName()).append(" IN ("); appendQuestions(query, distinctParentIds.size()); query.append(')'); for (Model parent : new LazyList<>(query.toString(), parentMetaModel, distinctParentIds.toArray())) { parentById.put(parent.getId(), parent); } //now that we have the parents in the has, we need to distribute them into list of children that are //stored in the delegate. for (Model child : delegate) { // parent could be null, which is fine child.setCachedParent(parentById.get(child.get(association.getFkName()))); } }
private void processParent(BelongsToAssociation association) { if (delegate.isEmpty()) { // no need to process parents if no models selected. return; } //need to remove duplicates because more than one child can belong to the same parent. Set<Object> distinctParentIds = collectDistinct(association.getFkName()); distinctParentIds.remove(null); // remove null parent id if (distinctParentIds.isEmpty()) { return; } final MetaModel parentMetaModel = Registry.instance().getMetaModel(association.getTarget()); final Map<Object, Model> parentById = new HashMap<Object, Model>(); StringBuilder query = new StringBuilder().append(parentMetaModel.getIdName()).append(" IN ("); appendQuestions(query, distinctParentIds.size()); query.append(')'); for (Model parent : new LazyList<Model>(query.toString(), parentMetaModel, distinctParentIds.toArray())) { parentById.put(parent.getId(), parent); } //now that we have the parents in the has, we need to distribute them into list of children that are //stored in the delegate. for (Model child : delegate) { // parent could be null, which is fine child.setCachedParent(parentById.get(child.get(association.getFkName()))); } }
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); } } }
/** * @author Evan Leonard */ private void processPolymorphicParent(BelongsToPolymorphicAssociation association) { if (delegate.isEmpty()) { // no need to process children if no models selected. return; } //need to remove duplicates because more than one child can belong to the same parent. Set<Object> distinctParentIds = collectDistinct("parent_id", "parent_type", association.getParentClassName()); distinctParentIds.remove(null); // remove null parent id if (distinctParentIds.isEmpty()) { return; } final MetaModel parentMetaModel = metaModelOf(association.getTargetClass()); final Map<Object, Model> parentById = new HashMap<>(); StringBuilder query = new StringBuilder().append(parentMetaModel.getIdName()).append(" IN ("); appendQuestions(query, distinctParentIds.size()); query.append(')'); for (Model parent : new LazyList<>(query.toString(), parentMetaModel, distinctParentIds.toArray())) { parentById.put(association.getParentClassName() + ":" + parent.getId(), parent); } //now that we have the parents in the has, we need to distribute them into list of children that are //stored in the delegate. for (Model child : delegate) { // parent could be null, which is fine child.setCachedParent(parentById.get(association.getParentClassName() + ":" + child.get("parent_id"))); } }
/** * @author Evan Leonard */ private void processPolymorphicParent(BelongsToPolymorphicAssociation association) { if (delegate.isEmpty()) { // no need to process children if no models selected. return; } //need to remove duplicates because more than one child can belong to the same parent. Set<Object> distinctParentIds = collectDistinct("parent_id", "parent_type", association.getParentClassName()); distinctParentIds.remove(null); // remove null parent id if (distinctParentIds.isEmpty()) { return; } final MetaModel parentMetaModel = Registry.instance().getMetaModel(association.getTarget()); final Map<Object, Model> parentById = new HashMap<Object, Model>(); StringBuilder query = new StringBuilder().append(parentMetaModel.getIdName()).append(" IN ("); appendQuestions(query, distinctParentIds.size()); query.append(')'); for (Model parent : new LazyList<Model>(query.toString(), parentMetaModel, distinctParentIds.toArray())) { parentById.put(association.getParentClassName() + ":" + parent.getId(), parent); } //now that we have the parents in the has, we need to distribute them into list of children that are //stored in the delegate. for (Model child : delegate) { // parent could be null, which is fine child.setCachedParent(parentById.get(association.getParentClassName() + ":" + child.get("parent_id"))); } }
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<>()); } } }