Changeset 5054


Ignore:
Timestamp:
Aug 18, 2009, 1:24:48 PM (13 years ago)
Author:
Nicklas Nordborg
Message:

References #108: Logging the change history of an item

  • Added special logger implementation for annotations. At the moment it can only catch CREATE and DELETE changes, since updating annotation only results in a change in the ParameterValues? table. I'll figure out a way to fix it.
Location:
trunk/src/core
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/common-queries.xml

    r5039 r5054  
    35323532    </description>
    35333533  </query>
    3534  
     3534  <query id="DBLOG_GET_ANNOTATIONTYPE_NAME" type="HQL">
     3535    <sql>
     3536      SELECT at.name
     3537      FROM AnnotationTypeData at
     3538      WHERE at.id = :annotationTypeId
     3539    </sql>
     3540    <description>
     3541      An HQL query that loads the name of an annotation type
     3542      given the ID.
     3543    </description>
     3544  </query>
     3545  <query id="DBLOG_GET_ANNOTATION_ITEMTYPE" type="HQL">
     3546    <sql>
     3547      SELECT as.itemType
     3548      FROM AnnotationSetData as
     3549      WHERE as.id = :annotationSetId
     3550    </sql>
     3551    <description>
     3552      An HQL query that loads the item type value an annotation
     3553      set with a given ID belongs to.
     3554    </description>
     3555  </query>
     3556  <query id="DBLOG_GET_ITEMID_WITH_ANNOTATION" type="HQL">
     3557    <sql>
     3558      SELECT i.id
     3559      FROM {1} i
     3560      WHERE i.annotationSet = :annotationSetId
     3561    </sql>
     3562    <description>
     3563      An HQL query that loads the ID of the item that
     3564      is associated with a given annotation set.
     3565    </description>
     3566  </query>
     3567
    35353568</predefined-queries>
  • trunk/src/core/net/sf/basedb/core/LogControl.java

    r5038 r5054  
    8383  }
    8484 
     85  /**
     86    Creates a Hibernate HQL query. Use this to get information
     87    from the database that is relevent for the logging implementation.
     88    The query uses the stateless session, which means that there
     89    is no first- or second-level cache and on support for initialization
     90    of proxies. We recommend that queries are used to return
     91    scalar values only, not entities.
     92    @return A Query
     93  */
     94  public org.hibernate.Query createHqlQuery(String hql)
     95  {
     96    return HibernateUtil.createQuery(getSession(), hql);
     97  }
     98 
     99  /**
     100    Creates a Hibernate SQL query. Use this to get information
     101    from the database that is relevent for the logging
     102    implementation. The query uses the stateless session.
     103    @return A query
     104  */
     105  public org.hibernate.Query createSqlQuery(String sql)
     106  {
     107    return HibernateUtil.createSqlQuery(session, sql);
     108  }
     109 
    85110  private org.hibernate.StatelessSession getSession()
    86111  {
  • trunk/src/core/net/sf/basedb/core/PredefinedQuery.java

    r4889 r5054  
    5858
    5959  @author Nicklas
    60   @version 2.0
     60  @version 2.0, 2.13 (made public)
    6161*/
    62 class PredefinedQuery
     62public class PredefinedQuery
    6363{
    6464
     
    134134  /**
    135135    Get the query string for the predefined query with
    136     the specified name.
     136    the specified name. This method was made public in BASE 2.13.
    137137    @throws BaseException If the query is not found or there
    138138      is any other error
     139    @since 2.13
    139140  */
    140   static String getQueryString(String name, String... replacements)
     141  public static String getQueryString(String name, String... replacements)
    141142    throws BaseException
    142143  {
  • trunk/src/core/net/sf/basedb/core/data/AnnotationData.java

    r4889 r5054  
    3636public class AnnotationData
    3737  extends BasicData
     38  implements LoggableData
    3839{
    3940  public AnnotationData()
  • trunk/src/core/net/sf/basedb/core/log/ChangeType.java

    r5038 r5054  
    3232{
    3333
    34   CREATE(1),
    35   UPDATE(2),
    36   DELETE(3);
     34  CREATE(1, "created"),
     35  UPDATE(2, "updated"),
     36  DELETE(3, "deleted");
    3737 
    3838  private final int value;
    39   private ChangeType(int value)
     39  private final String was;
     40 
     41  private ChangeType(int value, String was)
    4042  {
    4143    this.value = value;
     44    this.was = was;
    4245  }
    4346 
     
    4952  {
    5053    return value;
     54  }
     55 
     56  /**
     57    Create a string for display purposes that explains what
     58    has happened to the what. For example, if what is 'Annotation',
     59    this method may return 'Annotation created'.
     60    @param what The 'what' that something happened to
     61    @return A string
     62  */
     63  public String was(String what)
     64  {
     65    return what + " " + was;
    5166  }
    5267 
  • trunk/src/core/net/sf/basedb/core/log/db/DbLogManagerFactory.java

    r5052 r5054  
    2727import net.sf.basedb.core.Config;
    2828import net.sf.basedb.core.LogControl;
     29import net.sf.basedb.core.data.AnnotationData;
    2930import net.sf.basedb.core.data.BioMaterialEventData;
    3031import net.sf.basedb.core.data.LoggableData;
     
    5657    this.defaultLogger = new DefaultEntityLogger(detailedProperties);
    5758    setSpecialLogger(BioMaterialEventData.class, new BioMaterialEventLogger(detailedProperties));
    58     //setSpecialLogger(AnnotationData.class, new AnnotationLogger());
     59    setSpecialLogger(AnnotationData.class, new AnnotationLogger());
    5960  }
    6061
Note: See TracChangeset for help on using the changeset viewer.