KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > polepos > teams > hibernate > SepangHibernate


1 /*
2 This file is part of the PolePosition database benchmark
3 http://www.polepos.org
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 MA 02111-1307, USA. */

19
20 package org.polepos.teams.hibernate;
21
22 import org.polepos.circuits.sepang.*;
23 import org.polepos.teams.hibernate.data.*;
24
25 import net.sf.hibernate.*;
26
27 /**
28  * @author Herkules
29  */

30 public class SepangHibernate extends HibernateDriver implements SepangDriver{
31     
32     private long treeRootID; // TODO: get and use for findRoot
33

34     public void write(){
35         try{
36             Transaction tx = db().beginTransaction();
37             HibernateTree tree = HibernateTree.createTree(setup().getTreeDepth());
38             HibernateTree.traverse(tree, new HibernateTreeVisitor() {
39                 public void visit(HibernateTree tree) {
40                     try {
41                         db().save(tree);
42                     } catch (HibernateException e) {
43                         e.printStackTrace();
44                     }
45                 }
46             });
47             tx.commit();
48             
49         }
50         catch ( HibernateException hex ){
51             hex.printStackTrace();
52         }
53     }
54
55     
56     public void read(){
57         try{
58             HibernateTree tree = findRoot();
59             HibernateTree.traverse(tree, new HibernateTreeVisitor() {
60                 public void visit(HibernateTree tree) {
61                     addToCheckSum(tree.getDepth());
62                 }
63             });
64         }catch ( HibernateException hex ){
65             hex.printStackTrace();
66         }
67     }
68     
69     public void read_hot() {
70         read();
71     }
72     
73     public void delete(){
74         try{
75             Transaction tx = db().beginTransaction();
76             HibernateTree tree = findRoot();
77             HibernateTree.traverse(tree, new HibernateTreeVisitor() {
78                 public void visit(HibernateTree tree) {
79                     try {
80                         db().delete(tree);
81                     } catch (HibernateException e) {
82                         e.printStackTrace();
83                     }
84                 }
85             });
86             tx.commit();
87         }catch ( HibernateException hex ){
88             hex.printStackTrace();
89         }
90     }
91     
92     /**
93      * Finds the root of the tree.
94      */

95     private HibernateTree findRoot() throws HibernateException
96     {
97         Query q = db().createQuery( "select tree from tree in class org.polepos.teams.hibernate.data.HibernateTree where tree.name='root'" );
98         HibernateTree tree = (HibernateTree)q.list().get(0);
99         return tree;
100     }
101         
102 }
103
Popular Tags