1 13 19 package org.jahia.services.pages; 20 21 import org.jahia.exceptions.JahiaException; 22 import org.jahia.registries.ServicesRegistry; 23 import org.jahia.services.cache.Cache; 24 import org.jahia.services.version.EntryLoadRequest; 25 import org.jahia.services.version.EntryStateable; 26 import org.jahia.utils.JahiaTools; 27 28 import java.sql.*; 29 import java.util.Vector ; 30 31 32 40 class JahiaPagesDB { 41 42 private static org.apache.log4j.Logger logger = 43 org.apache.log4j.Logger.getLogger (JahiaPagesDB.class); 44 45 private static JahiaPagesDB mObject = null; 46 47 51 private JahiaPagesDB () { 52 } 53 54 55 public static JahiaPagesDB getInstance () { 57 if (mObject == null) { 58 mObject = new JahiaPagesDB (); 59 } 60 return mObject; 61 62 } 63 64 82 public Vector loadPageInfos (int pageID, EntryLoadRequest loadEntry) 83 throws JahiaException { 84 Connection dbConn = org.jahia.services.database.ConnectionDispenser.getConnection (); 86 if (dbConn == null) { 87 return null; 88 } 89 90 Vector result = new Vector (); 91 PreparedStatement stmt = null; 92 93 try { 94 95 String sqlQuery; 96 if (loadEntry.getWorkflowState () <= 0) { 97 stmt = dbConn.prepareStatement("SELECT * FROM jahia_pages_data WHERE id_jahia_pages_data=? AND workflow_state<=0 ORDER BY version_id DESC"); 98 stmt.setInt(1, pageID); 99 } else { 100 stmt = dbConn.prepareStatement("SELECT * FROM jahia_pages_data WHERE id_jahia_pages_data=? AND workflow_state>0"); 101 stmt.setInt(1, pageID); 102 } 103 104 if (stmt != null) { 105 ResultSet rs = stmt.executeQuery (); 106 if (rs != null) { 107 while (rs.next ()) { 108 JahiaPageInfo pageInfo = readPageInfoFromResultSet (pageID, rs); 109 result.add (pageInfo); 110 } 111 rs.close(); 112 } 113 } 114 } catch (SQLException se) { 115 String errorMsg = "Error in JahiaPagesDB.loadPageInfos : " + 116 se.getMessage () + " -> BAILING OUT"; 117 logger.debug (errorMsg, se); 118 throw new JahiaException ("Cannot load the page values from the database", 119 errorMsg, 120 JahiaException.DATABASE_ERROR, 121 JahiaException.CRITICAL_SEVERITY, 122 se); 123 } finally { 124 125 closeStatement (stmt); 126 } 127 128 return result; 129 } 130 131 145 public JahiaPageInfo loadPageInfo (int pageID, EntryStateable entryState) 146 throws JahiaException { 147 Connection dbConn = org.jahia.services.database.ConnectionDispenser.getConnection (); 149 if (dbConn == null) { 150 return null; 151 } 152 153 JahiaPageInfo pageInfo = null; 154 PreparedStatement statement = null; 155 156 try { 157 158 String sqlQuery; 159 sqlQuery = 160 "SELECT * FROM jahia_pages_data WHERE id_jahia_pages_data=?" + 161 " AND workflow_state=? AND version_id=? AND language_code=?"; 162 163 statement = dbConn.prepareStatement (sqlQuery); 164 statement.setInt (1, pageID); 165 statement.setInt (2, entryState.getWorkflowState ()); 166 statement.setInt (3, entryState.getVersionID ()); 167 statement.setString (4, entryState.getLanguageCode ()); 168 if (statement != null) { 169 logger.debug (sqlQuery); 170 ResultSet rs = statement.executeQuery (); 171 if (rs != null && rs.next ()) { 172 pageInfo = readPageInfoFromResultSet (pageID, rs); 173 } else { 174 logger.debug ("Page not found for entrySate :" + entryState.toString ()); 175 logger.debug ("Page not found for with query :" + sqlQuery); 176 } 177 } 178 } catch (SQLException se) { 179 String errorMsg = "Error in JahiaPagesDB.loadPageInfo : " + 180 se.getMessage () + " -> BAILING OUT"; 181 logger.debug (errorMsg, se); 182 throw new JahiaException ("Cannot load the page row from the database", 183 errorMsg, 184 JahiaException.DATABASE_ERROR, 185 JahiaException.CRITICAL_SEVERITY, 186 se); 187 } finally { 188 189 closeStatement (statement); 190 } 191 192 return pageInfo; 193 } 194 195 204 public void preloadingPageInfos (Cache pageInfosCache, Cache versioningPageInfosCache) throws JahiaException { 205 Connection dbConn = org.jahia.services.database.ConnectionDispenser.getConnection (); 207 208 if (pageInfosCache == null || versioningPageInfosCache == null) { 209 logger.warn(" Cache is null, skip preloading page infos"); 210 return; 211 } 212 213 if (dbConn == null) { 214 logger.warn(" DB Connection is null, skip preloading page infos"); 215 return; 216 } 217 218 Vector result = new Vector (); 219 Statement statement = null; 220 221 try { 222 223 String sqlQuery = "SELECT * FROM jahia_pages_data ORDER BY id_jahia_pages_data"; 224 225 statement = dbConn.createStatement (); 226 if (statement != null) { 227 logger.debug (sqlQuery); 228 ResultSet rs = statement.executeQuery (sqlQuery); 229 if (rs != null) { 230 while (rs.next ()) { 231 int pageId = rs.getInt("id_jahia_pages_data"); 232 JahiaPageInfo pageInfo = readPageInfoFromResultSet(pageId,rs); 233 Vector v = null; 234 if ( pageInfo.getWorkflowState()<EntryLoadRequest.ACTIVE_WORKFLOW_STATE ){ 235 v = (Vector ) versioningPageInfosCache.get(new 236 Integer (pageId)); 237 } else { 238 v = (Vector ) pageInfosCache.get(new 239 Integer (pageId)); 240 } 241 if ( v == null ){ 242 pageInfosCache.put(new Integer (pageId), new Vector ()); 243 versioningPageInfosCache.put(new Integer (pageId), new Vector ()); 244 v = new Vector (); 245 if ( pageInfo.getWorkflowState()<EntryLoadRequest.ACTIVE_WORKFLOW_STATE ){ 246 versioningPageInfosCache.put(new Integer (pageId), v); 247 } else { 248 pageInfosCache.put(new Integer (pageId), v); 249 } 250 } 251 v.add(pageInfo); 252 } 253 } 254 } 255 } catch (SQLException se) { 256 String errorMsg = "Error in JahiaPagesDB.preloadingPageInfos : " + 257 se.getMessage () + " -> BAILING OUT"; 258 logger.debug (errorMsg, se); 259 } finally { 260 closeStatement (statement); 261 } 262 } 263 264 public int getPageEntriesNb (int pageID) 265 throws JahiaException { 266 Connection dbConn = org.jahia.services.database.ConnectionDispenser.getConnection (); 268 if (dbConn == null) { 269 return -1; 270 } 271 272 int entriesCount = -1; 273 JahiaPageInfo pageInfo = null; 274 Statement statement = null; 275 276 try { 277 278 String sqlQuery; 279 sqlQuery = 280 "SELECT COUNT(*) AS nbentries FROM jahia_pages_data WHERE id_jahia_pages_data=" + pageID; 281 282 statement = dbConn.createStatement (); 283 if (statement != null) { 284 logger.debug (sqlQuery); 285 ResultSet rs = statement.executeQuery (sqlQuery); 286 if (rs != null) { 287 while (rs.next ()) { 288 entriesCount = rs.getInt ("nbentries"); 289 } 290 } 291 } 292 } catch (SQLException se) { 293 String errorMsg = "Error in JahiaPagesDB.getPageEntriesNb : " + 294 se.getMessage () + " -> BAILING OUT"; 295 logger.debug (errorMsg, se); 296 throw new JahiaException ("Cannot load the page values from the database", 297 errorMsg, 298 JahiaException.DATABASE_ERROR, 299 JahiaException.CRITICAL_SEVERITY, 300 se); 301 } finally { 302 303 closeStatement (statement); 304 } 305 306 return entriesCount; 307 308 } 309 310 311 312 325 public synchronized boolean createPageInfo (JahiaPageInfo pageInfo) 326 throws JahiaException { 327 Connection dbConn = org.jahia.services.database.ConnectionDispenser.getConnection (); 329 if (dbConn == null) { 330 throw new JahiaException ( 331 "Page creation error on database access", 332 "Cannot create a new page in the database, could not obtain a DB connection.", 333 JahiaException.DATABASE_ERROR, JahiaException.CRITICAL_SEVERITY); 334 } 335 336 boolean result = false; 337 Statement statement = null; 338 try { 339 340 statement = dbConn.createStatement (); 342 if (statement != null) { 343 344 String sqlQuery2 = "INSERT INTO jahia_pages_data (" + 346 "id_jahia_pages_data," + 347 "jahiaid_jahia_pages_data," + 348 "parentid_jahia_pages_data," + 349 "pagetype_jahia_pages_data," + 350 "title_jahia_pages_data," + 351 "pagedefid_jahia_pages_data," + 352 "remoteurl_jahia_pages_data," + 353 "pagelinkid_jahia_pages_data," + 354 "creator_jahia_pages_data," + 355 "doc_jahia_pages_data," + 356 "counter_jahia_pages_data," + 357 "rights_jahia_pages_data," + 358 "version_id," + 359 "workflow_state," + 360 "language_code) VALUES (" + 361 pageInfo.getID () + "," + 362 pageInfo.getJahiaID () + "," + 363 pageInfo.getParentID () + "," + 364 pageInfo.getPageType () + "," + 365 "'" + JahiaTools.quote (pageInfo.getTitle ()) + "'," + 366 pageInfo.getPageTemplateID () + "," + 367 "'" + JahiaTools.quote (pageInfo.getRemoteURL ()) + "'," + 368 pageInfo.getPageLinkID () + "," + 369 "'" + JahiaTools.quote (pageInfo.getCreator ()) + "'," + 370 "'" + JahiaTools.quote (pageInfo.getDoc ()) + "'," + 371 pageInfo.getCounter () + "," + 372 pageInfo.getAclID () + "," + 373 pageInfo.getVersionID () + "," + 374 pageInfo.getWorkflowState () + ",'" + 375 JahiaTools.quote (pageInfo.getLanguageCode ()) + 376 "')"; 377 logger.debug (sqlQuery2); 379 statement.execute (sqlQuery2); 380 381 result = true; 382 383 } 384 385 } catch (SQLException se) { 387 String errorMsg = "Error in createPageInfo : " + se.getMessage () + " -> BAILING OUT"; 388 logger.debug (errorMsg, se); 389 throw new JahiaException ("Cannot create a new page in the database", 390 errorMsg, JahiaException.DATABASE_ERROR, JahiaException.CRITICAL_SEVERITY); 391 } finally { 392 393 closeStatement (statement); 394 } 395 396 if (result) { 397 ServicesRegistry.getInstance ().getJahiaPageService ().invalidatePageCache ( 399 pageInfo.getID ()); 400 401 } 402 return result; 403 } 404 405 406 418 public boolean updatePageInfo (JahiaPageInfo pageInfo, 419 int newVersionID, 420 int newVersionStatus) 421 throws JahiaException { 422 423 Connection dbConn = org.jahia.services.database.ConnectionDispenser.getConnection (); 425 if (dbConn == null) { 426 throw new JahiaException ( 427 "Page update error on database access", 428 "Cannot update the requested page in the database, could not obtain a DB connection.", 429 JahiaException.DATABASE_ERROR, JahiaException.CRITICAL_SEVERITY); 430 } 431 boolean result = false; 432 Statement statement = null; 433 try { 434 435 StringBuffer sqlQuery = new StringBuffer ("UPDATE jahia_pages_data SET "); 437 sqlQuery.append ("jahiaid_jahia_pages_data = " + pageInfo.getJahiaID () + ","); 438 sqlQuery.append ("parentid_jahia_pages_data = " + pageInfo.getParentID () + ","); 439 sqlQuery.append ("pagetype_jahia_pages_data = " + pageInfo.getPageType () + ","); 440 sqlQuery.append ( 441 "title_jahia_pages_data = '" + JahiaTools.quote (pageInfo.getTitle ()) + "',"); 442 sqlQuery.append ( 443 "pagedefid_jahia_pages_data = " + pageInfo.getPageTemplateID () + ","); 444 sqlQuery.append ( 445 "remoteurl_jahia_pages_data = '" + JahiaTools.quote ( 446 pageInfo.getRemoteURL ()) + "',"); 447 sqlQuery.append ("pagelinkid_jahia_pages_data = " + pageInfo.getPageLinkID () + ","); 448 sqlQuery.append ( 449 "creator_jahia_pages_data = '" + JahiaTools.quote (pageInfo.getCreator ()) + "',"); 450 sqlQuery.append ( 451 "doc_jahia_pages_data = '" + JahiaTools.quote (pageInfo.getDoc ()) + "',"); 452 sqlQuery.append ("counter_jahia_pages_data = " + pageInfo.getCounter () + ","); 453 sqlQuery.append ("rights_jahia_pages_data = " + pageInfo.getAclID () + ","); 454 sqlQuery.append ("version_id = " + newVersionID + ","); 456 sqlQuery.append ("workflow_state = " + newVersionStatus); 457 sqlQuery.append (" WHERE id_jahia_pages_data = " + pageInfo.getID ()); 458 sqlQuery.append ( 459 " AND language_code = '" + JahiaTools.quote (pageInfo.getLanguageCode ()) + "'"); 460 sqlQuery.append (" AND workflow_state = " + pageInfo.getWorkflowState ()); 461 462 statement = dbConn.createStatement (); 464 if (statement != null) { 465 logger.debug (sqlQuery.toString ()); 466 statement.execute (sqlQuery.toString ()); 467 result = true; 468 ServicesRegistry.getInstance ().getJahiaPageService ().invalidatePageCache ( 470 pageInfo.getID ()); 471 } 472 } catch (SQLException se) { 474 String errorMsg = "Error in JahiaPagesDB.updatePageInfo : " + se.getMessage () + " -> BAILING OUT"; 475 logger.debug (errorMsg, se); 476 throw new JahiaException ("Cannot create a new page in the database", 477 errorMsg, 478 JahiaException.DATABASE_ERROR, 479 JahiaException.CRITICAL_SEVERITY, 480 se); 481 } finally { 482 483 closeStatement (statement); 484 } 485 return result; 486 } 487 488 489 501 public boolean deletePageInfo (JahiaPageInfo pageInfo) 502 throws JahiaException { 503 if (pageInfo == null) { 504 return false; 505 } 506 507 Connection dbConn = org.jahia.services.database.ConnectionDispenser.getConnection (); 509 if (dbConn == null) { 510 throw new JahiaException ( 511 "Page deletion error on database access", 512 "Cannot delete the requested page in the database, could not obtain a DB connection.", 513 JahiaException.DATABASE_ERROR, JahiaException.CRITICAL_SEVERITY); 514 } 515 516 boolean result = false; 517 Statement statement = null; 518 try { 519 String sqlQuery = "DELETE FROM jahia_pages_data WHERE id_jahia_pages_data = " + 521 pageInfo.getID () + 522 " AND workflow_state=" + 523 pageInfo.getWorkflowState () + 524 " AND language_code='" + 525 JahiaTools.quote (pageInfo.getLanguageCode ()) + "'"; 526 530 531 statement = dbConn.createStatement (); 533 if (statement != null) { 534 logger.debug (sqlQuery); 535 statement.execute (sqlQuery); 536 result = true; 537 ServicesRegistry.getInstance ().getJahiaPageService ().invalidatePageCache ( 539 pageInfo.getID ()); 540 } 541 } catch (SQLException se) { 543 String errorMsg = "Error in JahiaPagesDB.deletePageInfo : " + 544 se.getMessage () + " -> BAILING OUT"; 545 logger.debug (errorMsg, se); 546 throw new JahiaException ("Cannot delete a page in the database", 547 errorMsg, 548 JahiaException.DATABASE_ERROR, 549 JahiaException.CRITICAL_SEVERITY, 550 se); 551 } finally { 552 553 closeStatement (statement); 554 } 555 556 return result; 557 } 558 559 public void backupPageInfo (JahiaPageInfo pageInfo, 560 int newVersionID, 561 int newVersionStatus) 562 throws JahiaException { 563 Connection dbConn = null; 564 Statement stmt = null; 565 ResultSet rs = null; 566 567 int pageInfoID = pageInfo.getID (); 568 569 try { 570 String sqlQuery = "SELECT * FROM jahia_pages_data WHERE " + 571 "id_jahia_pages_data = " + pageInfo.getID () + 572 " AND workflow_state=" + pageInfo.getWorkflowState () + 573 " AND version_id=" + pageInfo.getVersionID () + 574 " AND language_code='" + pageInfo.getLanguageCode () + "'"; 575 576 dbConn = org.jahia.services.database.ConnectionDispenser.getConnection (); 577 stmt = dbConn.createStatement (); 578 logger.debug (sqlQuery); 579 rs = stmt.executeQuery (sqlQuery); 580 if (rs != null) 581 if (rs.next ()) { 582 int versionID = rs.getInt ("version_id"); 584 String languageCode = rs.getString ("language_code"); 585 sqlQuery = "INSERT INTO jahia_pages_data (" + 586 "id_jahia_pages_data," + 587 "jahiaid_jahia_pages_data," + 588 "parentid_jahia_pages_data," + 589 "pagetype_jahia_pages_data," + 590 "title_jahia_pages_data," + 591 "pagedefid_jahia_pages_data," + 592 "remoteurl_jahia_pages_data," + 593 "pagelinkid_jahia_pages_data," + 594 "creator_jahia_pages_data," + 595 "doc_jahia_pages_data," + 596 "counter_jahia_pages_data," + 597 "rights_jahia_pages_data," + 598 "version_id," + 599 "workflow_state," + 600 "language_code) VALUES (" + 601 pageInfoID + "," + 602 rs.getInt ("jahiaid_jahia_pages_data") + "," + 603 rs.getInt ("parentid_jahia_pages_data") + "," + 604 rs.getInt ("pagetype_jahia_pages_data") + "," + 605 "'" + JahiaTools.quote (rs.getString ("title_jahia_pages_data")) + "'," + 606 rs.getInt ("pagedefid_jahia_pages_data") + "," + 607 "'" + JahiaTools.quote ( 608 rs.getString ("remoteurl_jahia_pages_data")) + "'," + 609 rs.getInt ("pagelinkid_jahia_pages_data") + "," + 610 "'" + JahiaTools.quote (rs.getString ("creator_jahia_pages_data")) + "'," + 611 "'" + JahiaTools.quote (rs.getString ("doc_jahia_pages_data")) + "'," + 612 rs.getInt ("counter_jahia_pages_data") + "," + 613 rs.getInt ("rights_jahia_pages_data") + "," + 614 newVersionID + "," + 615 newVersionStatus + "," + 616 "'" + JahiaTools.quote (languageCode) + "'" + 617 ")"; 618 logger.debug (sqlQuery); 619 stmt.execute (sqlQuery); 620 ServicesRegistry.getInstance ().getJahiaPageService ().invalidatePageCache ( 622 pageInfo.getID ()); 623 } 624 } catch (SQLException se) { 625 throw new JahiaException ("Cannot backup field in the database", 626 se.getMessage (), JahiaException.DATABASE_ERROR, 627 JahiaException.ERROR_SEVERITY, se); 628 } finally { 629 try { 630 631 if (stmt != null) stmt.close (); 632 } catch (SQLException ex) { 633 throw new JahiaException ("Cannot free resources", "Cannot free resources", 634 JahiaException.DATABASE_ERROR, JahiaException.WARNING_SEVERITY, ex); 635 } 636 } 637 } 638 639 640 646 public synchronized int getNextID () { 647 int counter = -1; 648 649 Connection dbConn = org.jahia.services.database.ConnectionDispenser.getConnection (); 650 if (dbConn != null) { 651 Statement statement = null; 652 653 try { 654 String query = "SELECT MAX(id_jahia_pages_data) as MaxID FROM jahia_pages_data"; 655 statement = dbConn.createStatement (); 656 if (statement != null) { 657 logger.debug (query); 658 ResultSet rs = statement.executeQuery (query); 659 if (rs != null) { 660 if (rs.next ()) { 661 counter = rs.getInt ("MaxID"); 663 664 counter++; 666 } 667 } 668 } 669 } catch (SQLException ex) { 670 logger.debug ("Error", ex); 671 } finally { 672 673 closeStatement (statement); 674 } 675 } 676 return counter; 677 } 678 679 680 private void closeStatement (Statement statement) { 683 try { 685 if (statement != null) { 686 statement.close (); 687 } 688 } catch (SQLException sqlEx) { 689 JahiaException je = new JahiaException ("Cannot close a statement", 692 "Cannot close a statement", JahiaException.DATABASE_ERROR, 693 JahiaException.WARNING_SEVERITY); 694 } 695 } 696 697 private JahiaPageInfo readPageInfoFromResultSet (int pageID, ResultSet rs) 699 throws SQLException { 700 int jahiaID = rs.getInt ("jahiaid_jahia_pages_data"); 702 int parentID = rs.getInt ("parentid_jahia_pages_data"); 703 int pageType = rs.getInt ("pagetype_jahia_pages_data"); 704 String pageTitle = rs.getString ("title_jahia_pages_data"); 705 if (pageTitle == null) { 706 pageTitle = ""; 709 } 710 711 int pageTemplateID = rs.getInt ("pagedefid_jahia_pages_data"); 712 String remoteUrl = rs.getString ("remoteurl_jahia_pages_data"); 713 int pageLinkID = rs.getInt ("pagelinkid_jahia_pages_data") + 0; 714 String creator = rs.getString ("creator_jahia_pages_data") + ""; 715 String doc = rs.getString ("doc_jahia_pages_data") + ""; 716 int counter = rs.getInt ("counter_jahia_pages_data") + 0; 717 int rights = rs.getInt ("rights_jahia_pages_data") + 0; 718 int versionID = rs.getInt ("version_id") + 0; 719 int versionStatus = rs.getInt ("workflow_state") + 0; 720 String languageCode = rs.getString ("language_code"); 721 722 if (remoteUrl == null) { 723 remoteUrl = "<no url>"; 726 } 727 if (remoteUrl.equals ("<no url>")) { 728 remoteUrl = null; 729 } 730 731 return new JahiaPageInfo (pageID, jahiaID, parentID, pageType, 733 pageTitle, pageTemplateID, remoteUrl, pageLinkID, creator, 734 doc, counter, rights, versionID, versionStatus, languageCode); 735 } 736 737 protected void deleteEntry (int pageID, EntryStateable entryState) 738 throws JahiaException { 739 740 Connection dbConn = null; 741 PreparedStatement stmt = null; 742 ResultSet rs = null; 743 744 try { 745 String sqlQuery = 746 "DELETE FROM jahia_pages_data WHERE id_jahia_pages_data=?" + 747 " AND workflow_state=? AND version_id=? AND language_code=?"; 748 dbConn = org.jahia.services.database.ConnectionDispenser.getConnection (); 749 stmt = dbConn.prepareStatement (sqlQuery); 750 stmt.setInt (1, pageID); 751 stmt.setInt (2, entryState.getWorkflowState ()); 752 stmt.setInt (3, entryState.getVersionID ()); 753 stmt.setString (4, entryState.getLanguageCode ()); 754 int resultCount = stmt.executeUpdate (); 755 logger.debug (resultCount + " rows affected by delete of entry"); 756 } catch (SQLException se) { 757 throw new JahiaException ("Error while deleting entry", 758 se.getMessage (), 759 JahiaException.DATABASE_ERROR, 760 JahiaException.ERROR_SEVERITY, se); 761 } finally { 762 try { 763 if (stmt != null) 764 stmt.close (); 765 } catch (SQLException ex) { 766 throw new JahiaException ("Cannot free resources", 767 "Cannot free resources", 768 JahiaException.DATABASE_ERROR, 769 JahiaException.WARNING_SEVERITY, ex); 770 } 771 } 772 } 773 774 789 protected void copyEntry (int pageID, 790 EntryStateable fromEntryState, 791 EntryStateable toEntryState) 792 throws JahiaException { 793 794 Connection dbConn = null; 795 PreparedStatement stmt = null; 796 797 try { 798 String sqlQuery = 799 "SELECT " + 800 "id_jahia_pages_data," + 801 "jahiaid_jahia_pages_data," + 802 "parentid_jahia_pages_data," + 803 "pagetype_jahia_pages_data," + 804 "title_jahia_pages_data," + 805 "pagedefid_jahia_pages_data," + 806 "remoteurl_jahia_pages_data," + 807 "pagelinkid_jahia_pages_data," + 808 "creator_jahia_pages_data," + 809 "doc_jahia_pages_data," + 810 "counter_jahia_pages_data," + 811 "rights_jahia_pages_data," + 812 "version_id," + 813 "workflow_state," + 814 "language_code " + 815 "FROM jahia_pages_data WHERE id_jahia_pages_data=?" + 816 " AND workflow_state=? AND version_id=? AND language_code=?"; 817 dbConn = org.jahia.services.database.ConnectionDispenser.getConnection (); 818 stmt = dbConn.prepareStatement (sqlQuery); 819 stmt.setInt (1, pageID); 820 stmt.setInt (2, fromEntryState.getWorkflowState ()); 821 stmt.setInt (3, fromEntryState.getVersionID ()); 822 stmt.setString (4, fromEntryState.getLanguageCode ()); 823 ResultSet rs = stmt.executeQuery (); 824 if (rs.next ()) { 825 int jahiaID = rs.getInt ("jahiaid_jahia_pages_data"); 826 int parentID = rs.getInt ("parentid_jahia_pages_data"); 827 int pageType = rs.getInt ("pagetype_jahia_pages_data"); 828 String pageTitle = rs.getString ("title_jahia_pages_data"); 829 int pageTemplateID = rs.getInt ("pagedefid_jahia_pages_data"); 830 String remoteURL = rs.getString ("remoteurl_jahia_pages_data"); 831 int pageLinkID = rs.getInt ("pagelinkid_jahia_pages_data"); 832 String creator = rs.getString ("creator_jahia_pages_data"); 833 String doc = rs.getString ("doc_jahia_pages_data"); 834 int counter = rs.getInt ("counter_jahia_pages_data"); 835 int rights = rs.getInt ("rights_jahia_pages_data"); 836 int versionID = rs.getInt ("version_id"); 837 int versionStatus = rs.getInt ("workflow_state"); 838 String languageCode = rs.getString ("language_code"); 839 stmt.close (); 840 String insertQuery = "INSERT INTO jahia_pages_data (" + 841 "id_jahia_pages_data," + 842 "jahiaid_jahia_pages_data," + 843 "parentid_jahia_pages_data," + 844 "pagetype_jahia_pages_data," + 845 "title_jahia_pages_data," + 846 "pagedefid_jahia_pages_data," + 847 "remoteurl_jahia_pages_data," + 848 "pagelinkid_jahia_pages_data," + 849 "creator_jahia_pages_data," + 850 "doc_jahia_pages_data," + 851 "counter_jahia_pages_data," + 852 "rights_jahia_pages_data," + 853 "version_id," + 854 "workflow_state," + 855 "language_code" + 856 ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; 857 stmt = dbConn.prepareStatement (insertQuery); 858 stmt.setInt (1, pageID); 859 stmt.setInt (2, jahiaID); 860 stmt.setInt (3, parentID); 861 stmt.setInt (4, pageType); 862 stmt.setString (5, pageTitle); 863 stmt.setInt (6, pageTemplateID); 864 stmt.setString (7, remoteURL); 865 stmt.setInt (8, pageLinkID); 866 stmt.setString (9, creator); 867 stmt.setString (10, doc); 868 stmt.setInt (11, counter); 869 stmt.setInt (12, rights); 870 stmt.setInt (13, toEntryState.getVersionID ()); 871 stmt.setInt (14, toEntryState.getWorkflowState ()); 872 stmt.setString (15, toEntryState.getLanguageCode ()); 873 stmt.executeUpdate (); 874 } 875 } catch (SQLException se) { 876 logger.debug ( 877 "Exception copying entry state from : " + fromEntryState.toString () + "\n to : " + toEntryState.toString () + ", for page : " + pageID); 878 throw new JahiaException ("Error while copying entry", 879 se.getMessage (), 880 JahiaException.DATABASE_ERROR, 881 JahiaException.ERROR_SEVERITY, se); 882 } finally { 883 try { 884 if (stmt != null) 885 stmt.close (); 886 } catch (SQLException ex) { 887 throw new JahiaException ("Cannot free resources", 888 "Cannot free resources", 889 JahiaException.DATABASE_ERROR, 890 JahiaException.WARNING_SEVERITY, ex); 891 } 892 } 893 } 894 895 } 896 | Popular Tags |