1 13 20 21 28 package org.jahia.services.containers; 29 30 import org.jahia.data.JahiaDBDOMObject; 31 import org.jahia.data.JahiaDOMObject; 32 import org.jahia.data.containers.JahiaContainer; 33 import org.jahia.exceptions.JahiaException; 34 import org.jahia.services.database.ConnectionDispenser; 35 import org.jahia.services.version.EntryLoadRequest; 36 import org.jahia.services.version.JahiaSaveVersion; 37 38 import java.sql.Connection ; 39 import java.sql.PreparedStatement ; 40 import java.sql.ResultSet ; 41 import java.sql.SQLException ; 42 import java.sql.Statement ; 43 import java.util.Vector ; 44 45 public class JahiaContainersDB { 46 47 private static org.apache.log4j.Logger logger = 48 org.apache.log4j.Logger.getLogger (JahiaContainersDB.class); 49 50 53 public JahiaContainersDB () { 54 } 56 66 public Vector db_load_all_active_containers_info_from_page (int pageID) throws 67 JahiaException { 68 Vector result = new Vector (); 69 Connection dbConn = null; 70 PreparedStatement stmt = null; 71 ResultSet rs = null; 72 JahiaContainer theContainer = null; 73 try { 74 String sqlQuery = "SELECT * FROM jahia_ctn_entries WHERE pageid_jahia_ctn_entries=? AND workflow_state=1"; 75 76 dbConn = ConnectionDispenser.getConnection (); 77 stmt = dbConn.prepareStatement (sqlQuery); 78 stmt.setInt(1, pageID); 79 rs = stmt.executeQuery (); 80 81 while (rs.next ()) { 82 int ID = rs.getInt ("id_jahia_ctn_entries"); 84 int jahiaID = rs.getInt ("jahiaid_jahia_ctn_entries"); 85 int listID = rs.getInt ("listid_jahia_ctn_entries"); 86 int definitionID = rs.getInt ("ctndefid_jahia_ctn_entries"); 87 int rank = rs.getInt ("rank_jahia_ctn_entries"); 88 int rights = rs.getInt ("rights_jahia_ctn_entries"); 89 int versionID = rs.getInt ("version_id"); 90 int workflowState = rs.getInt ("workflow_state"); 91 92 theContainer = new JahiaContainer (ID, jahiaID, pageID, listID, 93 rank, rights, definitionID, 94 versionID, workflowState); 95 result.add (theContainer); 96 } 97 98 } catch (SQLException se) { 99 logger.debug ("Bailing out because of SQL exception", se); 100 String errorMsg = "Error in db_load_all_active_container : " + 101 se.getMessage () + " -> BAILING OUT"; 102 throw new JahiaException ("Cannot load fields from the database", 103 errorMsg, JahiaException.DATABASE_ERROR, 104 JahiaException.CRITICAL_SEVERITY, se); 105 } finally { 106 try { 107 if (stmt != null) { 108 stmt.close (); 109 } 110 } catch (SQLException ex) { 111 new JahiaException ("Cannot free resources", 112 "db_load_all_active_container : cannot free resources", 113 JahiaException.DATABASE_ERROR, 114 JahiaException.WARNING_SEVERITY); 115 } 116 } 117 return result; 118 } 120 133 public JahiaContainer db_load_container (int ctnid, 134 EntryLoadRequest loadVersion) throws 135 JahiaException { 136 Connection dbConn = null; 137 PreparedStatement stmt = null; 138 ResultSet rs = null; 139 JahiaContainer theContainer = null; 140 try { 141 String sqlQuery = "SELECT * FROM jahia_ctn_entries WHERE (id_jahia_ctn_entries=? AND workflow_state=1)"; 143 144 if (loadVersion.isStaging ()) { 146 sqlQuery = "SELECT * FROM jahia_ctn_entries WHERE (id_jahia_ctn_entries=? AND workflow_state>0) ORDER BY workflow_state DESC"; 147 } else if (loadVersion.isDeleted ()) { 148 sqlQuery = "SELECT * FROM jahia_ctn_entries WHERE (id_jahia_ctn_entries=? AND workflow_state=-1) ORDER BY version_id DESC"; 149 } else if (loadVersion.isVersioned ()) { 151 sqlQuery = "SELECT * FROM jahia_ctn_entries WHERE (id_jahia_ctn_entries=? AND workflow_state<2 AND version_id<=?) ORDER BY version_id DESC"; 152 } 153 154 dbConn = ConnectionDispenser.getConnection (); 155 stmt = dbConn.prepareStatement (sqlQuery); 156 stmt.setInt(1, ctnid); 157 if (loadVersion.isVersioned ()){ 158 stmt.setInt(2, loadVersion.getVersionID ()); 159 } 160 rs = stmt.executeQuery (); 161 162 if (rs.next ()) { 163 int ID = rs.getInt ("id_jahia_ctn_entries"); 165 int jahiaID = rs.getInt ("jahiaid_jahia_ctn_entries"); 166 int pageID = rs.getInt ("pageid_jahia_ctn_entries"); 167 int listID = rs.getInt ("listid_jahia_ctn_entries"); 168 int definitionID = rs.getInt ("ctndefid_jahia_ctn_entries"); 169 int rank = rs.getInt ("rank_jahia_ctn_entries"); 170 int rights = rs.getInt ("rights_jahia_ctn_entries"); 171 int versionID = rs.getInt ("version_id"); 172 int workflowState = rs.getInt ("workflow_state"); 173 174 if (!loadVersion.isWithDeleted () 175 && (workflowState == -1 || versionID == -1)) { 176 return null; 177 } 178 theContainer = new JahiaContainer (ID, jahiaID, pageID, listID, 179 rank, rights, definitionID, 180 versionID, workflowState); 181 } 182 183 } catch (SQLException se) { 184 logger.debug ("Bailing out because of SQL exception", se); 185 String errorMsg = "Error in db_load_container : " + se.getMessage () + 186 " -> BAILING OUT"; 187 throw new JahiaException ("Cannot load fields from the database", 188 errorMsg, JahiaException.DATABASE_ERROR, 189 JahiaException.CRITICAL_SEVERITY, se); 190 } finally { 191 try { 192 if (stmt != null) { 193 stmt.close (); 194 } 195 } catch (SQLException ex) { 196 new JahiaException ("Cannot free resources", 197 "db_load_container : cannot free resources", 198 JahiaException.DATABASE_ERROR, 199 JahiaException.WARNING_SEVERITY); 200 } 201 } 202 return theContainer; 203 } 205 214 public void db_create_container (JahiaContainer theContainer, 215 JahiaSaveVersion saveVersion) throws 216 JahiaException { 217 Connection dbConn = null; 218 PreparedStatement stmt = null; 219 try { 220 dbConn = ConnectionDispenser.getConnection (); 222 String sqlQuery = "INSERT INTO jahia_ctn_entries(id_jahia_ctn_entries,jahiaid_jahia_ctn_entries,pageid_jahia_ctn_entries,listid_jahia_ctn_entries,ctndefid_jahia_ctn_entries,rank_jahia_ctn_entries,rights_jahia_ctn_entries,workflow_state,version_id) VALUES (?,?,?,?,?,?,?,?,?)"; 223 stmt = dbConn.prepareStatement (sqlQuery); 224 225 stmt.setInt(1, theContainer.getID ()); 227 stmt.setInt(2, theContainer.getJahiaID ()); 228 stmt.setInt(3, theContainer.getPageID ()); 229 stmt.setInt(4, theContainer.getListID ()); 230 stmt.setInt(5, theContainer.getctndefid ()); 231 stmt.setInt(6, theContainer.getRank ()); 232 stmt.setInt(7,theContainer.getAclID ()); 233 stmt.setInt(8, saveVersion.getWorkflowState ()); 234 stmt.setInt(9, saveVersion.getWorkflowState() > 1 ? 0 : saveVersion.getVersionID()); 235 236 stmt.execute (); 238 239 } catch (SQLException se) { 240 logger.debug ("Bailing out because of SQL exception", se); 241 String errorMsg = "Error in db_create_container : " + se.getMessage () + 242 " -> BAILING OUT"; 243 throw new JahiaException ("Cannot create containers in the database", 244 errorMsg, JahiaException.DATABASE_ERROR, 245 JahiaException.CRITICAL_SEVERITY, se); 246 } finally { 247 try { 248 if (stmt != null) { 249 stmt.close (); 250 } 251 } catch (SQLException ex) { 252 new JahiaException ("Cannot free resources", 253 "db_create_container : cannot free resources", 254 JahiaException.DATABASE_ERROR, 255 JahiaException.WARNING_SEVERITY); 256 } 257 } 258 } 260 268 public void db_update_container (JahiaContainer theContainer, 269 JahiaSaveVersion saveVersion) throws 270 JahiaException { 271 Connection dbConn = null; 272 PreparedStatement stmt = null; 273 try { 274 dbConn = ConnectionDispenser.getConnection (); 275 276 String errorMsg = ""; 277 if (theContainer.getDefinition ().getName ().equals ("")) { 278 errorMsg = 279 "Error in db_update_container : container name value is an empty string"; 280 } 281 if (errorMsg != "") { 282 logger.debug (errorMsg); 283 throw new JahiaException ( 284 "Cannot update containers in the database", 285 errorMsg, JahiaException.DATABASE_ERROR, 286 JahiaException.CRITICAL_SEVERITY); 287 } 288 289 int ctnID = theContainer.getID (); 290 291 String sqlQuery = "UPDATE jahia_ctn_entries SET jahiaid_jahia_ctn_entries=?,pageid_jahia_ctn_entries=?,listid_jahia_ctn_entries=?,ctndefid_jahia_ctn_entries=?,rank_jahia_ctn_entries=?,rights_jahia_ctn_entries=?,version_id=? WHERE id_jahia_ctn_entries=? AND workflow_state>1"; 293 stmt = dbConn.prepareStatement (sqlQuery); 294 stmt.setInt(1, theContainer.getJahiaID ()); 295 stmt.setInt(2, theContainer.getPageID ()); 296 stmt.setInt(3, theContainer.getListID ()); 297 stmt.setInt(4, theContainer.getctndefid ()); 298 stmt.setInt(5, theContainer.getRank ()); 299 stmt.setInt(6, theContainer.getAclID ()); 300 stmt.setInt(7, 0); 301 stmt.setInt(8, theContainer.getID()); 302 303 if (saveVersion.isStaging ()) { 305 int rows = stmt.executeUpdate (); 307 logger.debug ("Updated rows=" + rows); 308 if (rows == 0) { 310 logger.debug ("Creating staged container..."); 311 createStagedContainer (dbConn, ctnID, saveVersion); 312 stmt.executeUpdate (); 313 } 314 } else { 316 if (saveVersion.isVersioned ()) { 317 backupContainerVersion (dbConn, ctnID); 318 } 319 stmt.setInt(7, saveVersion.getVersionID ()); 321 322 stmt.executeUpdate (); 324 } 325 } catch (SQLException se) { 327 logger.debug ("Bailing out because of SQL exception", se); 328 String errorMsg = "Error in db_update_container : " + se.getMessage (); 329 throw new JahiaException ("Cannot update containers in the database", 330 errorMsg, JahiaException.DATABASE_ERROR, 331 JahiaException.CRITICAL_SEVERITY, se); 332 } finally { 333 try { 334 if (stmt != null) { 335 stmt.close (); 336 } 337 } catch (SQLException ex) { 338 new JahiaException ("Cannot free resources", 339 "db_update_container : cannot free resources", 340 JahiaException.DATABASE_ERROR, 341 JahiaException.WARNING_SEVERITY, ex); 342 } 343 } 344 } 346 354 public void db_delete_container (int ctnID, JahiaSaveVersion saveVersion) throws 355 JahiaException { 356 JahiaContainer activeContainer = db_load_container (ctnID, 359 EntryLoadRequest.CURRENT); 360 361 Connection dbConn = null; 362 PreparedStatement stmt = null; 363 String sqlQuery = ""; 364 try { 365 dbConn = ConnectionDispenser.getConnection (); 366 367 if (saveVersion.isStaging ()) { 369 if (activeContainer != null 370 && activeContainer.getWorkflowState () == EntryLoadRequest.ACTIVE_WORKFLOW_STATE) { 371 374 sqlQuery = "UPDATE jahia_ctn_entries SET version_id=-1 WHERE id_jahia_ctn_entries=? AND workflow_state>1"; 376 stmt = dbConn.prepareStatement(sqlQuery); 377 stmt.setInt(1, ctnID); 378 379 int rows = stmt.executeUpdate (); 380 if (rows == 0) { 382 createStagedContainer (dbConn, ctnID, saveVersion); 383 stmt.executeUpdate (); 384 } 385 } else { 386 sqlQuery = "DELETE FROM jahia_ctn_entries WHERE id_jahia_ctn_entries=? AND workflow_state>1"; 389 stmt = dbConn.prepareStatement(sqlQuery); 390 stmt.setInt(1, ctnID); 391 stmt.executeUpdate (); 392 } 393 } else if (saveVersion.isVersioned ()) { 395 backupContainerVersion (dbConn, ctnID); 396 sqlQuery = "UPDATE jahia_ctn_entries SET version_id=?,workflow_state=-1 WHERE id_jahia_ctn_entries=? AND workflow_state=1"; 397 stmt = dbConn.prepareStatement(sqlQuery); 398 stmt.setInt(1, saveVersion.getVersionID ()); 399 stmt.setInt(2, ctnID); 400 stmt.executeUpdate (); 401 } else { 403 sqlQuery = "DELETE FROM jahia_ctn_entries WHERE id_jahia_ctn_entries=? AND workflow_state=1"; 404 stmt = dbConn.prepareStatement(sqlQuery); 405 stmt.setInt(1, ctnID); 406 stmt.executeUpdate (); 407 } 408 } 409 catch (SQLException se) { 411 logger.debug ("Bailing out because of SQL exception", se); 412 String errorMsg = "Error in db_delete_container : " + se.getMessage () + "\n sqlQuery=" + sqlQuery; 413 throw new JahiaException ("Cannot delete containers in the database", 414 errorMsg, JahiaException.DATABASE_ERROR, 415 JahiaException.CRITICAL_SEVERITY, se); 416 } finally { 417 try { 418 if (stmt != null) { 419 stmt.close (); 420 } 421 } catch (SQLException ex) { 422 new JahiaException ("Cannot free resources", 423 "db_delete_container : cannot free resources", 424 JahiaException.DATABASE_ERROR, 425 JahiaException.WARNING_SEVERITY, ex); 426 } 427 } 428 } 430 440 public void purgeContainer (int ctnID) throws JahiaException { 441 442 Connection dbConn = null; 443 PreparedStatement stmt = null; 444 try { 445 dbConn = ConnectionDispenser.getConnection (); 446 447 String sqlQuery ="DELETE FROM jahia_ctn_entries WHERE id_jahia_ctn_entries=?"; 448 stmt = dbConn.prepareStatement (sqlQuery); 449 stmt.setInt(1, ctnID); 450 stmt.executeUpdate (); 451 } 452 catch (SQLException se) { 454 logger.debug ("Bailing out because of SQL exception", se); 455 String errorMsg = "Error in purgeContainer : " + se.getMessage (); 456 throw new JahiaException ("Cannot delete containers in the database", 457 errorMsg, JahiaException.DATABASE_ERROR, 458 JahiaException.CRITICAL_SEVERITY, se); 459 } finally { 460 try { 461 if (stmt != null) { 462 stmt.close (); 463 } 464 } catch (SQLException ex) { 465 new JahiaException ("Cannot free resources", 466 "purgeContainer : cannot free resources", 467 JahiaException.DATABASE_ERROR, 468 JahiaException.WARNING_SEVERITY, ex); 469 } 470 } 471 } 472 473 477 private void backupContainerVersion(Connection dbConn, int ctnID) throws SQLException { 478 PreparedStatement queryStmt = null; 479 PreparedStatement insertStmt = null; 480 try { 481 String sqlQuery = "SELECT * FROM jahia_ctn_entries WHERE id_jahia_ctn_entries=? AND workflow_state=1"; 482 483 queryStmt = dbConn.prepareStatement(sqlQuery); 484 queryStmt.setInt(1, ctnID); 485 ResultSet rs = queryStmt.executeQuery(); 486 487 if (rs != null && rs.next()) { 488 sqlQuery = "INSERT INTO jahia_ctn_entries (id_jahia_ctn_entries,jahiaid_jahia_ctn_entries,pageid_jahia_ctn_entries,listid_jahia_ctn_entries,ctndefid_jahia_ctn_entries,rank_jahia_ctn_entries,rights_jahia_ctn_entries,version_id,workflow_state) VALUES (?,?,?,?,?,?,?,?,?)"; 489 insertStmt = dbConn.prepareStatement(sqlQuery); 490 insertStmt.setInt(1, ctnID); 491 insertStmt.setInt(2, rs.getInt("jahiaid_jahia_ctn_entries")); 492 insertStmt.setInt(3, rs.getInt("pageid_jahia_ctn_entries")); 493 insertStmt.setInt(4, rs.getInt("listid_jahia_ctn_entries")); 494 insertStmt.setInt(5, rs.getInt("ctndefid_jahia_ctn_entries")); 495 insertStmt.setInt(6, rs.getInt("rank_jahia_ctn_entries")); 496 insertStmt.setInt(7, rs.getInt("rights_jahia_ctn_entries")); 497 insertStmt.setInt(8, rs.getInt("version_id")); 498 insertStmt.setInt(9, 0); 499 insertStmt.executeUpdate(); 500 } 501 } finally { 502 if (queryStmt != null) { 503 queryStmt.close(); 504 } 505 if (insertStmt != null) { 506 insertStmt.close(); 507 } 508 } 509 } 510 511 516 private void createStagedContainer(Connection dbConn, int ctnID, JahiaSaveVersion saveVersion) throws SQLException { 517 PreparedStatement queryStmt = null; 518 PreparedStatement insertStmt = null; 519 try { 520 String sqlQuery = "SELECT * FROM jahia_ctn_entries WHERE id_jahia_ctn_entries=? AND workflow_state=1"; 521 522 queryStmt = dbConn.prepareStatement(sqlQuery); 523 queryStmt.setInt(1, ctnID); 524 ResultSet rs = queryStmt.executeQuery(); 525 526 if (rs != null && rs.next()) { 527 sqlQuery = "INSERT INTO jahia_ctn_entries (id_jahia_ctn_entries,jahiaid_jahia_ctn_entries,pageid_jahia_ctn_entries,listid_jahia_ctn_entries,ctndefid_jahia_ctn_entries,rank_jahia_ctn_entries,rights_jahia_ctn_entries,version_id,workflow_state) VALUES (?,?,?,?,?,?,?,?,?)"; 528 insertStmt = dbConn.prepareStatement(sqlQuery); 529 insertStmt.setInt(1, ctnID); 530 insertStmt.setInt(2, rs.getInt("jahiaid_jahia_ctn_entries")); 531 insertStmt.setInt(3, rs.getInt("pageid_jahia_ctn_entries")); 532 insertStmt.setInt(4, rs.getInt("listid_jahia_ctn_entries")); 533 insertStmt.setInt(5, rs.getInt("ctndefid_jahia_ctn_entries")); 534 insertStmt.setInt(6, rs.getInt("rank_jahia_ctn_entries")); 535 insertStmt.setInt(7, rs.getInt("rights_jahia_ctn_entries")); 536 insertStmt.setInt(8, saveVersion.getVersionID()); 537 insertStmt.setInt(9, saveVersion.getWorkflowState()); 538 insertStmt.executeUpdate(); 539 } 540 } finally { 541 if (queryStmt != null) { 542 queryStmt.close(); 543 } 544 if (insertStmt != null) { 545 insertStmt.close(); 546 } 547 } 548 } 549 550 559 public void db_validate_staged_container (int ctnID, 560 JahiaSaveVersion saveVersion) throws 561 JahiaException { 562 Connection dbConn = null; 563 Statement stmt = null; 564 try { 565 dbConn = org.jahia.services.database.ConnectionDispenser.getConnection (); 566 stmt = dbConn.createStatement (); 567 String sqlQuery = "SELECT * FROM jahia_ctn_entries WHERE " + 568 "id_jahia_ctn_entries = " + ctnID + 569 " AND workflow_state>1"; 570 ResultSet rs = stmt.executeQuery (sqlQuery); 571 if (rs != null) { 572 if (rs.next ()) { 573 int aclID = rs.getInt ("rights_jahia_ctn_entries"); 574 int ctn_jahiaID = rs.getInt ("jahiaid_jahia_ctn_entries"); 575 int ctn_pageID = rs.getInt ("pageid_jahia_ctn_entries"); 576 int ctn_listID = rs.getInt ("listid_jahia_ctn_entries"); 577 int ctn_ctndefID = rs.getInt ("ctndefid_jahia_ctn_entries"); 578 int ctn_rank = rs.getInt ("rank_jahia_ctn_entries"); 579 int versionID = rs.getInt ("version_id"); 580 581 if (saveVersion.isVersioned ()) { 583 backupContainerVersion (dbConn, ctnID); 584 585 } 587 if (versionID == -1) { 588 if (saveVersion.isVersioned ()) { 589 sqlQuery = "UPDATE jahia_ctn_entries SET " 591 + "version_id = " + saveVersion.getVersionID () + 592 "," 593 + "workflow_state = -1 " 594 + "WHERE id_jahia_ctn_entries = " + ctnID + " " 595 + "AND workflow_state>1"; 596 stmt.executeUpdate (sqlQuery); 597 } 598 sqlQuery = 600 "DELETE FROM jahia_ctn_entries WHERE id_jahia_ctn_entries=" + 601 ctnID + 602 " AND workflow_state>=1"; 603 stmt.executeUpdate (sqlQuery); 604 } else 605 { 607 sqlQuery = "UPDATE jahia_ctn_entries SET " 609 + "jahiaid_jahia_ctn_entries = " + ctn_jahiaID + 610 "," 611 + "pageid_jahia_ctn_entries = " + ctn_pageID + "," 612 + "listid_jahia_ctn_entries = " + ctn_listID + "," 613 + "ctndefid_jahia_ctn_entries = " + ctn_ctndefID + 614 "," 615 + "rank_jahia_ctn_entries = " + ctn_rank + "," 616 + "rights_jahia_ctn_entries = " + aclID + "," 617 + "version_id = " + saveVersion.getVersionID () + 618 " " 619 + "WHERE id_jahia_ctn_entries = " + ctnID + " " 620 + "AND workflow_state=1"; 621 int rows = stmt.executeUpdate (sqlQuery); 622 if (rows == 0) { 624 sqlQuery = "INSERT INTO jahia_ctn_entries (" + 625 "id_jahia_ctn_entries," + 626 "jahiaid_jahia_ctn_entries," + 627 "pageid_jahia_ctn_entries," + 628 "listid_jahia_ctn_entries," + 629 "ctndefid_jahia_ctn_entries," + 630 "rank_jahia_ctn_entries," + 631 "rights_jahia_ctn_entries," + 632 "version_id," + 633 "workflow_state) VALUES (" + 634 ctnID + "," + 635 ctn_jahiaID + "," + 636 ctn_pageID + "," + 637 ctn_listID + "," + 638 ctn_ctndefID + "," + 639 ctn_rank + "," + 640 aclID + "," + 641 saveVersion.getVersionID () + "," + 642 "1)"; 643 stmt.execute (sqlQuery); 644 } 645 646 sqlQuery = 648 "DELETE FROM jahia_ctn_entries WHERE id_jahia_ctn_entries=" + 649 ctnID + 650 " AND workflow_state>1"; 651 stmt.executeUpdate (sqlQuery); 652 } 653 } 654 } 655 } catch (SQLException se) { 656 logger.debug ("Bailing out because of SQL exception", se); 657 String errorMsg = "Error in db_validate_staged_container : " + 658 se.getMessage (); 659 throw new JahiaException ("Cannot update containers in the database", 660 errorMsg, JahiaException.DATABASE_ERROR, 661 JahiaException.CRITICAL_SEVERITY, se); 662 } finally { 663 try { 664 if (stmt != null) { 665 stmt.close (); 666 } 667 } catch (SQLException ex) { 668 new JahiaException ("Cannot free resources", 669 "db_validate_staged_container : cannot free resources", 670 JahiaException.DATABASE_ERROR, 671 JahiaException.WARNING_SEVERITY, ex); 672 } 673 } 674 } 675 676 686 public JahiaDOMObject getContainersAsDOM (int siteID) throws JahiaException { 687 688 Connection dbConn = null; 689 Statement statement = null; 690 691 JahiaDBDOMObject dom = null; 692 693 try { 694 String sqlQuery = 695 "SELECT * FROM jahia_ctn_entries where jahiaid_jahia_ctn_entries=" + 696 siteID; 697 698 dbConn = org.jahia.services.database.ConnectionDispenser.getConnection (); 699 statement = dbConn.createStatement (); 700 if (statement != null) { 701 ResultSet rs = statement.executeQuery (sqlQuery); 702 if (rs != null) { 703 dom = new JahiaDBDOMObject (); 704 dom.addTable ("jahia_ctn_entries", rs); 705 return dom; 706 } 707 } 708 } catch (SQLException se) { 709 logger.debug ("Bailing out because of SQL exception", se); 710 String errorMsg = "Error in getContainersAsDOM(int siteID) : " + 711 se.getMessage (); 712 throw new JahiaException ("Cannot load containers from the database", 713 errorMsg, JahiaException.DATABASE_ERROR, 714 JahiaException.CRITICAL_SEVERITY, se); 715 } finally { 716 717 closeStatement (statement); 718 } 719 720 return dom; 721 } 722 723 private void closeStatement (Statement statement) { 725 try { 727 if (statement != null) { 728 statement.close (); 729 } 730 } catch (SQLException sqlEx) { 731 new JahiaException ("Cannot close a statement", 734 "Cannot close a statement", JahiaException.DATABASE_ERROR, 735 JahiaException.WARNING_SEVERITY, sqlEx); 736 } 737 } 738 739 } | Popular Tags |