I have a problem where a general software product needs minor customizations for different customers. A core entity class (let's say "Article") is 90% common to all clients, but each customer needs a few additional customized fields.
I would very much like to keep the core of the application 100% identical for all customers and to facilitate customizations by way of plugins and configuration files. Also I would like to keep the database schema 100% identical for all customers.
I was thinking that in addition to the common properties (eg title, author, publishDate, etc) which can be accessed via the traditional getter/setter methods there would be a bundle of Properties which are defined by a configuration file. Eg:
<custom-properties> <property name="article.familyFriendly" datatype="boolean" /> <property name="article.commentsAllowed" datatype="boolean" /> <property name="article.cost" datatype="integer" /> </custom-properties>
In the code, to access a custom property I would use something like this:
Map<String,PropertyValue> properties = myArticle.getProperties(); and Integer cost = (Integer)myArticle.getPropertyValue("article.cost");
In the database I would have a properties table with columns for entity_id, property_name, property_value
If properties were strings and only strings this would be trivial to implement in Hibernate. However there are complications:
a) Custom properties can have multiple data types (boolean, integer, string and possibly other types such as date, enumarations etc) b) I must be able to query for objects using these properties as criteria in the query eg from Article as article join article.properties as property where property.name='article.cost' and property.value<45 c) There may be a requirement to add property value constraints (eg integer min and max values etc)
I have a partial solution implemented in Hibernate, but some of the implementation details are ugly. So before I invest much time in possible wheel reinvention, has this been done before? Or, if not, can anyone suggest other elegant solutions to this general problem?
Thanks in advance,
Joe.
|