Changeset 5052
- Timestamp:
- Aug 18, 2009, 8:47:26 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/config/dist/base.config
r5048 r5052 149 149 # If the "Change history" tab should be visible in the web interface 150 150 # or not. It is hidden by default. 151 # changelog.show-in-web = false 151 # changelog.show-in-web = true 152 153 # If DB logger should log detailed information about which properties 154 # that has been updated (default: false) 155 # changelog.dblogger.detailed-properties = true 152 156 153 157 # =============== -
trunk/src/core/net/sf/basedb/core/data/BioMaterialEventData.java
r4889 r5052 40 40 public class BioMaterialEventData 41 41 extends BasicData 42 implements RegisteredData 42 implements RegisteredData, LoggableData 43 43 { 44 44 -
trunk/src/core/net/sf/basedb/core/log/EntityDetails.java
r5038 r5052 26 26 import net.sf.basedb.core.data.ChangeHistoryDetailData; 27 27 28 import org.hibernate.EntityMode; 28 29 import org.hibernate.type.Type; 30 import org.hibernate.type.VersionType; 29 31 30 32 /** … … 125 127 126 128 /** 129 Get all modified properties as a string, separating each 130 property name with the given separator. 131 @param prefix A string that is added first in the result, or null 132 @param separator A separator string (if null, comma is used) 133 @param suffix A string that is added last in the result, or null 134 @return A string with the modified properties, or null 135 if this is a CREATE or DELETE change or if no modified 136 properties was found 137 */ 138 public String getModifiedProperties(String prefix, String separator, String suffix) 139 { 140 if (changeType != ChangeType.UPDATE) return null; 141 142 StringBuilder modified = new StringBuilder(); 143 if (prefix != null) modified.append(prefix); 144 if (separator == null) separator = ","; 145 String s = ""; 146 int numModified = 0; 147 for (int i = 0; i < types.length; ++i) 148 { 149 Type t = types[i]; 150 if (!t.isCollectionType() && !(t instanceof VersionType)) 151 { 152 Object c = state[i]; 153 Object o = previousState[i]; 154 if (!t.isEqual(c, o, EntityMode.POJO)) 155 { 156 modified.append(s).append(properties[i]); 157 s = separator; 158 numModified++; 159 } 160 } 161 } 162 if (suffix != null) modified.append(suffix); 163 return numModified == 0 ? null : modified.toString(); 164 } 165 166 /** 127 167 Create a new ChangeHistoryDetailData object from the information 128 168 in this object assuming that the entity is a subclass of 129 169 {@link BasicData}. 170 @param detailedProperties If TRUE, the {@link ChangeHistoryDetailData#getChangeInfo()} 171 is populated with a list of the names of the modified properties (only 172 relevant for UPDATE changes) 130 173 @return A new ChangeHistoryDetailData instance 131 174 */ 132 public ChangeHistoryDetailData toChangeHistoryDetailData() 175 public ChangeHistoryDetailData toChangeHistoryDetailData(boolean detailedProperties) 176 { 177 return toChangeHistoryDetailData((BasicData)entity, changeType, detailedProperties); 178 } 179 180 /** 181 Create a new ChangeHistoryDetailData object using a mix of the information 182 in this object, and the given parameters. 183 @param data The entity that was changed 184 @param changeType The change type 185 @param detailedProperties If TRUE, the {@link ChangeHistoryDetailData#getChangeInfo()} 186 is populated with a list of the names of the modified properties (only 187 relevant for UPDATE changes) 188 @return A new ChangeHistoryDetailData instance 189 */ 190 public ChangeHistoryDetailData toChangeHistoryDetailData(BasicData data, ChangeType changeType, boolean detailedProperties) 133 191 { 134 192 ChangeHistoryDetailData details = new ChangeHistoryDetailData(); 135 BasicData data = (BasicData)entity;136 193 details.setChangeType(changeType.getValue()); 137 194 details.setItemId(data.getId()); 138 195 details.setItemType(Item.fromDataObject(data).getValue()); 196 if (detailedProperties) 197 { 198 details.setChangeInfo(getModifiedProperties("Updated: ", ", ", null)); 199 } 139 200 return details; 140 201 } -
trunk/src/core/net/sf/basedb/core/log/db/DbLogManagerFactory.java
r5038 r5052 25 25 import java.util.Map; 26 26 27 import net.sf.basedb.core.Config; 27 28 import net.sf.basedb.core.LogControl; 29 import net.sf.basedb.core.data.BioMaterialEventData; 28 30 import net.sf.basedb.core.data.LoggableData; 29 31 import net.sf.basedb.core.log.EntityLogger; … … 46 48 private final Map<Class, EntityLogger> specialLoggers; 47 49 private final DefaultEntityLogger defaultLogger; 48 50 private final boolean detailedProperties; 49 51 50 52 public DbLogManagerFactory() 51 53 { 52 54 this.specialLoggers = new HashMap<Class, EntityLogger>(); 53 this.defaultLogger = new DefaultEntityLogger(); 55 this.detailedProperties = Config.getBoolean("changelog.dblogger.detailed-properties"); 56 this.defaultLogger = new DefaultEntityLogger(detailedProperties); 57 setSpecialLogger(BioMaterialEventData.class, new BioMaterialEventLogger(detailedProperties)); 54 58 //setSpecialLogger(AnnotationData.class, new AnnotationLogger()); 55 59 } -
trunk/src/core/net/sf/basedb/core/log/db/DefaultEntityLogger.java
r5038 r5052 40 40 { 41 41 42 public DefaultEntityLogger() 43 {} 42 private final boolean detailedProperties; 43 44 /** 45 Creates a new entity logger. 46 @param detailedProperties If TRUE, the log includes a list with 47 the properties that was modified 48 */ 49 public DefaultEntityLogger(boolean detailedProperties) 50 { 51 this.detailedProperties = detailedProperties; 52 } 44 53 45 54 /* … … 55 64 { 56 65 DbLogManager dbLogManager = (DbLogManager)logManager; 57 ChangeHistoryDetailData change = details.toChangeHistoryDetailData( );66 ChangeHistoryDetailData change = details.toChangeHistoryDetailData(detailedProperties); 58 67 dbLogManager.logChangeDetails(change); 59 68 }
Note: See TracChangeset
for help on using the changeset viewer.