public Set collectDistinct(String attributeName) { Set results = new LinkedHashSet(); collect(results, attributeName); return results; }
public Set collectDistinct(String attributeName, String filterAttribute, Object filterValue) { Set results = new LinkedHashSet(); collect(results, attributeName, filterAttribute, filterValue); return results; }
public List collect(String attributeName, String filterAttribute, Object filterValue) { List results = new ArrayList(); collect(results, attributeName, filterAttribute, filterValue); return results; }
/** * Collects values from a result set that correspond to a attribute name. * For example, if a list contains collection of <code>Person</code> models, then * you can collect first names like this: * <pre> * List firstNames = Person.findAll().collect("first_name"); * </pre> * provided that the corresponding table has a column <code>first_name</code>. * <p><p/> * Keep in mind, that if all you need is a one column data, this method of getting it is not * the most efficient (because since you are using a model, you will query all columns from a table, * but will use only one). In these cases, you might want to consider {@link Base#firstColumn(String, Object...)} and * {@link DB#firstColumn(String, Object...)}. * * @param attributeName name of attribute to collect. * @return list of collected values for a column. */ public List collect(String attributeName) { List results = new ArrayList(); collect(results, attributeName); return results; }
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<>()); } } }
public Set collectDistinct(String attributeName) { Set results = new LinkedHashSet(); collect(results, attributeName); return results; }
public Set collectDistinct(String attributeName, String filterAttribute, Object filterValue) { Set results = new LinkedHashSet(); collect(results, attributeName, filterAttribute, filterValue); return results; }
public List collect(String attributeName, String filterAttribute, Object filterValue) { List results = new ArrayList(); collect(results, attributeName, filterAttribute, filterValue); return results; }
public Set collectDistinct(String attributeName) { Set results = new LinkedHashSet(); collect(results, attributeName); return results; }
public Set collectDistinct(String attributeName, String filterAttribute, Object filterValue) { Set results = new LinkedHashSet(); collect(results, attributeName, filterAttribute, filterValue); return results; }
public List collect(String attributeName, String filterAttribute, Object filterValue) { List results = new ArrayList(); collect(results, attributeName, filterAttribute, filterValue); return results; }
/** * Collects values from a result set that correspond to a attribute name. * For example, if a list contains collection of <code>Person</code> models, then * you can collect first names like this: * <pre> * List firstNames = Person.findAll().collect("first_name"); * </pre> * provided that the corresponding table has a column <code>first_name</code>. * <p/><p/> * Keep in mind, that if all you need is a one column data, this method of getting it is not * the most efficient (because since you are using a model, you will query all columns from a table, * but will use only one). In these cases, you might want to consider {@link Base#firstColumn(String, Object...)} and * {@link DB#firstColumn(String, Object...)}. * * @param attributeName name of attribute to collect. * @return list of collected values for a column. */ public List collect(String attributeName) { List results = new ArrayList(); collect(results, attributeName); return results; }
/** * Collects values from a result set that correspond to a attribute name. * For example, if a list contains collection of <code>Person</code> models, then * you can collect first names like this: * <pre> * List firstNames = Person.findAll().collect("first_name"); * </pre> * provided that the corresponding table has a column <code>first_name</code>. * <p><p/> * Keep in mind, that if all you need is a one column data, this method of getting it is not * the most efficient (because since you are using a model, you will query all columns from a table, * but will use only one). In these cases, you might want to consider {@link Base#firstColumn(String, Object...)} and * {@link DB#firstColumn(String, Object...)}. * * @param attributeName name of attribute to collect. * @return list of collected values for a column. */ public List collect(String attributeName) { List results = new ArrayList(); collect(results, attributeName); return results; }
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 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 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 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); } } }