I'm trying to implement some simple auditing functionality for my java app. Here's a snippet of my audit class:
public class Audit<C, T> {
public final Class<C> modifiedClass;
public final Date modificationTime;
public final MyFieldMeta<C, T> fieldMeta; //contains Class<T>
public final T newValue;
//constructor, etc...
}
When it comes to persisting these audit objects, I'd prefer to have just one table storing all varieties independent of what T is. I'm using postresql, and I'm wondering what the best approach is for saving newValue to a column, then getting it back again.
newValue is limited to fairly simple types that have postgresql equivalents - String, Integer, Date etc. So storing the value as text and the type as varchar in a separate column, then mapping them back in the java wouldn't be too hard. Is there a slicker approach?