BrightSide Workbench Full Report + Source Code
DaoTree.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.jpa.iterator;
20 
21 import java.util.List;
22 import org.turro.collections.Item;
23 import org.turro.collections.Tree;
24 import org.turro.elephant.db.WhereClause;
25 import org.turro.jpa.Dao;
26 
33 public abstract class DaoTree<E, ID> extends Tree<E, ID> {
34 
35  protected Dao dao;
36 
37  public DaoTree(Dao dao) {
38  this.dao = dao;
39  }
40 
41  public Dao getDao() {
42  return dao;
43  }
44 
45  public void fillTree(String path) {
46  setPath(path);
47  WhereClause childrenClause = getChildrenClause(path);
48  if(childrenClause != null) {
49  for(E e : (List<E>) dao.getResultList(childrenClause)) {
50  if(e != null) {
51  Item i = addRoot(e, getId(e));
52  if(i != null) {
53  fillRoot(i);
54  }
55  }
56  }
57  }
58  WhereClause leafClause = getLeafClause(path);
59  if(leafClause != null) {
60  for(E e : (List<E>) dao.getResultList(leafClause)) {
61  if(e != null) {
62  addLeaf(e, getId(e));
63  }
64  }
65  }
66  }
67 
68  public void fillRoot(Item item) {
69  WhereClause childrenClause = getChildrenClause(item.getPath());
70  if(childrenClause != null) {
71  for(E e : (List<E>) dao.getResultList(childrenClause)) {
72  if(e != null) {
73  Item i = item.addChild(this, item, e, getId(e));
74  fillRoot(i);
75  }
76  }
77  }
78  WhereClause leafClause = getLeafClause(item.getPath());
79  if(leafClause != null) {
80  for(E e : (List<E>) dao.getResultList(leafClause)) {
81  if(e != null) {
82  item.addLeaf(this, item, e, getId(e));
83  }
84  }
85  }
86  }
87 
88  protected abstract WhereClause getChildrenClause(String currPath);
89  protected abstract WhereClause getLeafClause(String currPath);
90 
91 }
void fillRoot(Item item)
Definition: DaoTree.java:68
void fillTree(String path)
Definition: DaoTree.java:45
abstract WhereClause getChildrenClause(String currPath)
abstract WhereClause getLeafClause(String currPath)