Changeset 5058


Ignore:
Timestamp:
Aug 18, 2009, 2:56:25 PM (14 years ago)
Author:
Nicklas Nordborg
Message:

References #108: Logging the change history of an item

  • We must tell DbControll?.reattach() if the item has been updated while it was detached or not or the logging will not work as expected. NOTE!!! This is a backwards compatibility problem that needs to be documented!!!
Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/DbControl.java

    r5038 r5058  
    992992 
    993993  /**
     994    Reattach a detached item assuming that it has not been
     995    updated while it was detached.
     996    @see #reattachItem(BasicItem, boolean)
     997  */
     998  public void reattachItem(BasicItem item)
     999    throws PermissionDeniedException, ItemNotFoundException, BaseException
     1000  {
     1001    reattachItem(item, false);
     1002  }
     1003 
     1004  /**
    9941005    Reattach a detached item from this <code>DbControl</code>. If the
    9951006    reattached already exists in the database it will be managed and
     
    9971008   
    9981009    @param item The item to be reattached
     1010    @param updated If TRUE, the item has been updated while it was detached
     1011      and changes will be saved to the database. If FALSE, the item will
     1012      only be saved to the database if it is modified after the
     1013      reattachement
    9991014    @throws PermissionDeniedException If the logged in user doesn't have
    1000       read permission
     1015      read/write permission
    10011016    @throws BaseException If there is another error
    10021017    @see #detachItem(BasicItem)
    1003   */
    1004   public void reattachItem(BasicItem item)
     1018    @since 2.13
     1019  */
     1020  public void reattachItem(BasicItem item, boolean updated)
    10051021    throws PermissionDeniedException, ItemNotFoundException, BaseException
    10061022  {
     
    10111027    {
    10121028      item.initPermissions(0, 0);
    1013       if (item.hasPermission(Permission.RESTRICTED_WRITE))
    1014       {
    1015         HibernateUtil.lockData(hSession, item.getData(), org.hibernate.LockMode.NONE);
    1016 //        HibernateUtil.updateData(hSession, item.getData());
    1017       }
    1018       else if (item.hasPermission(Permission.READ))
    1019       {
    1020         HibernateUtil.lockData(hSession, item.getData(), org.hibernate.LockMode.NONE);
     1029      if (updated)
     1030      {
     1031        if (item.hasPermission(Permission.RESTRICTED_WRITE))
     1032        {
     1033          HibernateUtil.updateData(hSession, item.getData());
     1034        }
     1035        else
     1036        {
     1037          throw new PermissionDeniedException(Permission.WRITE, item.toString());
     1038        }
    10211039      }
    10221040      else
    10231041      {
    1024         throw new PermissionDeniedException(Permission.READ, item.toString());
     1042        if (item.hasPermission(Permission.READ))
     1043        {
     1044          HibernateUtil.lockData(hSession, item.getData(), org.hibernate.LockMode.NONE);
     1045        }
     1046        else
     1047        {
     1048          throw new PermissionDeniedException(Permission.READ, item.toString());
     1049        }
    10251050      }
    10261051      itemCache.put(item.getData(), item);
  • trunk/src/test/TestDbControl.java

    r4889 r5058  
    128128      r.setName("Detached role");
    129129      dc = TestUtil.getDbControl();
    130       dc.reattachItem(r);
     130      dc.reattachItem(r, true);
    131131      dc.commit();
    132132      dc.close();
Note: See TracChangeset for help on using the changeset viewer.