summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-11 23:08:29 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-11 23:08:29 +0000
commit725006d4c47e63986ac042ade23a4d193298b1fe (patch)
treeecb2465ddee739a48032ac5c7fa0311e4d90f309 /sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src
parent61c9466ff91ca40f4b1ebbe670d7848e521131d7 (diff)
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835131 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src')
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementation.java36
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementationFactory.java24
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementationProcessor.java99
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/PersistenceUnitInfoImplProcessor.java109
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerFactory.java100
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerImpl.java37
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyJDBCConfigurationImpl.java59
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyManagerRuntime.java51
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyStoreManager.java49
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/impl/JPAImplementationFactoryImpl.java39
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/impl/JPAImplementationImpl.java119
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAImplementationProvider.java101
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAImplementationProviderFactory.java45
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAInvoker.java63
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor19
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.openjpa.OpenJpaImplementationFactory18
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory19
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/java/org/apache/tuscany/sca/implementation/openjpa/ImplJpaTestCase.java69
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/java/sample/Abc.java34
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/java/sample/Message.java72
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/java/sample/MyObject.java33
-rw-r--r--sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/resources/openjpa.composite44
22 files changed, 1239 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementation.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementation.java
new file mode 100644
index 0000000000..c1ed6b4e58
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementation.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.openjpa;
+
+import java.util.Properties;
+
+import org.apache.openjpa.persistence.PersistenceUnitInfoImpl;
+import org.apache.tuscany.sca.assembly.Implementation;
+
+public interface JPAImplementation extends Implementation {
+
+ void setPersistenceUnitInfoImpl(PersistenceUnitInfoImpl buii);
+
+ PersistenceUnitInfoImpl getPersistenceUnitInfoImpl();
+
+ void setDataSourceMeta(Properties p);
+
+ Properties getDataSourceMeta();
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementationFactory.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementationFactory.java
new file mode 100644
index 0000000000..a5812b26e4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementationFactory.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.openjpa;
+
+public interface JPAImplementationFactory {
+ JPAImplementation createOpenJpaImplementation();
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementationProcessor.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementationProcessor.java
new file mode 100644
index 0000000000..7ddd30047a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/JPAImplementationProcessor.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.openjpa;
+
+import java.util.Properties;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.openjpa.persistence.PersistenceUnitInfoImpl;
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.implementation.openjpa.impl.JPAImplementationFactoryImpl;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+
+public class JPAImplementationProcessor implements StAXArtifactProcessor<JPAImplementation> {
+ private final QName QNAME = new QName(Constants.SCA10_TUSCANY_NS, "implementation.jpa");
+ private QName DS = new QName(Constants.SCA10_TUSCANY_NS, "datasource");
+
+ private JPAImplementationFactory jpaFactory;
+ private Log log = LogFactory.getLog(this.getClass());
+ private StAXArtifactProcessor<PersistenceUnitInfoImpl> puiiProcessor;
+
+ public JPAImplementationProcessor(ModelFactoryExtensionPoint modelFactories) {
+ AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ JavaInterfaceFactory javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class);
+
+ this.jpaFactory = new JPAImplementationFactoryImpl(assemblyFactory, javaFactory);
+ this.puiiProcessor = new PersistenceUnitInfoImplProcessor(modelFactories);
+ }
+
+ public Class<JPAImplementation> getModelType() {
+ return JPAImplementation.class;
+ }
+
+ public QName getArtifactType() {
+ return QNAME;
+ }
+
+ public JPAImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ assert QNAME.equals(reader.getName());
+ JPAImplementation implementation = jpaFactory.createOpenJpaImplementation();
+
+ implementation.setPersistenceUnitInfoImpl(puiiProcessor.read(reader));
+ Properties dsmeta = new Properties();
+ do {
+ int event = reader.next();
+ if (event == XMLStreamConstants.START_ELEMENT) {
+ if (!reader.getName().equals(DS)) {
+ dsmeta.setProperty(reader.getName().getLocalPart(), reader.getElementText());
+ }
+ } else if (event == XMLStreamConstants.END_ELEMENT && reader.getName().equals(DS)) {
+ implementation.setDataSourceMeta(dsmeta);
+ break;
+ }
+ } while (true);
+
+ return implementation;
+
+ }
+
+ public void write(JPAImplementation model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void resolve(JPAImplementation model, ModelResolver resolver) throws ContributionResolveException {
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/PersistenceUnitInfoImplProcessor.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/PersistenceUnitInfoImplProcessor.java
new file mode 100644
index 0000000000..d6e8276f25
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/PersistenceUnitInfoImplProcessor.java
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.openjpa;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.openjpa.persistence.PersistenceUnitInfoImpl;
+import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+
+public class PersistenceUnitInfoImplProcessor implements StAXArtifactProcessor<PersistenceUnitInfoImpl> {
+ private QName P_U = new QName(Constants.SCA10_TUSCANY_NS, "persistence-unit");
+ private QName BrokerFactory = new QName(Constants.SCA10_TUSCANY_NS, "jpa.BrokerFactory");
+ private QName CLASS = new QName(Constants.SCA10_TUSCANY_NS, "class");
+ private QName TRAN_MD = new QName(Constants.SCA10_TUSCANY_NS, "jpa.TransactionMode");
+ private QName LOG = new QName(Constants.SCA10_TUSCANY_NS, "jpa.Log");
+ private QName SYNCHRON = new QName(Constants.SCA10_TUSCANY_NS, "jpa.jdbc.SynchronizeMappings");
+
+ public PersistenceUnitInfoImplProcessor(ModelFactoryExtensionPoint modelFactories) {
+
+ }
+
+ public QName getArtifactType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ public PersistenceUnitInfoImpl read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+
+ PersistenceUnitInfoImpl _info = new PersistenceUnitInfoImpl();
+
+ while (true) {
+ int event = reader.next();
+ switch (event) {
+
+ case XMLStreamConstants.START_ELEMENT:
+ QName qn = reader.getName();
+ /*
+ * if (qn.equals(BrokerFactory)) {
+ * _info.setProperty("openjpa.BrokerFactory", reader
+ * .getElementText()); }
+ */
+ if (qn.equals(CLASS)) {
+ _info.addManagedClassName(reader.getElementText());
+
+ } else if (qn.equals(P_U)) {
+ _info.setPersistenceUnitName(reader.getAttributeValue(null, "name"));
+ } else {
+ _info.setProperty(qn.getLocalPart(), reader.getElementText());
+ } /*
+ * else if (qn.equals(LOG)) {
+ * _info.setProperty("openjpa.Log",
+ * reader.getElementText()); } else if
+ * (qn.equals(SYNCHRON)) {
+ * _info.setProperty("openjpa.jdbc.SynchronizeMappings",
+ * reader.getElementText()); }
+ */
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ if (reader.getName().equals(P_U))
+ return _info;
+ }
+ }
+ }
+
+ public void write(PersistenceUnitInfoImpl model, XMLStreamWriter writer) throws ContributionWriteException,
+ XMLStreamException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Class<PersistenceUnitInfoImpl> getModelType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void resolve(PersistenceUnitInfoImpl model, ModelResolver resolver) throws ContributionResolveException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerFactory.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerFactory.java
new file mode 100644
index 0000000000..c4b14a1a90
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerFactory.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.openjpa;
+
+import javax.sql.XAConnection;
+import javax.transaction.TransactionManager;
+
+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;
+
+ @Override
+ protected StoreManager newStoreManager() {
+ try {
+ if (xaconn == null) {
+ if (cp.getProperties().get("dbtype").equals("Derby")) {
+ EmbeddedXADataSource xads = new EmbeddedXADataSource();
+ xads.setDatabaseName((String)cp.getProperties().get("dbname"));
+
+ xaconn = xads.getXAConnection();
+ }
+
+ System.out.println("------------TuscanyBrokerFactory.newStoreManager....");
+
+ }
+ return new TuscanyStoreManager(xaconn);
+
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ throw new RuntimeException(ex);
+ }
+ }
+
+ 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");
+ 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);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerImpl.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerImpl.java
new file mode 100644
index 0000000000..f5972142de
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyBrokerImpl.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.openjpa;
+
+import javax.transaction.TransactionManager;
+
+import org.apache.openjpa.ee.ManagedRuntime;
+import org.apache.openjpa.kernel.BrokerImpl;
+
+public class TuscanyBrokerImpl extends BrokerImpl {
+ private TransactionManager tm;
+
+ public TuscanyBrokerImpl(TransactionManager tm) {
+ this.tm = tm;
+ }
+
+ public ManagedRuntime getManagedRuntime() {
+ return new TuscanyManagerRuntime(tm);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyJDBCConfigurationImpl.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyJDBCConfigurationImpl.java
new file mode 100644
index 0000000000..820121824a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyJDBCConfigurationImpl.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.openjpa;
+
+import javax.transaction.TransactionManager;
+
+import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+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,DataSource _ds) {
+ this.tm = tm;
+ ds2 = _ds;
+ }
+ public ManagedRuntime getManagedRuntimeInstance() {
+ return new TuscanyManagerRuntime(tm);
+ }
+
+ public Object getConnectionFactory() {
+ return null;
+ }
+
+ public DBDictionary getDBDictionaryInstance() {
+ DerbyDictionary dd = new DerbyDictionary();
+ Configurations.configureInstance(dd, this, "", "");
+ return dd;
+ }
+ private DataSource ds2;
+ @Override
+ public DataSource getDataSource2(StoreContext ctx) {
+
+ return ds2;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyManagerRuntime.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyManagerRuntime.java
new file mode 100644
index 0000000000..2fb35f83a1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyManagerRuntime.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.openjpa;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+
+import org.apache.openjpa.ee.ManagedRuntime;
+
+public class TuscanyManagerRuntime implements ManagedRuntime{
+ public TuscanyManagerRuntime(TransactionManager tm){
+ this.tm = tm;
+ }
+ public Throwable getRollbackCause() throws Exception {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object getTransactionKey() throws Exception, SystemException {
+ // TODO Auto-generated method stub
+ return "Geng";
+ }
+ private TransactionManager tm;
+ public TransactionManager getTransactionManager() throws Exception {
+
+
+ return tm;
+ }
+
+ public void setRollbackOnly(Throwable cause) throws Exception {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyStoreManager.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyStoreManager.java
new file mode 100644
index 0000000000..441ba666d7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/TuscanyStoreManager.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.openjpa;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.sql.XAConnection;
+
+import org.apache.openjpa.jdbc.kernel.JDBCStoreManager;
+
+public class TuscanyStoreManager extends JDBCStoreManager {
+ private XAConnection xaconn;
+
+ public TuscanyStoreManager(XAConnection xaconn) {
+ this.xaconn = xaconn;
+ }
+
+ protected _RefCountConnection connectInternal() throws SQLException {
+ Connection conn = xaconn.getConnection();
+ // conn.setAutoCommit(false);
+ _RefCountConnection rc = new _RefCountConnection(conn);
+ return rc;
+ }
+
+ class _RefCountConnection extends RefCountConnection {
+ public _RefCountConnection(Connection conn) {
+
+ super(conn);
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/impl/JPAImplementationFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/impl/JPAImplementationFactoryImpl.java
new file mode 100644
index 0000000000..2a7d1abd70
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/impl/JPAImplementationFactoryImpl.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.openjpa.impl;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.implementation.openjpa.*;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+
+public class JPAImplementationFactoryImpl implements JPAImplementationFactory {
+ private AssemblyFactory assemblyFactory;
+ private JavaInterfaceFactory javaFactory;
+
+ public JPAImplementationFactoryImpl(AssemblyFactory aF, JavaInterfaceFactory javaIF) {
+ this.assemblyFactory = aF;
+ this.javaFactory = javaIF;
+ }
+
+ public JPAImplementation createOpenJpaImplementation() {
+ return new JPAImplementationImpl(assemblyFactory, javaFactory);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/impl/JPAImplementationImpl.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/impl/JPAImplementationImpl.java
new file mode 100644
index 0000000000..055ecd4a4d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/impl/JPAImplementationImpl.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.openjpa.impl;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.PersistenceUnitInfoImpl;
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.implementation.openjpa.JPAImplementation;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+
+public class JPAImplementationImpl implements JPAImplementation {
+ private Service jpaService;
+ private PersistenceUnitInfoImpl puii;
+ private Properties dsmeta;
+
+ public void setPersistenceUnitInfoImpl(PersistenceUnitInfoImpl puii) {
+ this.puii = puii;
+ }
+
+ public PersistenceUnitInfoImpl getPersistenceUnitInfoImpl() {
+ return this.puii;
+ }
+
+ public void setDataSourceMeta(Properties p) {
+ dsmeta = p;
+ }
+
+ public Properties getDataSourceMeta() {
+ return dsmeta;
+ }
+
+ JPAImplementationImpl(AssemblyFactory assemblyFactory, JavaInterfaceFactory javaFactory) {
+
+ jpaService = assemblyFactory.createService();
+ jpaService.setName("EntityManager");
+ JavaInterface javaInterface;
+ try {
+ javaInterface = javaFactory.createJavaInterface(EntityManager.class);
+ } catch (InvalidInterfaceException e) {
+ throw new IllegalArgumentException(e);
+ }
+ JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract();
+ interfaceContract.setInterface(javaInterface);
+ jpaService.setInterfaceContract(interfaceContract);
+ }
+
+ public boolean isUnresolved() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public ConstrainingType getConstrainingType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<Property> getProperties() {
+ // TODO Auto-generated method stub
+ return Collections.emptyList();
+ }
+
+ public List<Reference> getReferences() {
+ return Collections.emptyList();
+ }
+
+ public List<Service> getServices() {
+ return Collections.singletonList(jpaService);
+ }
+
+ public String getURI() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void setConstrainingType(ConstrainingType constrainingType) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setURI(String uri) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAImplementationProvider.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAImplementationProvider.java
new file mode 100644
index 0000000000..fbff09341c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAImplementationProvider.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.openjpa.provider;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.EntityManagerFactory;
+import javax.transaction.TransactionManager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.openjpa.kernel.Bootstrap;
+import org.apache.openjpa.kernel.BrokerFactory;
+import org.apache.openjpa.persistence.JPAFacadeHelper;
+import org.apache.openjpa.persistence.PersistenceUnitInfoImpl;
+import org.apache.openjpa.persistence.PersistenceProductDerivation.ConfigurationProviderImpl;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.implementation.openjpa.JPAImplementation;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+public class JPAImplementationProvider implements ImplementationProvider {
+ private RuntimeComponent component;
+ private JPAImplementation implementation;
+ private EntityManagerFactory emf;
+ private TransactionManager tm;
+
+ public JPAImplementationProvider(RuntimeComponent component,
+ JPAImplementation implementation,
+ ExtensionPointRegistry extensionPoints) {
+ this.component = component;
+ this.implementation = implementation;
+ tm =
+ (TransactionManager)extensionPoints.getExtensionPoint(org.apache.geronimo.transaction.manager.XAWork.class);
+ try {
+ // tm.begin();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ initEntityManager();
+ }
+
+ private void initEntityManager() {
+ Map map = new HashMap();
+ map.put("TransactionManager", tm);
+ PersistenceUnitInfoImpl _info = implementation.getPersistenceUnitInfoImpl();
+ _info.fromUserProperties(map);
+ ConfigurationProviderImpl cp = new ConfigurationProviderImpl();
+ cp.addProperties(_info.toOpenJPAProperties());
+ cp.addProperties(implementation.getDataSourceMeta());
+
+ BrokerFactory factory = Bootstrap.newBrokerFactory(cp, null);
+
+ emf = JPAFacadeHelper.toEntityManagerFactory(factory);
+
+ }
+
+ private Log log = LogFactory.getLog(this.getClass());
+
+ public Invoker createInvoker(RuntimeComponentService service, Operation operation) {
+
+ return new JPAInvoker(operation, emf, tm);
+ }
+
+ public void start() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void stop() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean supportsOneWayInvocation() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAImplementationProviderFactory.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAImplementationProviderFactory.java
new file mode 100644
index 0000000000..11a92c5064
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAImplementationProviderFactory.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.openjpa.provider;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.implementation.openjpa.JPAImplementation;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+public class JPAImplementationProviderFactory implements ImplementationProviderFactory<JPAImplementation> {
+ private ExtensionPointRegistry eP;
+
+ public JPAImplementationProviderFactory(ExtensionPointRegistry extensionPoints) {
+ eP = extensionPoints;
+ }
+
+ public ImplementationProvider createImplementationProvider(RuntimeComponent component,
+ JPAImplementation implementation) {
+ return new JPAImplementationProvider(component, implementation, eP);
+ }
+
+ public Class<JPAImplementation> getModelType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAInvoker.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAInvoker.java
new file mode 100644
index 0000000000..8b74209d3e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/java/org/apache/tuscany/sca/implementation/openjpa/provider/JPAInvoker.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.openjpa.provider;
+
+import java.lang.reflect.Method;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.transaction.TransactionManager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+
+public class JPAInvoker implements Invoker {
+ private Operation operation;
+ private TransactionManager tm;
+
+ public JPAInvoker(Operation operation, EntityManagerFactory emf, TransactionManager tm) {
+ this.operation = operation;
+ this.tm = tm;
+ this.emf = emf;
+ }
+
+ private Log log = LogFactory.getLog(this.getClass());
+ private EntityManagerFactory emf;
+
+ public Message invoke(Message msg) {
+ try {
+ tm.begin();
+ Method method = JavaInterfaceUtil.findMethod(EntityManager.class, operation);
+ Object r = method.invoke(emf.createEntityManager(), (Object[])msg.getBody());
+ tm.commit();
+ log.info(method);
+ msg.setBody(r);
+ return msg;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
new file mode 100644
index 0000000000..3f8e373c88
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.implementation.openjpa.JPAImplementationProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#implementation.jpa,model=org.apache.tuscany.sca.implementation.openjpa.JPAImplementation \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.openjpa.OpenJpaImplementationFactory b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.openjpa.OpenJpaImplementationFactory
new file mode 100644
index 0000000000..13067543c9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.openjpa.OpenJpaImplementationFactory
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.implementation.openjpa.impl.JPAImplementationFactoryImpl \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory
new file mode 100644
index 0000000000..fb62ff853b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the implementation extension
+org.apache.tuscany.sca.implementation.openjpa.provider.JPAImplementationProviderFactory;model=org.apache.tuscany.sca.implementation.openjpa.JPAImplementation \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/java/org/apache/tuscany/sca/implementation/openjpa/ImplJpaTestCase.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/java/org/apache/tuscany/sca/implementation/openjpa/ImplJpaTestCase.java
new file mode 100644
index 0000000000..900fab3242
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/java/org/apache/tuscany/sca/implementation/openjpa/ImplJpaTestCase.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.openjpa;
+
+import junit.framework.*;
+import org.apache.tuscany.sca.host.embedded.*;
+import org.apache.commons.logging.*;
+import sample.*;
+import javax.persistence.*;
+import java.util.*;
+
+public class ImplJpaTestCase extends TestCase {
+ private EntityManager em;
+ private Log log = LogFactory.getLog(this.getClass());
+ private SCADomain domain;
+
+ public void setUp() {
+ 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");
+ 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();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/java/sample/Abc.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/java/sample/Abc.java
new file mode 100644
index 0000000000..0f8e9e4391
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/java/sample/Abc.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package sample;
+import javax.persistence.*;
+@Entity
+public class Abc {
+ private int id;
+ @Id
+ public int getId(){
+ return id;
+ }
+ public void setId(int i){
+ id = i;
+ }
+ public String toString(){
+ return "My Id is "+id;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/java/sample/Message.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/java/sample/Message.java
new file mode 100644
index 0000000000..da4fd1f3fc
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/java/sample/Message.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package sample;
+
+import java.util.*;
+import javax.persistence.*;
+
+
+/**
+ * A very simple persistent entity that holds a "message", has a
+ * "created" field that is initialized to the time at which the
+ * object was created, and an id field that is initialized to the
+ * current time.
+ */
+@Entity
+public class Message {
+ @Id
+ private long id = System.currentTimeMillis();
+
+ @Basic
+ private String message;
+
+ @Basic
+ private Date created = new Date();
+
+ public Message() {
+ }
+
+ public Message(String msg) {
+ message = msg;
+ }
+
+ public void setId(long val) {
+ id = val;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setMessage(String msg) {
+ message = msg;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setCreated(Date date) {
+ created = date;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/java/sample/MyObject.java b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/java/sample/MyObject.java
new file mode 100644
index 0000000000..d3b1baf182
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/java/sample/MyObject.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package sample;
+
+import java.io.*;
+import javax.persistence.*;
+@Entity
+public class MyObject implements Serializable{
+ private int id;
+ @Id
+ public int getId(){
+ return id;
+ }
+ public void setId(int i){
+ id =i;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/resources/openjpa.composite b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/resources/openjpa.composite
new file mode 100644
index 0000000000..1c1b6976bd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-1.4/modules/implementation-openjpa/src/test/resources/openjpa.composite
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
+ targetNamespace="http://sample/openjpa" name="impl-jpa">
+
+ <component name="OpenJPAServiceComponent">
+ <tuscany:implementation.jpa>
+ <tuscany:persistence-unit name="hellojpa">
+ <tuscany:openjpa.BrokerFactory>org.apache.tuscany.sca.implementation.openjpa.TuscanyBrokerFactory</tuscany:openjpa.BrokerFactory>
+ <tuscany:openjpa.TransactionMode>managed</tuscany:openjpa.TransactionMode>
+ <tuscany:openjpa.Log>DefaultLevel=WARN,SQL=TRACE</tuscany:openjpa.Log>
+ <tuscany:openjpa.jdbc.SynchronizeMappings>buildSchema</tuscany:openjpa.jdbc.SynchronizeMappings>
+
+ <tuscany:class>sample.Abc</tuscany:class>
+ <tuscany:class>sample.Message</tuscany:class>
+ </tuscany:persistence-unit>
+ <tuscany:datasource>
+ <dbtype>Derby</dbtype>
+ <dbname>test</dbname>
+ <dbcreate>create</dbcreate>
+ </tuscany:datasource>
+ </tuscany:implementation.jpa>
+ </component>
+
+</composite>