From 200a40b332420f94992eb39a6d0ea1cf1490ffc4 Mon Sep 17 00:00:00 2001 From: coreyg Date: Fri, 21 Nov 2014 09:30:19 +0000 Subject: Adding tuscany's website to their svn repo for svnpubsub git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1640879 13f79535-47bb-0310-9956-ffa450edef68 --- .../site-publish/sca-java-implementationjpa.html | 251 +++++++++++++++++++++ 1 file changed, 251 insertions(+) create mode 100644 site/trunk/site-publish/sca-java-implementationjpa.html (limited to 'site/trunk/site-publish/sca-java-implementationjpa.html') diff --git a/site/trunk/site-publish/sca-java-implementationjpa.html b/site/trunk/site-publish/sca-java-implementationjpa.html new file mode 100644 index 0000000000..e2bd90ebcb --- /dev/null +++ b/site/trunk/site-publish/sca-java-implementationjpa.html @@ -0,0 +1,251 @@ + + + + + + + + + + + + + + + Apache Tuscany : SCA Java implementation.jpa + + + + + + + + + + + + + + + +
+ + + + +   + +
+ + +
+
+ + + + + + + + + +
+  Apache Tuscany > Home > SCA Overview > SCA Java > Java SCA Documentation Menu > SCA Java implementation.jpa + + User List | Dev List | Issue Tracker   +
+ + + + + + + +
+ + +
+ +
+
+
Disclaimer
Work in progress, or should I say : Ideas in progress
+ +

Injection of JPA Entity Manager Factory/Entity Manager

+ +

The injection of JPA Entity Manager Factory/Entity Manager would allow sharing of EMFs across multiple components, this would be useful in scenarios where you have conversation. In this case, the runtime would be responsible for making sure the EM would be created and closed transparently for the application developer based on the conversation.

+ +

JPA Data Services

+ +

In this case, we would be extending the SCA programming model to expose services that interact with a persistent layer in a declarative fashion hiding the implementation details from the service developer.It's all about simplicity, allowing a service to be defined without explicitly coding the persistence layer. This would be a new Tuscany Component Type named Implementaiton.JPA. A developer would provide the business objects that would by JPA to do the OR mapping, and a business interface that would be introspect by Tuscany to properly make the JPA calls to the persistence layer to retrieve the information. Information on how to connect to the data source would be done in the composite, and we could provide some annotations to read

+ +

Business Object

+ +

The business object can be defined as per JPA programming model. You can define it as a JPA Entity and make use of JPA annotations, or use the ORM.xml as well.

+
+
+@Entity
+public class Customer {
+
+    @Id    protected int id;
+    @Basic protected String name;
+    @Basic protected String phone;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getPhone() {
+        return phone;
+    }
+
+    public void setPhone(String phone) {
+        this.phone = phone;
+    }
+}
+
+
+ +

Business Interface

+ +

The Business interface would define the access to the JPA entities, and we would introduce Java Annotations to bind a specific method to a JPA query.

+
+
+import org.osoa.sca.annotations.Remotable;
+
+@Remotable
+public interface CustomerService {
+
+    Customer[] getCustomers();
+
+    void setCustomer(Customer customer);
+
+    @Query(SELECT c FROM customer c WHERE c.name = '" + $1 + "'")
+    Customer queryCustomerByName(String name);
+
+}
+
+
+ +

We would use some Convention over Configuration to bind the interfaces methods to proper database activities :

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Method Correspondent db operation
createXXX Insert a new entity on the db. A collection of new entities should also be supported
getXXX Read a given entity from the db
A method signature with no parameters read a collection.
setXXX Update a previously existent entity on the db.
deleteXXX Remove a previously existent entity on the db.
queryXXX Execute a query on the db.
We would introduce a Java Annotation to bind a given query to the method invocation
+
+ + +

Note that introspection will be required by the runtime to properly identify the operation type being requested. Based on this introspection, the runtime will also be responsible for any necessary conversion to the proper collection being expected as a result.

+ +

Composite

+ +
+
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+     xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
+     targetNamespace="http://sample/implementation.jpa"
+     name="customer">
+
+	<component name="CustomerServiceComponent">
+		<tuscany:implementation.jpa>
+			<tuscany:persistence-unit name="customer">
+				<tuscany:class>assets.Customer</tuscany:class>
+			</tuscany:persistence-unit>
+
+                <tuscany:connectionInfo>
+		      <tuscany:connectionProperties
+			   driverClass="org.apache.derby.jdbc.EmbeddedDriver"
+			   databaseURL="jdbc:derby:target/test-classes/customer; create = true"
+			   loginTimeout="600000"/>
+	        </tuscany:connectionInfo>
+		</tuscany:implementation.jpa>
+	</component>
+
+</composite>
+
+
+ + +

Benefits

+ +
    +
  • Simplify the programming model for accessing data, hiding some of the API details required for this kind of components
  • +
  • Allow exposing data services trough multiple SCA Bindings (e.g ws, json-rpc, feeds, etc)
  • +
+ +
+
+
+ + +
+ + + + + + website stats + + + + + + -- cgit v1.2.3