KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > factories > MultiTreeFactory


1 package com.dotmarketing.factories;
2
3 import com.dotmarketing.beans.Inode;
4 import com.dotmarketing.beans.MultiTree;
5 import com.dotmarketing.db.DotConnect;
6 import com.dotmarketing.db.DotHibernate;
7 import com.dotmarketing.exception.DotRuntimeException;
8 import com.dotmarketing.util.Logger;
9 /**
10  *
11  * @author will
12  */

13 public class MultiTreeFactory {
14
15     public static void deleteMultiTree(Object JavaDoc o1, Object JavaDoc o2, Object JavaDoc o3) {
16         Inode inode1 = (Inode) o1;
17         Inode inode2 = (Inode) o2;
18         Inode inode3 = (Inode) o3;
19
20         try {
21
22
23             DotConnect db = new DotConnect();
24             db.setSQL("delete from multi_tree where parent1 =? and parent2 = ? and child = ? ");
25             db.addParam(inode1.getInode());
26             db.addParam(inode2.getInode());
27             db.addParam(inode3.getInode());
28             db.getResult();
29         }
30         catch (Exception JavaDoc e) {
31             throw new DotRuntimeException(e.getMessage());
32         }
33
34     }
35
36     public static boolean existsMultiTree(Object JavaDoc o1, Object JavaDoc o2, Object JavaDoc o3) {
37         Inode inode1 = (Inode) o1;
38         Inode inode2 = (Inode) o2;
39         Inode inode3 = (Inode) o3;
40
41         try {
42
43             DotConnect db = new DotConnect();
44             db.setSQL("select count(*) mycount from multi_tree where parent1 =? and parent2 = ? and child = ? ");
45             db.addParam(inode1.getInode());
46             db.addParam(inode2.getInode());
47             db.addParam(inode3.getInode());
48             
49             int count = db.getInt("mycount");
50             
51             return (count > 0);
52         }
53         catch (Exception JavaDoc e) {
54             throw new DotRuntimeException(e.getMessage());
55         }
56     }
57
58     public static void deleteMultiTree(MultiTree multiTree) {
59         DotHibernate.delete(multiTree);
60     }
61
62     public static MultiTree getMultiTree(Inode parent1, Inode parent2, Inode child) {
63         try {
64             DotHibernate dh = new DotHibernate(MultiTree.class);
65             dh.setQuery("from multi_tree in class com.dotmarketing.beans.MultiTree where parent1 = ? and parent2 = ? and child = ?");
66             dh.setParam(parent1.getInode());
67             dh.setParam(parent2.getInode());
68             dh.setParam(child.getInode());
69
70             return (MultiTree) dh.load();
71         } catch (Exception JavaDoc e) {
72             Logger.warn(MultiTreeFactory.class, "getMultiTree failed:" + e, e);
73         }
74         return new MultiTree();
75     }
76     
77     public static java.util.List JavaDoc getMultiTree(Inode parent) {
78         try {
79             DotHibernate dh = new DotHibernate(MultiTree.class);
80             dh.setQuery("from multi_tree in class com.dotmarketing.beans.MultiTree where parent1 = ? or parent2 = ? ");
81             dh.setParam(parent.getInode());
82             dh.setParam(parent.getInode());
83
84             return dh.list();
85             
86         } catch (Exception JavaDoc e) {
87             Logger.error(MultiTreeFactory.class, "getMultiTree failed:" + e, e);
88             throw new DotRuntimeException(e.toString());
89         }
90         //return new java.util.ArrayList();
91
}
92
93     public static java.util.List JavaDoc getMultiTreeByChild(Inode child) {
94         try {
95             DotHibernate dh = new DotHibernate(MultiTree.class);
96             dh.setQuery("from multi_tree in class com.dotmarketing.beans.MultiTree where child = ? ");
97             dh.setParam(child.getInode());
98
99             return dh.list();
100             
101         } catch (Exception JavaDoc e) {
102             Logger.error(MultiTreeFactory.class, "getMultiTreeByChild failed:" + e, e);
103             throw new DotRuntimeException(e.toString());
104         }
105         //return new java.util.ArrayList();
106
}
107
108     public static void saveMultiTree(MultiTree o) {
109         if(o.getChild() ==0 | o.getParent1() ==0 || o.getParent2() ==0) throw new DotRuntimeException("Make sure your Multitree is set!");
110         DotHibernate.saveOrUpdate(o);
111     }
112
113     public static java.util.List JavaDoc getChildrenClass(Inode p1, Inode p2, Class JavaDoc c) {
114
115         try {
116             String JavaDoc tableName = ((Inode) c.newInstance()).getType();
117             DotHibernate dh = new DotHibernate(c);
118             
119             String JavaDoc sql = "SELECT {" + tableName + ".*} from " + tableName + " " + tableName + ", multi_tree multi_tree, inode "+ tableName +"_1_ where multi_tree.parent1 = ? and multi_tree.parent2 = ? and multi_tree.child = " + tableName + ".inode and " + tableName + "_1_.inode = " + tableName + ".inode";
120             Logger.debug(MultiTreeFactory.class, "getChildrenClass\n " + sql+ "\n");
121             dh.setSQLQuery(sql);
122             Logger.debug(MultiTreeFactory.class, "inode p1: " + p1.getInode() + "\n");
123             Logger.debug(MultiTreeFactory.class, "inode p2: " + p2.getInode() + "\n");
124             
125             dh.setParam(p1.getInode());
126             dh.setParam(p2.getInode());
127
128             return dh.list();
129         }
130         catch (Exception JavaDoc e) {
131             Logger.error(MultiTreeFactory.class, "getChildrenClass failed:" + e, e);
132             throw new DotRuntimeException(e.toString());
133         }
134
135         //return new java.util.ArrayList();
136
}
137     
138     public static java.util.List JavaDoc getChildrenClass(Inode p1, Inode p2, Class JavaDoc c, String JavaDoc orderBy) {
139         try {
140             String JavaDoc tableName = ((Inode) c.newInstance()).getType();
141             DotHibernate dh = new DotHibernate(c);
142             
143             String JavaDoc sql = "SELECT {" + tableName + ".*} from " + tableName + " " + tableName + ", multi_tree multi_tree, inode "+ tableName +"_1_ where multi_tree.parent1 = ? and multi_tree.parent2 = ? and multi_tree.child = " + tableName + ".inode and " + tableName + "_1_.inode = " + tableName + ".inode order by " + orderBy;
144             Logger.debug(MultiTreeFactory.class, "dotHibernateSQL:getChildrenClass\n " + sql+ "\n");
145             dh.setSQLQuery(sql);
146             Logger.debug(MultiTreeFactory.class, "inode p1: " + p1.getInode() + "\n");
147             Logger.debug(MultiTreeFactory.class, "inode p2: " + p2.getInode() + "\n");
148
149             dh.setParam(p1.getInode());
150             dh.setParam(p2.getInode());
151
152             return dh.list();
153         }
154         catch (Exception JavaDoc e) {
155             Logger.error(MultiTreeFactory.class, "getChildrenClass failed:" + e, e);
156             throw new DotRuntimeException(e.toString());
157         }
158
159         //return new java.util.ArrayList();
160
}
161
162     public static java.util.List JavaDoc getChildrenClassByCondition(Inode p1, Inode p2, Class JavaDoc c, String JavaDoc condition) {
163         try {
164             String JavaDoc tableName = ((Inode) c.newInstance()).getType();
165             DotHibernate dh = new DotHibernate(c);
166             
167             String JavaDoc sql = "SELECT {" + tableName + ".*} from " + tableName + " " + tableName + ", multi_tree multi_tree, inode "+ tableName +"_1_ where multi_tree.parent1 = ? and multi_tree.parent2 = ? and multi_tree.child = " + tableName + ".inode and " + tableName + "_1_.inode = " + tableName + ".inode and " + condition;
168             Logger.debug(MultiTreeFactory.class, "dotHibernateSQL:getChildrenClassByCondition\n " + sql);
169             dh.setSQLQuery(sql);
170             Logger.debug(MultiTreeFactory.class, "inode p1: " + p1.getInode() + "\n");
171             Logger.debug(MultiTreeFactory.class, "inode p2: " + p2.getInode() + "\n");
172             
173             dh.setParam(p1.getInode());
174             dh.setParam(p2.getInode());
175
176             return dh.list();
177         }
178         catch (Exception JavaDoc e) {
179             Logger.error(MultiTreeFactory.class, "getChildrenClassByCondition failed:" + e, e);
180             throw new DotRuntimeException(e.toString());
181         }
182
183         //return new java.util.ArrayList();
184
}
185
186     public static java.util.List JavaDoc getChildrenClassByCondition(long p1, long p2, Class JavaDoc c, String JavaDoc condition) {
187         try {
188             String JavaDoc tableName = ((Inode) c.newInstance()).getType();
189             DotHibernate dh = new DotHibernate(c);
190             
191             String JavaDoc sql = "SELECT {" + tableName + ".*} from " + tableName + " " + tableName + ", multi_tree multi_tree, inode "+ tableName +"_1_ where multi_tree.parent1 = ? and multi_tree.parent2 = ? and multi_tree.child = " + tableName + ".inode and " + tableName + "_1_.inode = " + tableName + ".inode and " + condition;
192             Logger.debug(MultiTreeFactory.class, "dotHibernateSQL:getChildrenClassByCondition\n " + sql);
193             dh.setSQLQuery(sql);
194             Logger.debug(MultiTreeFactory.class, "inode p1: " + p1 + "\n");
195             Logger.debug(MultiTreeFactory.class, "inode p2: " + p2 + "\n");
196             
197             dh.setParam(p1);
198             dh.setParam(p2);
199
200             return dh.list();
201         }
202         catch (Exception JavaDoc e) {
203             Logger.error(MultiTreeFactory.class, "getChildrenClassByCondition failed:" + e, e);
204             throw new DotRuntimeException(e.toString());
205         }
206
207         //return new java.util.ArrayList();
208
}
209
210     public static java.util.List JavaDoc getChildrenClassByConditionAndOrderBy(Inode p1, Inode p2, Class JavaDoc c, String JavaDoc condition, String JavaDoc orderby) {
211         try {
212
213             String JavaDoc tableName = ((Inode) c.newInstance()).getType();
214             DotHibernate dh = new DotHibernate(c);
215             
216             String JavaDoc sql = "SELECT {" + tableName + ".*} from " + tableName + " " + tableName + ", multi_tree multi_tree, inode "+ tableName +"_1_ where multi_tree.parent1 = ? and multi_tree.parent2 = ? and multi_tree.child = " + tableName + ".inode and " + tableName + "_1_.inode = " + tableName + ".inode and " + condition + " order by " + orderby;
217             Logger.debug(MultiTreeFactory.class, "dotHibernateSQL:getChildrenClassByConditionAndOrderBy\n " + sql+ "\n");
218             dh.setSQLQuery(sql);
219             Logger.debug(MultiTreeFactory.class, "inode p1: " + p1.getInode() + "\n");
220             Logger.debug(MultiTreeFactory.class, "inode p2: " + p2.getInode() + "\n");
221             
222             dh.setParam(p1.getInode());
223             dh.setParam(p2.getInode());
224
225             return dh.list();
226         }
227         catch (Exception JavaDoc e) {
228             Logger.error(MultiTreeFactory.class, "getChildrenClassByConditionAndOrderBy failed:" + e, e);
229             throw new DotRuntimeException(e.toString());
230         }
231
232         //return new java.util.ArrayList();
233
}
234     
235     public static java.util.List JavaDoc getChildrenClassByConditionAndOrderBy(long p1, long p2, Class JavaDoc c, String JavaDoc condition, String JavaDoc orderby) {
236         try {
237
238             String JavaDoc tableName = ((Inode) c.newInstance()).getType();
239             DotHibernate dh = new DotHibernate(c);
240             
241             String JavaDoc sql = "SELECT {" + tableName + ".*} from " + tableName + " " + tableName + ", multi_tree multi_tree, inode "+ tableName +"_1_ where multi_tree.parent1 = ? and multi_tree.parent2 = ? and multi_tree.child = " + tableName + ".inode and " + tableName + "_1_.inode = " + tableName + ".inode and " + condition + " order by " + orderby;
242             Logger.debug(MultiTreeFactory.class, "dotHibernateSQL:getChildrenClassByConditionAndOrderBy\n " + sql+ "\n");
243             dh.setSQLQuery(sql);
244             Logger.debug(MultiTreeFactory.class, "inode p1: " + p1 + "\n");
245             Logger.debug(MultiTreeFactory.class, "inode p2: " + p2 + "\n");
246             
247             dh.setParam(p1);
248             dh.setParam(p2);
249
250             return dh.list();
251         }
252         catch (Exception JavaDoc e) {
253             Logger.error(MultiTreeFactory.class, "getChildrenClassByConditionAndOrderBy failed:" + e, e);
254             throw new DotRuntimeException(e.toString());
255         }
256
257         //return new java.util.ArrayList();
258
}
259
260     public static java.util.List JavaDoc getChildrenClassByOrder(Inode p1, Inode p2, Class JavaDoc c, String JavaDoc order) {
261         try {
262             String JavaDoc tableName = ((Inode) c.newInstance()).getType();
263             DotHibernate dh = new DotHibernate(c);
264             
265             String JavaDoc sql = "SELECT {" + tableName + ".*} from " + tableName + " " + tableName + ", multi_tree multi_tree, inode "+ tableName +"_1_ where multi_tree.parent1 = ? and multi_tree.parent2 = ? and multi_tree.child = " + tableName + ".inode and " + tableName + "_1_.inode = " + tableName + ".inode order by " + order;
266             
267             Logger.debug(MultiTreeFactory.class, "dotHibernateSQL:getChildrenClassByOrder\n " + sql);
268             dh.setSQLQuery(sql);
269             Logger.debug(MultiTreeFactory.class, "inode p1: " + p1.getInode() + "\n");
270             Logger.debug(MultiTreeFactory.class, "inode p2: " + p2.getInode() + "\n");
271             Logger.debug(MultiTreeFactory.class, "order: " + order + "\n");
272             
273             dh.setParam(p1.getInode());
274             dh.setParam(p2.getInode());
275
276             return dh.list();
277         }
278         catch (Exception JavaDoc e) {
279             Logger.error(MultiTreeFactory.class, "getChildrenClassByOrder failed:" + e, e);
280             throw new DotRuntimeException(e.toString());
281         }
282
283         //return new java.util.ArrayList();
284
}
285     
286
287     public static java.util.List JavaDoc getParentsOfClassByCondition(Inode p, Class JavaDoc c, String JavaDoc condition) {
288         try {
289             String JavaDoc tableName = ((Inode) c.newInstance()).getType();
290             DotHibernate dh = new DotHibernate(c);
291             
292             String JavaDoc sql = "SELECT {" + tableName + ".*} from " + tableName + " " + tableName + ", multi_tree multi_tree, inode "+ tableName +"_1_ where multi_tree.child = ? and (multi_tree.parent1 = " + tableName + ".inode or multi_tree.parent2 = " + tableName + ".inode) and " + tableName + "_1_.inode = " + tableName + ".inode and " + condition;
293             Logger.debug(MultiTreeFactory.class, "dotHibernateSQL:getParentsOfClassByCondition\n " + sql);
294             Logger.debug(MultiTreeFactory.class, "inode: " + p.getInode() + "\n");
295             Logger.debug(MultiTreeFactory.class, "condition: " + condition + "\n");
296             dh.setSQLQuery(sql);
297             dh.setParam(p.getInode());
298
299             return dh.list();
300         }
301         catch (Exception JavaDoc e) {
302             Logger.error(MultiTreeFactory.class, "getParentsOfClassByCondition failed:" + e, e);
303             throw new DotRuntimeException(e.toString());
304         }
305
306         //return new java.util.ArrayList();
307
}
308     
309     public static java.util.List JavaDoc getParentsOfClass(Inode p, Class JavaDoc c) {
310         try {
311
312             String JavaDoc tableName = ((Inode) c.newInstance()).getType();
313             DotHibernate dh = new DotHibernate(c);
314             String JavaDoc sql = "SELECT {" + tableName + ".*} from " + tableName + " " + tableName + ", multi_tree multi_tree, inode "+ tableName +"_1_ where multi_tree.child = ? and (multi_tree.parent1 = " + tableName + ".inode or multi_tree.parent2 = " + tableName + ".inode) and " + tableName + "_1_.inode = " + tableName + ".inode ";
315             Logger.debug(MultiTreeFactory.class, "dotHibernateSQL:getParentOfClass:\n " + sql+ "\n");
316             dh.setSQLQuery(sql);
317             dh.setParam(p.getInode());
318             Logger.debug(MultiTreeFactory.class, "inode: " + p.getInode() + "\n");
319             return dh.list();
320         }
321         catch (Exception JavaDoc e) {
322             Logger.error(MultiTreeFactory.class, "getParentsOfClass failed:" + e, e);
323             throw new DotRuntimeException(e.toString());
324         }
325
326         //return new java.util.ArrayList();
327
}
328 }
329
Popular Tags