public List<History> fetchHistoryRecords() { this.open(); List<History> history = History.findAll().orderBy("ID desc").limit(FETCH_LIMIT); history.size(); this.close(); return history; }
public List<History> fetchHistoryRecordsByNode(String historyNode) { this.open(); List<History> history = History.where("CHANGE_SUMMARY like ?", historyNode).orderBy("ID desc").limit(FETCH_LIMIT); history.size(); this.close(); return history; }
/** * This method will return a list of records for a specific page. * * @param pageNumber page number to return. This is indexed at 1, not 0. Any value below 1 is illegal and will * be rejected. * @return list of records that match a query make up a "page". */ public LazyList<T> getPage(int pageNumber) { if (pageNumber < 1) throw new IllegalArgumentException("minimum page index == 1"); try { LazyList<T> list = find(query, params).offset((pageNumber - 1) * pageSize).limit(pageSize); if (orderBys != null) { list.orderBy(orderBys); } currentPageIndex = pageNumber; return list; } catch (Exception mustNeverHappen) { throw new InternalException(mustNeverHappen); } }
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<>()); } } }
/** * This method will return a list of records for a specific page. * * @param pageNumber page number to return. This is indexed at 1, not 0. Any value below 1 is illegal and will * be rejected. * @return list of records that match a query make up a "page". */ public LazyList<T> getPage(int pageNumber) { if (pageNumber < 1) throw new IllegalArgumentException("minimum page index == 1"); try { LazyList<T> list = find(query, params).offset((pageNumber - 1) * pageSize).limit(pageSize); if (orderBys != null) { list.orderBy(orderBys); } currentPage = pageNumber; return list; } catch (Exception mustNeverHappen) { throw new InternalException(mustNeverHappen); } }
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); } } }
/** * This method will return a list of records for a specific page. * * @param pageNumber page number to return. This is indexed at 1, not 0. Any value below 1 is illegal and will * be rejected. * @return list of records that match a query make up a "page". */ public LazyList<T> getPage(int pageNumber) { if (pageNumber < 1) throw new IllegalArgumentException("minimum page index == 1"); try { LazyList<T> list = find(query, params).offset((pageNumber - 1) * pageSize).limit(pageSize); if (orderBys != null) { list.orderBy(orderBys); } currentPageIndex = pageNumber; return list; } catch (Exception mustNeverHappen) { throw new InternalException(mustNeverHappen); } }
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<>()); } } }