KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > containers > JahiaContainerListsDB


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12

13 package org.jahia.services.containers;
14
15 import org.jahia.data.JahiaDBDOMObject;
16 import org.jahia.data.JahiaDOMObject;
17 import org.jahia.data.containers.JahiaContainerList;
18 import org.jahia.exceptions.JahiaException;
19 import org.jahia.registries.ServicesRegistry;
20 import org.jahia.services.database.ConnectionDispenser;
21 import org.jahia.services.version.EntryLoadRequest;
22 import org.jahia.services.version.JahiaSaveVersion;
23
24 import java.sql.Connection JavaDoc;
25 import java.sql.ResultSet JavaDoc;
26 import java.sql.SQLException JavaDoc;
27 import java.sql.Statement JavaDoc;
28 import java.sql.PreparedStatement JavaDoc;
29
30
31 /**
32  * Holds all the methods enabling container lists load, create, update and
33  * delete.
34  *
35  * @author Eric Vassalli
36  */

37 public class JahiaContainerListsDB {
38
39     final private static org.apache.log4j.Logger logger =
40             org.apache.log4j.Logger.getLogger (JahiaContainerListsDB.class);
41
42
43     /**
44      * constructor
45      */

46     public JahiaContainerListsDB () {
47     }
48
49
50     /**
51      * loads a container list from its list ID
52      *
53      * @param listID the list ID
54      *
55      * @return returns a JahiaContainerList object
56      *
57      * @throws throws a critical JahiaException if a data access occurs
58      * @throws throws a warning JahiaException if cannot free resources
59      * @see org.jahia.data.containers.JahiaContainerList JahiaContainerList
60      */

61     public JahiaContainerList db_load_container_list (int listID, EntryLoadRequest loadVersion)
62             throws JahiaException {
63         Connection JavaDoc dbConn = null;
64         PreparedStatement JavaDoc stmt = null;
65         ResultSet JavaDoc rs = null;
66         JahiaContainerList theList = null;
67         try {
68             dbConn = ConnectionDispenser.getConnection ();
69
70             // if we want to load the staged version
71
if (loadVersion.isStaging ()) {
72                 stmt = dbConn.prepareStatement("SELECT * FROM jahia_ctn_lists WHERE (id_jahia_ctn_lists=? AND workflow_state>0) ORDER BY workflow_state DESC");
73                 stmt.setInt(1, listID);
74             }
75
76             // if we want to load the version ID
77
if (loadVersion.isVersioned ()) {
78                 stmt = dbConn.prepareStatement("SELECT * FROM jahia_ctn_lists WHERE (id_jahia_ctn_lists=? AND workflow_state<2 AND version_id<=?) ORDER BY version_id DESC");
79                 stmt.setInt(1, listID);
80                 stmt.setInt(2, loadVersion.getVersionID());
81             }
82
83             if (stmt == null) {
84                 stmt = dbConn.prepareStatement("SELECT * FROM jahia_ctn_lists WHERE id_jahia_ctn_lists=?");
85                 stmt.setInt(1, listID);
86             }
87
88             rs = stmt.executeQuery ();
89
90             if (rs.next ()) {
91                 int id = rs.getInt ("id_jahia_ctn_lists");
92                 int parentid = rs.getInt ("parententryid_jahia_ctn_lists");
93                 int pageid = rs.getInt ("pageid_jahia_ctn_lists");
94                 int defid = rs.getInt ("ctndefid_jahia_ctn_lists");
95                 int rights = rs.getInt ("rights_jahia_ctn_lists");
96                 theList = new JahiaContainerList (id, parentid, pageid, defid, rights);
97             }
98             rs.close();
99
100         } catch (SQLException JavaDoc se) {
101             String JavaDoc errorMsg = "Cannot load containers from the database -> BAILING OUT";
102             logger.warn (errorMsg, se);
103             throw new JahiaException (errorMsg, errorMsg, JahiaException.DATABASE_ERROR,
104                     JahiaException.CRITICAL_SEVERITY, se);
105
106         } finally {
107             try {
108                 if (stmt != null)
109                     stmt.close ();
110
111             } catch (SQLException JavaDoc ex) {
112                 logger.warn ("Cannot free resources", ex);
113             }
114         }
115         return theList;
116     }
117
118
119     /**
120      * creates a new containerlist with the new ID already set.
121      *
122      * @param theContainerList the JahiaContainerList object to save
123      *
124      * @throws throws a critical JahiaException if a data access occurs
125      * @throws throws a warning JahiaException if cannot free resources
126      * @see org.jahia.data.containers.JahiaContainerList
127      */

128     public void db_create_container_list2 (JahiaContainerList theContainerList,
129                                            JahiaSaveVersion saveVersion)
130             throws JahiaException {
131         Connection JavaDoc dbConn = null;
132         Statement JavaDoc stmt = null;
133         try {
134             // opens connection
135
dbConn = ConnectionDispenser.getConnection ();
136             stmt = dbConn.createStatement ();
137
138             // creates empty line
139
StringBuffer JavaDoc sqlQuery = new StringBuffer JavaDoc (
140                     "INSERT INTO jahia_ctn_lists(id_jahia_ctn_lists,parententryid_jahia_ctn_lists,pageid_jahia_ctn_lists,ctndefid_jahia_ctn_lists,rights_jahia_ctn_lists,workflow_state,version_id) VALUES (");
141             sqlQuery.append (theContainerList.getID ());
142             sqlQuery.append (",");
143             sqlQuery.append (theContainerList.getParentEntryID ());
144             sqlQuery.append (",");
145             sqlQuery.append (theContainerList.getPageID ());
146             sqlQuery.append (",");
147             sqlQuery.append (theContainerList.getctndefid ());
148             sqlQuery.append (",");
149             sqlQuery.append (theContainerList.getAclID ());
150             sqlQuery.append (",");
151             sqlQuery.append (saveVersion.getWorkflowState ());
152             sqlQuery.append (",");
153             sqlQuery.append (
154                     ((saveVersion.getWorkflowState () > 1) ? 0 : saveVersion.getVersionID ()));
155             sqlQuery.append (")");
156
157             // executes the query, then closes the connection
158
stmt.execute (sqlQuery.toString ());
159
160         } catch (SQLException JavaDoc se) {
161             String JavaDoc errorMsg = "Cannot create container in the database";
162             logger.warn (errorMsg, se);
163             throw new JahiaException (errorMsg, errorMsg, JahiaException.DATABASE_ERROR,
164                     JahiaException.CRITICAL_SEVERITY, se);
165         } finally {
166             try {
167
168                 if (stmt != null) stmt.close ();
169             } catch (SQLException JavaDoc ex) {
170                 logger.warn ("Cannot free resources", ex);
171             }
172         }
173     }
174
175
176     /**
177      * creates a new containerlist, and assignes it a new ID
178      *
179      * @param theContainerList the JahiaContainerList object to save
180      *
181      * @throws throws a critical JahiaException if a data access occurs
182      * @throws throws a warning JahiaException if cannot free resources
183      * @see org.jahia.data.containers.JahiaContainerList
184      */

185     public void db_create_container_list (JahiaContainerList theContainerList,
186                                           JahiaSaveVersion saveVersion)
187             throws JahiaException {
188         // gets the field id
189
int theListID = ServicesRegistry.getInstance ().getJahiaIncrementorsDBService ()
190                 .autoIncrement ("jahia_ctn_lists");
191         theContainerList.setID (theListID);
192         db_create_container_list2 (theContainerList, saveVersion);
193     }
194
195
196     /**
197      * updates a container list in the database
198      *
199      * @param theContainerList a JahiaContainerList object
200      *
201      * @throws throws a critical JahiaException if SQL error
202      * @throws throws a warning JahiaException if cannot free resources
203      */

204     public void db_update_container_list (JahiaContainerList theContainerList,
205                                           JahiaSaveVersion saveVersion)
206             throws JahiaException {
207         Connection JavaDoc dbConn = null;
208         Statement JavaDoc stmt = null;
209
210         try {
211
212             dbConn = ConnectionDispenser.getConnection ();
213             stmt = dbConn.createStatement ();
214
215             int ctnListID = theContainerList.getID ();
216
217             // update staged version
218
if (saveVersion.isStaging ()) {
219                 // composes the query
220
StringBuffer JavaDoc sqlQuery = new StringBuffer JavaDoc (
221                         "UPDATE jahia_ctn_lists SET parententryid_jahia_ctn_lists = ");
222                 sqlQuery.append (theContainerList.getParentEntryID ());
223                 sqlQuery.append (",");
224                 sqlQuery.append ("pageid_jahia_ctn_lists = ");
225                 sqlQuery.append (theContainerList.getPageID ());
226                 sqlQuery.append (",");
227                 sqlQuery.append ("ctndefid_jahia_ctn_lists = ");
228                 sqlQuery.append (theContainerList.getctndefid ());
229                 sqlQuery.append (",");
230                 sqlQuery.append ("rights_jahia_ctn_lists = ");
231                 sqlQuery.append (theContainerList.getAclID ());
232                 sqlQuery.append (",");
233                 sqlQuery.append ("version_id = 0 "); // no version id in staged mode
234
sqlQuery.append ("WHERE id_jahia_ctn_lists = ");
235                 sqlQuery.append (theContainerList.getID ());
236                 sqlQuery.append (" ");
237                 sqlQuery.append ("AND workflow_state>1");
238
239                 // executes the query
240
int rows = stmt.executeUpdate (sqlQuery.toString ());
241
242                 // the staged version of the field doesn't already exist
243
if (rows == 0) {
244                     createStagedContainerList (stmt, ctnListID, saveVersion);
245                     // we try an update again.
246
stmt.executeUpdate (sqlQuery.toString ());
247                 }
248
249                 // update active version
250
} else {
251                 if (saveVersion.isVersioned ()) {
252                     backupContainerListVersion (stmt, ctnListID);
253                 }
254                 // composes the query
255
StringBuffer JavaDoc sqlQuery = new StringBuffer JavaDoc (
256                         "UPDATE jahia_ctn_lists SET parententryid_jahia_ctn_lists = ");
257                 sqlQuery.append (theContainerList.getParentEntryID ());
258                 sqlQuery.append (",");
259                 sqlQuery.append ("pageid_jahia_ctn_lists = ");
260                 sqlQuery.append (theContainerList.getPageID ());
261                 sqlQuery.append (",");
262                 sqlQuery.append ("ctndefid_jahia_ctn_lists = ");
263                 sqlQuery.append (theContainerList.getctndefid ());
264                 sqlQuery.append (",");
265                 sqlQuery.append ("rights_jahia_ctn_lists = ");
266                 sqlQuery.append (theContainerList.getAclID ());
267                 sqlQuery.append (",");
268                 sqlQuery.append ("version_id = ");
269                 sqlQuery.append (saveVersion.getVersionID ());
270                 sqlQuery.append (" ");
271                 sqlQuery.append ("WHERE id_jahia_ctn_lists = ");
272                 sqlQuery.append (theContainerList.getID ());
273                 sqlQuery.append (" ");
274                 sqlQuery.append ("AND workflow_state=1");
275                 // executes the query
276
stmt.executeUpdate (sqlQuery.toString ());
277
278                 // updates field properties
279
}
280
281             // catches error if cannot execute update query
282
} catch (SQLException JavaDoc se) {
283             String JavaDoc errorMsg = "Cannot update containers in the database";
284             logger.warn (errorMsg, se);
285             throw new JahiaException (errorMsg, errorMsg, JahiaException.DATABASE_ERROR,
286                     JahiaException.CRITICAL_SEVERITY, se);
287
288         } finally {
289             try {
290                 if (stmt != null)
291                     stmt.close ();
292
293             } catch (SQLException JavaDoc ex) {
294                 logger.warn ("Cannot free resources", ex);
295             }
296         }
297     }
298
299
300     /**
301      * deletes a container list in the database
302      *
303      * @param listID the container list id
304      *
305      * @throws throws a critical JahiaException if SQL error
306      * @throws throws a warning JahiaException if cannot free resources
307      */

308     public void db_delete_container_list (int listID, JahiaSaveVersion saveVersion)
309             throws JahiaException {
310         ContentContainerList containerList =
311                 ContentContainerList.getContainerList (listID);
312
313         Connection JavaDoc dbConn = null;
314         Statement JavaDoc stmt = null;
315         try {
316             dbConn = ConnectionDispenser.getConnection ();
317             stmt = dbConn.createStatement ();
318
319             // the site is in staging mode, we update the staging version
320
if (saveVersion.isStaging ()) {
321                 if (containerList != null && containerList.hasActiveEntries ()) {
322                     // composes the query
323
String JavaDoc sqlQuery = "UPDATE jahia_ctn_lists SET version_id = -1 WHERE id_jahia_ctn_lists = " +
324                             listID + " AND workflow_state>1";
325
326                     int rows = stmt.executeUpdate (sqlQuery);
327                     // the staged version of the containerlist doesn't already exist
328
if (rows == 0) {
329                         createStagedContainerList (stmt, listID, saveVersion);
330                         stmt.executeUpdate (sqlQuery);
331                     }
332                 } else {
333                     String JavaDoc sqlQuery = "DELETE FROM jahia_ctn_lists WHERE id_jahia_ctn_lists=" + listID +
334                             " AND workflow_state>1";
335                     stmt.executeUpdate (sqlQuery);
336                 }
337             } else
338             // Versioning mode ?
339
if (saveVersion.isVersioned ()) {
340                     backupContainerListVersion (stmt, listID);
341                     String JavaDoc sqlQuery = "UPDATE jahia_ctn_lists SET workflow_state = -1, version_id = " +
342                             saveVersion.getVersionID () +
343                             " WHERE id_jahia_ctn_lists = " + listID +
344                             " AND workflow_state=1";
345                     stmt.executeUpdate (sqlQuery);
346                 } else
347                 // Normal mode (no staging, no versioning)
348
{
349                     String JavaDoc sqlQuery = "DELETE FROM jahia_ctn_lists WHERE id_jahia_ctn_lists=" + listID +
350                             " AND workflow_state=1";
351                     stmt.executeUpdate (sqlQuery);
352                 }
353
354             // catches error if cannot execute update query
355
} catch (SQLException JavaDoc se) {
356             String JavaDoc errorMsg = "Cannot delete containerlists in the database";
357             logger.warn (errorMsg, se);
358             throw new JahiaException (errorMsg, errorMsg, JahiaException.DATABASE_ERROR,
359                     JahiaException.CRITICAL_SEVERITY, se);
360
361         } finally {
362             try {
363                 if (stmt != null)
364                     stmt.close ();
365
366             } catch (SQLException JavaDoc ex) {
367                 logger.warn ("Cannot free resources", ex);
368             }
369         }
370     }
371
372
373     /**
374      * @param listID the list ID
375      *
376      * @throws JahiaException
377      */

378     public void purgeContainerList (int listID)
379             throws JahiaException {
380         Connection JavaDoc dbConn = null;
381         Statement JavaDoc stmt = null;
382         try {
383             dbConn = ConnectionDispenser.getConnection ();
384             stmt = dbConn.createStatement ();
385
386             String JavaDoc sqlQuery = "DELETE FROM jahia_ctn_lists WHERE id_jahia_ctn_lists=" + listID;
387             stmt.executeUpdate (sqlQuery);
388         }
389                 // catches error if cannot execute update query
390
catch (SQLException JavaDoc se) {
391             String JavaDoc errorMsg = "Cannot purge containerlist in the database";
392             logger.warn (errorMsg, se);
393             throw new JahiaException (errorMsg, errorMsg, JahiaException.DATABASE_ERROR,
394                     JahiaException.CRITICAL_SEVERITY, se);
395
396         } finally {
397             try {
398                 if (stmt != null)
399                     stmt.close ();
400
401             } catch (SQLException JavaDoc ex) {
402                 logger.warn ("Cannot free resources", ex);
403             }
404         }
405     }
406
407
408     /**
409      * To be called when the site is in versioning mode, to backup the
410      * old containerlist before changing it.
411      */

412     private void backupContainerListVersion (Statement JavaDoc stmt, int ctnListID)
413             throws SQLException JavaDoc {
414         String JavaDoc sqlQuery = "SELECT * FROM jahia_ctn_lists WHERE " +
415                 "id_jahia_ctn_lists = " + ctnListID +
416                 " AND workflow_state=1";
417         ResultSet JavaDoc rs = stmt.executeQuery (sqlQuery);
418         if (rs != null)
419             if (rs.next ()) {
420                 sqlQuery = "INSERT INTO jahia_ctn_lists (" +
421                         "id_jahia_ctn_lists," +
422                         "parententryid_jahia_ctn_lists," +
423                         "pageid_jahia_ctn_lists," +
424                         "ctndefid_jahia_ctn_lists," +
425                         "rights_jahia_ctn_lists," +
426                         "version_id," +
427                         "workflow_state) VALUES (" +
428                         ctnListID + "," +
429                         rs.getInt ("parententryid_jahia_ctn_lists") + "," +
430                         rs.getInt ("pageid_jahia_ctn_lists") + "," +
431                         rs.getInt ("ctndefid_jahia_ctn_lists") + "," +
432                         rs.getInt ("rights_jahia_ctn_lists") + "," +
433                         rs.getInt ("version_id") + "," +
434                         "0 )";
435                 stmt.executeUpdate (sqlQuery);
436             }
437     }
438
439
440     /**
441      * creates a staged version of a containerlist , to be called when the site is in
442      * staging mode, and that a containerlist only exist in Active mode and we want
443      * to change it...
444      */

445     private void createStagedContainerList (Statement JavaDoc stmt, int ctnListID,
446                                             JahiaSaveVersion saveVersion)
447             throws SQLException JavaDoc {
448         String JavaDoc sqlQuery = "SELECT * FROM jahia_ctn_lists WHERE " +
449                 "id_jahia_ctn_lists = " + ctnListID +
450                 " AND workflow_state=1";
451         ResultSet JavaDoc rs = stmt.executeQuery (sqlQuery);
452         if (rs != null)
453             if (rs.next ()) {
454                 sqlQuery = "INSERT INTO jahia_ctn_lists (" +
455                         "id_jahia_ctn_lists," +
456                         "parententryid_jahia_ctn_lists," +
457                         "pageid_jahia_ctn_lists," +
458                         "ctndefid_jahia_ctn_lists," +
459                         "rights_jahia_ctn_lists," +
460                         "version_id," +
461                         "workflow_state) VALUES (" +
462                         ctnListID + "," +
463                         rs.getInt ("parententryid_jahia_ctn_lists") + "," +
464                         rs.getInt ("pageid_jahia_ctn_lists") + "," +
465                         rs.getInt ("ctndefid_jahia_ctn_lists") + "," +
466                         rs.getInt ("rights_jahia_ctn_lists") + "," +
467                         saveVersion.getVersionID () + "," +
468                         saveVersion.getWorkflowState () + ")";
469                 stmt.execute (sqlQuery);
470             }
471     }
472
473
474     /**
475      * Validates the staged containerlist that way:
476      * if (versioning):backup containerlist,
477      * update active version with staged version,
478      * delete staged version
479      *
480      * @param saveVersion with the right versionID, and right isStaging() and isVersionID()
481      */

482     public void db_validate_staged_container_list (int listID, JahiaSaveVersion saveVersion)
483             throws JahiaException {
484         Connection JavaDoc dbConn = null;
485         Statement JavaDoc stmt = null;
486         try {
487             dbConn = ConnectionDispenser.getConnection ();
488             if (!ConnectionDispenser.isUsingUserTransactions())
489               dbConn.setAutoCommit (false);
490             stmt = dbConn.createStatement ();
491             String JavaDoc sqlQuery = "SELECT * FROM jahia_ctn_lists WHERE " +
492                     "id_jahia_ctn_lists = " + listID +
493                     " AND workflow_state>1";
494             ResultSet JavaDoc rs = stmt.executeQuery (sqlQuery);
495             if (rs != null)
496                 if (rs.next ()) {
497                     int aclID = rs.getInt ("rights_jahia_ctn_lists");
498                     int list_parententryID = rs.getInt ("parententryid_jahia_ctn_lists");
499                     int list_pageID = rs.getInt ("pageid_jahia_ctn_lists");
500                     int list_ctndefID = rs.getInt ("ctndefid_jahia_ctn_lists");
501                     int versionID = rs.getInt ("version_id");
502                     int workflowState = rs.getInt ("workflow_state");
503
504                     // the site is in versioning, backup version
505
if (saveVersion.isVersioned ())
506                         backupContainerListVersion (stmt, listID);
507
508                     // we must delete this container ?
509
if (versionID == -1) {
510                         if (saveVersion.isVersioned ()) {
511                             // update staged version into inactive version
512
sqlQuery = "UPDATE jahia_ctn_lists SET "
513                                     + "version_id = " + saveVersion.getVersionID () + ","
514                                     + "workflow_state = -1 "
515                                     + "WHERE id_jahia_ctn_lists = " + listID + " "
516                                     + "AND workflow_state>1";
517                             stmt.executeUpdate (sqlQuery);
518                         }
519                         // delete active & staged version
520
sqlQuery = "DELETE FROM jahia_ctn_lists WHERE id_jahia_ctn_lists=" + listID +
521                                 " AND workflow_state>=1";
522                         stmt.executeUpdate (sqlQuery);
523                     } else
524                     // no, we must validate it
525
{
526                         // delete the active
527
sqlQuery = "DELETE FROM jahia_ctn_lists WHERE id_jahia_ctn_lists=" + listID +
528                                 " AND workflow_state=1";
529                         stmt.executeUpdate (sqlQuery);
530
531                         // update staging to active version
532
sqlQuery = "UPDATE jahia_ctn_lists SET "
533                                 + "parententryid_jahia_ctn_lists = " + list_parententryID + ","
534                                 + "pageid_jahia_ctn_lists = " + list_pageID + ","
535                                 + "ctndefid_jahia_ctn_lists = " + list_ctndefID + ","
536                                 + "rights_jahia_ctn_lists = " + aclID + ","
537                                 + "version_id = " + saveVersion.getVersionID () + ", "
538                                 + "workflow_state=1 "
539                                 + "WHERE id_jahia_ctn_lists = " + listID + " "
540                                 + "AND workflow_state=" + workflowState;
541                         int rows = stmt.executeUpdate (sqlQuery);
542                         // this is a new containerlist, we insert it
543
if (rows == 0) {
544                             sqlQuery = "INSERT INTO jahia_ctn_lists (" +
545                                     "id_jahia_ctn_lists," +
546                                     "parententryid_jahia_ctn_lists," +
547                                     "pageid_jahia_ctn_lists," +
548                                     "ctndefid_jahia_ctn_lists," +
549                                     "rights_jahia_ctn_lists," +
550                                     "version_id," +
551                                     "workflow_state) VALUES (" +
552                                     listID + "," +
553                                     list_parententryID + "," +
554                                     list_pageID + "," +
555                                     list_ctndefID + "," +
556                                     aclID + "," +
557                                     saveVersion.getVersionID () + "," +
558                                     "1)";
559                             stmt.execute (sqlQuery);
560                         }
561
562
563                         // delete staged version
564
sqlQuery = "DELETE FROM jahia_ctn_lists WHERE id_jahia_ctn_lists=" + listID +
565                                 " AND workflow_state>1";
566                         stmt.executeUpdate (sqlQuery);
567                     }
568                 }
569         } catch (SQLException JavaDoc se) {
570             if (ConnectionDispenser.isUsingUserTransactions())
571               ConnectionDispenser.abortConnection();
572             String JavaDoc errorMsg = "Cannot update containerlists in the database";
573             logger.warn (errorMsg, se);
574             throw new JahiaException (errorMsg, errorMsg, JahiaException.DATABASE_ERROR,
575                     JahiaException.CRITICAL_SEVERITY, se);
576         } catch (RuntimeException JavaDoc re) {
577             if (ConnectionDispenser.isUsingUserTransactions())
578               ConnectionDispenser.abortConnection();
579             throw re;
580         } finally {
581           if (!ConnectionDispenser.isUsingUserTransactions())
582           {
583             try {
584
585                 if (stmt != null) stmt.close ();
586             } catch (SQLException JavaDoc ex) {
587                 logger.warn ("Cannot free resources", ex);
588             }
589           }
590         }
591     }
592
593
594     /**
595      * return a DOM document of all container lists of a site
596      *
597      * @param siteID the site id
598      *
599      * @return JahiaDOMObject a DOM representation of this object
600      */

601     public JahiaDOMObject getContainerListsAsDOM (int siteID)
602             throws JahiaException {
603
604         Connection JavaDoc dbConn = null;
605         Statement JavaDoc statement = null;
606         JahiaDBDOMObject dom = null;
607
608         try {
609             String JavaDoc sqlQuery = "SELECT DISTINCT jahia_ctn_lists.id_jahia_ctn_lists,jahia_ctn_lists.parententryid_jahia_ctn_lists,jahia_ctn_lists.pageid_jahia_ctn_lists,jahia_ctn_lists.ctndefid_jahia_ctn_lists,jahia_ctn_lists.rights_jahia_ctn_lists FROM jahia_ctn_lists,jahia_ctn_def where jahia_ctn_lists.ctndefid_jahia_ctn_lists=jahia_ctn_def.id_jahia_ctn_def AND jahia_ctn_def.jahiaid_jahia_ctn_def=" +
610                     siteID;
611
612             dbConn = ConnectionDispenser.getConnection ();
613             statement = dbConn.createStatement ();
614             if (statement != null) {
615                 ResultSet JavaDoc rs = statement.executeQuery (sqlQuery);
616                 if (rs != null) {
617                     dom = new JahiaDBDOMObject ();
618                     dom.addTable ("jahia_ctn_lists", rs);
619                     return dom;
620                 }
621             }
622
623         } catch (SQLException JavaDoc se) {
624             String JavaDoc errorMsg = "Cannot load container lists in the database";
625             logger.warn (errorMsg, se);
626             throw new JahiaException (errorMsg, errorMsg, JahiaException.DATABASE_ERROR,
627                     JahiaException.CRITICAL_SEVERITY, se);
628
629         } finally {
630             closeStatement (statement);
631         }
632
633         return dom;
634     }
635
636
637     private void closeStatement (Statement JavaDoc statement) {
638         // Close the opened statement
639
try {
640             if (statement != null) {
641                 statement.close ();
642             }
643
644         } catch (SQLException JavaDoc sqlEx) {
645             logger.warn ("Cannot close a statement", sqlEx);
646         }
647     }
648
649 }
650
Popular Tags