KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > content > ObjectLinkDB


1 package org.jahia.content;
2
3 import java.sql.Connection JavaDoc;
4 import java.sql.PreparedStatement JavaDoc;
5 import java.sql.ResultSet JavaDoc;
6 import java.sql.SQLException JavaDoc;
7 import java.sql.Statement JavaDoc;
8 import java.sql.Timestamp JavaDoc;
9 import java.util.ArrayList JavaDoc;
10 import java.util.HashMap JavaDoc;
11
12 import org.jahia.exceptions.JahiaException;
13 import org.jahia.registries.ServicesRegistry;
14
15 /**
16  * <p>Title: ObjectLink database persistence class</p>
17  * <p>Description: This class provides all the methods to retrieve, update
18  * and remove object links in the database. This class should never be used
19  * directly. Instead use the static methods available in the ObjectLink
20  * class</p>
21  * <p>Copyright: Copyright (c) 2002</p>
22  * <p>Company: Jahia Ltd</p>
23  * @author Serge Huber
24  * @version 1.0
25  */

26
27 public class ObjectLinkDB {
28
29     private static org.apache.log4j.Logger logger =
30         org.apache.log4j.Logger.getLogger(ObjectLinkDB.class);
31
32     private static ObjectLinkDB singletonInstance = null;
33
34     /**
35      * Return an instance of this class
36      */

37     protected static synchronized ObjectLinkDB getInstance () {
38         if (singletonInstance == null) {
39             singletonInstance = new ObjectLinkDB();
40         }
41         return singletonInstance;
42     }
43
44 /////////////// BELOW ARE DATABASE ACCESS RELATED METHODS /////////////////
45

46     protected ObjectLink getObjectLink (int linkID)
47         throws JahiaException {
48
49         ObjectLink link = null;
50         Connection JavaDoc dbConn = null;
51         Statement JavaDoc stmt = null;
52         ResultSet JavaDoc rs = null;
53
54         final String JavaDoc selectFields = "id," +
55                                     "left_oid," +
56                                     "right_oid," +
57                                     "type," +
58                                     "status," +
59                                     "creation_date," +
60                                     "creation_user," +
61                                     "lastmodif_date," +
62                                     "lastmodif_user";
63
64         try {
65             String JavaDoc sqlQuery = "SELECT " +
66                               selectFields +
67                               " FROM jahia_link WHERE id=" + linkID;
68
69             dbConn = org.jahia.services.database.ConnectionDispenser.getConnection();
70             stmt = dbConn.createStatement();
71             rs = stmt.executeQuery( sqlQuery);
72
73             // is there at least one element in the resultset ?
74
if (rs.next()) {
75                 // yes, we get first value
76
int id = rs.getInt("id");
77                 String JavaDoc leftOID = rs.getString("left_oid");
78                 String JavaDoc rightOID = rs.getString("right_oid");
79                 String JavaDoc type = rs.getString("type");
80                 int status = rs.getInt("status");
81                 Timestamp JavaDoc creationDate = rs.getTimestamp("creation_date");
82                 String JavaDoc creationUserKey = rs.getString("creation_user");
83                 Timestamp JavaDoc lastModificationDate = rs.getTimestamp(
84                     "lastmodif_date");
85                 String JavaDoc lastModificationUserKey = rs.getString("lastmodif_user");
86
87                 try {
88                     link = new ObjectLink(id, ObjectKey.getInstance(leftOID),
89                                           ObjectKey.getInstance(rightOID), type,
90                                           status,
91                                           creationDate, creationUserKey,
92                                           lastModificationDate,
93                                           lastModificationUserKey, new HashMap JavaDoc(),
94                                           new HashMap JavaDoc(), new HashMap JavaDoc());
95                 } catch (ClassNotFoundException JavaDoc cnfe) {
96                     logger.error("Couldn't create instance of an ObjectKey", cnfe);
97                 }
98             }
99
100         } catch (SQLException JavaDoc se) {
101             throw new JahiaException("Cannot load object link " + linkID +
102                                      "from the database",
103                                      se.getMessage(),
104                                      JahiaException.DATABASE_ERROR,
105                                      JahiaException.ERROR_SEVERITY, se);
106         } finally {
107             try {
108                 if (stmt != null)
109                     stmt.close();
110             } catch (SQLException JavaDoc ex) {
111                 throw new JahiaException("Cannot free resources",
112                                          "Cannot free resources",
113                                          JahiaException.DATABASE_ERROR,
114                                          JahiaException.WARNING_SEVERITY, ex);
115             }
116         }
117
118         return link;
119     }
120
121     protected ArrayList JavaDoc findByLeftObjectKey (ObjectKey leftObjectKey)
122         throws JahiaException {
123
124         ArrayList JavaDoc resultList = new ArrayList JavaDoc();
125         Connection JavaDoc dbConn = null;
126         PreparedStatement JavaDoc stmt = null;
127         ResultSet JavaDoc rs = null;
128
129         final String JavaDoc selectFields = "id," +
130                                     "left_oid," +
131                                     "right_oid," +
132                                     "type," +
133                                     "status," +
134                                     "creation_date," +
135                                     "creation_user," +
136                                     "lastmodif_date," +
137                                     "lastmodif_user";
138
139         try {
140             String JavaDoc sqlQuery = "SELECT " +
141                               selectFields +
142                               " FROM jahia_link WHERE left_oid=?";
143
144             dbConn = org.jahia.services.database.ConnectionDispenser.getConnection();
145             stmt = dbConn.prepareStatement(sqlQuery);
146             stmt.setString(1, leftObjectKey.toString());
147             // rs can't be null (cf. api)
148
rs = stmt.executeQuery();
149
150             while (rs.next()) {
151                 int id = rs.getInt("id");
152                 String JavaDoc leftOID = rs.getString("left_oid");
153                 String JavaDoc rightOID = rs.getString("right_oid");
154                 String JavaDoc type = rs.getString("type");
155                 int status = rs.getInt("status");
156                 Timestamp JavaDoc creationDate = rs.getTimestamp("creation_date");
157
158                 String JavaDoc creationUserKey = rs.getString("creation_user");
159                 Timestamp JavaDoc lastModificationDate = rs.getTimestamp(
160                     "lastmodif_date");
161                 String JavaDoc lastModificationUserKey = rs.getString("lastmodif_user");
162
163                 try {
164                     resultList.add(new ObjectLink(id,
165                                                   ObjectKey.getInstance(leftOID),
166                                                   ObjectKey.getInstance(rightOID),
167                                                   type,
168                                                   status,
169                                                   creationDate, creationUserKey,
170                                                   lastModificationDate,
171                                                   lastModificationUserKey,
172                                                   new HashMap JavaDoc(),
173                                                   new HashMap JavaDoc(), new HashMap JavaDoc()));
174                 } catch (ClassNotFoundException JavaDoc cnfe) {
175                     logger.error("Couldn't create instance of an ObjectKey", cnfe);
176                 }
177             }
178
179         } catch (SQLException JavaDoc se) {
180             throw new JahiaException(
181                 "Cannot load object link by left object key " + leftObjectKey +
182                 "from the database",
183                 se.getMessage(),
184                 JahiaException.DATABASE_ERROR,
185                 JahiaException.ERROR_SEVERITY, se);
186         } finally {
187             try {
188                 if (stmt != null)
189                     stmt.close();
190             } catch (SQLException JavaDoc ex) {
191                 throw new JahiaException("Cannot free resources",
192                                          "Cannot free resources",
193                                          JahiaException.DATABASE_ERROR,
194                                          JahiaException.WARNING_SEVERITY, ex);
195             }
196         }
197
198         return resultList;
199     }
200
201     protected ArrayList JavaDoc findByRightObjectKey (ObjectKey rightObjectKey)
202         throws JahiaException {
203
204         ArrayList JavaDoc resultList = new ArrayList JavaDoc();
205         Connection JavaDoc dbConn = null;
206         PreparedStatement JavaDoc stmt = null;
207         ResultSet JavaDoc rs = null;
208
209         final String JavaDoc selectFields = "id," +
210                                     "left_oid," +
211                                     "right_oid," +
212                                     "type," +
213                                     "status," +
214                                     "creation_date," +
215                                     "creation_user," +
216                                     "lastmodif_date," +
217                                     "lastmodif_user";
218
219         try {
220             String JavaDoc sqlQuery = "SELECT " +
221                               selectFields +
222                               " FROM jahia_link WHERE right_oid=?";
223
224             dbConn = org.jahia.services.database.ConnectionDispenser.getConnection();
225             stmt = dbConn.prepareStatement(sqlQuery);
226             stmt.setString(1, rightObjectKey.toString());
227             // rs can't be null (cf. api)
228
rs = stmt.executeQuery();
229
230             while (rs.next()) {
231                 int id = rs.getInt("id");
232                 String JavaDoc leftOID = rs.getString("left_oid");
233                 String JavaDoc rightOID = rs.getString("right_oid");
234                 String JavaDoc type = rs.getString("type");
235                 int status = rs.getInt("status");
236                 Timestamp JavaDoc creationDate = rs.getTimestamp("creation_date");
237                 String JavaDoc creationUserKey = rs.getString("creation_user");
238                 Timestamp JavaDoc lastModificationDate = rs.getTimestamp(
239                     "lastmodif_date");
240                 String JavaDoc lastModificationUserKey = rs.getString("lastmodif_user");
241
242                 try {
243                     resultList.add(new ObjectLink(id,
244                                                   ObjectKey.getInstance(leftOID),
245                                                   ObjectKey.getInstance(rightOID),
246                                                   type,
247                                                   status,
248                                                   creationDate, creationUserKey,
249                                                   lastModificationDate,
250                                                   lastModificationUserKey,
251                                                   new HashMap JavaDoc(),
252                                                   new HashMap JavaDoc(), new HashMap JavaDoc()));
253                 } catch (ClassNotFoundException JavaDoc cnfe) {
254                     logger.error("Couldn't create instance of an ObjectKey", cnfe);
255                 }
256             }
257
258         } catch (SQLException JavaDoc se) {
259             throw new JahiaException(
260                 "Cannot load object link by right object key " + rightObjectKey +
261                 "from the database",
262                 se.getMessage(),
263                 JahiaException.DATABASE_ERROR,
264                 JahiaException.ERROR_SEVERITY, se);
265         } finally {
266             try {
267                 if (stmt != null)
268                     stmt.close();
269             } catch (SQLException JavaDoc ex) {
270                 throw new JahiaException("Cannot free resources",
271                                          "Cannot free resources",
272                                          JahiaException.DATABASE_ERROR,
273                                          JahiaException.WARNING_SEVERITY, ex);
274             }
275         }
276
277         return resultList;
278     }
279
280     protected ArrayList JavaDoc findByLeftAndRightObjectKeys (ObjectKey leftObjectKey,
281         ObjectKey rightObjectKey)
282         throws JahiaException {
283
284         ArrayList JavaDoc resultList = new ArrayList JavaDoc();
285         Connection JavaDoc dbConn = null;
286         PreparedStatement JavaDoc stmt = null;
287         ResultSet JavaDoc rs = null;
288
289         final String JavaDoc selectFields = "id," +
290                                     "left_oid," +
291                                     "right_oid," +
292                                     "type," +
293                                     "status," +
294                                     "creation_date," +
295                                     "creation_user," +
296                                     "lastmodif_date," +
297                                     "lastmodif_user";
298
299         try {
300             String JavaDoc sqlQuery = "SELECT " +
301                               selectFields +
302                               " FROM jahia_link WHERE left_oid=? AND right_oid=?";
303
304             dbConn = org.jahia.services.database.ConnectionDispenser.getConnection();
305             stmt = dbConn.prepareStatement(sqlQuery);
306             stmt.setString(1, leftObjectKey.toString());
307             stmt.setString(2, rightObjectKey.toString());
308             // rs can't be null (cf. api)
309
rs = stmt.executeQuery();
310
311             while (rs.next()) {
312                 int id = rs.getInt("id");
313                 String JavaDoc leftOID = rs.getString("left_oid");
314                 String JavaDoc rightOID = rs.getString("right_oid");
315                 String JavaDoc type = rs.getString("type");
316                 int status = rs.getInt("status");
317                 Timestamp JavaDoc creationDate = rs.getTimestamp("creation_date");
318                 String JavaDoc creationUserKey = rs.getString("creation_user");
319                 Timestamp JavaDoc lastModificationDate = rs.getTimestamp(
320                     "lastmodif_date");
321                 String JavaDoc lastModificationUserKey = rs.getString("lastmodif_user");
322
323                 try {
324                     resultList.add(new ObjectLink(id,
325                                                   ObjectKey.getInstance(leftOID),
326                                                   ObjectKey.getInstance(rightOID),
327                                                   type,
328                                                   status,
329                                                   creationDate, creationUserKey,
330                                                   lastModificationDate,
331                                                   lastModificationUserKey,
332                                                   new HashMap JavaDoc(),
333                                                   new HashMap JavaDoc(), new HashMap JavaDoc()));
334                 } catch (ClassNotFoundException JavaDoc cnfe) {
335                     logger.error("Couldn't create instance of an ObjectKey", cnfe);
336                 }
337             }
338
339         } catch (SQLException JavaDoc se) {
340             throw new JahiaException(
341                 "Cannot load object link by right object key " + rightObjectKey +
342                 "from the database",
343                 se.getMessage(),
344                 JahiaException.DATABASE_ERROR,
345                 JahiaException.ERROR_SEVERITY, se);
346         } finally {
347             try {
348                 if (stmt != null)
349                     stmt.close();
350             } catch (SQLException JavaDoc ex) {
351                 throw new JahiaException("Cannot free resources",
352                                          "Cannot free resources",
353                                          JahiaException.DATABASE_ERROR,
354                                          JahiaException.WARNING_SEVERITY, ex);
355             }
356         }
357
358         return resultList;
359     }
360
361     protected ArrayList JavaDoc findByTypeAndLeftAndRightObjectKeys (String JavaDoc type,
362         ObjectKey leftObjectKey,
363         ObjectKey rightObjectKey)
364         throws JahiaException {
365
366         ArrayList JavaDoc resultList = new ArrayList JavaDoc();
367         Connection JavaDoc dbConn = null;
368         PreparedStatement JavaDoc stmt = null;
369         ResultSet JavaDoc rs = null;
370
371         final String JavaDoc selectFields = "id," +
372                                     "left_oid," +
373                                     "right_oid," +
374                                     "type," +
375                                     "status," +
376                                     "creation_date," +
377                                     "creation_user," +
378                                     "lastmodif_date," +
379                                     "lastmodif_user";
380
381         try {
382             String JavaDoc sqlQuery = "SELECT " +
383                               selectFields +
384                               " FROM jahia_link WHERE type=? AND left_oid=? AND right_oid=?";
385
386             dbConn = org.jahia.services.database.ConnectionDispenser.getConnection();
387             stmt = dbConn.prepareStatement(sqlQuery);
388             stmt.setString(1, type);
389             stmt.setString(2, leftObjectKey.toString());
390             stmt.setString(3, rightObjectKey.toString());
391             // rs can't be null (cf. api)
392
rs = stmt.executeQuery();
393
394             while (rs.next()) {
395                 int id = rs.getInt("id");
396                 String JavaDoc leftOID = rs.getString("left_oid");
397                 String JavaDoc rightOID = rs.getString("right_oid");
398                 int status = rs.getInt("status");
399                 Timestamp JavaDoc creationDate = rs.getTimestamp("creation_date");
400                 String JavaDoc creationUserKey = rs.getString("creation_user");
401                 Timestamp JavaDoc lastModificationDate = rs.getTimestamp(
402                     "lastmodif_date");
403                 String JavaDoc lastModificationUserKey = rs.getString("lastmodif_user");
404
405                 try {
406                     resultList.add(new ObjectLink(id,
407                                                   ObjectKey.getInstance(leftOID),
408                                                   ObjectKey.getInstance(rightOID),
409                                                   type,
410                                                   status,
411                                                   creationDate, creationUserKey,
412                                                   lastModificationDate,
413                                                   lastModificationUserKey,
414                                                   new HashMap JavaDoc(),
415                                                   new HashMap JavaDoc(), new HashMap JavaDoc()));
416                 } catch (ClassNotFoundException JavaDoc cnfe) {
417                     logger.error("Couldn't create instance of an ObjectKey",
418                                  cnfe);
419                 }
420             }
421
422         } catch (SQLException JavaDoc se) {
423             throw new JahiaException(
424                 "Cannot load object link by right object key " + rightObjectKey +
425                 "from the database",
426                 se.getMessage(),
427                 JahiaException.DATABASE_ERROR,
428                 JahiaException.ERROR_SEVERITY, se);
429         } finally {
430             try {
431                 if (stmt != null)
432                     stmt.close();
433             } catch (SQLException JavaDoc ex) {
434                 throw new JahiaException("Cannot free resources",
435                                          "Cannot free resources",
436                                          JahiaException.DATABASE_ERROR,
437                                          JahiaException.WARNING_SEVERITY, ex);
438             }
439         }
440
441         return resultList;
442     }
443
444     protected ArrayList JavaDoc findByTypeAndLeftObjectKey (String JavaDoc type,
445         ObjectKey leftObjectKey)
446         throws JahiaException {
447
448         ArrayList JavaDoc resultList = new ArrayList JavaDoc();
449         Connection JavaDoc dbConn = null;
450         PreparedStatement JavaDoc stmt = null;
451         ResultSet JavaDoc rs = null;
452
453         final String JavaDoc selectFields = "id," +
454                                     "left_oid," +
455                                     "right_oid," +
456                                     "type," +
457                                     "status," +
458                                     "creation_date," +
459                                     "creation_user," +
460                                     "lastmodif_date," +
461                                     "lastmodif_user";
462
463         try {
464             String JavaDoc sqlQuery = "SELECT " +
465                               selectFields +
466                               " FROM jahia_link WHERE type=? AND left_oid=?";
467
468             dbConn = org.jahia.services.database.ConnectionDispenser.getConnection();
469             stmt = dbConn.prepareStatement(sqlQuery);
470             stmt.setString(1, type);
471             stmt.setString(2, leftObjectKey.toString());
472             // rs can't be null (cf. api)
473
rs = stmt.executeQuery();
474
475             while (rs.next()) {
476                 int id = rs.getInt("id");
477                 String JavaDoc leftOID = rs.getString("left_oid");
478                 String JavaDoc rightOID = rs.getString("right_oid");
479                 int status = rs.getInt("status");
480                 Timestamp JavaDoc creationDate = rs.getTimestamp("creation_date");
481                 String JavaDoc creationUserKey = rs.getString("creation_user");
482                 Timestamp JavaDoc lastModificationDate = rs.getTimestamp(
483                     "lastmodif_date");
484                 String JavaDoc lastModificationUserKey = rs.getString("lastmodif_user");
485
486                 try {
487                     resultList.add(new ObjectLink(id,
488                                                   ObjectKey.getInstance(leftOID),
489                                                   ObjectKey.getInstance(rightOID),
490                                                   type,
491                                                   status,
492                                                   creationDate, creationUserKey,
493                                                   lastModificationDate,
494                                                   lastModificationUserKey,
495                                                   new HashMap JavaDoc(),
496                                                   new HashMap JavaDoc(), new HashMap JavaDoc()));
497                 } catch (ClassNotFoundException JavaDoc cnfe) {
498                     logger.error("Couldn't create instance of an ObjectKey",
499                                  cnfe);
500                 }
501             }
502
503         } catch (SQLException JavaDoc se) {
504             throw new JahiaException(
505                 "Cannot load object link by type " + type +
506                 " and left object key " + leftObjectKey +
507                 "from the database",
508                 se.getMessage(),
509                 JahiaException.DATABASE_ERROR,
510                 JahiaException.ERROR_SEVERITY, se);
511         } finally {
512             try {
513                 if (stmt != null)
514                     stmt.close();
515             } catch (SQLException JavaDoc ex) {
516                 throw new JahiaException("Cannot free resources",
517                                          "Cannot free resources",
518                                          JahiaException.DATABASE_ERROR,
519                                          JahiaException.WARNING_SEVERITY, ex);
520             }
521         }
522
523         return resultList;
524     }
525
526     protected ArrayList JavaDoc findByTypeAndRightObjectKey (String JavaDoc type,
527         ObjectKey rightObjectKey)
528         throws JahiaException {
529
530         ArrayList JavaDoc resultList = new ArrayList JavaDoc();
531         Connection JavaDoc dbConn = null;
532         PreparedStatement JavaDoc stmt = null;
533         ResultSet JavaDoc rs = null;
534
535         final String JavaDoc selectFields = "id," +
536                                     "left_oid," +
537                                     "right_oid," +
538                                     "type," +
539                                     "status," +
540                                     "creation_date," +
541                                     "creation_user," +
542                                     "lastmodif_date," +
543                                     "lastmodif_user";
544
545         try {
546             String JavaDoc sqlQuery = "SELECT " +
547                               selectFields +
548                               " FROM jahia_link WHERE type=? AND right_oid=?";
549
550             dbConn = org.jahia.services.database.ConnectionDispenser.getConnection();
551             stmt = dbConn.prepareStatement(sqlQuery);
552             stmt.setString(1, type);
553             stmt.setString(2, rightObjectKey.toString());
554             // rs can't be null (cf. api)
555
rs = stmt.executeQuery();
556
557             while (rs.next()) {
558                 int id = rs.getInt("id");
559                 String JavaDoc leftOID = rs.getString("left_oid");
560                 String JavaDoc rightOID = rs.getString("right_oid");
561                 int status = rs.getInt("status");
562                 Timestamp JavaDoc creationDate = rs.getTimestamp("creation_date");
563                 String JavaDoc creationUserKey = rs.getString("creation_user");
564                 Timestamp JavaDoc lastModificationDate = rs.getTimestamp(
565                     "lastmodif_date");
566                 String JavaDoc lastModificationUserKey = rs.getString("lastmodif_user");
567
568                 try {
569                     resultList.add(new ObjectLink(id,
570                                                   ObjectKey.getInstance(leftOID),
571                                                   ObjectKey.getInstance(rightOID),
572                                                   type,
573                                                   status,
574                                                   creationDate, creationUserKey,
575                                                   lastModificationDate,
576                                                   lastModificationUserKey,
577                                                   new HashMap JavaDoc(),
578                                                   new HashMap JavaDoc(), new HashMap JavaDoc()));
579                 } catch (ClassNotFoundException JavaDoc cnfe) {
580                     logger.error("Couldn't create instance of an ObjectKey",
581                                  cnfe);
582                 }
583             }
584
585         } catch (SQLException JavaDoc se) {
586             throw new JahiaException(
587                 "Cannot load object link by type "+type+" and right object key " + rightObjectKey +
588                 "from the database",
589                 se.getMessage(),
590                 JahiaException.DATABASE_ERROR,
591                 JahiaException.ERROR_SEVERITY, se);
592         } finally {
593             try {
594                 if (stmt != null)
595                     stmt.close();
596             } catch (SQLException JavaDoc ex) {
597                 throw new JahiaException("Cannot free resources",
598                                          "Cannot free resources",
599                                          JahiaException.DATABASE_ERROR,
600                                          JahiaException.WARNING_SEVERITY, ex);
601             }
602         }
603
604         return resultList;
605     }
606
607     protected void createObjectLink (ObjectLink link)
608         throws JahiaException {
609         Connection JavaDoc dbConn = null;
610         PreparedStatement JavaDoc stmt = null;
611         ResultSet JavaDoc rs = null;
612
613         int linkID = ServicesRegistry.getInstance().getJahiaIncrementorsDBService().autoIncrement("jahia_link");
614         link.setID(linkID);
615
616         try {
617             String JavaDoc sqlQuery = "INSERT INTO jahia_link (" +
618                               "id," +
619                               "left_oid," +
620                               "right_oid," +
621                               "type," +
622                               "status," +
623                               "creation_date," +
624                               "creation_user," +
625                               "lastmodif_date," +
626                               "lastmodif_user" +
627                               ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
628             dbConn = org.jahia.services.database.ConnectionDispenser.getConnection();
629             stmt = dbConn.prepareStatement(sqlQuery);
630             stmt.setInt(1, link.getID());
631             stmt.setString(2, link.getLeftObjectKey().toString());
632             stmt.setString(3, link.getRightObjectKey().toString());
633             stmt.setString(4, link.getType());
634             stmt.setInt(5, link.getStatus());
635             stmt.setTimestamp(6, new Timestamp JavaDoc(link.getCreationDate().getTime()));
636             stmt.setString(7, link.getCreationUserKey());
637             stmt.setTimestamp(8, new Timestamp JavaDoc(link.getLastModificationDate().getTime()));
638             stmt.setString(9, link.getLastModificationUserKey());
639             stmt.execute();
640         } catch (SQLException JavaDoc se) {
641             throw new JahiaException("Cannot store link in the database",
642                                      se.getMessage(),
643                                      JahiaException.DATABASE_ERROR,
644                                      JahiaException.ERROR_SEVERITY, se);
645         } finally {
646             try {
647                 if (stmt != null)
648                     stmt.close();
649             } catch (SQLException JavaDoc ex) {
650                 throw new JahiaException("Cannot free resources",
651                                          "Cannot free resources",
652                                          JahiaException.DATABASE_ERROR,
653                                          JahiaException.WARNING_SEVERITY, ex);
654             }
655         }
656     }
657
658     protected void updateObjectLink (ObjectLink link)
659         throws JahiaException {
660         Connection JavaDoc dbConn = null;
661         PreparedStatement JavaDoc stmt = null;
662         ResultSet JavaDoc rs = null;
663
664         try {
665             String JavaDoc sqlQuery = "UPDATE jahia_link SET " +
666                               "id=?," +
667                               "left_oid=?," +
668                               "right_oid=?," +
669                               "type=?," +
670                               "status=?," +
671                               "creation_date=?," +
672                               "creation_user=?," +
673                               "lastmodif_date=?," +
674                               "lastmodif_user=? " +
675                               "WHERE id=?";
676             dbConn = org.jahia.services.database.ConnectionDispenser.getConnection();
677             stmt = dbConn.prepareStatement(sqlQuery);
678             stmt.setInt(1, link.getID());
679             stmt.setString(2, link.getLeftObjectKey().toString());
680             stmt.setString(3, link.getRightObjectKey().toString());
681             stmt.setString(4, link.getType());
682             stmt.setInt(5, link.getStatus());
683             stmt.setTimestamp(6, new Timestamp JavaDoc(link.getCreationDate().getTime()));
684             stmt.setString(7, link.getCreationUserKey());
685             stmt.setTimestamp(8, new Timestamp JavaDoc(link.getLastModificationDate().getTime()));
686             stmt.setString(9, link.getLastModificationUserKey());
687             stmt.setInt(10, link.getID());
688             stmt.executeUpdate();
689         } catch (SQLException JavaDoc se) {
690             throw new JahiaException("Cannot store link in the database",
691                                      se.getMessage(),
692                                      JahiaException.DATABASE_ERROR,
693                                      JahiaException.ERROR_SEVERITY, se);
694         } finally {
695             try {
696                 if (stmt != null)
697                     stmt.close();
698             } catch (SQLException JavaDoc ex) {
699                 throw new JahiaException("Cannot free resources",
700                                          "Cannot free resources",
701                                          JahiaException.DATABASE_ERROR,
702                                          JahiaException.WARNING_SEVERITY, ex);
703             }
704         }
705     }
706
707
708     protected void removeObjectLink (int linkID)
709         throws JahiaException {
710
711         Connection JavaDoc dbConn = null;
712         Statement JavaDoc stmt = null;
713         ResultSet JavaDoc rs = null;
714
715         try {
716             String JavaDoc sqlQuery = "DELETE FROM jahia_link WHERE id=" + linkID;
717             dbConn = org.jahia.services.database.ConnectionDispenser.getConnection();
718             stmt = dbConn.createStatement();
719             stmt.executeUpdate(sqlQuery);
720         } catch (SQLException JavaDoc se) {
721             throw new JahiaException("Cannot remove link from database",
722                                      se.getMessage(),
723                                      JahiaException.DATABASE_ERROR,
724                                      JahiaException.ERROR_SEVERITY, se);
725         } finally {
726             try {
727                 if (stmt != null)
728                     stmt.close();
729             } catch (SQLException JavaDoc ex) {
730                 throw new JahiaException("Cannot free resources",
731                                          "Cannot free resources",
732                                          JahiaException.DATABASE_ERROR,
733                                          JahiaException.WARNING_SEVERITY, ex);
734             }
735         }
736     }
737
738 }
Popular Tags