openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pinaki Poddar <ppod...@apache.org>
Subject Re: Synchronizing two databases with the same model
Date Mon, 19 May 2008 23:28:54 GMT

Hi,
  Here is a prototype for migrating data using OpenJPA attached as ~100KB
jar that *must* precede openjpa jars in the classpath. 

  The solution is based on OpenJPA module named 'Slice' which supports a
single EntityManager be connected to multiple databases (or slices) in the
*same* transaction. This notion is extended to create a specialized Slice
configuration which accepts two and only two databases as 'source' and
'target' slices and a specialized StoreManager that directs all read
operation to 'source' slice and write operation to 'target' slice. The
user-visible effect is of migration i.e. whatever data is read *and dirtied*
from the 'source' database is written to the 'target' database. 

  Because of the special nature of configuration, I named this configuration
as 'nomad' and hence the configuration for migration looks like
<persistence-unit name="migrate">
        <properties>
            <property name="openjpa.BrokerFactory" value="nomad"/>
            <property name="openjpa.ConnectionDriverName"
value="com.mysql.jdbc.Driver"/>
            <property name="openjpa.slice.source.ConnectionURL"
value="jdbc:mysql://localhost/data1"/>
            <property name="openjpa.slice.target.ConnectionURL"
value="jdbc:mysql://localhost/data2"/>
        </properties>
</persistence>

 Of course, the 'source' and 'target' slice can use different database
drivers etc. as per-slice configuration allows. The only thing to remember
is the slice names are hard coded as 'source' and 'target' and the
specialized BrokerFactory is aliased as 'nomad'.

  The behavior is exemplified by the attached JUnit Testcase.

http://www.nabble.com/file/p17330349/openjpa-nomad.jar openjpa-nomad.jar 
http://www.nabble.com/file/p17330349/persistence.xml persistence.xml 
http://www.nabble.com/file/p17330349/TestMigration.java TestMigration.java 
http://www.nabble.com/file/p17330349/PObject.java PObject.java  

   Note that this is a quick prototype and whoever plans to play with it
should be ready for exception stack traces.
-- 
View this message in context: http://www.nabble.com/Synchronizing-two-databases-with-the-same-model-tp16989856p17330349.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message