001: package allinone;
002:
003: import com.lutris.appserver.server.sql.*;
004: import com.lutris.util.*;
005: import org.enhydra.dods.*;
006: import java.sql.SQLException;
007:
008: import javax.swing.*;
009: import java.util.*;
010: import java.awt.*;
011: import java.awt.event.*;
012: import java.net.*;
013: import java.io.*;
014: import org.apache.log4j.Logger;
015: import org.apache.log4j.xml.DOMConfigurator;
016: import com.lutris.appserver.server.sql.*;
017: import allinone.data.person.*;
018:
019: public class SelfReference {
020:
021: void showTable(DBTransaction dbTrans) throws Exception {
022: try {
023: PersonSelfQuery queryPersonSelf = new PersonSelfQuery(
024: dbTrans);
025: PersonSelfDO[] allADO = queryPersonSelf.getDOArray();
026: System.err.println();
027: System.err
028: .println("-------------TablePersonSelf-----begin----------");
029: if (allADO != null) {
030: if (allADO.length > 0)
031: System.err
032: .println("------oid---------Firstname--------Lastname-----Login------Boss-----");
033: for (int i = 0; i < allADO.length; i++) {
034: System.err.print(" " + allADO[i].getOId());
035: System.err.print(" " + allADO[i].getFirstname());
036: System.err.print(" " + allADO[i].getLastname());
037: System.err.print(" " + allADO[i].getLogin());
038: System.err
039: .print(" "
040: + ((null != allADO[i].getBoss()) ? allADO[i]
041: .getBoss().getOId()
042: : null));
043: System.err.println();
044: }
045: } else {
046: System.err.println("noData");
047: }
048: System.err
049: .println("-------------TablePersonSelf-----end------------");
050: } catch (Exception e) {
051: e.printStackTrace();
052: throw new Exception("Couldn't showTables ", e);
053: }
054: }
055:
056: void runTest(DBTransaction dbTrans1) {
057: try {
058: boolean autoWrite = ((StandardDatabaseManager) DODS
059: .getDatabaseManager())
060: .getDatabaseManagerConfiguration().getAutoWrite();
061: System.err
062: .println("___ - + * startin SelfReference * + - ___");
063: showTable(dbTrans1);
064:
065: PersonSelfDO person0 = PersonSelfDO.createVirgin(dbTrans1);
066: PersonSelfDO person1 = PersonSelfDO.createVirgin(dbTrans1);
067: PersonSelfDO person2 = PersonSelfDO.createVirgin(dbTrans1);
068: PersonSelfDO person3 = PersonSelfDO.createVirgin(dbTrans1);
069: PersonSelfDO person4 = PersonSelfDO.createVirgin(dbTrans1);
070: PersonSelfDO person5 = PersonSelfDO.createVirgin(dbTrans1);
071:
072: //person0 points to itself
073: person0.setFirstname("PersonSelf0Name");
074: person0.setLastname("PersonSelf0LastName");
075: person0.setLogin("p0");
076: person0.setPassword("p0");
077: person0.save();
078: System.err.println("Person 0 saved " + person0.getOId());
079: // if(!autoWrite)
080: dbTrans1.write();
081:
082: person0.setBoss(person0);
083: person0.save();
084: System.err.println("\tPerson 0 saved " + person0.getOId());
085: // if(!autoWrite)
086: // dbTrans1.write();
087:
088: //person1 points to person2, and person2 points to person1
089: person1.setFirstname("PersonSelf1Name");
090: person1.setLastname("PersonSelf1LastName");
091: person1.setLogin("p1");
092: person1.setPassword("p1");
093: person1.save();
094: System.err.println("Person 1 saved " + person1.getOId());
095: if (!autoWrite)
096: dbTrans1.write();
097:
098: person2.setFirstname("PersonSelf2Name");
099: person2.setLastname("PersonSelf2LastName");
100: person2.setLogin("p2");
101: person2.setPassword("p2");
102: person2.setBoss(person1);
103: person2.save();
104: System.err.println("Person 2 saved " + person2.getOId());
105: if (!autoWrite)
106: dbTrans1.write();
107:
108: person1.setBoss(person2);
109: person1.save();
110: System.err.println("\tPerson 1 saved " + person1.getOId());
111: if (!autoWrite)
112: dbTrans1.write();
113:
114: //person3 points to person4, and person4 points to person5, person5 points to person3
115: person3.setFirstname("PersonSelf3Name");
116: person3.setLastname("PersonSelf3LastName");
117: person3.setLogin("p3");
118: person3.setPassword("p3");
119: person3.save();
120: System.err.println("Person 3 saved " + person3.getOId());
121: if (!autoWrite)
122: dbTrans1.write();
123:
124: person4.setFirstname("PersonSelf4Name");
125: person4.setLastname("PersonSelf4LastName");
126: person4.setLogin("p4");
127: person4.setPassword("p4");
128: person4.save();
129: System.err.println("Person 4 saved " + person4.getOId());
130: if (!autoWrite)
131: dbTrans1.write();
132:
133: person5.setFirstname("PersonSelf5Name");
134: person5.setLastname("PersonSelf5LastName");
135: person5.setLogin("p5");
136: person5.setPassword("p5");
137: person5.setBoss(person3);
138: person5.save();
139: System.err.println("Person 5 saved " + person5.getOId());
140: if (!autoWrite)
141: dbTrans1.write();
142:
143: person3.setBoss(person4);
144: person3.save();
145: System.err.println("\tPerson 3 saved " + person3.getOId());
146: if (!autoWrite)
147: dbTrans1.write();
148:
149: person4.setBoss(person5);
150: person4.save();
151: System.err.println("\tPerson 4 saved " + person4.getOId());
152: if (!autoWrite)
153: dbTrans1.write();
154: if (null != dbTrans1)
155: dbTrans1.commit();
156:
157: showTable(dbTrans1);
158:
159: person0.setBoss(null);
160: person0.save();
161: if (!autoWrite)
162: dbTrans1.write();
163: person0.delete();
164:
165: // person1.delete(); gets deleted by next lines
166: person2.setBoss(null);
167: person2.save();
168: if (!autoWrite)
169: dbTrans1.write();
170:
171: person2.delete();
172: // person3.delete(); these two
173: // person4.delete(); get deleted by next lines
174: person5.setBoss(null);
175: person5.save();
176: if (!autoWrite)
177: dbTrans1.write();
178:
179: person5.delete();
180:
181: if (null != dbTrans1)
182: dbTrans1.commit();
183: showTable(dbTrans1);
184: } catch (Exception ex) {
185: System.err.println(ex.toString());
186: ex.printStackTrace();
187: }
188: }
189: }
|