Author: lresende
Date: Sat Nov 17 14:24:59 2007
New Revision: 596015
URL: http://svn.apache.org/viewvc?rev=596015&view=rev
Log:
TUSCANY-1903 - Applying patch from Geng Shaoguang
Modified:
incubator/tuscany/java/sca/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerFactory.java
incubator/tuscany/java/sca/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyJDBCConfigurationImpl.java
incubator/tuscany/java/sca/modules/implementation-openjpa/src/test/java/org/apache/tuscany/sca/implementation/openjpa/ImplJpaTestCase.java
incubator/tuscany/java/sca/modules/implementation-openjpa/src/test/resources/openjpa.composite
incubator/tuscany/java/sca/modules/implementation-openjpa/test/db.lck
incubator/tuscany/java/sca/modules/implementation-openjpa/test/log/log.ctrl
incubator/tuscany/java/sca/modules/implementation-openjpa/test/log/log1.dat
incubator/tuscany/java/sca/modules/implementation-openjpa/test/log/logmirror.ctrl
incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c150.dat
incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c161.dat
incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c171.dat
incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c230.dat
incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c300.dat
incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c311.dat
incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c90.dat
Modified:
incubator/tuscany/java/sca/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerFactory.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerFactory.java?rev=596015&r1=596014&r2=596015&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerFactory.java
(original)
+++
incubator/tuscany/java/sca/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerFactory.java
Sat Nov 17 14:24:59 2007
@@ -22,15 +22,33 @@
import javax.sql.XAConnection;
import javax.transaction.TransactionManager;
-import org.apache.derby.jdbc.EmbeddedXADataSource;
+import org.apache.derby.jdbc.*;
import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.kernel.AbstractBrokerFactory;
import org.apache.openjpa.kernel.StoreManager;
import org.apache.openjpa.lib.conf.ConfigurationProvider;
+import java.util.*;
+import org.apache.commons.logging.*;
+import org.apache.openjpa.jdbc.meta.MappingTool;
+import org.apache.openjpa.jdbc.conf.*;
+import org.apache.openjpa.meta.*;
public class TuscanyBrokerFactory extends AbstractBrokerFactory {
+ private Log log = LogFactory.getLog(this.getClass());
protected TuscanyBrokerFactory(OpenJPAConfiguration conf) {
super(conf);
+ if (buildSchema != null && buildSchema.equals("buildSchema")) {
+ MappingTool tool = new MappingTool((JDBCConfiguration)
conf,
+ (String) buildSchema, false);
+ Collection classes = meta.loadPersistentTypes(false,
this
+ .getClass().getClassLoader());
+ for (Iterator itr = classes.iterator(); itr.hasNext();)
{
+ tool.run((Class) itr.next());
+ }
+ log
+ .info("creating database and tables
accroding to class mappings...");
+ tool.record();
+ }
}
private XAConnection xaconn;
@@ -42,7 +60,7 @@
if (cp.getProperties().get("dbtype").equals("Derby")) {
EmbeddedXADataSource xads = new EmbeddedXADataSource();
xads.setDatabaseName((String)cp.getProperties().get("dbname"));
-
xads.setCreateDatabase((String)cp.getProperties().get("dbcreate"));
+
xaconn = xads.getXAConnection();
}
@@ -59,11 +77,23 @@
private static TransactionManager tm;
private static ConfigurationProvider cp;
+ private static Object buildSchema;
+ private static MetaDataRepository meta;
public static TuscanyBrokerFactory newInstance(ConfigurationProvider _cp) {
tm = (TransactionManager)_cp.getProperties().get("TransactionManager");
- TuscanyJDBCConfigurationImpl conf = new
TuscanyJDBCConfigurationImpl(tm);
+ EmbeddedDataSource ds2 = null;
+ if (_cp.getProperties().get("dbtype").equals("Derby")) {
+ ds2 = new EmbeddedDataSource();
+ ds2.setDatabaseName((String)
_cp.getProperties().get("dbname"));
+ ds2.setCreateDatabase((String)
_cp.getProperties().get("dbcreate"));
+ }
+ TuscanyJDBCConfigurationImpl conf = new
TuscanyJDBCConfigurationImpl(tm, ds2);
_cp.setInto(conf);
+ buildSchema = _cp.getProperties().get(
+ "openjpa.jdbc.SynchronizeMappings");
+
+ meta = conf.getMetaDataRepositoryInstance();
cp = _cp;
return new TuscanyBrokerFactory(conf);
}
Modified:
incubator/tuscany/java/sca/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyJDBCConfigurationImpl.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyJDBCConfigurationImpl.java?rev=596015&r1=596014&r2=596015&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyJDBCConfigurationImpl.java
(original)
+++
incubator/tuscany/java/sca/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyJDBCConfigurationImpl.java
Sat Nov 17 14:24:59 2007
@@ -26,17 +26,20 @@
import org.apache.openjpa.jdbc.sql.DerbyDictionary;
import org.apache.openjpa.kernel.BrokerImpl;
import org.apache.openjpa.lib.conf.Configurations;
+import javax.sql.*;
+import org.apache.openjpa.ee.*;
+import org.apache.openjpa.kernel.*;
public class TuscanyJDBCConfigurationImpl extends JDBCConfigurationImpl {
private TransactionManager tm;
- public TuscanyJDBCConfigurationImpl(TransactionManager tm) {
+ public TuscanyJDBCConfigurationImpl(TransactionManager tm,DataSource _ds) {
this.tm = tm;
+ ds2 = _ds;
}
-
- public BrokerImpl newBrokerInstance(String user, String pass) {
- return new TuscanyBrokerImpl(tm);
- }
+ public ManagedRuntime getManagedRuntimeInstance() {
+ return new TuscanyManagerRuntime(tm);
+ }
public Object getConnectionFactory() {
return null;
@@ -47,4 +50,10 @@
Configurations.configureInstance(dd, this, "", "");
return dd;
}
+ private DataSource ds2;
+ @Override
+ public DataSource getDataSource2(StoreContext ctx) {
+
+ return ds2;
+ }
}
Modified:
incubator/tuscany/java/sca/modules/implementation-openjpa/src/test/java/org/apache/tuscany/sca/implementation/openjpa/ImplJpaTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-openjpa/src/test/java/org/apache/tuscany/sca/implementation/openjpa/ImplJpaTestCase.java?rev=596015&r1=596014&r2=596015&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/implementation-openjpa/src/test/java/org/apache/tuscany/sca/implementation/openjpa/ImplJpaTestCase.java
(original)
+++
incubator/tuscany/java/sca/modules/implementation-openjpa/src/test/java/org/apache/tuscany/sca/implementation/openjpa/ImplJpaTestCase.java
Sat Nov 17 14:24:59 2007
@@ -26,26 +26,44 @@
import java.util.*;
public class ImplJpaTestCase extends TestCase {
- private EntityManager em;
- private Log log = LogFactory.getLog(this.getClass());
+ private EntityManager em;
+ private Log log = LogFactory.getLog(this.getClass());
+ private SCADomain domain;
- public void setUp() {
- SCADomain domain = SCADomain.newInstance("openjpa.composite");
- em = domain.getService(EntityManager.class,
"OpenJPAServiceComponent");
-
- }
-
- public void testAccess() {
- Abc a = new Abc();
- int i = new Random().nextInt();
- a.setId(i);
- em.persist(a);
- log.info(em.find(Abc.class, i));
- Query q = em.createQuery("select a from Abc a");
- log.info("There are "+q.getResultList().size()+" Abc in the
database now");
- }
+ public void setUp() {
+ domain = SCADomain.newInstance("openjpa.composite");
+ em = domain.getService(EntityManager.class, "OpenJPAServiceComponent");
- public void tearDown() {
+ }
- }
+ public void testAccess() {
+ Abc a = new Abc();
+ int i = new Random().nextInt();
+ a.setId(i);
+ em.persist(a);
+ log.info(em.find(Abc.class, i));
+ Query q = em.createQuery("select a from Abc a");
+ q.setMaxResults(5);
+ log.info("There are " + q.getResultList().size() + " Abc in the
database now");
+ }
+
+ public void testRollback() {
+ try {
+ Abc a = new Abc();
+ int i = new Random().nextInt();
+ a.setId(i);
+ em.persist(a);
+ Abc a2 = new Abc();
+ a2.setId(i);
+ em.persist(a2);
+
+ } catch (RuntimeException ex) {
+ log.info("An expected exception occured, Tuscany is rolling
back...");
+ }
+ }
+
+ public void tearDown() {
+ em.close();
+ domain.close();
+ }
}
Modified:
incubator/tuscany/java/sca/modules/implementation-openjpa/src/test/resources/openjpa.composite
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-openjpa/src/test/resources/openjpa.composite?rev=596015&r1=596014&r2=596015&view=diff
==============================================================================
---
incubator/tuscany/java/sca/modules/implementation-openjpa/src/test/resources/openjpa.composite
(original)
+++
incubator/tuscany/java/sca/modules/implementation-openjpa/src/test/resources/openjpa.composite
Sat Nov 17 14:24:59 2007
@@ -36,9 +36,9 @@
<tuscany:datasource>
<dbtype>Derby</dbtype>
<dbname>test</dbname>
- <dbcreate>no thanks</dbcreate>
+ <dbcreate>create</dbcreate>
</tuscany:datasource>
</tuscany:implementation.jpa>
</component>
-</composite>
\ No newline at end of file
+</composite>
Modified: incubator/tuscany/java/sca/modules/implementation-openjpa/test/db.lck
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-openjpa/test/db.lck?rev=596015&r1=596014&r2=596015&view=diff
==============================================================================
Binary files - no diff available.
Modified:
incubator/tuscany/java/sca/modules/implementation-openjpa/test/log/log.ctrl
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-openjpa/test/log/log.ctrl?rev=596015&r1=596014&r2=596015&view=diff
==============================================================================
Binary files - no diff available.
Modified:
incubator/tuscany/java/sca/modules/implementation-openjpa/test/log/log1.dat
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-openjpa/test/log/log1.dat?rev=596015&r1=596014&r2=596015&view=diff
==============================================================================
Binary files - no diff available.
Modified:
incubator/tuscany/java/sca/modules/implementation-openjpa/test/log/logmirror.ctrl
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-openjpa/test/log/logmirror.ctrl?rev=596015&r1=596014&r2=596015&view=diff
==============================================================================
Binary files - no diff available.
Modified:
incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c150.dat
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c150.dat?rev=596015&r1=596014&r2=596015&view=diff
==============================================================================
Binary files - no diff available.
Modified:
incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c161.dat
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c161.dat?rev=596015&r1=596014&r2=596015&view=diff
==============================================================================
Binary files - no diff available.
Modified:
incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c171.dat
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c171.dat?rev=596015&r1=596014&r2=596015&view=diff
==============================================================================
Binary files - no diff available.
Modified:
incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c230.dat
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c230.dat?rev=596015&r1=596014&r2=596015&view=diff
==============================================================================
Binary files - no diff available.
Modified:
incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c300.dat
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c300.dat?rev=596015&r1=596014&r2=596015&view=diff
==============================================================================
Binary files - no diff available.
Modified:
incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c311.dat
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c311.dat?rev=596015&r1=596014&r2=596015&view=diff
==============================================================================
Binary files - no diff available.
Modified:
incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c90.dat
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/implementation-openjpa/test/seg0/c90.dat?rev=596015&r1=596014&r2=596015&view=diff
==============================================================================
Binary files - no diff available.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]