KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > pim > business > DataManager


1 package org.enhydra.pim.business;
2
3 import java.util.HashMap JavaDoc;
4
5 import org.enhydra.pim.exception.EnhydraPimDatabaseException;
6 import org.enhydra.pim.exception.EnhydraPimException;
7
8 import com.lutris.appserver.server.sql.DBTransaction;
9
10 /**
11  * @author p
12  *
13  * TODO To change the template for this generated type comment go to
14  * Window - Preferences - Java - Code Style - Code Templates
15  */

16 public class DataManager implements DataManagerI {
17
18
19     
20     
21     public void adminClean() throws EnhydraPimException {
22         DBTransaction dbTrans = null;
23         
24         try {
25             
26             dbTrans = PimBase.getPrimaryDatabase().createTransaction();
27             
28             org.enhydra.pim.data.production.ContactQuery contactQuery =
29                                         new org.enhydra.pim.data.production.ContactQuery(dbTrans);
30             org.enhydra.pim.data.production.ContactDO[] contactDOs = contactQuery.getDOArray();
31             if (contactDOs!=null && contactDOs.length>0){
32                 for(int i=0; i<contactDOs.length ; i++){
33                     contactDOs[i].delete(dbTrans);
34                 }
35             }
36             dbTrans.write();
37             
38             org.enhydra.pim.data.production.ContactTypeQuery contactTypeQuery =
39                                         new org.enhydra.pim.data.production.ContactTypeQuery(dbTrans);
40             org.enhydra.pim.data.production.ContactTypeDO[] contactTypeDOs = contactTypeQuery.getDOArray();
41             if (contactTypeDOs!=null && contactTypeDOs.length>0){
42                 for(int i=0; i<contactTypeDOs.length ; i++){
43                     contactTypeDOs[i].delete(dbTrans);
44                 }
45             }
46             dbTrans.write();
47             
48             org.enhydra.pim.data.production.TaskQuery taskQuery =
49                                         new org.enhydra.pim.data.production.TaskQuery(dbTrans);
50             org.enhydra.pim.data.production.TaskDO[] taskDOs = taskQuery.getDOArray();
51             if (taskDOs!=null && taskDOs.length>0){
52                 for(int i=0; i<taskDOs.length ; i++){
53                     taskDOs[i].delete(dbTrans);
54                 }
55             }
56             dbTrans.write();
57                         
58             org.enhydra.pim.data.production.NoteQuery noteQuery =
59                                         new org.enhydra.pim.data.production.NoteQuery(dbTrans);
60             org.enhydra.pim.data.production.NoteDO[] noteDOs = noteQuery.getDOArray();
61             if (noteDOs!=null && noteDOs.length>0){
62                 for(int i=0; i<noteDOs.length ; i++){
63                     noteDOs[i].delete(dbTrans);
64                 }
65             }
66             dbTrans.write();
67                                 
68             org.enhydra.pim.data.production.PersonQuery personQuery =
69                                         new org.enhydra.pim.data.production.PersonQuery(dbTrans);
70             org.enhydra.pim.data.production.PersonDO[] personDOs = personQuery.getDOArray();
71             if (personDOs!=null && personDOs.length>0){
72                 for(int i=0; i<personDOs.length ; i++){
73                     personDOs[i].delete(dbTrans);
74                 }
75             }
76             dbTrans.write();
77                         
78             org.enhydra.pim.data.production.OwnerQuery ownerQuery =
79                                         new org.enhydra.pim.data.production.OwnerQuery(dbTrans);
80             org.enhydra.pim.data.production.OwnerDO[] ownerDOs = ownerQuery.getDOArray();
81             if (ownerDOs!=null && ownerDOs.length>0){
82                 for(int i=0; i<ownerDOs.length ; i++){
83                     ownerDOs[i].delete(dbTrans);
84                 }
85             }
86             
87             dbTrans.write();
88             dbTrans.commit();
89                             
90         } catch (Exception JavaDoc e) {
91             try {
92                 dbTrans.rollback();
93             } catch (Exception JavaDoc ex) {
94                 ex.printStackTrace();
95             }
96             e.printStackTrace();
97             PimBase.logError("[id=9905]Database access error");
98             throw new EnhydraPimDatabaseException("[id=9905]Database access error");
99         } finally {
100             if (dbTrans != null)
101                 dbTrans.release();
102         }
103     }
104     
105     public void adminCleanBackup() throws EnhydraPimException {
106         DBTransaction dbTrans = null;
107         
108         try {
109             
110             dbTrans = PimBase.getBackupDatabase().createTransaction();
111             
112             org.enhydra.pim.data.backup.ContactQuery contactQuery =
113                                         new org.enhydra.pim.data.backup.ContactQuery(dbTrans);
114             org.enhydra.pim.data.backup.ContactDO[] contactDOs = contactQuery.getDOArray();
115             if (contactDOs!=null && contactDOs.length>0){
116                 for(int i=0; i<contactDOs.length ; i++){
117                     contactDOs[i].delete(dbTrans);
118                 }
119             }
120             dbTrans.write();
121             
122             org.enhydra.pim.data.backup.ContactTypeQuery contactTypeQuery =
123                                         new org.enhydra.pim.data.backup.ContactTypeQuery(dbTrans);
124             org.enhydra.pim.data.backup.ContactTypeDO[] contactTypeDOs = contactTypeQuery.getDOArray();
125             if (contactTypeDOs!=null && contactTypeDOs.length>0){
126                 for(int i=0; i<contactTypeDOs.length ; i++){
127                     contactTypeDOs[i].delete(dbTrans);
128                 }
129             }
130             dbTrans.write();
131             
132             org.enhydra.pim.data.backup.TaskQuery taskQuery =
133                                         new org.enhydra.pim.data.backup.TaskQuery(dbTrans);
134             org.enhydra.pim.data.backup.TaskDO[] taskDOs = taskQuery.getDOArray();
135             if (taskDOs!=null && taskDOs.length>0){
136                 for(int i=0; i<taskDOs.length ; i++){
137                     taskDOs[i].delete(dbTrans);
138                 }
139             }
140             dbTrans.write();
141                         
142             org.enhydra.pim.data.backup.NoteQuery noteQuery =
143                                         new org.enhydra.pim.data.backup.NoteQuery(dbTrans);
144             org.enhydra.pim.data.backup.NoteDO[] noteDOs = noteQuery.getDOArray();
145             if (noteDOs!=null && noteDOs.length>0){
146                 for(int i=0; i<noteDOs.length ; i++){
147                     noteDOs[i].delete(dbTrans);
148                 }
149             }
150             dbTrans.write();
151                                 
152             org.enhydra.pim.data.backup.PersonQuery personQuery =
153                                         new org.enhydra.pim.data.backup.PersonQuery(dbTrans);
154             org.enhydra.pim.data.backup.PersonDO[] personDOs = personQuery.getDOArray();
155             if (personDOs!=null && personDOs.length>0){
156                 for(int i=0; i<personDOs.length ; i++){
157                     personDOs[i].delete(dbTrans);
158                 }
159             }
160             dbTrans.write();
161                         
162             org.enhydra.pim.data.backup.OwnerQuery ownerQuery =
163                                         new org.enhydra.pim.data.backup.OwnerQuery(dbTrans);
164             org.enhydra.pim.data.backup.OwnerDO[] ownerDOs = ownerQuery.getDOArray();
165             if (ownerDOs!=null && ownerDOs.length>0){
166                 for(int i=0; i<ownerDOs.length ; i++){
167                     ownerDOs[i].delete(dbTrans);
168                 }
169             }
170             
171
172             dbTrans.commit();
173                             
174         } catch (Exception JavaDoc e) {
175             try {
176                 dbTrans.rollback();
177             } catch (Exception JavaDoc ex) {
178                 ex.printStackTrace();
179             }
180             e.printStackTrace();
181             PimBase.logError("[id=9906]Database access error");
182             throw new EnhydraPimDatabaseException("[id=9906]Database access error");
183         } finally {
184             if (dbTrans != null)
185                 dbTrans.release();
186         }
187     }
188     
189     
190     public void adminBackup() throws EnhydraPimException {
191         
192         
193         DBTransaction dbtBackup = null;
194         DBTransaction dbtProduction = null;
195         
196         try {
197             
198             dbtProduction = PimBase.getPrimaryDatabase().createTransaction();
199             dbtBackup = PimBase.getBackupDatabase().createTransaction();
200             
201             HashMap JavaDoc contactTypeDOMap = new HashMap JavaDoc();
202             
203 //
204
// dbtProduction.write();
205
// dbtBackup.write();
206

207             org.enhydra.pim.data.backup.ContactTypeDO backupContactTypeDO = null;
208             org.enhydra.pim.data.backup.OwnerDO backupOwnerDO = null;
209             org.enhydra.pim.data.backup.PersonDO backupPersonDO = null;
210             org.enhydra.pim.data.backup.ContactDO backupContactDO = null;
211                 
212                 
213                     
214             org.enhydra.pim.data.production.ContactTypeQuery contactTypeQuery = new org.enhydra.pim.data.production.ContactTypeQuery(dbtProduction);
215             org.enhydra.pim.data.production.ContactTypeDO[] contactTypeDOs = contactTypeQuery.getDOArray();
216             if (contactTypeDOs!=null && contactTypeDOs.length>0){
217                 for(int i=0; i<contactTypeDOs.length ; i++){
218                     
219                     backupContactTypeDO = org.enhydra.pim.data.backup.ContactTypeDO.createVirgin(dbtBackup);
220                     backupContactTypeDO.setContact_type(contactTypeDOs[i].getContact_type());
221                     backupContactTypeDO.save(dbtBackup);
222                     
223                     contactTypeDOMap.put(contactTypeDOs[i].get_Handle(),backupContactTypeDO);
224                 }
225             }
226             dbtBackup.write();
227                                 
228                         
229             org.enhydra.pim.data.production.OwnerQuery ownerQuery = new org.enhydra.pim.data.production.OwnerQuery(dbtProduction);
230             org.enhydra.pim.data.production.OwnerDO[] ownerDOs = ownerQuery.getDOArray();
231             if (ownerDOs!=null && ownerDOs.length>0){
232                 for(int i=0; i<ownerDOs.length ; i++){
233                     
234                     backupOwnerDO = org.enhydra.pim.data.backup.OwnerDO.createVirgin(dbtBackup);
235                     
236                     backupOwnerDO.setUsername(ownerDOs[i].getUsername());
237                     backupOwnerDO.setPassword(ownerDOs[i].getPassword());
238                     
239                     backupOwnerDO.save(dbtBackup);
240
241                     
242                     org.enhydra.pim.data.production.PersonQuery personQuery = new org.enhydra.pim.data.production.PersonQuery(dbtProduction);
243                     org.enhydra.pim.data.production.PersonDO[] personDOs = personQuery.getDOArray();
244                     if (personDOs!=null && personDOs.length>0){
245                         for(int j=0; j<personDOs.length ; j++){
246
247                             
248                             backupPersonDO = org.enhydra.pim.data.backup.PersonDO.createVirgin(dbtBackup);
249                             
250                             backupPersonDO.setOwner(backupOwnerDO);
251                             backupPersonDO.setFirstname(personDOs[j].getFirstname());
252                             backupPersonDO.setLastname(personDOs[j].getLastname());
253                             backupPersonDO.setNicname(personDOs[j].getNicname());
254                             backupPersonDO.setNote(personDOs[j].getNote());
255                             
256                             backupPersonDO.save(dbtBackup);
257                             
258                             org.enhydra.pim.data.production.ContactQuery contactQuery = new org.enhydra.pim.data.production.ContactQuery(dbtProduction);
259                             contactQuery.setQueryPerson(personDOs[j]);
260                             org.enhydra.pim.data.production.ContactDO[] contactDOs = contactQuery.getDOArray();
261                             if (contactDOs!=null && contactDOs.length>0){
262                                 for(int k=0; k<contactDOs.length ; k++){
263
264                                     backupContactDO = org.enhydra.pim.data.backup.ContactDO.createVirgin(dbtBackup);
265                                     
266                                     backupContactDO.setContact_data(contactDOs[k].getContact_data());
267                                     backupContactDO.setPerson(backupPersonDO);
268                                     backupContactDO.setNote(contactDOs[k].getNote());
269                                     
270                                     backupContactTypeDO = (org.enhydra.pim.data.backup.ContactTypeDO)contactTypeDOMap.get(contactDOs[k].getContact_type().get_Handle());
271                                     backupContactDO.setContact_type(backupContactTypeDO);
272                                     
273                                     backupContactDO.save(dbtBackup);
274                                 }
275                             }
276                         }
277                     }
278                 }
279             }
280             dbtBackup.commit();
281             dbtProduction.commit();
282         } catch (Exception JavaDoc e) {
283             e.printStackTrace();
284             PimBase.logError("[id=9903]Database access error");
285             throw new EnhydraPimDatabaseException("[id=9903]Database access error");
286         } finally {
287             if (dbtBackup != null)
288                 dbtBackup.release();
289             if (dbtProduction != null)
290                 dbtProduction.release();
291         }
292     }
293     
294     public void adminRestore() throws EnhydraPimException {
295         
296         
297         DBTransaction dbtBackup = null;
298         DBTransaction dbtProduction = null;
299         
300         try {
301             
302             dbtBackup = PimBase.getBackupDatabase().createTransaction();
303             dbtProduction = PimBase.getPrimaryDatabase().createTransaction();
304
305             
306             HashMap JavaDoc contactTypeDOMap = new HashMap JavaDoc();
307             
308 // adminClean();
309

310             dbtProduction.write();
311             dbtBackup.write();
312             
313             org.enhydra.pim.data.production.ContactTypeDO productionContactTypeDO = null;
314             org.enhydra.pim.data.production.OwnerDO productionOwnerDO = null;
315             org.enhydra.pim.data.production.PersonDO productionPersonDO = null;
316             org.enhydra.pim.data.production.ContactDO productionContactDO = null;
317                 
318                 
319                     
320             org.enhydra.pim.data.backup.ContactTypeQuery contactTypeQuery = new org.enhydra.pim.data.backup.ContactTypeQuery(dbtBackup);
321             org.enhydra.pim.data.backup.ContactTypeDO[] contactTypeDOs = contactTypeQuery.getDOArray();
322             if (contactTypeDOs!=null && contactTypeDOs.length>0){
323                 for(int i=0; i<contactTypeDOs.length ; i++){
324                     
325                     productionContactTypeDO = org.enhydra.pim.data.production.ContactTypeDO.createVirgin(dbtProduction);
326                     productionContactTypeDO.setContact_type(contactTypeDOs[i].getContact_type());
327                     
328                     productionContactTypeDO.save(dbtProduction);
329                     
330                     contactTypeDOMap.put(contactTypeDOs[i].get_Handle(),productionContactTypeDO);
331                 }
332             }
333             dbtProduction.write();
334                                 
335                         
336             org.enhydra.pim.data.backup.OwnerQuery ownerQuery = new org.enhydra.pim.data.backup.OwnerQuery(dbtBackup);
337             org.enhydra.pim.data.backup.OwnerDO[] ownerDOs = ownerQuery.getDOArray();
338             if (ownerDOs!=null && ownerDOs.length>0){
339                 for(int i=0; i<ownerDOs.length ; i++){
340                     
341                     productionOwnerDO = org.enhydra.pim.data.production.OwnerDO.createVirgin(dbtProduction);
342                     
343                     productionOwnerDO.setUsername(ownerDOs[i].getUsername());
344                     productionOwnerDO.setPassword(ownerDOs[i].getPassword());
345                     
346                     productionOwnerDO.save(dbtProduction);
347
348                     
349                     org.enhydra.pim.data.backup.PersonQuery personQuery = new org.enhydra.pim.data.backup.PersonQuery(dbtBackup);
350                     org.enhydra.pim.data.backup.PersonDO[] personDOs = personQuery.getDOArray();
351                     if (personDOs!=null && personDOs.length>0){
352                         for(int j=0; j<personDOs.length ; j++){
353
354                             
355                             productionPersonDO = org.enhydra.pim.data.production.PersonDO.createVirgin(dbtProduction);
356                             
357                             productionPersonDO.setOwner(productionOwnerDO);
358                             productionPersonDO.setFirstname(personDOs[j].getFirstname());
359                             productionPersonDO.setLastname(personDOs[j].getLastname());
360                             productionPersonDO.setNicname(personDOs[j].getNicname());
361                             productionPersonDO.setNote(personDOs[j].getNote());
362                             
363                             productionPersonDO.save(dbtProduction);
364                             
365                             org.enhydra.pim.data.backup.ContactQuery contactQuery = new org.enhydra.pim.data.backup.ContactQuery(dbtBackup);
366                             contactQuery.setQueryPerson(personDOs[j]);
367                             org.enhydra.pim.data.backup.ContactDO[] contactDOs = contactQuery.getDOArray();
368                             if (contactDOs!=null && contactDOs.length>0){
369                                 for(int k=0; k<contactDOs.length ; k++){
370
371                                     productionContactDO = org.enhydra.pim.data.production.ContactDO.createVirgin(dbtProduction);
372                                     
373                                     productionContactDO.setContact_data(contactDOs[k].getContact_data());
374                                     productionContactDO.setPerson(productionPersonDO);
375                                     productionContactDO.setNote(contactDOs[k].getNote());
376                                     
377                                     productionContactTypeDO = (org.enhydra.pim.data.production.ContactTypeDO)contactTypeDOMap.get(contactDOs[k].getContact_type().get_Handle());
378                                     productionContactDO.setContact_type(productionContactTypeDO);
379                                     
380                                     productionContactDO.save(dbtProduction);
381                                 }
382                             }
383                         }
384                     }
385                 }
386             }
387             dbtBackup.commit();
388             dbtProduction.commit();
389         } catch (Exception JavaDoc e) {
390             e.printStackTrace();
391             PimBase.logError("[id=9903]Database access error");
392             throw new EnhydraPimDatabaseException("[id=9903]Database access error");
393         } finally {
394             if (dbtBackup != null)
395                 dbtBackup.release();
396             if (dbtProduction != null)
397                 dbtProduction.release();
398         }
399     }
400     
401 }
402
Popular Tags