class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><" />

根据hibernate拦截器实现可配置日志的记录

系统 1924 0

对于日志和事件的记录在每个项目中都会用到,如果在每个manager层中触发时间记录的话,会比较难以扩展和维护,所以可配置的日志和事件记录在项目中会用到!

首先在spring的配置文件中加入hibernate拦截器

Java代码 复制代码
  1. <bean<wbr>id=</wbr> "sessionFactory" <wbr></wbr> class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean" > <wbr><wbr></wbr></wbr>
  2. <wbr><wbr><wbr><wbr>&lt;property<wbr>name=</wbr></wbr></wbr></wbr></wbr> "entityInterceptor" > <wbr><wbr></wbr></wbr>
  3. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>&lt;ref<wbr>bean=</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> "myInterceptor" /> <wbr><wbr></wbr></wbr>
  4. <wbr><wbr><wbr><wbr>&lt;/property<span>&gt;<wbr><wbr></wbr></wbr></span> </wbr></wbr></wbr></wbr>
  5. </bean> <wbr><wbr></wbr></wbr>
  6. <wbr><wbr></wbr></wbr>
  7. <wbr><wbr></wbr></wbr>
  8. <bean<wbr>id=</wbr> "myInterceptor" <wbr></wbr> class = "com.creawor.cbsms.util.MyInterceptor" <wbr>/&gt;<wbr><wbr></wbr></wbr></wbr>
      <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="entityInterceptor"> <ref bean="myInterceptor"/> </property> </bean> <bean id="myInterceptor" class="com.creawor.cbsms.util.MyInterceptor" />
    

<wbr>MyInterceptor拦截器为:</wbr>

Java代码 复制代码
  1. package <wbr>com.creawor.cbsms.util; <wbr><wbr></wbr></wbr></wbr>
  2. <wbr><wbr></wbr></wbr>
  3. import <wbr>java.io.Serializable; <wbr><wbr></wbr></wbr></wbr>
  4. import <wbr>java.lang.reflect.InvocationTargetExceptio<wbr>n; <wbr><wbr></wbr></wbr></wbr></wbr>
  5. import <wbr>java.lang.reflect.Method; <wbr><wbr></wbr></wbr></wbr>
  6. import <wbr>java.util.Iterator; <wbr><wbr></wbr></wbr></wbr>
  7. <wbr><wbr></wbr></wbr>
  8. import <wbr>javacommon.util.ApplicationContextHolder<wbr>; <wbr><wbr></wbr></wbr></wbr></wbr>
  9. <wbr><wbr></wbr></wbr>
  10. import <wbr>org.hibernate.CallbackException; <wbr><wbr></wbr></wbr></wbr>
  11. import <wbr>org.hibernate.EntityMode; <wbr><wbr></wbr></wbr></wbr>
  12. import <wbr>org.hibernate.Interceptor; <wbr><wbr></wbr></wbr></wbr>
  13. import <wbr>org.hibernate.Transaction; <wbr><wbr></wbr></wbr></wbr>
  14. import <wbr>org.hibernate.type.Type; <wbr><wbr></wbr></wbr></wbr>
  15. <wbr><wbr></wbr></wbr>
  16. import <wbr>com.creawor.cbsms.event.EventRecord; <wbr><wbr></wbr></wbr></wbr>
  17. import <wbr>com.creawor.cbsms.model.CbsChannel; <wbr><wbr></wbr></wbr></wbr>
  18. import <wbr>com.creawor.cbsms.model.CbsMessage; <wbr><wbr></wbr></wbr></wbr>
  19. <wbr><wbr></wbr></wbr>
  20. <wbr><wbr></wbr></wbr>
  21. public <wbr></wbr> class <wbr>MyInterceptor<wbr></wbr></wbr> implements <wbr>Interceptor{ <wbr><wbr></wbr></wbr></wbr>
  22. <wbr><wbr></wbr></wbr>
  23. <wbr><wbr></wbr></wbr>
  24. <wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr> //删除时记录时间 <wbr><wbr></wbr></wbr>
  25. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> void <wbr>onDelete(Object<wbr>obj,<wbr>Serializable<wbr>arg1,<wbr>Object[]<wbr>arg2,<wbr>String[]<wbr>arg3,<wbr>Type[]<wbr>arg4)<wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> throws <wbr>CallbackException<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr>
  26. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> //<wbr>TODO<wbr>Auto-generated<wbr>method<wbr>stub</wbr></wbr></wbr></wbr> <wbr><wbr></wbr></wbr>
  27. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>String[]<wbr>entitys<wbr>=<wbr>EventRecord.getDeleteEntitysFireEven<wbr>t(); <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  28. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> for <wbr>(String<wbr>entityName<wbr>:<wbr>entitys)<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  29. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> if <wbr>(entityName.equals(obj.getClass().getSimpleName()))<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr>
  30. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>getEventRecordMethod(entityName,<wbr>obj,EventRecord.getDeleteInfo()); <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  31. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  32. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  33. <wbr><wbr></wbr></wbr>
  34. <wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  35. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> //修改时记录事件 <wbr><wbr></wbr></wbr>
  36. <wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> boolean <wbr>onFlushDirty(Object<wbr>obj,<wbr>Serializable<wbr>id,<wbr>Object[]<wbr>currentState,<wbr>Object[]<wbr>previousState<wbr>,<wbr>String[]<wbr>propertyNames,<wbr>Type[]<wbr>types){ <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  37. <wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  38. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>String[]<wbr>entitys<wbr>=<wbr>EventRecord.getUpdateEntitysFireEven<wbr>t(); <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  39. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> for <wbr>(String<wbr>entityName<wbr>:<wbr>entitys)<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  40. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> if <wbr>(entityName.equals(obj.getClass().getSimpleName()))<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr>
  41. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>getEventRecordMethod(entityName,<wbr>obj,<wbr>EventRecord.getUpdateInfo()); <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  42. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  43. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  44. <wbr><wbr></wbr></wbr>
  45. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> return <wbr></wbr> false ; <wbr><wbr></wbr></wbr>
  46. <wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  47. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> public <wbr>String<wbr>onPrepareStatement(String<wbr>arg0)<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  48. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> //<wbr>TODO<wbr>Auto-generated<wbr>method<wbr>stub</wbr></wbr></wbr></wbr> <wbr><wbr></wbr></wbr>
  49. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> return <wbr>arg0; <wbr><wbr></wbr></wbr></wbr>
  50. <wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  51. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> //保存时记录事件 <wbr><wbr></wbr></wbr>
  52. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> boolean <wbr>onSave(Object<wbr>obj,<wbr>Serializable<wbr>arg1,<wbr>Object[]<wbr>arg2,<wbr>String[]<wbr>arg3,<wbr>Type[]<wbr>arg4)<wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> throws <wbr>CallbackException<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr>
  53. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> //<wbr>TODO<wbr>Auto-generated<wbr>method<wbr>stub</wbr></wbr></wbr></wbr> <wbr><wbr></wbr></wbr>
  54. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>String[]<wbr>entitys<wbr>=<wbr>EventRecord.getSaveEntitysFireEvent(); <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  55. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> for <wbr>(String<wbr>entityName<wbr>:<wbr>entitys)<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  56. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> if <wbr>(entityName.equals(obj.getClass().getSimpleName()))<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr>
  57. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>getEventRecordMethod(entityName,<wbr>obj,EventRecord.getSaveInfo()); <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  58. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  59. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  60. <wbr><wbr></wbr></wbr>
  61. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> return <wbr></wbr> false ; <wbr><wbr></wbr></wbr>
  62. <wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  63. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> //根据反射机制执行事件记录类中相应的函数 <wbr><wbr></wbr></wbr>
  64. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> void <wbr>getEventRecordMethod(String<wbr>entityName,Object<wbr>obj,String<wbr>info){ <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  65. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> try <wbr>{ <wbr><wbr></wbr></wbr></wbr>
  66. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Class[]<wbr>parameterTypes<wbr>=<wbr>{String.</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> class ,Class.forName(EventRecord.getPrefixPackageName()+entityName)}; <wbr><wbr></wbr></wbr>
  67. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Method<wbr>method<wbr>=<wbr>EventRecord.</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> class .getMethod(EventRecord.getPrefixMethodName()+entityName,<wbr>parameterTypes); <wbr><wbr></wbr></wbr></wbr>
  68. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Object[]<wbr>objs<wbr>=<wbr>{info,<wbr>Class.forName(EventRecord.getPrefixPackageName()+entityName).cast(obj)}; <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  69. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>method.invoke((EventRecord)ApplicationContextHolder<wbr>.getBean(</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> "eventRecord" ),objs); <wbr><wbr></wbr></wbr>
  70. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> catch <wbr>(Exception<wbr>e)<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr>
  71. //<wbr>TODO<wbr>Auto-generated<wbr>catch<wbr>block</wbr></wbr></wbr></wbr> <wbr><wbr></wbr></wbr>
  72. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>e.printStackTrace(); <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  73. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  74. <wbr><wbr></wbr></wbr>
  75. }<wbr><wbr></wbr></wbr>
      package com.creawor.cbsms.util; import java.io.Serializable; import java.lang.reflect.InvocationTargetExceptio<wbr>n; import java.lang.reflect.Method; import java.util.Iterator; import javacommon.util.ApplicationContextHolder<wbr>; import org.hibernate.CallbackException; import org.hibernate.EntityMode; import org.hibernate.Interceptor; import org.hibernate.Transaction; import org.hibernate.type.Type; import com.creawor.cbsms.event.EventRecord; import com.creawor.cbsms.model.CbsChannel; import com.creawor.cbsms.model.CbsMessage; public class MyInterceptor implements Interceptor{ //删除时记录时间 public void onDelete(Object obj, Serializable arg1, Object[] arg2, String[] arg3, Type[] arg4) throws CallbackException { // TODO Auto-generated method stub String[] entitys = EventRecord.getDeleteEntitysFireEven<wbr>t(); for (String entityName : entitys) { if (entityName.equals(obj.getClass().getSimpleName())) { getEventRecordMethod(entityName, obj,EventRecord.getDeleteInfo()); } } } //修改时记录事件 public boolean onFlushDirty(Object obj, Serializable id, Object[] currentState, Object[] previousState , String[] propertyNames, Type[] types){ String[] entitys = EventRecord.getUpdateEntitysFireEven<wbr>t(); for (String entityName : entitys) { if (entityName.equals(obj.getClass().getSimpleName())) { getEventRecordMethod(entityName, obj, EventRecord.getUpdateInfo()); } } return false; } public String onPrepareStatement(String arg0) { // TODO Auto-generated method stub return arg0; } //保存时记录事件 public boolean onSave(Object obj, Serializable arg1, Object[] arg2, String[] arg3, Type[] arg4) throws CallbackException { // TODO Auto-generated method stub String[] entitys = EventRecord.getSaveEntitysFireEvent(); for (String entityName : entitys) { if (entityName.equals(obj.getClass().getSimpleName())) { getEventRecordMethod(entityName, obj,EventRecord.getSaveInfo()); } } return false; } //根据反射机制执行事件记录类中相应的函数 public void getEventRecordMethod(String entityName,Object obj,String info){ try { Class[] parameterTypes = {String.class,Class.forName(EventRecord.getPrefixPackageName()+entityName)}; Method method = EventRecord.class.getMethod(EventRecord.getPrefixMethodName()+entityName, parameterTypes); Object[] objs = {info, Class.forName(EventRecord.getPrefixPackageName()+entityName).cast(obj)}; method.invoke((EventRecord)ApplicationContextHolder<wbr>.getBean("eventRecord"),objs); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }</wbr></wbr></wbr></wbr></wbr>
    

<wbr>事件记录类:</wbr>

Java代码 复制代码
  1. package <wbr>com.creawor.cbsms.event; <wbr><wbr></wbr></wbr></wbr>
  2. <wbr><wbr></wbr></wbr>
  3. import <wbr>java.sql.Timestamp; <wbr><wbr></wbr></wbr></wbr>
  4. <wbr><wbr></wbr></wbr>
  5. import <wbr>javacommon.util.ApplicationContextHolder<wbr>; <wbr><wbr></wbr></wbr></wbr></wbr>
  6. <wbr><wbr></wbr></wbr>
  7. import <wbr>com.creawor.cbsms.dao.CbsEventDao; <wbr><wbr></wbr></wbr></wbr>
  8. import <wbr>com.creawor.cbsms.model.CbsBsc; <wbr><wbr></wbr></wbr></wbr>
  9. import <wbr>com.creawor.cbsms.model.CbsBscCells; <wbr><wbr></wbr></wbr></wbr>
  10. import <wbr>com.creawor.cbsms.model.CbsChannel; <wbr><wbr></wbr></wbr></wbr>
  11. import <wbr>com.creawor.cbsms.model.CbsEvent; <wbr><wbr></wbr></wbr></wbr>
  12. import <wbr>com.creawor.cbsms.model.CbsUserRegister; <wbr><wbr></wbr></wbr></wbr>
  13. import <wbr>com.creawor.cbsms.service.CbsEventManager; <wbr><wbr></wbr></wbr></wbr>
  14. import <wbr>com.creawor.security.model.PermUser; <wbr><wbr></wbr></wbr></wbr>
  15. <wbr><wbr></wbr></wbr>
  16. public <wbr></wbr> class <wbr>EventRecord<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr>
  17. <wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  18. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> //<wbr>保存时要记录事件的对象</wbr> <wbr><wbr></wbr></wbr>
  19. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> private <wbr></wbr> static <wbr>String[]<wbr>saveEntitysFireEvent<wbr>=<wbr>{<wbr></wbr></wbr></wbr></wbr></wbr> "CbsBscCells" , <wbr><wbr></wbr></wbr>
  20. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> "CbsChannel" ,<wbr><wbr><wbr></wbr></wbr></wbr>
  21. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> "CbsBsc" <wbr>}; <wbr><wbr></wbr></wbr></wbr>
  22. <wbr><wbr></wbr></wbr>
  23. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> //<wbr>删除时要记录事件的对象</wbr> <wbr><wbr></wbr></wbr>
  24. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> private <wbr></wbr> static <wbr>String[]<wbr>deleteEntitysFireEvent<wbr>=<wbr>{<wbr></wbr></wbr></wbr></wbr></wbr> "CbsBscCells" , <wbr><wbr></wbr></wbr>
  25. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> "CbsChannel" , <wbr><wbr></wbr></wbr>
  26. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> "CbsBsc" <wbr>}; <wbr><wbr></wbr></wbr></wbr>
  27. <wbr><wbr></wbr></wbr>
  28. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> //<wbr>更新时要记录事件的对象</wbr> <wbr><wbr></wbr></wbr>
  29. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> private <wbr></wbr> static <wbr>String[]<wbr>updateEntitysFireEvent<wbr>=<wbr>{<wbr></wbr></wbr></wbr></wbr></wbr> "CbsBscCells" , <wbr><wbr></wbr></wbr>
  30. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> "CbsChannel" ,<wbr><wbr><wbr></wbr></wbr></wbr>
  31. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> "CbsBsc" <wbr>}; <wbr><wbr></wbr></wbr></wbr>
  32. <wbr><wbr></wbr></wbr>
  33. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> //<wbr>包的前缀,反射得到类时使用</wbr> <wbr><wbr></wbr></wbr>
  34. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> private <wbr></wbr> static <wbr>String<wbr>prefixPackageName<wbr>=<wbr></wbr></wbr></wbr></wbr> "com.creawor.cbsms.model." ; <wbr><wbr></wbr></wbr>
  35. <wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  36. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> //<wbr>记录该次操作的登录用户名:EventRecord为session范围</wbr> <wbr><wbr></wbr></wbr>
  37. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> private <wbr>String<wbr>userName; <wbr><wbr></wbr></wbr></wbr></wbr>
  38. <wbr><wbr></wbr></wbr>
  39. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> //<wbr>调用函数的前缀,反射执行函数时使用</wbr> <wbr><wbr></wbr></wbr>
  40. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> private <wbr></wbr> static <wbr>String<wbr>prefixMethodName<wbr>=<wbr></wbr></wbr></wbr></wbr> "recordFor" ; <wbr><wbr></wbr></wbr>
  41. <wbr><wbr></wbr></wbr>
  42. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> //<wbr>执行save时,事件描述</wbr> <wbr><wbr></wbr></wbr>
  43. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> private <wbr></wbr> static <wbr>String<wbr>saveInfo<wbr>=<wbr></wbr></wbr></wbr></wbr> "创建" ; <wbr><wbr></wbr></wbr>
  44. <wbr><wbr></wbr></wbr>
  45. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> //<wbr>执行delete时,事件描述</wbr> <wbr><wbr></wbr></wbr>
  46. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> private <wbr></wbr> static <wbr>String<wbr>deleteInfo<wbr>=<wbr></wbr></wbr></wbr></wbr> "删除" ; <wbr><wbr></wbr></wbr>
  47. <wbr><wbr></wbr></wbr>
  48. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> //<wbr>执行update时,事件描述</wbr> <wbr><wbr></wbr></wbr>
  49. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> private <wbr></wbr> static <wbr>String<wbr>updateInfo<wbr>=<wbr></wbr></wbr></wbr></wbr> "修改" ; <wbr><wbr></wbr></wbr>
  50. <wbr><wbr></wbr></wbr>
  51. <wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  52. <wbr><wbr></wbr></wbr>
  53. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> private <wbr>CbsEventManager<wbr>cbsEventManager; <wbr><wbr></wbr></wbr></wbr></wbr>
  54. <wbr><wbr></wbr></wbr>
  55. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> //<wbr>spring自动注入</wbr> <wbr><wbr></wbr></wbr>
  56. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> void <wbr>setCbsEventManager(CbsEventManager<wbr>cbsEventManager)<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr>
  57. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> this .cbsEventManager<wbr>=<wbr>cbsEventManager; <wbr><wbr></wbr></wbr></wbr></wbr>
  58. <wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  59. <wbr><wbr></wbr></wbr>
  60. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> <wbr><wbr></wbr></wbr>
  61. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> void <wbr>recordForCbsChannel(String<wbr>desc,<wbr>CbsChannel<wbr>channel)<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  62. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>StringBuffer<wbr>eventDesc<wbr>=<wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> new <wbr>StringBuffer(desc); <wbr><wbr></wbr></wbr></wbr>
  63. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>eventDesc.append(</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> "频道" <wbr>+<wbr>channel.getChannelName()).append(</wbr></wbr> "[" ).append( <wbr><wbr></wbr></wbr>
  64. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>channel.getChannelNum()).append(</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> "]" ); <wbr><wbr></wbr></wbr>
  65. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>record(eventDesc.toString(),<wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> null ); <wbr><wbr></wbr></wbr>
  66. <wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  67. <wbr><wbr></wbr></wbr>
  68. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> <wbr><wbr></wbr></wbr>
  69. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> void <wbr>recordForCbsBscCells(String<wbr>desc,<wbr>CbsBscCells<wbr>cell)<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  70. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>StringBuffer<wbr>eventDesc<wbr>=<wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> new <wbr>StringBuffer(desc); <wbr><wbr></wbr></wbr></wbr>
  71. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>eventDesc.append(</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> "小区" +cell.getCellName()).append( "[" ).append( <wbr><wbr></wbr></wbr>
  72. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>cell.getCellId()).append(</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> "]" ); <wbr><wbr></wbr></wbr>
  73. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>record(eventDesc.toString(),<wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> null ); <wbr><wbr></wbr></wbr>
  74. <wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  75. <wbr><wbr></wbr></wbr>
  76. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> <wbr><wbr></wbr></wbr>
  77. <wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> void <wbr>record(String<wbr>eventDesc,<wbr>String<wbr>eventOrigin)<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  78. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>CbsEvent<wbr>event<wbr>=<wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> new <wbr>CbsEvent(); <wbr><wbr></wbr></wbr></wbr>
  79. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>event.setEventDesc(userName<wbr>+<wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> "<wbr><wbr><wbr>"</wbr></wbr></wbr> <wbr>+<wbr>eventDesc); <wbr><wbr></wbr></wbr></wbr></wbr>
  80. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>event.setEventOrigin(eventOrigin); <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  81. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>event.setStartTime(</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> new <wbr>Timestamp(System.currentTimeMillis())); <wbr><wbr></wbr></wbr></wbr>
  82. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>cbsEventManager.save(event); <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  83. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  84. <wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  85. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> void <wbr>setUserName(String<wbr>userName)<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr>
  86. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> this .userName<wbr>=<wbr>userName; <wbr><wbr></wbr></wbr></wbr></wbr>
  87. <wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  88. <wbr><wbr></wbr></wbr>
  89. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> static <wbr>String[]<wbr>getDeleteEntitysFireEven<wbr>t()<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  90. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> return <wbr>deleteEntitysFireEvent; <wbr><wbr></wbr></wbr></wbr>
  91. <wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  92. <wbr><wbr></wbr></wbr>
  93. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> static <wbr>String[]<wbr>getSaveEntitysFireEvent()<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr>
  94. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> return <wbr>saveEntitysFireEvent; <wbr><wbr></wbr></wbr></wbr>
  95. <wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  96. <wbr><wbr></wbr></wbr>
  97. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> static <wbr>String[]<wbr>getUpdateEntitysFireEven<wbr>t()<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  98. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> return <wbr>updateEntitysFireEvent; <wbr><wbr></wbr></wbr></wbr>
  99. <wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  100. <wbr><wbr></wbr></wbr>
  101. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> static <wbr>String<wbr>getPrefixPackageName()<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr>
  102. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> return <wbr>prefixPackageName; <wbr><wbr></wbr></wbr></wbr>
  103. <wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  104. <wbr><wbr></wbr></wbr>
  105. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> static <wbr></wbr> void <wbr>setPrefixPackageName(String<wbr>prefixPackageName)<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr>
  106. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>EventRecord.prefixPackageName<wbr>=<wbr>prefixPackageName; <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  107. <wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  108. <wbr><wbr></wbr></wbr>
  109. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> static <wbr>String<wbr>getPrefixMethodName()<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr>
  110. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> return <wbr>prefixMethodName; <wbr><wbr></wbr></wbr></wbr>
  111. <wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  112. <wbr><wbr></wbr></wbr>
  113. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> static <wbr>String<wbr>getDeleteInfo()<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr>
  114. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> return <wbr>deleteInfo; <wbr><wbr></wbr></wbr></wbr>
  115. <wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  116. <wbr><wbr></wbr></wbr>
  117. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> static <wbr>String<wbr>getSaveInfo()<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr>
  118. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> return <wbr>saveInfo; <wbr><wbr></wbr></wbr></wbr>
  119. <wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  120. <wbr><wbr></wbr></wbr>
  121. <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr> public <wbr></wbr> static <wbr>String<wbr>getUpdateInfo()<wbr>{ <wbr><wbr></wbr></wbr></wbr></wbr></wbr>
  122. <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr> return <wbr>updateInfo; <wbr><wbr></wbr></wbr></wbr>
  123. <wbr><wbr><wbr><wbr>} <wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
  124. <wbr><wbr></wbr></wbr>
  125. }<wbr><wbr></wbr></wbr>
      package com.creawor.cbsms.event; import java.sql.Timestamp; import javacommon.util.ApplicationContextHolder<wbr>; import com.creawor.cbsms.dao.CbsEventDao; import com.creawor.cbsms.model.CbsBsc; import com.creawor.cbsms.model.CbsBscCells; import com.creawor.cbsms.model.CbsChannel; import com.creawor.cbsms.model.CbsEvent; import com.creawor.cbsms.model.CbsUserRegister; import com.creawor.cbsms.service.CbsEventManager; import com.creawor.security.model.PermUser; public class EventRecord { // 保存时要记录事件的对象 private static String[] saveEntitysFireEvent = { "CbsBscCells", "CbsChannel", "CbsBsc" }; // 删除时要记录事件的对象 private static String[] deleteEntitysFireEvent = { "CbsBscCells", "CbsChannel", "CbsBsc" }; // 更新时要记录事件的对象 private static String[] updateEntitysFireEvent = { "CbsBscCells", "CbsChannel", "CbsBsc" }; // 包的前缀,反射得到类时使用 private static String prefixPackageName = "com.creawor.cbsms.model."; // 记录该次操作的登录用户名:EventRecord为session范围 private String userName; // 调用函数的前缀,反射执行函数时使用 private static String prefixMethodName = "recordFor"; // 执行save时,事件描述 private static String saveInfo = "创建"; // 执行delete时,事件描述 private static String deleteInfo = "删除"; // 执行update时,事件描述 private static String updateInfo = "修改"; private CbsEventManager cbsEventManager; // spring自动注入 public void setCbsEventManager(CbsEventManager cbsEventManager) { this.cbsEventManager = cbsEventManager; } public void recordForCbsChannel(String desc, CbsChannel channel) { StringBuffer eventDesc = new StringBuffer(desc); eventDesc.append("频道" + channel.getChannelName()).append("[").append( channel.getChannelNum()).append("]"); record(eventDesc.toString(), null); } public void recordForCbsBscCells(String desc, CbsBscCells cell) { StringBuffer eventDesc = new StringBuffer(desc); eventDesc.append("小区"+cell.getCellName()).append("[").append( cell.getCellId()).append("]"); record(eventDesc.toString(), null); } <wbr>public void record(String eventDesc, String eventOrigin) { <wbr><wbr> CbsEvent event = new CbsEvent(); <wbr><wbr> event.setEventDesc(userName + "<wbr><wbr> " + eventDesc); <wbr><wbr> event.setEventOrigin(eventOrigin); <wbr><wbr> event.setStartTime(new Timestamp(System.currentTimeMillis())); <wbr><wbr>cbsEventManager.save(event); <wbr>} public void setUserName(String userName) { this.userName = userName; } public static String[] getDeleteEntitysFireEven<wbr>t() { return deleteEntitysFireEvent; } public static String[] getSaveEntitysFireEvent() { return saveEntitysFireEvent; } public static String[] getUpdateEntitysFireEven<wbr>t() { return updateEntitysFireEvent; } public static String getPrefixPackageName() { return prefixPackageName; } public static void setPrefixPackageName(String prefixPackageName) { EventRecord.prefixPackageName = prefixPackageName; } public static String getPrefixMethodName() { return prefixMethodName; } public static String getDeleteInfo() { return deleteInfo; } public static String getSaveInfo() { return saveInfo; } public static String getUpdateInfo() { return updateInfo; } }</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
    

<wbr>其中EventRecord 在spring中的配置为:</wbr>

Java代码 复制代码
  1. <bean<wbr>id=</wbr> "eventRecord" <wbr></wbr> class = "com.creawor.cbsms.event.EventRecord" <wbr><wbr>scope=</wbr></wbr> "session" <wbr>autowire=</wbr> "byName" /><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
      <bean id="eventRecord" class="com.creawor.cbsms.event.EventRecord" scope="session" />
    

<wbr>EventRecord 为session范围可以使字段userName记录每次登录人员的姓名</wbr>

具体在每次登录后从spring容器中得到EventRecord然后set其userName即可!

最后一步要想让session范围生效还要在web.xml中添加配置:

Java代码 复制代码
  1. <web-app> <wbr><wbr></wbr></wbr>
  2. <wbr><wbr>... <wbr><wbr></wbr></wbr></wbr></wbr>
  3. <wbr><wbr>&lt;listener&gt; <wbr><wbr></wbr></wbr></wbr></wbr>
  4. <wbr><wbr><wbr><wbr>&lt;listener-</wbr></wbr></wbr></wbr> class >org.springframework.web.context.request.RequestContextListener</listener- class > <wbr><wbr></wbr></wbr>
  5. <wbr><wbr>&lt;/listener&gt; <wbr><wbr></wbr></wbr></wbr></wbr>
  6. <wbr><wbr>... <wbr><wbr></wbr></wbr></wbr></wbr>
  7. </web-app><wbr><wbr></wbr></wbr>
      <web-app> ... <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> ... </web-app>
    

<wbr>这样如果想要记录一个业务bean增删改的操作只需在EventRecord中设置saveEntitysFireEvent,deleteEntitysFireEvent,updateEntitysFireEvent属性即可,同样也可使用配置文件配置,这样都可以使日志和事件的记录变得很简单!</wbr>

根据hibernate拦截器实现可配置日志的记录


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论