openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "C N Davies" <...@cndavies.com>
Subject RE: Dynamic entity definition creation - is it possible?
Date Sat, 25 Jul 2009 07:03:44 GMT
How this works in the commercial application I mentioned (Sorry can't name
it as I am still under contractual obligations) you only have to make
changes to the UI if you want to present the newly added entity properties
in the UI in a static way.  From a reporting perspective this is not an
issue. In the application I am currently working on the additional data is
only used as additional columns in a tabular report, so my code retrieves
the data from the known fields and also process the table meta data to see
if there are any additional columns added. Any additional columns are added
to the result set and rendered in the report.

Regards

Chris

-----Original Message-----
From: Donald Woods [mailto:dwoods@apache.org] 
Sent: Saturday, 25 July 2009 1:47 AM
To: users@openjpa.apache.org
Subject: Re: Dynamic entity definition creation - is it possible?

Some more thoughts...

If you're dynamically changing the DB schema and entity code, where is 
your business logic in this scenario and how are you not having to 
redesign the UI layer after every minor change?

Seems that the controlled approach for updating the app would be to:
1) Setup a Dev/Staging environment with current app/DB
2) Generate updated schema XML and DDL scripts
3) Alter the test db
4) Regenerate the Java entities from the XML schema (and reapply any JPA 
or Bean Validation annotations)
5) Update the business logic and presentation layer
6) Package up a new version of your app war/ear
7) Deploy db updates to production
8) Deploy new app to production
That way, you have a controlled roll-out of changes and can rollback to 
a previous version if needed....


-Donald


C N Davies wrote:
> Hmm thanks Donald I'll take a look at these projects..so much I don't know
> :)
> 
> 
> -----Original Message-----
> From: Donald Woods [mailto:dwoods@apache.org] 
> Sent: Friday, 24 July 2009 2:31 AM
> To: users@openjpa.apache.org
> Subject: Re: Dynamic entity definition creation - is it possible?
> 
> Just taking a stab at this, as I've never tried it....
> 
> 1) Use DdlUtils to dump the existing DB schema to XML, update the schema 
> with the new columns and then alter the DB -
>     http://db.apache.org/ddlutils/
> 2) Use Torque to generate Java classes from the schema XML -
>     http://db.apache.org/torque/index.html
> 3) Use the new JPA2 Metamodel and Criteria API features in OpenJPA trunk
>     - use the metamodel generator in scripts/mmg.bat to create the 
> *_.java classes
>     - use the criteria api and metamodel updated classes for your 
> persistence code
> 
> I may be mistaken about #3, but Pinaki can correct me and provide more 
> details on if those new JPA2 features apply here.
> 
> 
> -Donald
> 
> 
> 
> C N Davies wrote:
>> I might be thinking in the wrong direction so feel free to berate me if I
>> am.
>>
>>  
>>
>> My app imports data from various sources including excel (uses Apache
> POI),
>> CSV, SQL result set etc. Prior to starting to use OpenJPA, if my import
>> processes noted any changes to the incoming data set (ie additional
> fields)
>> I would dynamically generate SQL to  modify the data tables to
accommodate
>> any changes to the incoming data set. (ie a vendor adds a new column to a
>> spreadsheet I imports regularly so I add the required columns) and then
>> commit the new data so that any changes to the structure of the incoming
>> data can be dynamically managed at runtime.
>>
>>  
>>
>> Since JPA requires class files to define the structure of an entity, if I
>> have an entity class that expects certain fields, but I receive an
>> additional column in my incoming dataset, then my entity will just miss
> the
>> new data.
>>
>>  
>>
>> I was thinking that maybe there is a solution that would function at
> runtime
>> like this:
>>
>>  
>>
>> 1.       Examine the incoming data from a CSV file for example (easy to
do
>> and already done)
>>
>> 2.       Create the appropriate entity definition at runtime (possible
> ???)
>> 3.       Create an instance of this new definition  (assuming 2 can be
> done
>> this should be as per usual)
>>
>> 4.       Populate the new instance (assuming 2 can be done this should be
> as
>> per usual)
>>
>> 5.       Call OpenJPA persist/merge (What about JPA enhancement of the
>> modified/generated entity classes?)
>>
>>  
>>
>> I do understand the implications of doing this kind of dynamic
> restructuring
>> in a production system, however I'm painting a generic picture of my
> thought
>> process here in order to convey a concept rather than babble on about the
>> specifics of the system.
>>
>>  
>>
>> Have I lost the plot or can this be done using OpenJPA?  I've read the
> whole
>> doc a dozen times, search the mail lists but can't see any way to do it. 
>>
>>  
>>
>> Thanks!
>>
>>  
>>
>> Chris
>>
>>  
>>
>>
> 
> 


Mime
View raw message