Changeset 6080


Ignore:
Timestamp:
Aug 7, 2012, 1:28:40 PM (11 years ago)
Author:
Nicklas Nordborg
Message:

References #1601: Convert logging plug-in system to an extension point

Updated the documentation. Implemented a few utility methods that can be useful when implementing other logging implementations.

Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/src/docbook/appendix/base.config.xml

    r5895 r6080  
    564564    <para>
    565565      This section contains settings for logging the change history
    566       of items.
     566      of items. Logging is disabled by default, but BASE ships
     567      with one implementation that log changes to the database.
     568      To enable it, log in to the web client with administrator
     569      privileges and enable the <guilabel>Database log manager</guilabel>
     570      extension. See <xref linkend="extensions_developer.logging" /> for more
     571      information about implementing custom logging.
    567572    </para>
    568573   
    569574    <variablelist>
    570     <varlistentry>
    571       <term><property>changelog.factory</property></term>
    572       <listitem>
    573         <para>
    574         The factory class that controls the entire logging system. The
    575         factory has control of what should be logged, were it should
    576         be logged, etc. BASE ships with one factory implementation
    577         <classname docapi="net.sf.basedb.core.log.db">DbLogManagerFactory</classname>
    578         which logs changes into tables in the database. The server admin
    579         may choose a different implementation provided that it implements
    580         the <interfacename docapi="net.sf.basedb.core.log">LogManagerFactory</interfacename>
    581         interface. See <xref linkend="plugin_developer.other.logging" />.
    582         If no factory is specified, logging is disabled.
    583           </para>
    584       </listitem>
    585     </varlistentry>
    586575    <varlistentry>
    587576      <term><property>changelog.show-in-web</property></term>
     
    592581        tab will show log information that has been stored in the database
    593582        and it doesn't make sense to show this tab unless the
    594         <classname docapi="net.sf.basedb.core.log.db">DbLogManagerFactory</classname>
    595         is used.
     583        <guilabel>Database log manager</guilabel> has been enabled.
    596584          </para>
    597585         
     
    612600        <para>
    613601        A boolean value that specifies the amount of information
    614         that should be logged. If set, the log will contain information
    615         about which properties that was modified on each item,
    616         otherwise only the type of change (create, update, delete) is
    617         logged.
     602        that should be logged by the database log manager. If set, the log
     603        will contain information about which properties that was modified on each item,
     604        otherwise only the type of change (create, update, delete) is logged.
    618605        </para>
    619606      </listitem>
  • trunk/doc/src/docbook/appendix/incompatible.xml

    r6077 r6080  
    4747      using it.
    4848    </para>
     49
     50    <bridgehead>Change history logging is now an extension point</bridgehead>
     51    <para>
     52      The change history logging has been converted to an extension point.
     53      The <constant>changelog.factory</constant> setting in <filename>base.config</filename>
     54      is no longer used. Existing logging implementations should be updated
     55      to use the extension system. See <xref linkend="extensions_developer.logging" />.
     56      A temporary solution is to use one of the debugging action factories to
     57      define the extension point:
     58    </para>
     59   
     60    <programlisting language="xml">
     61<![CDATA[
     62<extension
     63   id="id-of-custom-log-manager"
     64   extends="net.sf.basedb.core.log-manager"
     65   >
     66   <about>
     67      <name>My custom log manager</name>
     68      <description>
     69         Temporary solution to allow the old log manager to work with the extension system.
     70      </description>
     71   </about>
     72   <index>1</index>
     73   <action-factory>
     74      <factory-class>net.sf.basedb.util.extensions.debug.BeanActionFactory</factory-class>
     75      <parameters>
     76         <beanClass>my.custom.LogmangerClass</beanClass>
     77      </parameters>
     78   </action-factory>
     79</extension>
     80]]>
     81</programlisting>
     82
    4983  </sect1>
    5084 
  • trunk/doc/src/docbook/developer/extensions.xml

    r6052 r6080  
    17741774    </sect2>
    17751775 
     1776    <sect2 id="extensions_developer.logging">
     1777      <title>Logging managers</title>
     1778     
     1779      <para>
     1780        This extension point makes it possible to detect changes that are made to
     1781        item and generate log entries in real time. The core will send notifications
     1782        for all item creations, updates and deletions to all registered logging
     1783        managers. It is up to each implementation to decide if an event should be
     1784        logged, where to log it and how much information that should be stored.
     1785        The BASE core provides a logging implementation that save some information
     1786        to the database which can also be viewed through the web interface.
     1787      </para>
     1788     
     1789      <para>
     1790        The logging mechanism works on the data layer level and hooks into
     1791        callbacks provided by Hibernate. <interfacename
     1792        docapi="net.sf.basedb.core.log">EntityLogger</interfacename>:s are used to
     1793        extract relevant information from Hibernate and create log entries.
     1794        While it is possible to have a generic logger it is usually better
     1795        to have different implementations depending on the type of entity that
     1796        was changed. For example, a change in a child item should, for usability
     1797        reasons, be logged as a change in the parent item. Entity loggers
     1798        are created by a <interfacename
     1799        docapi="net.sf.basedb.core.log">LogManagerFactory</interfacename>. All changes
     1800        made in a single transaction are usually collected by a <interfacename
     1801        docapi="net.sf.basedb.core.log">LogManager</interfacename> which is also
     1802        created by the factory.
     1803      </para>
     1804     
     1805      <sect3 id="extensions_developer.logging.factory">
     1806        <title>The LogManagerFactory interface</title>
     1807       
     1808        <para>
     1809          Each registered action factory shoulds create a <interfacename
     1810          docapi="net.sf.basedb.core.log">LogManagerFactory</interfacename>
     1811          that is used throughout a single transaction. If the factory is
     1812          thread-safe, the same instance can be re-used for multiple requests
     1813          at the same time. Here is a list of
     1814          the methods the factory must implement:
     1815        </para>
     1816       
     1817        <variablelist>
     1818          <varlistentry>
     1819            <term>
     1820              <methodsynopsis language="java">
     1821                <modifier>public</modifier>
     1822                <type>LogManager</type>
     1823                <methodname>getLogManager</methodname>
     1824                <methodparam>
     1825                  <type>LogControl</type>
     1826                  <parameter>logControl</parameter>
     1827                </methodparam>
     1828              </methodsynopsis>
     1829            </term>
     1830            <listitem>
     1831              <para>
     1832              Creates a log manager for a single transaction. Since a transaction
     1833              is not thread-safe the log manager implementation doesn't have to
     1834              be either. The factory has the possibility to create new log managers
     1835              for each transaction.
     1836              </para>
     1837            </listitem>
     1838          </varlistentry>
     1839         
     1840          <varlistentry>
     1841            <term>
     1842              <methodsynopsis language="java">
     1843                <modifier>public</modifier>
     1844                <type>boolean</type>
     1845                <methodname>isLoggable</methodname>
     1846                <methodparam>
     1847                  <type>Object</type>
     1848                  <parameter>entity</parameter>
     1849                </methodparam>
     1850              </methodsynopsis>
     1851            </term>
     1852            <listitem>
     1853              <para>
     1854              Checks if changes to the given entity should be
     1855              logged or not. For performance reasons, it usually makes sense to
     1856              not log everything. For example, the database logger implementation
     1857              only logs changes if the entity implements the <interfacename
     1858              docapi="net.sf.basedb.core.data">LoggableData</interfacename>
     1859              interface. The return value of this method should be consistent
     1860              with <methodname>getEntityLogger()</methodname>.
     1861              </para>
     1862            </listitem>
     1863          </varlistentry>
     1864
     1865          <varlistentry>
     1866            <term>
     1867              <methodsynopsis language="java">
     1868                <modifier>public</modifier>
     1869                <type>EntityLogger</type>
     1870                <methodname>getEntityLogger</methodname>
     1871                <methodparam>
     1872                  <type>LogManager</type>
     1873                  <parameter>logManager</parameter>
     1874                </methodparam>
     1875                <methodparam>
     1876                  <type>Object</type>
     1877                  <parameter>entity</parameter>
     1878                </methodparam>
     1879              </methodsynopsis>
     1880            </term>
     1881            <listitem>
     1882              <para>
     1883              Create or get an entity logger that knows how to log
     1884              changes to the given entity. If the entity should not be
     1885              logged, <constant>null</constant> can be returned. This method
     1886              is called for each modified item in the transaction.
     1887              </para>
     1888            </listitem>
     1889          </varlistentry>
     1890        </variablelist>
     1891       
     1892      </sect3>
     1893     
     1894      <sect3 id="extensions_developer.logging.manager">
     1895        <title>The LogManager interface</title>
     1896       
     1897        <para>
     1898          A new log manager is created for each transaction. The log manager
     1899          is responsible for collecting all changes made in the transaction
     1900          and store those changes in the appropriate place. The interface doesn't define
     1901          any methods for this collection, since each implementation may have
     1902          very different needs.
     1903        </para>
     1904       
     1905        <variablelist>
     1906          <varlistentry>
     1907            <term>
     1908              <methodsynopsis language="java">
     1909                <modifier>public</modifier>
     1910                <type>LogControl</type>
     1911                <methodname>getLogControl</methodname>
     1912              </methodsynopsis>
     1913            </term>
     1914            <listitem>
     1915              <para>
     1916              Get the log control object that was supplied by the BASE core
     1917              when the transaction was started. The log controller contains
     1918              methods for accessing information about the transaction, such
     1919              as the logged in user, executing plug-in, etc. It can also
     1920              be used to execute queries against the database to get
     1921              even more information.
     1922              </para>
     1923             
     1924              <warning>
     1925                <para>
     1926                  Be careful about the queries that are executed by the log
     1927                  controller. Since all logging code is executed at flush
     1928                  time in callbacks from Hibernate we are not allowed to
     1929                  use the regular session. Instead, all queries are sent
     1930                  through the stateless session. The stateless session has no
     1931                  caching functionality which means that Hibernate will use
     1932                  extra queries to load associations. Our recommendation is
     1933                  to avoid quires that return full entities, use scalar
     1934                  queries instead to just load the values that are needed.
     1935                </para>
     1936              </warning>
     1937            </listitem>
     1938          </varlistentry>
     1939          <varlistentry>
     1940            <term>
     1941              <methodsynopsis language="java">
     1942                <modifier>public</modifier>
     1943                <void/>
     1944                <methodname>afterCommit</methodname>
     1945              </methodsynopsis>
     1946            </term>
     1947            <term>
     1948              <methodsynopsis language="java">
     1949                <modifier>public</modifier>
     1950                <void/>
     1951                <methodname>afterRollback</methodname>
     1952              </methodsynopsis>
     1953            </term>
     1954            <listitem>
     1955              Called after a successful commit or after a rollback. Note
     1956              that the connection to the database has been closed at this
     1957              time and it is not possible to save any more information to
     1958              it at this time.
     1959            </listitem>
     1960          </varlistentry>
     1961        </variablelist>
     1962      </sect3>
     1963
     1964      <sect3 id="extensions_developer.logging.entitylogger">
     1965        <title>The EntityLogger interface</title>
     1966       
     1967        <para>
     1968          An entity logger is responsible for extracting the changes
     1969          made to an entity and converting it to something that is useful
     1970          as a log entry. In most cases, this is not very complicated, but
     1971          in some cases, a change in one entity should actually be logged
     1972          as a change in a different entity. For example, changes to
     1973          annotations are handled by the <classname
     1974          docapi="net.sf.basedb.core.log.db">AnnotationLogger</classname> which
     1975          which log it as a change on the parent item.
     1976        </para>
     1977       
     1978        <variablelist>
     1979          <varlistentry>
     1980            <term>
     1981              <methodsynopsis language="java">
     1982                <modifier>public</modifier>
     1983                <void/>
     1984                <methodname>logChanges</methodname>
     1985                <methodparam>
     1986                  <type>LogManager</type>
     1987                  <parameter>logManager</parameter>
     1988                </methodparam>
     1989                <methodparam>
     1990                  <type>EntityDetails</type>
     1991                  <parameter>details</parameter>
     1992                </methodparam>
     1993              </methodsynopsis>
     1994            </term>
     1995            <listitem>
     1996              <para>
     1997              This method is called whenever a change has been detected
     1998              in an entity. The <varname>details</varname> variable contains
     1999              information about the entity and, to a certain degree,
     2000              what changes that has been made.
     2001              </para>
     2002            </listitem>
     2003          </varlistentry>
     2004        </variablelist>
     2005      </sect3>
     2006     
     2007    </sect2>
     2008 
     2009 
    17762010    <sect2 id="extensions_developer.overview_loader">
    17772011      <title>Item overview loaders</title>
  • trunk/doc/src/docbook/developer/plugins.xml

    r5827 r6080  
    44314431     
    44324432    </sect2>
    4433    
    4434     <sect2 id="plugin_developer.other.logging">
    4435       <title>Logging plug-ins</title>
    4436      
    4437       <para>
    4438         BASE provides a plug-in mechanism for logging changes that are made to items.
    4439         This plug-in mechanism is not the same as the regular plug-in API. That is, you do not
    4440         have worry about user interaction or implementing the <interfacename
    4441         docapi="net.sf.basedb.core.plugin">Plugin</interfacename> interface.
    4442       </para>
    4443      
    4444       <important>
    4445         <title>This may be converted to an extension point in the future</title>
    4446        
    4447         <para>
    4448         There are certain plans to convert the logging mechanism to
    4449         an extension point in the future. There are several benefits with this:
    4450         </para>
    4451         <itemizedlist>
    4452           <listitem>
    4453             <para>
    4454             Easier installation since code doesn't have to be installed in the
    4455             WEB-INF/lib or WEB-INF/classes directory.
    4456             </para>
    4457           </listitem>
    4458           <listitem>
    4459             <para>
    4460             Allow support for multiple logging modules. Specialized logging modules
    4461             could for example, be used to log additional information to files.
    4462             </para>
    4463           </listitem>
    4464         </itemizedlist>
    4465        
    4466         <para>
    4467           See <ulink url="http://base.thep.lu.se/ticket/1599">ticket #1601: Convert
    4468           logging plug-in system to an extension point</ulink> for more
    4469           information.
    4470         </para>
    4471      
    4472       </important>
    4473      
    4474      
    4475       <para>
    4476         The logging mechanism works on the data layer level and hooks into
    4477         callbacks provided by Hibernate. <interfacename
    4478         docapi="net.sf.basedb.core.log">EntityLogger</interfacename>:s are used to
    4479         extract relevant information from Hibernate and create log entries.
    4480         While it is possible to have a generic logger it is usually better
    4481         to have different implementations depending on the type of entity that
    4482         was changed. For example, a change in a child item should, for usability
    4483         reasons, be logged as a change in the parent item. Entity loggers
    4484         are created by a <interfacename
    4485         docapi="net.sf.basedb.core.log">LogManagerFactory</interfacename>. All changes
    4486         made in a single transaction are usually collected by a <interfacename
    4487         docapi="net.sf.basedb.core.log">LogManager</interfacename> which is also
    4488         created by the factory.
    4489       </para>
    4490      
    4491       <sect3 id="plugin_developer.other.logmanagerfactory">
    4492         <title>The LogManagerFactory interface</title>
    4493        
    4494         <para>
    4495           Which <interfacename
    4496           docapi="net.sf.basedb.core.log">LogManagerFactory</interfacename> to use
    4497           is configured in <filename>base.config</filename> (See <xref
    4498           linkend="appendix.base.config.log"/>). A single factory instance is created
    4499           when BASE starts and is used for the lifetime of the virtual machine. The
    4500           factory implementation must of course be thread-safe. Here is a list of
    4501           the methods the factory must implement:
    4502         </para>
    4503        
    4504         <variablelist>
    4505           <varlistentry>
    4506             <term>
    4507               <methodsynopsis language="java">
    4508                 <modifier>public</modifier>
    4509                 <type>LogManager</type>
    4510                 <methodname>getLogManager</methodname>
    4511                 <methodparam>
    4512                   <type>LogControl</type>
    4513                   <parameter>logControl</parameter>
    4514                 </methodparam>
    4515               </methodsynopsis>
    4516             </term>
    4517             <listitem>
    4518               <para>
    4519               Creates a log manager for a single transaction. Since a transaction
    4520               is not thread-safe the log manager implementation doesn't have to
    4521               be either. The factory has the possibility to create new log managers
    4522               for each transaction.
    4523               </para>
    4524             </listitem>
    4525           </varlistentry>
    4526          
    4527           <varlistentry>
    4528             <term>
    4529               <methodsynopsis language="java">
    4530                 <modifier>public</modifier>
    4531                 <type>boolean</type>
    4532                 <methodname>isLoggable</methodname>
    4533                 <methodparam>
    4534                   <type>Object</type>
    4535                   <parameter>entity</parameter>
    4536                 </methodparam>
    4537               </methodsynopsis>
    4538             </term>
    4539             <listitem>
    4540               <para>
    4541               Checks if changes to the given entity should be
    4542               logged or not. For performance reasons, it usually makes sense to
    4543               not log everything. For example, the database logger implementation
    4544               only logs changes if the entity implements the <interfacename
    4545               docapi="net.sf.basedb.core.data">LoggableData</interfacename>
    4546               interface. The return value of this method should be consistent
    4547               with <methodname>getEntityLogger()</methodname>.
    4548               </para>
    4549             </listitem>
    4550           </varlistentry>
    4551 
    4552           <varlistentry>
    4553             <term>
    4554               <methodsynopsis language="java">
    4555                 <modifier>public</modifier>
    4556                 <type>EntityLogger</type>
    4557                 <methodname>getEntityLogger</methodname>
    4558                 <methodparam>
    4559                   <type>LogManager</type>
    4560                   <parameter>logManager</parameter>
    4561                 </methodparam>
    4562                 <methodparam>
    4563                   <type>Object</type>
    4564                   <parameter>entity</parameter>
    4565                 </methodparam>
    4566               </methodsynopsis>
    4567             </term>
    4568             <listitem>
    4569               <para>
    4570               Create or get an entity logger that knows how to log
    4571               changes to the given entity. If the entity should not be
    4572               logged, <constant>null</constant> can be returned. This method
    4573               is called for each modified item in the transaction.
    4574               </para>
    4575             </listitem>
    4576           </varlistentry>
    4577         </variablelist>
    4578        
    4579       </sect3>
    4580      
    4581       <sect3 id="plugin_developer.other.logmanager">
    4582         <title>The LogManager interface</title>
    4583        
    4584         <para>
    4585           A new log manager is created for each transaction. The log manager
    4586           is responsible for collecting all changes made in the transaction
    4587           and store those changes in the appropriate place. The interface doesn't define
    4588           any methods for this collection, since each implementation may have
    4589           very different needs.
    4590         </para>
    4591        
    4592         <variablelist>
    4593           <varlistentry>
    4594             <term>
    4595               <methodsynopsis language="java">
    4596                 <modifier>public</modifier>
    4597                 <type>LogControl</type>
    4598                 <methodname>getLogControl</methodname>
    4599               </methodsynopsis>
    4600             </term>
    4601             <listitem>
    4602               <para>
    4603               Get the log control object that was supplied by the BASE core
    4604               when the transaction was started. The log controller contains
    4605               methods for accessing information about the transaction, such
    4606               as the logged in user, executing plug-in, etc. It can also
    4607               be used to execute queries against the database to get
    4608               even more information.
    4609               </para>
    4610              
    4611               <warning>
    4612                 <para>
    4613                   Be careful about the queries that are executed by the log
    4614                   controller. Since all logging code is executed at flush
    4615                   time in callbacks from Hibernate we are not allowed to
    4616                   use the regular session. Instead, all queries are sent
    4617                   through the stateless session. The stateless session has no
    4618                   caching functionality which means that Hibernate will use
    4619                   extra queries to load associations. Our recommendation is
    4620                   to avoid quires that return full entities, use scalar
    4621                   queries instead to just load the values that are needed.
    4622                 </para>
    4623               </warning>
    4624             </listitem>
    4625           </varlistentry>
    4626           <varlistentry>
    4627             <term>
    4628               <methodsynopsis language="java">
    4629                 <modifier>public</modifier>
    4630                 <void/>
    4631                 <methodname>afterCommit</methodname>
    4632               </methodsynopsis>
    4633             </term>
    4634             <term>
    4635               <methodsynopsis language="java">
    4636                 <modifier>public</modifier>
    4637                 <void/>
    4638                 <methodname>afterRollback</methodname>
    4639               </methodsynopsis>
    4640             </term>
    4641             <listitem>
    4642               Called after a successful commit or after a rollback. Note
    4643               that the connection to the database has been closed at this
    4644               time and it is not possible to save any more information to
    4645               it at this time.
    4646             </listitem>
    4647           </varlistentry>
    4648         </variablelist>
    4649       </sect3>
    4650 
    4651       <sect3 id="plugin_developer.other.entitylogger">
    4652         <title>The EntityLogger interface</title>
    4653        
    4654         <para>
    4655           An entity logger is responsible for extracting the changes
    4656           made to an entity and converting it to something that is useful
    4657           as a log entry. In most cases, this is not very complicated, but
    4658           in some cases, a change in one entity should actually be logged
    4659           as a change in a different entity. For example, changes to
    4660           annotations are handled by the <classname
    4661           docapi="net.sf.basedb.core.log.db">AnnotationLogger</classname> which
    4662           which log it as a change on the parent item.
    4663         </para>
    4664        
    4665         <variablelist>
    4666           <varlistentry>
    4667             <term>
    4668               <methodsynopsis language="java">
    4669                 <modifier>public</modifier>
    4670                 <void/>
    4671                 <methodname>logChanges</methodname>
    4672                 <methodparam>
    4673                   <type>LogManager</type>
    4674                   <parameter>logManager</parameter>
    4675                 </methodparam>
    4676                 <methodparam>
    4677                   <type>EntityDetails</type>
    4678                   <parameter>details</parameter>
    4679                 </methodparam>
    4680               </methodsynopsis>
    4681             </term>
    4682             <listitem>
    4683               <para>
    4684               This method is called whenever a change has been detected
    4685               in an entity. The <varname>details</varname> variable contains
    4686               information about the entity and, to a certain degree,
    4687               what changes that has been made.
    4688               </para>
    4689             </listitem>
    4690           </varlistentry>
    4691         </variablelist>
    4692       </sect3>
    4693     </sect2>
     4433
    46944434  </sect1>
    46954435 
  • trunk/src/core/net/sf/basedb/core/LogControl.java

    r5384 r6080  
    5858      DbControl tmp = dc.get();
    5959      if (tmp == null || tmp.isClosed()) throw new ConnectionClosedException();
    60       transactionDetails = new TransactionDetails(tmp.getSessionControl());
     60      transactionDetails = new TransactionDetails(this, tmp.getSessionControl());
    6161    }
    6262    return transactionDetails;
  • trunk/src/core/net/sf/basedb/core/log/EntityDetails.java

    r6079 r6080  
    117117  {
    118118    return types;
     119  }
     120 
     121  public int getDirty(int index)
     122  {
     123    if (changeType != ChangeType.UPDATE) return -1;
     124    if (dirty[index] == 0)
     125    {
     126      Object c = state[index];
     127      Object o = previousState[index];
     128      dirty[index] = types[index].isEqual(c, o, EntityMode.POJO) ? -1 : 1;
     129    }
     130    return dirty[index];
    119131  }
    120132 
  • trunk/src/core/net/sf/basedb/core/log/TransactionDetails.java

    r5038 r6080  
    2424import java.util.Date;
    2525
     26import org.hibernate.Query;
     27
     28import net.sf.basedb.core.LogControl;
    2629import net.sf.basedb.core.SessionControl;
    2730import net.sf.basedb.core.data.ChangeHistoryData;
     
    3740public class TransactionDetails
    3841{
     42  private final LogControl logControl;
    3943  private final int userId;
    4044  private final int sessionId;
     
    4448  private final int jobId;
    4549 
     50  private String userName;
     51  private String projectName;
     52  private String pluginName;
     53  private String jobName;
     54 
    4655  /**
    4756    Creates a new transaction details object with information from
    4857    given session control
    4958  */
    50   public TransactionDetails(SessionControl sc)
    51   {
     59  public TransactionDetails(LogControl logControl, SessionControl sc)
     60  {
     61    this.logControl = logControl;
    5262    this.userId = sc.getLoggedInUserId();
    5363    this.sessionId = sc.getCurrentSessionId();
     
    124134  }
    125135 
    126  
     136  /**
     137    Utility method for loading the name of the currently logged in user.
     138    The first call to this method will lookup the name in the database
     139    but is then cached.
     140    @return The name of the currently logged in user
     141    @since 3.2
     142  */
     143  public String getUserName()
     144  {
     145    if (userName == null && userId != 0)
     146    {
     147      Query query = logControl.createHqlQuery("select usr.name from UserData usr where usr.id = " + userId);
     148      userName = (String)query.uniqueResult();
     149    }
     150    return userName;
     151  }
     152 
     153  /**
     154    Utility method for loading the name of the currently active project.
     155    The first call to this method will lookup the name in the database
     156    but is then cached.
     157    @return The name of the currently active project, or null if no project is active
     158    @since 3.2
     159  */
     160  public String getProjectName()
     161  {
     162    if (projectName == null && projectId != 0)
     163    {
     164      Query query = logControl.createHqlQuery("select prj.name from ProjectData prj where prj.id = " + projectId);
     165      projectName = (String)query.uniqueResult();
     166    }
     167    return projectName;
     168  }
     169
     170  /**
     171    Utility method for loading the name of the currently executing plugin.
     172    The first call to this method will lookup the name in the database
     173    but is then cached.
     174    @return The name of the currently executing plugin, or null if no plugin is executing
     175    @since 3.2
     176  */
     177  public String getPluginName()
     178  {
     179    if (pluginName == null && pluginId != 0)
     180    {
     181      Query query = logControl.createHqlQuery("select plg.name from PluginDefinitionData plg where plg.id = " + pluginId);
     182      pluginName = (String)query.uniqueResult();
     183    }
     184    return pluginName;
     185  }
     186
     187  /**
     188    Utility method for loading the name of the currently executing job.
     189    The first call to this method will lookup the name in the database
     190    but is then cached.
     191    @return The name of the currently executing job, or null if no job is executing
     192    @since 3.2
     193  */
     194  public String getJobName()
     195  {
     196    if (jobName == null && jobId != 0)
     197    {
     198      Query query = logControl.createHqlQuery("select job.name from JobData job where job.id = " + jobId);
     199      jobName = (String)query.uniqueResult();
     200    }
     201    return jobName;
     202  }
     203
    127204}
  • trunk/src/core/net/sf/basedb/core/log/db/AnnotationLogger.java

    r5066 r6080  
    115115    change.setItemType(itemType);
    116116    change.setChangeInfo(details.getChangeType().was("Annotation") + ": " + annotationType);
    117     ((DbLogManager)logManager).logChangeDetails(change);
     117    ((DbLogManager)logManager).logChangeDetails(change, details);
    118118  }
    119119  // -------------------------------
  • trunk/src/core/net/sf/basedb/core/log/db/AnnotationSetLogger.java

    r5689 r6080  
    9494      change.setChangeInfo(details.getModifiedProperties("Updated: ", ", ", null));
    9595    }
    96     ((DbLogManager)logManager).logChangeDetails(change);
     96    ((DbLogManager)logManager).logChangeDetails(change, details);
    9797  }
    9898  // -------------------------------
  • trunk/src/core/net/sf/basedb/core/log/db/BioMaterialEventLogger.java

    r5642 r6080  
    7979      }
    8080    }
    81     if (change != null) ((DbLogManager)logManager).logChangeDetails(change);
     81    if (change != null) ((DbLogManager)logManager).logChangeDetails(change, details);
    8282  }
    8383  // -------------------------------
  • trunk/src/core/net/sf/basedb/core/log/db/DbLogManager.java

    r5038 r6080  
    2525import net.sf.basedb.core.data.ChangeHistoryData;
    2626import net.sf.basedb.core.data.ChangeHistoryDetailData;
     27import net.sf.basedb.core.log.EntityDetails;
    2728import net.sf.basedb.core.log.LogManager;
    2829
     
    7172    from the current transaction.
    7273  */
    73   public void logChangeDetails(ChangeHistoryDetailData details)
     74  public void logChangeDetails(ChangeHistoryDetailData changeDetails, EntityDetails entityDetails)
    7475  {
    7576    if (history == null) createHistory();
    76     details.setChangeHistory(history);
    77     logControl.log(details);
     77    changeDetails.setChangeHistory(history);
     78    logControl.log(changeDetails);
    7879  }
    7980 
  • trunk/src/core/net/sf/basedb/core/log/db/DefaultEntityLogger.java

    r5052 r6080  
    6565    DbLogManager dbLogManager = (DbLogManager)logManager;
    6666    ChangeHistoryDetailData change = details.toChangeHistoryDetailData(detailedProperties);
    67     dbLogManager.logChangeDetails(change);
     67    dbLogManager.logChangeDetails(change, details);
    6868  }
    6969  // -------------------------------
  • trunk/src/core/net/sf/basedb/core/log/db/FileSetMemberLogger.java

    r5063 r6080  
    110110    change.setItemType(itemType);
    111111    change.setChangeInfo(details.getChangeType().was("File") + ": " + fileType);
    112     ((DbLogManager)logManager).logChangeDetails(change);
     112    ((DbLogManager)logManager).logChangeDetails(change, details);
    113113  }
    114114  // -------------------------------
  • trunk/src/core/net/sf/basedb/core/log/db/PlateEventLogger.java

    r5063 r6080  
    9898      }
    9999    }
    100     ((DbLogManager)logManager).logChangeDetails(change);
     100    ((DbLogManager)logManager).logChangeDetails(change, details);
    101101  }
    102102  // -------------------------------
Note: See TracChangeset for help on using the changeset viewer.