Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Pattern »

Re: AW: How to realize extendable data objects?

PavanKumar Keely

2003-09-25

Replies:

Hi,

I feel the best approach would be to use configuration
file to specify the fields need to be loaded. So, when
you add fields in the persistant storage you just add
one more field to the list of the configuration file.
This approach is called declarative approach ( EJB
follows this approach in many concepts..for example,
transaction declaration, security, mapping of entity
fields with the database etc).

So, if we take the whole scenario with the solution
that I have given before:

Material object will contain a hashmap which stores
the key value pairs. When you construct the Materail
object just get the all the values that need to be
loaded from the config file and form a query. Separate
this logic from the business logic component. You can
use DAO pattern for this seperation.Once you execute
the query that is formed in the previous step, and set
out all the values in the hashmap and the Material
instance is ready to be used by the clients. ( Here
client means the component which is using this
Material object ). In this approach you need not
change the query everytime you change the database
schema and most importantly the components in your
application.

When you retrieve the values from the Material object,
just get the required mapping and get that value from
the Hashmap.

I accept the truth that we lose compile-time checking.
But if you do not want to change the definition of the
class, then it's a possible way to do in this
approach. Anyway, you are the best judge of all
suggestions.

All the best,

please let me know your final solution.

Keely Pavan
TATA Consultancy Services,
Bangalore, India


--- Udo Cirkel <u.cirkel@(protected):
> Hello all,
>
> thanks for your suggestions!
>
> Keely: Yes, your understanding of the scenario is
> correct...
>
> ...and there is one more dimension of my problem to
> think about:
>
> The material data has to persist in a database. The
> initial
> database representation should be a table with a
> column
> for each attribute of Material. The sense of this
> requirement
> is to allow sql-queries about the attributes of
> Material.
>
> When deploying a new module how to achieve an
> appropriate
> extension of the database schema? Appropriate means,
> that the
> new database representation of Material and the
> added attributes
> can be queried, too (one goal is to provide an
> user-interface
> for auto generating sql-queries; these queries
> should possibly
> work about all - initial and new - attributes of
> Material).
>
> Which approach is appropriate to realize the access
> to all
> material data/attributes over a general access
> class?
>
> Please read this mail in conjunction with the first
> one.
>
> Thanks in advance, Udo
>
>
>
> -----Ursprungliche Nachricht-----
> Von: An interest list for Sun Java Center J2EE
> Pattern Catalog
> [mailto:J2EEPATTERNS-INTEREST@(protected)
> Auftrag von PavanKumar
> Keely
> Gesendet: Dienstag, 23. September 2003 18:28
> An: J2EEPATTERNS-INTEREST@(protected)
> Betreff: Re: How to realize extendable data objects?
>
>
> If my understanding is correct,
> Existing scenario: If new module is installed then
> Material has to be changed according to the new
> module
> ( adding attributes etc )
> Many modules in the application will use this
> Material
> object. Making this Material Object an instance of
> Hashtable/HashMap can solve your problem. Because
> you
> can just add one more attribute to this as simple as
> that and use that attribute in the new module. But
> one
> problem with this approach is we need to stick to
> the
> standard key names throughout the application. But
> avoid hardcoding the key name and use some
> initialization file, which will be initiated at the
> start of the server. This solution is on the lines
> of
> EJB Design pattern "DTO using HashMap".
>
>
> One more way of achieving extendibility is using XML
> data object. Whenever you create Material object
> that
> should form the data in the XML. But one problem
> with
> this approach is building XML and parsing the XML.
>
>
> if you have any queries or if you get a better
> solution than this please do let me know.
>
>
> thanks and best regards,
>
> Keely Pavan
> TATA Consultancy Services, Bangalore
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site
> design software
> http://sitebuilder.yahoo.com
>
>
====================================================================
> Companion Site: http://www.corej2eepatterns.com
> J2EE BluePrints:
> http://java.sun.com/blueprints/corej2eepatterns
> List Archive:
>
http://archives.java.sun.com/archives/j2eepatterns-interest.html
> Unsubscribing: email "signoff J2EEPATTERNS-INTEREST"
> to
> listserv@(protected)
>
>
====================================================================
> Companion Site: http://www.corej2eepatterns.com
> J2EE BluePrints:
> http://java.sun.com/blueprints/corej2eepatterns
> List Archive:
>
http://archives.java.sun.com/archives/j2eepatterns-interest.html
> Unsubscribing: email "signoff J2EEPATTERNS-INTEREST"
> to listserv@(protected)


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

====================================================================
Companion Site: http://www.corej2eepatterns.com
J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns
List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html
Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)


©2008 junlu.com - Jax Systems, LLC, U.S.A.