1 4 package org.jahia.services.webdav.stores; 5 6 import org.apache.slide.store.impl.rdbms.AbstractRDBMSAdapter; 7 import org.apache.slide.store.impl.rdbms.StandardRDBMSAdapter; 8 import org.apache.slide.common.*; 9 import org.apache.slide.util.logger.Logger; 10 import org.apache.slide.structure.ObjectNode; 11 import org.apache.slide.structure.ObjectAlreadyExistsException; 12 import org.apache.slide.structure.ObjectNotFoundException; 13 import org.apache.slide.structure.LinkNode; 14 import org.apache.slide.lock.NodeLock; 15 import org.apache.slide.lock.LockTokenNotFoundException; 16 import org.apache.slide.security.NodePermission; 17 import org.apache.slide.content.*; 18 import org.jahia.registries.ServicesRegistry; 19 import org.jahia.exceptions.JahiaException; 20 21 import java.util.*; 22 import java.sql.Connection ; 23 import java.sql.PreparedStatement ; 24 import java.sql.ResultSet ; 25 import java.sql.SQLException ; 26 import java.lang.reflect.Constructor ; 27 28 42 public class JahiaJDBCAdapter extends AbstractRDBMSAdapter { 43 44 45 protected static final String LOG_CHANNEL = StandardRDBMSAdapter.class.getName(); 46 47 protected boolean bcompress; 48 49 public JahiaJDBCAdapter(Service aService, Logger aLogger) { 50 super(aService, aLogger); 51 bcompress = false; 52 } 53 54 public void setParameters(Hashtable parameters) 55 throws ServiceParameterErrorException, ServiceParameterMissingException { 56 try { 57 bcompress = "true".equalsIgnoreCase((String ) parameters.get("compress")); 58 if (bcompress) 59 getLogger().log("Switching on content compression", LOG_CHANNEL, Logger.INFO); 60 super.setParameters(parameters); 61 } catch (Exception e) { 62 getLogger().log(e.toString(), LOG_CHANNEL, Logger.ERROR); 63 } 64 } 65 66 68 public void createObject(Connection connection, Uri uri, ObjectNode object) 69 throws ObjectAlreadyExistsException, ServiceAccessException { 70 if (!storeObject(connection, uri, object, true)) 71 throw new ObjectAlreadyExistsException(uri.toString()); 72 } 73 74 public void storeObject(Connection connection, Uri uri, ObjectNode object) 75 throws ObjectNotFoundException, ServiceAccessException { 76 if (!storeObject(connection, uri, object, false)) 77 throw new ObjectNotFoundException(uri.toString()); 78 } 79 80 protected synchronized boolean storeObject(Connection connection, Uri uri, ObjectNode object, boolean create) 81 throws ServiceAccessException { 82 String className = object.getClass().getName(); 83 long uriid; 84 try { 85 PreparedStatement statement = null; 86 ResultSet res = null; 87 try { 88 uriid = assureUriId(connection, uri.toString()); 89 statement = 90 connection.prepareStatement( 91 "select 1 from jahia_sl2_object o, jahia_sl2_uri u where o.uri_id=u.uri_id and u.uri_string=? and u.namespace=?"); 92 statement.setString(1, uri.toString()); 93 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 94 res = statement.executeQuery(); 95 if (res.next()) { 96 if (create) 97 return false; 98 } else { 99 if (!create) 100 return false; 101 } 102 } finally { 103 close(statement, res); 104 } 105 106 if (create) { 107 try { 109 statement = connection.prepareStatement("insert into jahia_sl2_object (uri_id,class_name) values (?,?)"); 110 statement.setLong(1, uriid); 111 statement.setString(2, className); 112 statement.executeUpdate(); 113 } finally { 114 close(statement); 115 } 116 } 117 118 120 Set updatedBindings = object.getUpdatedBindings(); 121 Set updatedBindingNames = new HashSet(); 122 for (Iterator iterator = updatedBindings.iterator(); iterator.hasNext();) { 123 String bindingUri = (String ) iterator.next(); 124 String bindingName = bindingUri.substring(bindingUri.lastIndexOf('/')+1); 125 updatedBindingNames.add(bindingName); 126 } 127 128 statement = connection.prepareStatement("select name, child_uuri_id from jahia_sl2_binding where uri_id=?"); 129 statement.setLong(1, uriid); 130 ResultSet s = statement.executeQuery(); 131 while (s.next()) { 132 String bindingName = s.getString(1); 133 long cuuid = s.getLong(2); 134 135 PreparedStatement updateStatement = null; 136 137 if (updatedBindingNames.remove(bindingName)) { 138 if (object.getBindingUuri(bindingName) == null) { 139 try { 140 updateStatement = 141 connection.prepareStatement( 142 "delete from jahia_sl2_binding where uri_id=? and name=? and child_uuri_id=?"); 143 updateStatement.setLong(1, uriid); 144 updateStatement.setString(2, bindingName); 145 updateStatement.setLong(3, cuuid); 146 updateStatement.executeUpdate(); 147 } finally { 148 close(updateStatement); 149 } 150 try { 151 updateStatement = 152 connection.prepareStatement( 153 "delete from jahia_sl2_parent_binding where uri_id=? and name=? and parent_uuri_id=?"); 154 updateStatement.setLong(1, cuuid); 155 updateStatement.setString(2, bindingName); 156 updateStatement.setLong(3, uriid); 157 updateStatement.executeUpdate(); 158 } finally { 159 close(updateStatement); 160 } 161 } 162 } 163 } 164 165 for (Iterator iterator = updatedBindingNames.iterator(); iterator.hasNext();) { 166 String bindingName = (String ) iterator.next(); 167 if (object.getBindingUuri(bindingName) != null) { 168 long cuuid = assureUriId(connection, object.getBindingUuri(bindingName)); 169 try { 170 statement = 171 connection.prepareStatement( 172 "insert into jahia_sl2_binding (uri_id, name, child_uuri_id) values (?, ?, ?)"); 173 statement.setLong(1, uriid); 174 statement.setString(2, bindingName); 175 statement.setLong(3, cuuid); 176 statement.executeUpdate(); 177 } finally { 178 close(statement); 179 } 180 try { 181 statement = 182 connection.prepareStatement( 183 "insert into jahia_sl2_parent_binding (uri_id, name, parent_uuri_id) values (?, ?, ?)"); 184 statement.setLong(1, cuuid); 185 statement.setString(2, bindingName); 186 statement.setLong(3, uriid); 187 statement.executeUpdate(); 188 } finally { 189 close(statement); 190 } 191 } 192 } 193 194 if (object instanceof LinkNode) { 195 try { 197 statement = connection.prepareStatement("delete from jahia_sl2_links where uri_id = ?"); 198 statement.setLong(1, uriid); 199 statement.executeUpdate(); 200 } finally { 201 close(statement); 202 } 203 try { 204 long luuid = assureUriId(connection, ((LinkNode) object).getLinkedUri()); 205 statement = 206 connection.prepareStatement( 207 "insert into jahia_sl2_links (uri_id, link_to_id) values (?, ?)"); 208 statement.setLong(1, uriid); 209 statement.setLong(2, luuid); 210 statement.executeUpdate(); 211 } finally { 212 close(statement); 213 } 214 } 215 } catch (SQLException e) { 216 throw createException(e, uri.toString()); 217 } catch (JahiaException e) { 218 throw createException(e, uri.toString()); 219 } 220 object.resetUpdatedBindings(); 221 return true; 222 } 223 224 public synchronized void removeObject(Connection connection, Uri uri, ObjectNode object) 225 throws ServiceAccessException, ObjectNotFoundException { 226 PreparedStatement statement = null; 227 try { 228 229 long uriId = getUriId(connection, uri.toString()); 230 clearBinding(connection, uriId); 231 232 try { 234 statement = 235 connection.prepareStatement( 236 "delete from jahia_sl2_links where uri_id = ?"); 237 statement.setLong(1, uriId); 238 statement.executeUpdate(); 239 } finally { 240 close(statement); 241 } 242 try { 245 statement = 246 connection.prepareStatement( 247 "delete from jahia_sl2_version_history where uri_id = ?"); 248 statement.setLong(1, uriId); 249 statement.executeUpdate(); 250 } finally { 251 close(statement); 252 } 253 try { 255 statement = 256 connection.prepareStatement( 257 "delete from jahia_sl2_version where uri_id = ?"); 258 statement.setLong(1, uriId); 259 statement.executeUpdate(); 260 } finally { 261 close(statement); 262 } 263 try { 265 statement = 266 connection.prepareStatement( 267 "delete from jahia_sl2_object where uri_id = ?"); 268 statement.setLong(1, uriId); 269 statement.executeUpdate(); 270 } finally { 271 close(statement); 272 } 273 try { 275 statement = connection.prepareStatement("delete from jahia_sl2_uri where uri_string = ? and namespace = ?"); 276 statement.setString(1, uri.toString()); 277 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 278 statement.executeUpdate(); 279 } finally { 280 close(statement); 281 } 282 } catch (SQLException e) { 283 throw createException(e, uri.toString()); 284 } catch (JahiaException e) { 285 throw createException(e, uri.toString()); 286 287 } 288 } 289 290 public ObjectNode retrieveObject(Connection connection, Uri uri) 291 throws ServiceAccessException, ObjectNotFoundException { 292 ObjectNode result = null; 293 try { 294 PreparedStatement statement = null; 295 ResultSet res = null; 296 String className; 297 Vector children = new Vector(); 298 Vector parents = new Vector(); 299 Vector links = new Vector(); 300 try { 301 statement = 302 connection.prepareStatement( 303 "select o.class_name from jahia_sl2_object o, jahia_sl2_uri u where o.uri_id = u.uri_id and u.uri_string = ? and u.namespace = ?"); 304 statement.setString(1, uri.toString()); 305 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 306 res = statement.executeQuery(); 307 if (res.next()) { 308 className = res.getString(1); 309 } else { 310 throw new ObjectNotFoundException(uri); 311 } 312 } finally { 313 close(statement, res); 314 } 315 316 try { 317 statement = 318 connection.prepareStatement( 319 "SELECT c.name, cu.uri_string FROM jahia_sl2_uri u, jahia_sl2_uri cu, jahia_sl2_binding c WHERE cu.uri_id = c.child_uuri_id AND c.uri_id = u.uri_id and u.uri_string = ? and u.namespace = ?"); 320 statement.setString(1, uri.toString()); 321 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 322 res = statement.executeQuery(); 323 while (res.next()) { 324 children.addElement(new ObjectNode.Binding(res.getString(1), res.getString(2))); 325 } 326 } finally { 327 close(statement, res); 328 } 329 330 try { 331 statement = 332 connection.prepareStatement( 333 "SELECT c.name, cu.uri_string FROM jahia_sl2_uri u, jahia_sl2_uri cu, jahia_sl2_parent_binding c WHERE cu.uri_id = c.parent_uuri_id AND c.uri_id = u.uri_id and u.uri_string = ? and u.namespace = ?"); 334 statement.setString(1, uri.toString()); 335 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 336 res = statement.executeQuery(); 337 while (res.next()) { 338 parents.addElement(new ObjectNode.ParentBinding(res.getString(1), res.getString(2))); 339 } 340 } finally { 341 close(statement, res); 342 } 343 344 try { 345 statement = 346 connection.prepareStatement( 347 "SELECT lu.uri_string FROM jahia_sl2_uri u, jahia_sl2_uri lu, jahia_sl2_links l WHERE lu.uri_id = l.uri_id AND l.link_to_id = u.uri_id and u.uri_string = ? and u.namespace = ?"); 348 statement.setString(1, uri.toString()); 349 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 350 res = statement.executeQuery(); 351 while (res.next()) { 352 links.addElement(res.getString(1)); 353 } 354 } finally { 355 close(statement, res); 356 } 357 if (className.equals(LinkNode.class.getName())) { 358 try { 359 statement = 360 connection.prepareStatement( 361 "SELECT lu.uri_string FROM jahia_sl2_uri u, jahia_sl2_uri lu, jahia_sl2_links l WHERE lu.uri_id = l.link_to_id AND l.uri_id = u.uri_id and u.uri_string = ? and u.namespace = ?"); 362 statement.setString(1, uri.toString()); 363 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 364 res = statement.executeQuery(); 365 if (res.next()) { 366 String linkTarget = res.getString(1); 367 result = new LinkNode(uri.toString(), children, links, linkTarget); 368 } else { 369 result = new LinkNode(uri.toString(), children, links); 370 } 371 } finally { 372 close(statement, res); 373 } 374 } else { 375 try { 376 Class objclass = Class.forName(className); 377 Class argClasses[] = { String .class, Vector.class, Vector.class, Vector.class }; 378 Object arguments[] = { uri.toString(), children, parents, links }; 379 Constructor constructor = objclass.getConstructor(argClasses); 380 result = (ObjectNode) constructor.newInstance(arguments); 381 result.setUri(result.getUuri()); 382 } catch (Exception e) { 383 throw new ServiceAccessException(service, e); 384 } 385 } 386 } catch (SQLException e) { 387 throw createException(e, uri.toString()); 388 } 389 return result; 390 } 391 392 public Enumeration enumerateLocks(Connection connection, Uri uri) throws ServiceAccessException { 394 395 Vector lockVector = new Vector(); 396 PreparedStatement statement = null; 397 ResultSet res = null; 398 try { 399 statement = 400 connection.prepareStatement( 401 "select l.expiration_date, l.is_inheritable, l.is_exclusive, u2.uri_string as lck, u3.uri_string as subject, u4.uri_string as type, l.owner from jahia_sl2_locks l, jahia_sl2_uri u, jahia_sl2_uri u2, jahia_sl2_uri u3, jahia_sl2_uri u4 where l.object_id=u.uri_id and u.uri_string=? and u.namespace=? and l.lock_id=u2.uri_id and l.subject_id=u3.uri_id and l.type_id = u4.uri_id"); 402 statement.setString(1, uri.toString()); 403 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 404 res = statement.executeQuery(); 405 406 while (res.next()) { 407 Date expirationDate = null; 408 try { 409 Long timeValue = new Long (res.getLong("expiration_date")); 410 expirationDate = new Date(timeValue.longValue()); 411 } catch (NumberFormatException e) { 412 getLogger().log(e, LOG_CHANNEL, Logger.WARNING); 413 expirationDate = new Date(); 414 } 415 NodeLock lock = 416 new NodeLock( 417 res.getString("lck"), 418 uri.toString(), 419 res.getString("subject"), 420 res.getString("type"), 421 expirationDate, 422 res.getInt("is_inheritable") == 1, 423 res.getInt("is_exclusive") == 1, 424 res.getString("owner")); 425 426 lockVector.addElement(lock); 427 } 428 } catch (SQLException e) { 429 throw createException(e, uri.toString()); 430 } finally { 431 close(statement, res); 432 } 433 return lockVector.elements(); 434 } 435 436 public synchronized void killLock(Connection connection, Uri uri, NodeLock lock) 437 throws ServiceAccessException, LockTokenNotFoundException { 438 removeLock(connection, uri, lock); 439 } 440 441 public synchronized void putLock(Connection connection, Uri uri, NodeLock lock) throws ServiceAccessException { 442 PreparedStatement statement = null; 443 try { 444 int inheritable = lock.isInheritable() ? 1 : 0; 445 int exclusive = lock.isExclusive() ? 1 : 0; 446 long lockid = assureUriId(connection, lock.getLockId()); 447 long objectId = getUriId(connection, lock.getObjectUri()); 448 long subjectId = assureUriId(connection, lock.getSubjectUri()); 449 long typeId = getUriId(connection, lock.getTypeUri()); 450 451 statement = 452 connection.prepareStatement( 453 "insert into jahia_sl2_locks (lock_id,object_id,subject_id,type_id,expiration_date,is_inheritable,is_exclusive,owner) values (?,?,?,?,?,?,?,?)"); 454 statement.setLong(1, lockid); 455 statement.setLong(2, objectId); 456 statement.setLong(3, subjectId); 457 statement.setLong(4, typeId); 458 statement.setLong(5, lock.getExpirationDate().getTime()); 459 statement.setInt(6, inheritable); 460 statement.setInt(7, exclusive); 461 statement.setString(8, lock.getOwnerInfo()); 462 statement.execute(); 463 } catch (SQLException e) { 464 throw createException(e, uri.toString()); 465 } catch (JahiaException e) { 466 throw createException(e, uri.toString()); 467 } finally { 468 close(statement); 469 } 470 } 471 472 public synchronized void renewLock(Connection connection, Uri uri, NodeLock lock) 473 throws ServiceAccessException, LockTokenNotFoundException { 474 try { 475 PreparedStatement statement = null; 476 ResultSet rslt = null; 477 try { 478 statement = 479 connection.prepareStatement( 480 "select 1 from jahia_sl2_locks l, jahia_sl2_uri u where l.lock_id = u.uri_id and u.uri_string = ? and u.namespace=?"); 481 statement.setString(1, lock.getLockId()); 482 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 483 rslt = statement.executeQuery(); 484 if (rslt.next()) { 485 removeLock(connection,uri,lock); 486 putLock(connection, uri, lock); 487 } else { 488 throw new LockTokenNotFoundException(lock); 489 } 490 } finally { 491 close(statement, rslt); 492 } 493 } catch (SQLException e) { 494 throw createException(e, uri.toString()); 495 } 496 } 497 498 public synchronized void removeLock(Connection connection, Uri uri, NodeLock lock) 499 throws ServiceAccessException, LockTokenNotFoundException { 500 PreparedStatement statement = null; 501 try { 502 try { 503 statement = 504 connection.prepareStatement( 505 "delete from jahia_sl2_locks where lock_id = ?"); 506 statement.setLong(1, getUriId(connection, uri.toString())); 507 statement.executeUpdate(); 508 } finally { 509 close(statement); 510 } 511 try { 512 } finally { 519 close(statement); 520 } 521 } catch (SQLException e) { 522 throw createException(e, uri.toString()); 523 } catch (JahiaException e) { 524 throw createException(e, uri.toString()); 525 } 526 } 527 528 530 public Enumeration enumeratePermissions(Connection connection, Uri uri) throws ServiceAccessException { 531 Vector permissions = new Vector(); 532 PreparedStatement statement = null; 533 ResultSet res = null; 534 try { 535 statement = 536 connection.prepareStatement( 537 "select ou.uri_string, su.uri_string, au.uri_string, p.version_no, p.is_inheritable, p.is_negative from jahia_sl2_permissions p, jahia_sl2_uri ou, jahia_sl2_uri su, jahia_sl2_uri au where p.object_id = ou.uri_id and ou.uri_string = ? and ou.namespace = ? and p.subject_id = su.uri_id and p.action_id = au.uri_id order by succession"); 538 statement.setString(1, uri.toString()); 539 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 540 res = statement.executeQuery(); 541 while (res.next()) { 542 String object = res.getString(1); 543 String subject = res.getString(2); 544 String action = res.getString(3); 545 String revision = res.getString(4); 546 if ("NULL".equals(revision) || "".equals(revision)) { 547 revision = null; 548 } 549 boolean inheritable = (res.getInt(5) == 1); 550 boolean negative = (res.getInt(6) == 1); 551 NodePermission permission = 552 new NodePermission(object, revision, subject, action, inheritable, negative); 553 permissions.add(permission); 554 } 555 } catch (SQLException e) { 556 throw createException(e, uri.toString()); 557 } finally { 558 close(statement, res); 559 } 560 return permissions.elements(); 561 } 562 563 public synchronized void grantPermission(Connection connection, Uri uri, NodePermission permission) 564 throws ServiceAccessException { 565 PreparedStatement statement = null; 566 ResultSet res = null; 567 int succession = 0; 568 569 try { 570 575 try { 576 statement = 577 connection.prepareStatement( 578 "select max(p.succession) from jahia_sl2_uri ou, jahia_sl2_permissions p where p.object_id = ou.uri_id and ou.uri_string = ? and ou.namespace = ? "); 579 statement.setString(1, permission.getObjectUri()); 580 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 581 res = statement.executeQuery(); 582 res.next(); 583 succession = res.getInt(1) + 1; 584 } finally { 585 close(statement, res); 586 } 587 588 assureUriId(connection,permission.getSubjectUri()); 589 assureUriId(connection,permission.getActionUri()); 590 591 try { 592 593 int inheritable = permission.isInheritable() ? 1 : 0; 594 int negative = permission.isNegative() ? 1 : 0; 595 596 statement = 597 connection.prepareStatement( 598 "insert into jahia_sl2_permissions (object_id,subject_id,action_id,version_no, is_inheritable,is_negative,succession) select ou.uri_id, su.uri_id, au.uri_id, ?, ?, ?, ? from jahia_sl2_uri ou, jahia_sl2_uri su, jahia_sl2_uri au where ou.uri_string = ? and su.uri_string = ? and au.uri_string = ? and ou.namespace = ? and su.namespace = ? and au.namespace = ?"); 599 statement.setString(1, getRevisionNumberAsString(permission.getRevisionNumber())); 600 statement.setInt(2, inheritable); 601 statement.setInt(3, negative); 602 statement.setInt(4, succession); 603 statement.setString(5, permission.getObjectUri()); 604 statement.setString(6, permission.getSubjectUri()); 605 statement.setString(7, permission.getActionUri()); 606 statement.setInt(8, ((JahiaDescriptorsStore)service).getSiteId()); 607 statement.setInt(9, ((JahiaDescriptorsStore)service).getSiteId()); 608 statement.setInt(10, ((JahiaDescriptorsStore)service).getSiteId()); 609 if (statement.executeUpdate() != 1) { 610 String msg = "Failed to insert permission (" 611 + permission.getObjectUri() 612 + "," + permission.getSubjectUri() 613 + "," + permission.getActionUri() 614 + ")"; 615 getLogger().log(msg,LOG_CHANNEL,Logger.ERROR); 616 } 617 } finally { 618 close(statement); 619 } 620 } catch (SQLException e) { 621 throw createException(e, uri.toString()); 622 } catch (JahiaException e) { 623 throw createException(e, uri.toString()); 624 } 625 } 626 627 public synchronized void revokePermission(Connection connection, Uri uri, NodePermission permission) 628 throws ServiceAccessException { 629 PreparedStatement statement = null; 630 try { 631 statement = 632 connection.prepareStatement( 633 "delete from jahia_sl2_permissions where object_id = ? and subject_id = ? and action_id = ?"); 634 statement.setLong(1, getUriId(connection, permission.getObjectUri())); 635 statement.setLong(2, getUriId(connection, permission.getSubjectUri())); 636 statement.setLong(3, getUriId(connection, permission.getActionUri())); 637 statement.executeUpdate(); 639 } catch (SQLException e) { 640 throw createException(e, uri.toString()); 641 } catch (JahiaException e) { 642 throw createException(e, uri.toString()); 643 } finally { 644 close(statement); 645 } 646 } 647 648 public void revokePermissions(Connection connection, Uri uri) throws ServiceAccessException { 649 PreparedStatement statement = null; 650 try { 651 statement = 652 connection.prepareStatement( 653 "delete from jahia_sl2_permissions where object_id = ?"); 654 statement.setLong(1, getUriId(connection, uri.toString())); 655 statement.executeUpdate(); 656 } catch (SQLException e) { 657 throw createException(e, uri.toString()); 658 } catch (JahiaException e) { 659 throw createException(e, uri.toString()); 660 } finally { 661 close(statement); 662 } 663 } 664 665 public synchronized void createRevisionDescriptor(Connection connection, Uri uri, NodeRevisionDescriptor revisionDescriptor) 666 throws ServiceAccessException { 667 668 PreparedStatement statement = null; 669 try { 670 671 assureVersionInfo(connection, uri, revisionDescriptor); 672 createVersionLabels(connection, uri, revisionDescriptor); 673 for (Enumeration properties = revisionDescriptor.enumerateProperties(); properties.hasMoreElements();) { 674 try { 675 NodeProperty property = (NodeProperty) properties.nextElement(); 676 long versionId = getVersionId(connection, uri.toString(), revisionDescriptor.getRevisionNumber().toString()); 677 statement = 678 connection.prepareStatement( 679 "insert into jahia_sl2_properties (version_id,property_namespace,property_name,property_value,property_type,is_protected) values (?, ?, ?, ?, ?, ?) "); 680 int protectedProperty = property.isProtected() ? 1 : 0; 681 statement.setLong(1, versionId); 682 statement.setString(2, property.getNamespace()); 683 statement.setString(3, property.getName()); 684 statement.setString(4, property.getValue().toString()); 685 statement.setString(5, property.getType()); 686 statement.setInt(6, protectedProperty); 687 statement.executeUpdate(); 688 } finally { 689 close(statement); 690 } 691 } 692 } catch (JahiaException e) { 693 throw createException(e, uri.toString()); 694 } catch (SQLException e) { 695 throw createException(e, uri.toString()); 696 } 697 } 698 699 public synchronized void removeRevisionDescriptor(Connection connection, Uri uri, NodeRevisionNumber revisionNumber) 700 throws ServiceAccessException { 701 PreparedStatement statement = null; 702 try { 703 removeVersionLabels(connection, uri, revisionNumber); 704 try { 705 statement = 706 connection.prepareStatement("delete from jahia_sl2_properties where version_id = ?"); 707 statement.setLong(1, getVersionId(connection, uri.toString(), revisionNumber.toString())); 708 statement.executeUpdate(); 709 } finally { 710 close(statement); 711 } 712 } catch (SQLException e) { 713 throw createException(e, uri.toString()); 714 } catch (JahiaException e) { 715 throw createException(e, uri.toString()); 716 } 717 } 718 719 public synchronized void removeRevisionDescriptors(Connection connection, Uri uri) throws ServiceAccessException { 720 PreparedStatement statement = null; 721 PreparedStatement select = null; 722 ResultSet s = null; 723 try { 724 statement = connection.prepareStatement( "delete from jahia_sl2_version_preds where version_id = ?"); 725 select = connection.prepareStatement( "select vh.version_id from jahia_sl2_version_history vh where vh.uri_id=?"); 726 select.setLong(1, getUriId(connection, uri.toString())); 727 s = select.executeQuery(); 728 while (s.next()) { 729 statement.setLong(1, s.getLong(1)); 730 statement.executeUpdate(); 731 } 732 } catch (JahiaException e) { 733 throw createException(e, uri.toString()); 734 } catch (SQLException e) { 735 throw createException(e, uri.toString()); 736 } finally { 737 close(statement); 738 close(select, s); 739 } 740 } 741 742 public NodeRevisionDescriptor retrieveRevisionDescriptor( 743 Connection connection, 744 Uri uri, 745 NodeRevisionNumber revisionNumber) 746 throws ServiceAccessException, RevisionDescriptorNotFoundException { 747 NodeRevisionDescriptor revisionDescriptor = null; 748 if (revisionNumber == null) 749 throw new RevisionDescriptorNotFoundException(uri.toString()); 750 try { 751 PreparedStatement statement = null; 752 ResultSet res = null; 753 754 String branch = null; 755 Vector labels = new Vector(); 756 List properties = new ArrayList(); 757 long versionId = 0; 758 try { 759 statement = 760 connection.prepareStatement( 761 "select vh.version_id, b.branch_string from jahia_sl2_version_history vh, jahia_sl2_branch b, jahia_sl2_uri u where vh.uri_id = u.uri_id and u.uri_string = ? and u.namespace=? and b.branch_id = vh.branch_id and vh.revision_no = ?"); 762 statement.setString(1, uri.toString()); 763 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 764 statement.setString(3, revisionNumber.toString()); 765 res = statement.executeQuery(); 766 if (res.next()) { 767 versionId = res.getLong(1); 768 branch = res.getString(2); 769 } else { 770 throw new RevisionDescriptorNotFoundException(uri.toString()); 771 } 772 } finally { 773 close(statement, res); 774 } 775 try { 776 statement = 777 connection.prepareStatement( 778 "select l.label_string from jahia_sl2_version_labels vl, jahia_sl2_label l where vl.version_id = ? and l.label_id = vl.label_id"); 779 statement.setLong(1, versionId); 780 res = statement.executeQuery(); 781 while (res.next()) { 782 labels.addElement(res.getString(1)); 783 } 784 } finally { 785 close(statement, res); 786 } 787 try { 788 statement = 789 connection.prepareStatement( 790 "select property_name, property_namespace, property_value, property_type, is_protected from jahia_sl2_properties where version_id = ?"); 791 statement.setLong(1, versionId); 792 res = statement.executeQuery(); 793 while (res.next()) { 794 String propertyName = res.getString(1); 795 String propertyNamespace = res.getString(2); 796 NodeProperty property = 797 new NodeProperty( 798 propertyName, 799 res.getString(3), 800 propertyNamespace, 801 res.getString(4), 802 res.getInt(5) == 1); 803 properties.add(property); 804 } 805 } finally { 806 close(statement, res); 807 } 808 revisionDescriptor = new NodeRevisionDescriptor(revisionNumber, branch, labels, properties); 809 } catch (SQLException e) { 810 throw createException(e, uri.toString()); 811 } 812 return revisionDescriptor; 813 } 814 815 public NodeRevisionDescriptors retrieveRevisionDescriptors(Connection connection, Uri uri) 816 throws ServiceAccessException, RevisionDescriptorNotFoundException { 817 818 NodeRevisionDescriptors revisionDescriptors = null; 819 PreparedStatement statement = null; 820 ResultSet res = null; 821 try { 822 NodeRevisionNumber initialRevision = new NodeRevisionNumber(); 823 Hashtable workingRevisions = new Hashtable(); 825 Hashtable latestRevisionNumbers = new Hashtable(); 826 Hashtable branches = new Hashtable(); 827 Vector allRevisions = new Vector(); 828 829 boolean isVersioned = false; 830 try { 832 statement = 833 connection.prepareStatement( 834 "select is_versioned from jahia_sl2_version v, jahia_sl2_uri u where v.uri_id = u.uri_id and u.uri_string = ? and u.namespace=?"); 835 statement.setString(1, uri.toString()); 836 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 837 res = statement.executeQuery(); 838 if (res.next()) { 839 isVersioned = (res.getInt("is_versioned") == 1); 840 } else { 841 throw new RevisionDescriptorNotFoundException(uri.toString()); 842 } 843 } finally { 844 close(statement, res); 845 } 846 try { 848 statement = 849 connection 850 .prepareStatement( 851 "select vh.revision_no, b.branch_string from jahia_sl2_version_history vh, jahia_sl2_branch b, jahia_sl2_uri u where vh.branch_id = b.branch_id and vh.uri_id = u.uri_id and u.uri_string = ? and u.namespace=? "); 852 statement.setString(1, uri.toString()); 855 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 856 res = statement.executeQuery(); 857 while (res.next()) { 858 NodeRevisionNumber revisionNumber = new NodeRevisionNumber(res.getString(1)); 859 allRevisions.add(revisionNumber); latestRevisionNumbers.put(res.getString(2), revisionNumber); } 862 } finally { 863 close(statement, res); 864 } 865 866 for (Enumeration e = allRevisions.elements(); e.hasMoreElements();) { 867 NodeRevisionNumber revisionNumber = (NodeRevisionNumber) e.nextElement(); 868 try { 870 statement = 871 connection.prepareStatement( 872 "select pvh.revision_no from jahia_sl2_version_history vh, jahia_sl2_version_history pvh, jahia_sl2_version_preds vp, jahia_sl2_uri u where pvh.version_id = vp.version_id and vp.version_id = vh.version_id and vh.uri_id = u.uri_id and u.uri_string = ? and u.namespace=? and vh.revision_no = ?"); 873 statement.setString(1, uri.toString()); 874 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 875 statement.setString(3, revisionNumber.toString()); 876 res = statement.executeQuery(); 877 Vector predecessors = new Vector(); 878 while (res.next()) { 879 predecessors.add(new NodeRevisionNumber(res.getString(1))); 880 } 881 branches.put(new NodeRevisionNumber(revisionNumber.toString()), predecessors); 883 } finally { 884 close(statement, res); 885 } 886 } 887 revisionDescriptors = 888 new NodeRevisionDescriptors( 889 uri.toString(), 890 initialRevision, 891 workingRevisions, 892 latestRevisionNumbers, 893 branches, 894 isVersioned); 895 } catch (SQLException e) { 896 throw createException(e, uri.toString()); 897 } 898 return revisionDescriptors; 899 } 900 901 public synchronized void createRevisionDescriptors(Connection connection, Uri uri, NodeRevisionDescriptors revisionDescriptors) 902 throws ServiceAccessException { 903 904 PreparedStatement statement = null; 905 ResultSet res = null; 906 try { 907 long uriid = getUriId(connection,uri.toString()); 908 int isVersioned = 0; 909 if (revisionDescriptors.isVersioned()) 910 isVersioned = 1; 911 boolean revisionExists; 912 try { 913 statement = 914 connection.prepareStatement( 915 "SELECT 1 FROM jahia_sl2_version v, jahia_sl2_uri u WHERE v.uri_id = u.uri_id and u.uri_string = ? and u.namespace=?"); 916 statement.setString(1, uri.toString()); 917 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 918 res = statement.executeQuery(); 919 revisionExists = res.next(); 920 } finally { 921 close(statement, res); 922 } 923 if (!revisionExists) { 924 try { 925 statement = 926 connection.prepareStatement( 927 "insert into jahia_sl2_version (uri_id, is_versioned) values (?, ?)"); 928 statement.setLong(1, uriid); 929 statement.setInt(2, isVersioned); 930 statement.executeUpdate(); 931 } finally { 932 close(statement, res); 933 } 934 } 935 boolean versionHistoryExists; 936 NodeRevisionNumber versionNumber = revisionDescriptors.hasRevisions() ? revisionDescriptors.getLatestRevision() : new NodeRevisionNumber(); 937 try { 938 statement = 939 connection.prepareStatement( 940 "SELECT 1 FROM jahia_sl2_version_history vh, jahia_sl2_uri u WHERE vh.uri_id = u.uri_id and u.uri_string = ? and u.namespace=? and revision_no = ?"); 941 statement.setString(1, uri.toString()); 942 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 943 statement.setString(3, versionNumber.toString()); 944 res = statement.executeQuery(); 945 versionHistoryExists = res.next(); 946 } finally { 947 close(statement, res); 948 } 949 if (!versionHistoryExists && revisionDescriptors.getLatestRevision() != null) { 950 try { 951 long branchId = getBranchId(connection, NodeRevisionDescriptors.MAIN_BRANCH); 952 statement = 953 connection.prepareStatement( 954 "insert into jahia_sl2_version_history (version_id, uri_id, branch_id, revision_no) values (?,?,?,?)"); 955 statement.setInt(1, ServicesRegistry.getInstance().getJahiaIncrementorsDBService().autoIncrement("jahia_sl2_version_history")); 956 statement.setLong(2, uriid); 957 statement.setLong(3, branchId); 958 statement.setString(4, getRevisionNumberAsString(versionNumber)); 959 statement.executeUpdate(); 961 } finally { 962 close(statement, res); 963 } 964 } 965 966 967 Enumeration revisionNumbers = revisionDescriptors.enumerateRevisionNumbers(); 969 while (revisionNumbers.hasMoreElements()) { 970 NodeRevisionNumber nodeRevisionNumber = (NodeRevisionNumber) revisionNumbers.nextElement(); 971 972 Enumeration successors = revisionDescriptors.getSuccessors(nodeRevisionNumber); 973 while (successors.hasMoreElements()) 974 { 975 try { 976 NodeRevisionNumber successor = (NodeRevisionNumber) successors.nextElement(); 977 978 statement = 979 connection.prepareStatement( 980 "insert into jahia_sl2_version_preds (version_id, predecessor_id) " + 981 " select vr.version_id, suc.version_id" + 982 " FROM jahia_sl2_uri uri, jahia_sl2_version_history vr, jahia_sl2_version_history suc " + 983 " where vr.uri_id = uri.uri_id " + 984 " and suc.uri_id = uri.uri_id " + 985 " and uri.uri_string = ? " + 986 " and uri.namespace = ? " + 987 " and vr.revision_no = ? " + 988 " and suc.revision_no = ? " ); 989 990 statement.setString(1, uri.toString()); 991 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 992 statement.setString(3, nodeRevisionNumber.toString()); 993 statement.setString(4, successor.toString()); 994 statement.executeUpdate(); 995 } finally { 996 close(statement); 997 } 998 } 999 } 1000 getLogger().log( 1001 revisionDescriptors.getOriginalUri() + revisionDescriptors.getInitialRevision(), 1002 LOG_CHANNEL, 1003 Logger.DEBUG); 1004 } catch (SQLException e) { 1005 throw createException(e, uri.toString()); 1006 } catch (JahiaException e) { 1007 throw createException(e, uri.toString()); 1008 } 1009 } 1010 1011 protected long getVersionId(Connection connection, String uri, String revNo) 1012 throws SQLException , JahiaException { 1013 PreparedStatement statement = null; 1014 ResultSet res = null; 1015 try { 1016 statement = 1017 connection.prepareStatement( 1018 "select vh.version_id from jahia_sl2_version_history vh, jahia_sl2_uri u where vh.uri_id = u.uri_id and u.uri_string = ? and u.namespace=? and revision_no = ?"); 1019 statement.setString(1, uri); 1020 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 1021 statement.setString(3, revNo); 1022 res = statement.executeQuery(); 1023 if (res.next()) { 1024 long id = res.getLong(1); 1025 return id; 1026 } 1027 } finally { 1028 close(statement, res); 1029 } 1030 return -1; 1031 } 1032 protected void assureVersionInfo(Connection connection, Uri uri, NodeRevisionDescriptor revisionDescriptor) 1033 throws SQLException , JahiaException { 1034 PreparedStatement statement = null; 1035 ResultSet res = null; 1036 long uriid = getUriId(connection, uri.toString()); 1037 boolean revisionExists; 1038 try { 1039 statement = 1040 connection.prepareStatement( 1041 "select 1 from jahia_sl2_version v, jahia_sl2_uri u where v.uri_id = u.uri_id and u.uri_string = ? and u.namespace=?"); 1042 statement.setString(1, uri.toString()); 1043 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 1044 res = statement.executeQuery(); 1045 revisionExists = res.next(); 1046 } finally { 1047 close(statement, res); 1048 } 1049 if (!revisionExists) { 1051 try { 1052 statement = 1053 connection.prepareStatement( 1054 "insert into jahia_sl2_version (uri_id, is_versioned) values (?, ?)"); 1055 statement.setLong(1, uriid); 1056 statement.setInt(2, 0); 1057 statement.executeUpdate(); 1058 } finally { 1059 close(statement); 1060 } 1061 } 1062 boolean versionHistoryExists; 1063 try { 1064 statement = 1065 connection.prepareStatement( 1066 "select 1 from jahia_sl2_version_history vh, jahia_sl2_uri u where vh.uri_id = u.uri_id and u.uri_string = ? and u.namespace=? and revision_no = ?"); 1067 statement.setString(1, uri.toString()); 1068 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 1069 statement.setString(3, revisionDescriptor.getRevisionNumber().toString()); 1070 res = statement.executeQuery(); 1071 versionHistoryExists = res.next(); 1072 } finally { 1073 close(statement, res); 1074 } 1075 if (!versionHistoryExists) { 1076 long branchId = assureBranchId(connection, revisionDescriptor.getBranchName()); 1077 try { 1078 statement = 1079 connection.prepareStatement( 1080 "insert into jahia_sl2_version_history (version_id, uri_id, branch_id, revision_no) values (?, ?, ?, ?)"); 1081 statement.setInt(1, ServicesRegistry.getInstance().getJahiaIncrementorsDBService().autoIncrement("jahia_sl2_version_history")); 1082 statement.setLong(2, uriid); 1083 statement.setLong(3, branchId); 1084 statement.setString(4, getRevisionNumberAsString(revisionDescriptor.getRevisionNumber())); 1085 statement.executeUpdate(); 1086 } finally { 1087 close(statement); 1088 } 1089 } 1090 } 1091 1092 1093 public synchronized void storeRevisionDescriptor(Connection connection, Uri uri, NodeRevisionDescriptor revisionDescriptor) 1094 throws ServiceAccessException, RevisionDescriptorNotFoundException { 1095 removeRevisionDescriptor(connection, uri, revisionDescriptor.getRevisionNumber()); 1096 createRevisionDescriptor(connection, uri, revisionDescriptor); 1097 } 1098 1099 public synchronized void storeRevisionDescriptors(Connection connection, Uri uri, NodeRevisionDescriptors revisionDescriptors) 1100 throws ServiceAccessException, RevisionDescriptorNotFoundException { 1101 removeRevisionDescriptors(connection, uri); 1102 createRevisionDescriptors(connection, uri, revisionDescriptors); 1103 } 1104 1105 protected synchronized void removeVersionLabels(Connection connection, Uri uri, NodeRevisionNumber revisionNumber) 1106 throws SQLException , JahiaException { 1107 PreparedStatement statement = null; 1108 try { 1109 statement = connection 1110 .prepareStatement("delete from jahia_sl2_version_labels where version_id = ?"); 1111 statement.setLong(1, getVersionId(connection, uri.toString(), revisionNumber.toString())); 1112 statement.executeUpdate(); 1113 } finally { 1114 close(statement); 1115 } 1116 } 1117 1118 protected synchronized void createVersionLabels(Connection connection, Uri uri, NodeRevisionDescriptor revisionDescriptor) 1119 throws SQLException , JahiaException { 1120 1121 PreparedStatement statement = null; 1122 for (Enumeration labels = revisionDescriptor.enumerateLabels(); labels.hasMoreElements();) { 1123 long labelId = assureLabelId(connection, (String ) labels.nextElement()); 1124 try { 1125 statement = connection 1126 .prepareStatement("insert into jahia_sl2_version_labels (version_id, label_id) select version_id, ? from jahia_sl2_version_history vh, jahia_sl2_uri u where vh.uri_id = u.uri_id and u.uri_string = ? and u.namespace=? and vh.revision_no = ?"); 1127 statement.setLong(1, labelId); 1128 statement.setString(2, uri.toString()); 1129 statement.setInt(3, ((JahiaDescriptorsStore)service).getSiteId()); 1130 statement.setString(4, revisionDescriptor.getRevisionNumber().toString()); 1131 statement.executeUpdate(); 1132 } finally { 1133 close(statement); 1134 } 1135 } 1136 } 1137 1138 protected long getUriId(Connection connection, String uri) throws JahiaException, SQLException { 1139 PreparedStatement statement = null; 1140 ResultSet res = null; 1141 try { 1142 statement = connection.prepareStatement("select uri_id from jahia_sl2_uri where uri_string=? and namespace=?"); 1143 statement.setString(1, uri); 1144 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 1145 res = statement.executeQuery(); 1146 if (res.next()) { 1147 long id = res.getLong(1); 1148 return id; 1149 } 1150 } finally { 1151 close(statement, res); 1152 } 1153 return -1; 1154 } 1155 1156 protected long assureUriId(Connection connection, String uri) throws JahiaException, SQLException { 1157 PreparedStatement statement = null; 1158 ResultSet res = null; 1159 try { 1160 statement = connection.prepareStatement("select uri_id from jahia_sl2_uri where uri_string=? and namespace=?"); 1161 statement.setString(1, uri); 1162 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 1163 res = statement.executeQuery(); 1164 if (res.next()) { 1165 long id = res.getLong(1); 1166 return id; 1167 } 1168 } finally { 1169 close(statement, res); 1170 } 1171 try { 1172 statement = connection.prepareStatement("insert into jahia_sl2_uri (uri_id,uri_string,namespace) values (?,?,?)"); 1173 statement.setInt(1, ServicesRegistry.getInstance().getJahiaIncrementorsDBService().autoIncrement("jahia_sl2_uri")); 1174 statement.setString(2, uri); 1175 statement.setInt(3, ((JahiaDescriptorsStore)service).getSiteId()); 1176 statement.executeUpdate(); 1177 } finally { 1178 close(statement); 1179 } 1180 return assureUriId(connection, uri); 1181 } 1182 1183 protected long getBranchId(Connection connection, String branch) throws JahiaException, SQLException { 1184 PreparedStatement statement = null; 1185 ResultSet res = null; 1186 try { 1187 statement = connection.prepareStatement("select branch_id from jahia_sl2_branch where branch_string=? and namespace=?"); 1188 statement.setString(1, branch); 1189 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 1190 res = statement.executeQuery(); 1191 if (res.next()) { 1192 long id = res.getLong(1); 1193 return id; 1194 } 1195 } finally { 1196 close(statement, res); 1197 } 1198 return -1; 1199 } 1200 1201 protected long assureBranchId(Connection connection, String branch) throws JahiaException, SQLException { 1202 PreparedStatement statement = null; 1203 ResultSet res = null; 1204 try { 1205 statement = connection.prepareStatement("select branch_id from jahia_sl2_branch where branch_string=? and namespace=?"); 1206 statement.setString(1, branch); 1207 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 1208 res = statement.executeQuery(); 1209 if (res.next()) { 1210 long id = res.getLong(1); 1211 return id; 1212 } 1213 } finally { 1214 close(statement, res); 1215 } 1216 try { 1217 statement = connection.prepareStatement("insert into jahia_sl2_branch (branch_id,branch_string,namespace) values (?,?,?)"); 1218 statement.setInt(1, ServicesRegistry.getInstance().getJahiaIncrementorsDBService().autoIncrement("jahia_sl2_branch")); 1219 statement.setString(2, branch); 1220 statement.setInt(3, ((JahiaDescriptorsStore)service).getSiteId()); 1221 statement.executeUpdate(); 1222 } finally { 1223 close(statement); 1224 } 1225 return assureBranchId(connection, branch); 1226 } 1227 1228 protected long assureLabelId(Connection connection, String label) throws JahiaException, SQLException { 1229 PreparedStatement statement = null; 1230 ResultSet res = null; 1231 try { 1232 statement = connection.prepareStatement("select label_id from jahia_sl2_label where label_string=? and namespace=?"); 1233 statement.setString(1, label); 1234 statement.setInt(2, ((JahiaDescriptorsStore)service).getSiteId()); 1235 res = statement.executeQuery(); 1236 if (res.next()) { 1237 long id = res.getLong(1); 1238 return id; 1239 } 1240 } finally { 1241 close(statement, res); 1242 } 1243 try { 1244 statement = connection.prepareStatement("insert into jahia_sl2_label (label_id,label_string,namespace) values (?,?,?)"); 1245 statement.setInt(1, ServicesRegistry.getInstance().getJahiaIncrementorsDBService().autoIncrement("jahia_sl2_label")); 1246 statement.setString(2, label); 1247 statement.setInt(3, ((JahiaDescriptorsStore)service).getSiteId()); 1248 statement.executeUpdate(); 1249 } finally { 1250 close(statement); 1251 } 1252 return assureLabelId(connection, label); 1253 } 1254 1255 protected void clearBinding(Connection connection, long uriId) 1256 throws ServiceAccessException, ObjectNotFoundException, SQLException { 1257 PreparedStatement statement = null; 1258 1259 1261 try { 1262 statement = 1263 connection.prepareStatement( 1264 "delete from jahia_sl2_binding where uri_id = ?"); 1265 statement.setLong(1, uriId); 1266 statement.executeUpdate(); 1267 } finally { 1268 close(statement); 1269 } 1270 1271 try { 1272 statement = 1273 connection.prepareStatement( 1274 "delete from jahia_sl2_parent_binding where uri_id = ?"); 1275 statement.setLong(1, uriId); 1276 statement.executeUpdate(); 1277 } finally { 1278 close(statement); 1279 } 1280 } 1281 1282 protected String getRevisionNumberAsString(NodeRevisionNumber revisionNumber) { 1284 return revisionNumber != null ? revisionNumber.toString() : null; 1285 } 1286 1287 protected String convertRevisionNumberToComparable(String revisioNumber) { 1288 return "convert(numeric, SUBSTRING("+revisioNumber+",1,charindex('.',"+revisioNumber+"))), convert(numeric, SUBSTRING("+revisioNumber+",charindex('.',"+revisioNumber+")+1,100))"; 1289 } 1290 1291 protected void close(PreparedStatement statement) { 1292 try { 1293 if (statement != null) { 1294 statement.close(); 1295 } 1296 } catch (SQLException e) { 1297 getLogger().log(e, LOG_CHANNEL, Logger.WARNING); 1298 } 1299 } 1300 1301 protected void close(PreparedStatement statement, ResultSet resultSet) { 1302 try { 1303 if (resultSet != null) { 1304 resultSet.close(); 1305 } 1306 } catch (SQLException e) { 1307 getLogger().log(e, LOG_CHANNEL, Logger.WARNING); 1308 } finally { 1309 try { 1310 if (statement != null) { 1311 statement.close(); 1312 } 1313 } catch (SQLException e) { 1314 getLogger().log(e, LOG_CHANNEL, Logger.WARNING); 1315 } 1316 } 1317 } 1318 1319 protected ServiceAccessException createException(SQLException e, String uri) { 1321 getLogger().log( 1322 "SQL error " + e.getErrorCode() + " on " + uri + ": " + e.getMessage(), 1323 LOG_CHANNEL, 1324 Logger.ERROR); 1325 return new ServiceAccessException(service, e); 1326 } 1327 1328 protected ServiceAccessException createException(JahiaException e, String uri) { 1329 getLogger().log( 1330 "Jahia error " + e.getErrorCode() + " on " + uri + ": " + e.getMessage(), 1331 LOG_CHANNEL, 1332 Logger.ERROR); 1333 return new ServiceAccessException(service, e); 1334 } 1335 1336 1337 public NodeRevisionContent retrieveRevisionContent(Connection conn, Uri uri, NodeRevisionDescriptor revisionDescriptor, boolean temporaryConnection) throws ServiceAccessException, RevisionNotFoundException { 1338 throw new ServiceAccessException(service,"Content not supported"); 1339 } 1340 1341 public void createRevisionContent(Connection conn, Uri uri, NodeRevisionDescriptor revisionDescriptor, NodeRevisionContent revisionContent) throws ServiceAccessException, RevisionAlreadyExistException { 1342 throw new ServiceAccessException(service,"Content not supported"); 1343 } 1344 1345 public void storeRevisionContent(Connection conn, Uri uri, NodeRevisionDescriptor revisionDescriptor, NodeRevisionContent revisionContent) throws ServiceAccessException, RevisionNotFoundException { 1346 throw new ServiceAccessException(service,"Content not supported"); 1347 } 1348 1349 public void removeRevisionContent(Connection conn, Uri uri, NodeRevisionDescriptor revisionDescriptor) throws ServiceAccessException { 1350 throw new ServiceAccessException(service,"Content not supported"); 1351 } 1352 1353} 1354 | Popular Tags |