KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > allinone > SelfReference


1 package allinone;
2
3 import com.lutris.appserver.server.sql.*;
4 import com.lutris.util.*;
5 import org.enhydra.dods.*;
6 import java.sql.SQLException JavaDoc;
7
8
9 import javax.swing.*;
10 import java.util.*;
11 import java.awt.*;
12 import java.awt.event.*;
13 import java.net.*;
14 import java.io.*;
15 import org.apache.log4j.Logger;
16 import org.apache.log4j.xml.DOMConfigurator;
17 import com.lutris.appserver.server.sql.*;
18 import allinone.data.person.*;
19
20
21 public class SelfReference {
22
23     void showTable(DBTransaction dbTrans) throws Exception JavaDoc{
24         try{
25             PersonSelfQuery queryPersonSelf = new PersonSelfQuery(dbTrans);
26             PersonSelfDO[] allADO = queryPersonSelf.getDOArray();
27             System.err.println();
28             System.err.println("-------------TablePersonSelf-----begin----------");
29             if(allADO!=null) {
30                 if(allADO.length>0)System.err.println("------oid---------Firstname--------Lastname-----Login------Boss-----");
31                 for(int i=0; i<allADO.length; i++){
32                     System.err.print(" "+allADO[i].getOId());
33                     System.err.print(" "+allADO[i].getFirstname());
34                     System.err.print(" "+allADO[i].getLastname());
35                     System.err.print(" "+allADO[i].getLogin());
36                     System.err.print(" "+((null!=allADO[i].getBoss())?allADO[i].getBoss().getOId():null));
37                     System.err.println();
38                 }
39             } else {
40                 System.err.println("noData");
41             }
42             System.err.println("-------------TablePersonSelf-----end------------");
43         }catch(Exception JavaDoc e){
44             e.printStackTrace();
45             throw new Exception JavaDoc("Couldn't showTables ", e);
46         }
47     }
48
49     void runTest(DBTransaction dbTrans1) {
50         try {
51             boolean autoWrite = ((StandardDatabaseManager)DODS.getDatabaseManager()).getDatabaseManagerConfiguration().getAutoWrite();
52             System.err.println("___ - + * startin SelfReference * + - ___");
53             showTable(dbTrans1);
54
55             PersonSelfDO person0 = PersonSelfDO.createVirgin(dbTrans1);
56             PersonSelfDO person1 = PersonSelfDO.createVirgin(dbTrans1);
57             PersonSelfDO person2 = PersonSelfDO.createVirgin(dbTrans1);
58             PersonSelfDO person3 = PersonSelfDO.createVirgin(dbTrans1);
59             PersonSelfDO person4 = PersonSelfDO.createVirgin(dbTrans1);
60             PersonSelfDO person5 = PersonSelfDO.createVirgin(dbTrans1);
61
62             //person0 points to itself
63
person0.setFirstname("PersonSelf0Name");
64             person0.setLastname("PersonSelf0LastName");
65             person0.setLogin("p0");
66             person0.setPassword("p0");
67             person0.save();
68             System.err.println("Person 0 saved "+person0.getOId());
69             // if(!autoWrite)
70
dbTrans1.write();
71
72             person0.setBoss(person0);
73             person0.save();
74             System.err.println("\tPerson 0 saved "+person0.getOId());
75             // if(!autoWrite)
76
// dbTrans1.write();
77

78             //person1 points to person2, and person2 points to person1
79
person1.setFirstname("PersonSelf1Name");
80             person1.setLastname("PersonSelf1LastName");
81             person1.setLogin("p1");
82             person1.setPassword("p1");
83             person1.save();
84             System.err.println("Person 1 saved "+person1.getOId());
85             if(!autoWrite)
86                 dbTrans1.write();
87
88             person2.setFirstname("PersonSelf2Name");
89             person2.setLastname("PersonSelf2LastName");
90             person2.setLogin("p2");
91             person2.setPassword("p2");
92             person2.setBoss(person1);
93             person2.save();
94             System.err.println("Person 2 saved "+person2.getOId());
95             if(!autoWrite)
96                 dbTrans1.write();
97
98             person1.setBoss(person2);
99             person1.save();
100             System.err.println("\tPerson 1 saved "+person1.getOId());
101             if(!autoWrite)
102                 dbTrans1.write();
103
104             //person3 points to person4, and person4 points to person5, person5 points to person3
105
person3.setFirstname("PersonSelf3Name");
106             person3.setLastname("PersonSelf3LastName");
107             person3.setLogin("p3");
108             person3.setPassword("p3");
109             person3.save();
110             System.err.println("Person 3 saved "+person3.getOId());
111             if(!autoWrite)
112                 dbTrans1.write();
113
114             person4.setFirstname("PersonSelf4Name");
115             person4.setLastname("PersonSelf4LastName");
116             person4.setLogin("p4");
117             person4.setPassword("p4");
118             person4.save();
119             System.err.println("Person 4 saved "+person4.getOId());
120             if(!autoWrite)
121                 dbTrans1.write();
122
123             person5.setFirstname("PersonSelf5Name");
124             person5.setLastname("PersonSelf5LastName");
125             person5.setLogin("p5");
126             person5.setPassword("p5");
127             person5.setBoss(person3);
128             person5.save();
129             System.err.println("Person 5 saved "+person5.getOId());
130             if(!autoWrite)
131                 dbTrans1.write();
132
133             person3.setBoss(person4);
134             person3.save();
135             System.err.println("\tPerson 3 saved "+person3.getOId());
136             if(!autoWrite)
137                 dbTrans1.write();
138
139             person4.setBoss(person5);
140             person4.save();
141             System.err.println("\tPerson 4 saved "+person4.getOId());
142             if(!autoWrite)
143                 dbTrans1.write();
144             if (null != dbTrans1)
145                 dbTrans1.commit();
146
147             showTable(dbTrans1);
148
149             person0.setBoss(null);
150             person0.save();
151             if(!autoWrite)
152                 dbTrans1.write();
153             person0.delete();
154
155             // person1.delete(); gets deleted by next lines
156
person2.setBoss(null);
157             person2.save();
158             if(!autoWrite)
159                 dbTrans1.write();
160
161             person2.delete();
162             // person3.delete(); these two
163
// person4.delete(); get deleted by next lines
164
person5.setBoss(null);
165             person5.save();
166             if(!autoWrite)
167                 dbTrans1.write();
168
169             person5.delete();
170
171             if (null != dbTrans1)
172                 dbTrans1.commit();
173             showTable(dbTrans1);
174         }catch (Exception JavaDoc ex){
175             System.err.println(ex.toString());
176             ex.printStackTrace();
177         }
178     }
179 }
180
Popular Tags