diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-13 01:40:20 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-01-13 01:40:20 +0000 |
commit | 582fd9c234bb82da33b4071b627fd69e3d256e49 (patch) | |
tree | 0d34331e3790cfdc81f03661b46cf5c81b9b11e0 /sandbox/lresende/backup | |
parent | 0d7f33c760f570722bf6b13f0765f5d2772a7897 (diff) |
Cleaning up sandbox
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@898601 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/lresende/backup')
14 files changed, 972 insertions, 0 deletions
diff --git a/sandbox/lresende/backup/company-das/build.xml b/sandbox/lresende/backup/company-das/build.xml new file mode 100644 index 0000000000..704b698aac --- /dev/null +++ b/sandbox/lresende/backup/company-das/build.xml @@ -0,0 +1,116 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> + +<project name="sample-company-das" default="compile"> + + <target name="compile"> + <mkdir dir="target/classes"/> + <javac destdir="target/classes" debug="on" source="1.5" target="1.5"> + <src path="src\main\java"/> + <classpath> + <fileset refid="tuscany.jars"/> + <fileset refid="3rdparty.jars"/> + </classpath> + </javac> + <copy todir="target/classes"> + <fileset dir="src\main\resources"/> + <fileset dir="."/> + </copy> + <jar destfile="target/sample-company-das.jar" basedir="target/classes"> + <manifest> + <attribute name="Main-Class" value="das.DASServiceClient"/> + </manifest> + </jar> + </target> + + <target name="run"> + <java classname="org.apache.tuscany.samples.das.service.client.DASServiceClient" fork="true"> + <classpath> + <pathelement location="target/sample-company-das.jar"/> + <fileset refid="tuscany.jars"/> + <fileset refid="3rdparty.jars"/> + </classpath> + </java> + </target> + + <target name="clean"> + <delete includeemptydirs="true"> + <fileset dir="target"/> + </delete> + </target> + + <fileset id="tuscany.jars" dir="../../modules"> + <include name="tuscany-interface-java-xml-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-implementation-java-runtime-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-implementation-java-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-node-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-binding-sca-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-assembly-xml-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-interface-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-contribution-java-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-implementation-java-xml-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-policy-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-binding-sca-xml-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-contribution-impl-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-definitions-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-core-spi-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-contribution-namespace-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-domain-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-contribution-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-node-api-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-interface-java-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-definitions-xml-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-sca-api-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-assembly-xsd-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-policy-logging-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-assembly-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-core-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-core-databinding-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-host-embedded-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-domain-api-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-databinding-1.0.1-incubating-SNAPSHOT.jar"/> + <include name="tuscany-policy-xml-1.0.1-incubating-SNAPSHOT.jar"/> + </fileset> + <fileset id="3rdparty.jars" dir="../../lib"> + <include name="stax-api-1.0.1.jar"/> + <include name="tuscany-das-rdb-1.0-incubating-beta2.jar"/> + <include name="xml-apis-1.3.03.jar"/> + <include name="wstx-asl-3.2.0.jar"/> + <include name="commons-logging-1.1.jar"/> + <include name="axiom-impl-1.2.5.jar"/> + <include name="xalan-2.7.0.jar"/> + <include name="log4j-1.2.14.jar"/> + <include name="tuscany-sdo-lib-1.0-incubating.jar"/> + <include name="tuscany-sdo-api-r2.1-1.0-incubating.jar"/> + <include name="ecore-xmi-2.2.3.jar"/> + <include name="neethi-2.0.2.jar"/> + <include name="geronimo-commonj_1.1_spec-1.0.jar"/> + <include name="jaxen-1.1-beta-9.jar"/> + <include name="ecore-2.2.3.jar"/> + <include name="common-2.2.3.jar"/> + <include name="axiom-api-1.2.5.jar"/> + <include name="xsd-2.2.3.jar"/> + <include name="xercesImpl-2.8.1.jar"/> + <include name="cglib-nodep-2.1_3.jar"/> + <include name="tuscany-sdo-impl-1.0-incubating.jar"/> + <include name="ecore-change-2.2.3.jar"/> + </fileset> + +</project> diff --git a/sandbox/lresende/backup/company-das/company.sql b/sandbox/lresende/backup/company-das/company.sql new file mode 100644 index 0000000000..8fb5c2d4cd --- /dev/null +++ b/sandbox/lresende/backup/company-das/company.sql @@ -0,0 +1,40 @@ +DROP TABLE EMPLOYEE;
+DROP TABLE DEPARTMENT;
+DROP TABLE COMPANY;
+
+CREATE TABLE COMPANY (
+ ID INT PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY,
+ NAME VARCHAR(30));
+
+CREATE TABLE DEPARTMENT (ID INT PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY,
+ NAME VARCHAR(30),
+ LOCATION VARCHAR(30),
+ DEPNUMBER VARCHAR(10),
+ COMPANYID INT);
+
+CREATE TABLE EMPLOYEE (ID INT PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY,
+ NAME VARCHAR(30),
+ SN VARCHAR(10),
+ MANAGER SMALLINT,
+ DEPARTMENTID INT);
+
+
+INSERT INTO COMPANY (NAME) VALUES('ACME Publishing');
+INSERT INTO COMPANY (NAME) VALUES('Do-rite plumbing');
+INSERT INTO COMPANY (NAME) VALUES('MegaCorp');
+
+INSERT INTO DEPARTMENT (NAME, LOCATION, DEPNUMBER, COMPANYID) VALUES('Advanced Technologies','NY','123', 1);
+INSERT INTO DEPARTMENT (NAME, LOCATION, DEPNUMBER, COMPANYID) VALUES('Default Name 2','','', 1);
+INSERT INTO DEPARTMENT (NAME, LOCATION, DEPNUMBER, COMPANYID) VALUES('Default Name 3','','', 1);
+INSERT INTO DEPARTMENT (NAME, LOCATION, DEPNUMBER, COMPANYID) VALUES('Default Name 4','','', 1);
+INSERT INTO DEPARTMENT (NAME, LOCATION, DEPNUMBER, COMPANYID) VALUES('Default Name 5','','', 1);
+INSERT INTO DEPARTMENT (NAME, LOCATION, DEPNUMBER, COMPANYID) VALUES('Default Name 6','','', 1);
+INSERT INTO DEPARTMENT (NAME, LOCATION, DEPNUMBER, COMPANYID) VALUES('Default Name 7','','', 1);
+INSERT INTO DEPARTMENT (NAME, LOCATION, DEPNUMBER, COMPANYID) VALUES('Default Name 8','','', 1);
+
+INSERT INTO EMPLOYEE (NAME, SN, MANAGER, DEPARTMENTID) VALUES('John Jones','E0001', 0, 1);
+INSERT INTO EMPLOYEE (NAME, SN, MANAGER, DEPARTMENTID) VALUES('Mary Smith','E0002', 1, null);
+INSERT INTO EMPLOYEE (NAME, SN, MANAGER, DEPARTMENTID) VALUES('Jane Doe','E0003', 0, 1);
+INSERT INTO EMPLOYEE (NAME, SN, MANAGER, DEPARTMENTID) VALUES('Al Smith','E0004', 1, 1);
+
+
diff --git a/sandbox/lresende/backup/company-das/pom.xml b/sandbox/lresende/backup/company-das/pom.xml new file mode 100644 index 0000000000..2c0ba4da8b --- /dev/null +++ b/sandbox/lresende/backup/company-das/pom.xml @@ -0,0 +1,149 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-sca</artifactId>
+ <version>1.1-incubating-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>sample-company-das</artifactId>
+ <name>Apache Tuscany SCA Company Data Access Service Sample</name>
+ <packaging>jar</packaging>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-sca-api</artifactId>
+ <version>1.2-incubating-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-host-embedded</artifactId>
+ <version>1.2-incubating-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-implementation-java-runtime</artifactId>
+ <version>1.2-incubating-SNAPSHOT</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sdo</groupId>
+ <artifactId>tuscany-sdo-impl</artifactId>
+ <version>1.0-incubating-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.das</groupId>
+ <artifactId>tuscany-das-rdb</artifactId>
+ <version>1.0-incubating-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ <version>10.1.2.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.2</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>das.DASServiceClient</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>sql-maven-plugin</artifactId>
+ <!-- 1.1 due to MOJO-619 -->
+ <version>1.1-SNAPSHOT</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ <version>10.1.2.1</version>
+ </dependency>
+ </dependencies>
+
+ <executions>
+ <execution>
+ <id>create-db</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ <configuration>
+ <driver>org.apache.derby.jdbc.EmbeddedDriver</driver>
+ <url>jdbc:derby:${pom.basedir}/target/company_db;create=true</url>
+ <autocommit>true</autocommit>
+ <onError>continue</onError>
+ <onConnectionError>skip</onConnectionError>
+ <delimiter>;</delimiter>
+ <srcFiles>
+ <srcFile>${pom.basedir}/company.sql</srcFile>
+ </srcFiles>
+ </configuration>
+ </execution>
+
+ <!-- Shutdown DB in order to be able to run unit tests -->
+ <execution>
+ <id>shutdown-database-sothat-test-can-run</id>
+ <phase>process-test-resources</phase>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ <configuration>
+ <driver>org.apache.derby.jdbc.EmbeddedDriver</driver>
+ <url>jdbc:derby:${pom.basedir}/target/company_db;shutdown=true</url>
+ <skipOnConnectionError>true</skipOnConnectionError>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/sandbox/lresende/backup/company-das/readme.html b/sandbox/lresende/backup/company-das/readme.html new file mode 100644 index 0000000000..ec6b492b72 --- /dev/null +++ b/sandbox/lresende/backup/company-das/readme.html @@ -0,0 +1,110 @@ +<!--
+ 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.
+ -->
+<html>
+
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
+<title>Tuscany RDB DAS exposed as an SCA service</title>
+
+<style>
+.code {font-size: 11px; color: #006699}
+.codebox {border: 1px solid #6699CC; background-color: #F1F7FA;padding:15px}
+.codebox2 {border: 1px solid #6699CC; background-color: #F1F7FA;padding:15px; width:85%}
+.codeboxW {border: 1px solid #6699CC; background-color: #FFFFFF;padding:15px}
+.codeboxB {background-color: #C9DBED;padding:1px 10px 10px 10px}
+</style>
+
+</head>
+
+
+
+
+<body>
+
+<h1>Tuscany RDB DAS exposed as an SCA service</h1>
+
+
+<h3>Introduction</h3>
+
+<p>This is a sample SCA service that exposes DAS functionality.</p>
+<p>This service would allow you to utilize DAS in a language neutral fashion, consuming existent or adHoc commands.</p>
+
+
+<h3>Consuming the DAS service</h3>
+
+
+<p>You should add the dependency on your client project pom file</p>
+
+
+<p>
+<div class="codebox2">
+<pre>
+<!-- DAS Service -->
+<dependency>
+ <groupId>org.apache.tuscany.das.samples</groupId>
+ <artifactId>sample-das-service</artifactId>
+ <version>${pom.version}</version>
+</dependency>
+</pre>
+</div>
+</p>
+
+<br>
+<p>In order to consume the service, you would have to create a SCDL that references it, see sample below:</p>
+
+<p>
+<div class="codebox2">
+<pre>
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" name="DASServiceComposite">
+ <component name="DASServiceComponent">
+ <implementation.composite name="DASServiceComposite" jarLocation="lib/sample-das-service-1.0-incubator-SNAPSHOT.jar"/>
+ </component>
+</composite>
+</pre>
+</div>
+</p>
+
+
+<h3>Sample Architecture</h3>
+
+<p>This service utilizes the following Interface as its definition:</p>
+
+
+<p>
+<div class="codebox2">
+<pre>
+
+public interface DASService {
+
+ public void configureService(InputStream configStream) throws DASServiceException;
+
+ public DataObject executeCommand(String commandName, Vector commandArguments) throws DASServiceException;
+
+ public DataObject execute(String adHocQuery, Vector commandArguments) throws DASServiceException;
+
+ public void applyChanges(DataObject graphRoot) throws DASServiceException;
+
+}
+</pre>
+</div>
+</p>
+
+</body>
+
+</html>
diff --git a/sandbox/lresende/backup/company-das/src/main/java/das/DASService.java b/sandbox/lresende/backup/company-das/src/main/java/das/DASService.java new file mode 100644 index 0000000000..0387341b87 --- /dev/null +++ b/sandbox/lresende/backup/company-das/src/main/java/das/DASService.java @@ -0,0 +1,61 @@ +/*
+ * 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 das;
+
+import java.io.InputStream;
+import java.util.Vector;
+
+import commonj.sdo.DataObject;
+
+public interface DASService {
+
+ /**
+ * Set DAS configuration file to be used
+ * @param configStream
+ * @throws DASServiceException
+ */
+ public void configureService(InputStream configStream) throws DASServiceException;
+
+ /**
+ * Execute an existing command. The commands are defined in the DAS Configuration file being used by the service
+ * @param commandName Command name as it appears on the DAS Configuration file
+ * @param commandArguments Vector with arguments to be used by the command
+ * @throws DASServiceException
+ * @return
+ */
+ public DataObject executeCommand(String commandName, Vector commandArguments) throws DASServiceException;
+
+ /**
+ * Execute a new command, this can be any arbitrary valid query based on the backend implementation (e.g. SQL Query for DAS RDB)
+ * @param adHocQuery A new command to be executed (e.g SQL Query)
+ * @param commandArguments Vector with arguments to be used by the command
+ * @throws DASServiceException
+ * @return
+ */
+ public DataObject execute(String adHocQuery, Vector commandArguments) throws DASServiceException;
+
+ /**
+ * Apply all changes on the graph back to the persistent repository.
+ * This would save the changes on the SDO ChangeSummary back to the database
+ * Note: Your SDO ojects should have been created with ChangeSummary support
+ * @param graphRoot SDO Object with changes to be commited to persistent repository
+ * @throws DASServiceException
+ */
+ public void applyChanges(DataObject graphRoot) throws DASServiceException;
+}
diff --git a/sandbox/lresende/backup/company-das/src/main/java/das/DASServiceClient.java b/sandbox/lresende/backup/company-das/src/main/java/das/DASServiceClient.java new file mode 100644 index 0000000000..b23731df21 --- /dev/null +++ b/sandbox/lresende/backup/company-das/src/main/java/das/DASServiceClient.java @@ -0,0 +1,48 @@ +/* + * 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 das; + +import java.util.List; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +import commonj.sdo.DataObject; + +public class DASServiceClient { + + public static void main(String[] args) throws Exception { + + SCADomain scaDomain = SCADomain.newInstance("dasservice.composite"); + DASService dasService = scaDomain.getService(DASService.class, "DASServiceComponent"); + + + dasService.configureService(DASServiceClient.class.getClassLoader().getResourceAsStream("company.xml")); + + DataObject root = dasService.executeCommand("all companies", null); + List companyList = root.getList("COMPANY"); + + for(int i=0; i<companyList.size(); i++){ + System.out.println(" ID:"+(((DataObject)companyList.get(i)).getInt("ID"))+ + " NAME:"+(((DataObject)companyList.get(i)).getString("NAME"))); + } + + } + +} diff --git a/sandbox/lresende/backup/company-das/src/main/java/das/DASServiceException.java b/sandbox/lresende/backup/company-das/src/main/java/das/DASServiceException.java new file mode 100644 index 0000000000..e62201a4de --- /dev/null +++ b/sandbox/lresende/backup/company-das/src/main/java/das/DASServiceException.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 das;
+
+public class DASServiceException extends Exception {
+
+ private static final long serialVersionUID = -7514653215235902874L;
+
+ public DASServiceException() {
+ super();
+ }
+
+ public DASServiceException(String msg) {
+ super(msg);
+ }
+
+ public DASServiceException(String msg, Throwable ex) {
+ super(msg, ex);
+ }
+
+}
diff --git a/sandbox/lresende/backup/company-das/src/main/java/das/DASServiceImpl.java b/sandbox/lresende/backup/company-das/src/main/java/das/DASServiceImpl.java new file mode 100644 index 0000000000..5b9beb21cb --- /dev/null +++ b/sandbox/lresende/backup/company-das/src/main/java/das/DASServiceImpl.java @@ -0,0 +1,153 @@ +/*
+ * 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 das;
+
+import java.io.InputStream;
+import java.util.Vector;
+
+import org.apache.tuscany.das.rdb.Command;
+import org.apache.tuscany.das.rdb.DAS;
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Scope;
+
+import commonj.sdo.DataObject;
+
+@Scope("COMPOSITE")
+public class DASServiceImpl implements DASService {
+
+ private DAS das = null;
+
+ /**
+ * Initialize DAS
+ * @return
+ * @throws DASServiceException
+ */
+ private void initDAS(InputStream config) throws DASServiceException {
+ if(config == null){
+ throw new DASServiceException("Missing configuration information");
+ }
+
+ if(this.das != null){
+ this.das.releaseResources();
+ this.das = null;
+ }
+
+ this.das = DAS.FACTORY.createDAS(config);
+ }
+
+ @Destroy
+ protected void destroyDAS() {
+ if(das != null) {
+ das.releaseResources();
+ }
+ }
+
+ /**
+ * Get a DAS instance based on the configuration
+ * @return
+ * @throws DASServiceException
+ */
+ private DAS getDAS() throws DASServiceException {
+ if(this.das == null){
+ throw new DASServiceException("DAS not initialized. Please provide DAS configuration torugh das.SetConfig");
+ }
+
+ return this.das;
+ }
+
+ /**
+ * Set DAS configuration file to be used
+ * @param configStream
+ * @throws DASServiceException
+ */
+ public void configureService(InputStream configStream) throws DASServiceException{
+ this.initDAS(configStream);
+ }
+
+
+
+ /**
+ * Execute an existing command. The commands are defined in the DAS Configuration file being used by the service
+ * @param commandName Command name as it appears on the DAS Configuration file
+ * @param commandArguments Vector with arguments to be used by the command
+ * @throws DASServiceException
+ * @return
+ */
+ public DataObject executeCommand(String commandName, Vector commandArguments) throws DASServiceException{
+ Command command = this.getDAS().getCommand(commandName);
+
+ if(command == null){
+ throw new DASServiceException("Invalid command: " + commandName);
+ }
+
+ //check if arguments was passed
+ if(commandArguments != null && commandArguments.size() > 0){
+ //we need to set the arguments
+ int pos=0;
+ for(Object argument : commandArguments){
+ pos++;
+ command.setParameter(pos, argument);
+ }
+ }
+
+ DataObject root = command.executeQuery();
+
+ return root;
+ }
+
+ /**
+ * Execute a new command, this can be any arbitrary valid query based on the backend implementation (e.g. SQL Query for DAS RDB)
+ * @param newCommand A new command to be executed (e.g SQL Query)
+ * @param commandArguments Vector with arguments to be used by the command
+ * @throws DASServiceException
+ * @return
+ */
+ public DataObject execute(String adHocQuery, Vector commandArguments) throws DASServiceException {
+ Command command = this.getDAS().createCommand(adHocQuery);
+
+ if(command == null){
+ throw new DASServiceException("Invalid command: " + adHocQuery);
+ }
+
+ //check if arguments was passed
+ if(commandArguments != null && commandArguments.size() > 0){
+ //we need to set the arguments
+ int pos=0;
+ for(Object argument : commandArguments){
+ pos++;
+ command.setParameter(pos, argument);
+ }
+ }
+ DataObject root = command.executeQuery();
+
+ return root;
+ }
+
+ /**
+ * Apply all changes on the graph back to the persistent repository.
+ * This would save the changes on the SDO ChangeSummary back to the database
+ * Note: Your SDO ojects should have been created with ChangeSummary support
+ * @throws DASServiceException
+ * @param graphRoot SDO Object with changes to be commited to persistent repository
+ */
+ public void applyChanges(DataObject graphRoot) throws DASServiceException{
+ // TODO Auto-generated method stub
+
+ }
+}
diff --git a/sandbox/lresende/backup/company-das/src/main/resources/company.xml b/sandbox/lresende/backup/company-das/src/main/resources/company.xml new file mode 100644 index 0000000000..39935fe025 --- /dev/null +++ b/sandbox/lresende/backup/company-das/src/main/resources/company.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. + --> +<Config xmlns="http:///org.apache.tuscany.das.rdb/config.xsd"> + + <ConnectionInfo> + <ConnectionProperties + driverClass="org.apache.derby.jdbc.EmbeddedDriver" + databaseURL="jdbc:derby:target/company_db;create=true" + loginTimeout="600000"/> + </ConnectionInfo> + + + <Command name="all companies" SQL="select * from COMPANY" kind="Select"/> + + <Command name="all companies and departments" SQL="select * from COMPANY left outer join DEPARTMENT on COMPANY.ID = DEPARTMENT.COMPANYID" kind="Select"/> + + <Command name="all departments for company" SQL="select * from COMPANY inner join DEPARTMENT on COMPANY.ID = DEPARTMENT.COMPANYID where COMPANY.ID = ?" kind="Select"/> + + <Command name="company by id with departments" SQL="select * from COMPANY left outer join DEPARTMENT on COMPANY.ID = DEPARTMENT.COMPANYID where COMPANY.ID = ?" kind="Select"/> + + + <Table tableName="COMPANY"> + <Column columnName="ID" primaryKey="true" generated="true"/> + </Table> + + <Table tableName="DEPARTMENT"> + <Column columnName="ID" primaryKey="true" generated="true"/> + </Table> + + <Relationship name="departments" primaryKeyTable="COMPANY" foreignKeyTable="DEPARTMENT" many="true"> + <KeyPair primaryKeyColumn="ID" foreignKeyColumn="COMPANYID"/> + </Relationship> + + +</Config> diff --git a/sandbox/lresende/backup/company-das/src/main/resources/dasservice.composite b/sandbox/lresende/backup/company-das/src/main/resources/dasservice.composite new file mode 100644 index 0000000000..06063184c9 --- /dev/null +++ b/sandbox/lresende/backup/company-das/src/main/resources/dasservice.composite @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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"
+ targetNamespace="http://das-service"
+ xmlns:das-service="http://das-service"
+ name="DASService">
+
+ <component name="DASServiceComponent">
+ <implementation.java class="das.DASServiceImpl"/>
+ </component>
+
+</composite>
diff --git a/sandbox/lresende/backup/company-das/src/main/resources/log4j.properties b/sandbox/lresende/backup/company-das/src/main/resources/log4j.properties new file mode 100644 index 0000000000..ab4ebbb785 --- /dev/null +++ b/sandbox/lresende/backup/company-das/src/main/resources/log4j.properties @@ -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. +# +# Set root logger level to DEBUG and its only appender to A1. +log4j.rootLogger=INFO, NULL + +# NULL Appender +log4j.appender.NULL=org.apache.log4j.varia.NullAppender + +log4j.appender.NULL.layout=org.apache.log4j.PatternLayout +log4j.appender.NULL.layout.ConversionPattern=[DAS RDB] - %c{1}.%M (%L) : %m %n + +# CONSOLE is set to be a ConsoleAppender. +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender + +# A1 uses PatternLayout. +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=[DAS RDB] - %c{1}.%M (%L) : %m %n + + +# Print only messages of level WARN or above in the package com.foo. +log4j.logger.org.apache.tuscany=NONE
\ No newline at end of file diff --git a/sandbox/lresende/backup/company-das/src/test/java/das/DASServiceTestCase.java b/sandbox/lresende/backup/company-das/src/test/java/das/DASServiceTestCase.java new file mode 100644 index 0000000000..b866336db6 --- /dev/null +++ b/sandbox/lresende/backup/company-das/src/test/java/das/DASServiceTestCase.java @@ -0,0 +1,53 @@ +/*
+ * 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 das;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+
+import commonj.sdo.DataObject;
+
+public class DASServiceTestCase extends TestCase {
+
+ private SCADomain scaDomain;
+ private DASService dasService;
+
+ @Override
+ protected void setUp() throws Exception {
+ scaDomain = SCADomain.newInstance("dasservice.composite");
+ dasService = scaDomain.getService(DASService.class, "DASServiceComponent");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ scaDomain.close();
+ }
+
+ public void testDAS() throws Exception{
+ dasService.configureService(getClass().getResourceAsStream("/company.xml"));
+ DataObject root = dasService.executeCommand("all companies", null);
+ List companyList = root.getList("COMPANY");
+
+ assertNotNull(companyList);
+ assertEquals(3,companyList.size());
+ }
+}
diff --git a/sandbox/lresende/backup/company-das/src/test/resources/company.xml b/sandbox/lresende/backup/company-das/src/test/resources/company.xml new file mode 100644 index 0000000000..43da819521 --- /dev/null +++ b/sandbox/lresende/backup/company-das/src/test/resources/company.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+<Config xmlns="http:///org.apache.tuscany.das.rdb/config.xsd">
+
+ <ConnectionInfo>
+ <ConnectionProperties
+ driverClass="org.apache.derby.jdbc.EmbeddedDriver"
+ databaseURL="jdbc:derby:target/company_db;create=true"
+ loginTimeout="600000"/>
+ </ConnectionInfo>
+
+
+ <Command name="all companies" SQL="select * from COMPANY" kind="Select"/>
+
+ <Command name="all companies and departments" SQL="select * from COMPANY left outer join DEPARTMENT on COMPANY.ID = DEPARTMENT.COMPANYID" kind="Select"/>
+
+ <Command name="all departments for company" SQL="select * from COMPANY inner join DEPARTMENT on COMPANY.ID = DEPARTMENT.COMPANYID where COMPANY.ID = ?" kind="Select"/>
+
+ <Command name="company by id with departments" SQL="select * from COMPANY left outer join DEPARTMENT on COMPANY.ID = DEPARTMENT.COMPANYID where COMPANY.ID = ?" kind="Select"/>
+
+
+ <Table tableName="COMPANY">
+ <Column columnName="ID" primaryKey="true" generated="true"/>
+ </Table>
+
+ <Table tableName="DEPARTMENT">
+ <Column columnName="ID" primaryKey="true" generated="true"/>
+ </Table>
+
+ <Relationship name="departments" primaryKeyTable="COMPANY" foreignKeyTable="DEPARTMENT" many="true">
+ <KeyPair primaryKeyColumn="ID" foreignKeyColumn="COMPANYID"/>
+ </Relationship>
+
+
+</Config>
diff --git a/sandbox/lresende/backup/company-das/src/test/resources/log4j.properties b/sandbox/lresende/backup/company-das/src/test/resources/log4j.properties new file mode 100644 index 0000000000..ab4ebbb785 --- /dev/null +++ b/sandbox/lresende/backup/company-das/src/test/resources/log4j.properties @@ -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. +# +# Set root logger level to DEBUG and its only appender to A1. +log4j.rootLogger=INFO, NULL + +# NULL Appender +log4j.appender.NULL=org.apache.log4j.varia.NullAppender + +log4j.appender.NULL.layout=org.apache.log4j.PatternLayout +log4j.appender.NULL.layout.ConversionPattern=[DAS RDB] - %c{1}.%M (%L) : %m %n + +# CONSOLE is set to be a ConsoleAppender. +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender + +# A1 uses PatternLayout. +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=[DAS RDB] - %c{1}.%M (%L) : %m %n + + +# Print only messages of level WARN or above in the package com.foo. +log4j.logger.org.apache.tuscany=NONE
\ No newline at end of file |