diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2008-08-09 22:58:07 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2008-08-09 22:58:07 +0000 |
commit | f21ed5242ed195c2bfc082765c9a5ec95a26348c (patch) | |
tree | 906d8089cc9b098cea770d4723290d4f74d7b58a /sandbox/lresende/sca/samples/organization-das/src/main | |
parent | 365a5ce26809d650d18414dbdf82f48f8d96ac29 (diff) |
TUSCANY-2525 - Investigating data access integration issues - Initial scenario based on user application
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@684376 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
6 files changed, 340 insertions, 0 deletions
diff --git a/sandbox/lresende/sca/samples/organization-das/src/main/java/org/osoa/services/OrganizationDataService.java b/sandbox/lresende/sca/samples/organization-das/src/main/java/org/osoa/services/OrganizationDataService.java new file mode 100644 index 0000000000..1dcf8bf814 --- /dev/null +++ b/sandbox/lresende/sca/samples/organization-das/src/main/java/org/osoa/services/OrganizationDataService.java @@ -0,0 +1,31 @@ +/* + * 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.osoa.services; + +import org.soa.types.SchemaInfoType; + +public interface OrganizationDataService { + + public commonj.sdo.DataObject findOrganizationBugTwo(java.lang.String id, SchemaInfoType schemaInfo); + + public commonj.sdo.DataObject findOrganizationBugOne(java.lang.String id, SchemaInfoType schemaInfo); + + public void updateOrganization(commonj.sdo.DataObject organization, SchemaInfoType schemaInfo); +} diff --git a/sandbox/lresende/sca/samples/organization-das/src/main/java/org/osoa/services/OrganizationDataServiceImpl.java b/sandbox/lresende/sca/samples/organization-das/src/main/java/org/osoa/services/OrganizationDataServiceImpl.java new file mode 100644 index 0000000000..6f74774dcd --- /dev/null +++ b/sandbox/lresende/sca/samples/organization-das/src/main/java/org/osoa/services/OrganizationDataServiceImpl.java @@ -0,0 +1,106 @@ +/* + * 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.osoa.services; + +import java.io.InputStream; +import java.sql.Connection; +import java.sql.DriverManager; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; +import org.soa.types.SchemaInfoType; + +import commonj.sdo.DataObject; + + +public class OrganizationDataServiceImpl implements OrganizationDataService { + + private java.sql.Connection getConnection(SchemaInfoType schemaInfo) + { + Connection conn = null; + + // schemaInfo should be your SID. Something like xe (for Oracle Personal Edition) + String url = "jdbc:derby:target/dastest; create = true"; + String driver = "org.apache.derby.jdbc.EmbeddedDriver"; + + try { + Class.forName(driver); + conn = DriverManager.getConnection(url, schemaInfo.getUSERNAME(), schemaInfo.getPASSWORD()); + conn.setAutoCommit(false); + } + catch (Exception e) { + e.printStackTrace(); + } + + return conn; + } + + + public DataObject findOrganizationBugTwo(String id, SchemaInfoType schemaInfo) { + DataObject root = null; + InputStream in = getClass().getClassLoader().getResourceAsStream("dasConfiguration.xml"); + + java.sql.Connection conn = getConnection(schemaInfo); + + DAS das = DAS.FACTORY.createDAS(in, conn); + Command read = das.getCommand("getAccountByID"); + read.setParameter(1, Integer.valueOf(id)); + + root = read.executeQuery(); + + // Testing the root datagraph after returning to test runner. + + return root; + } + + public DataObject findOrganizationBugOne(String id, SchemaInfoType schemaInfo) { + DataObject root = null; + InputStream in = getClass().getClassLoader().getResourceAsStream("dasConfiguration.xml"); + + java.sql.Connection conn = getConnection(schemaInfo); + + DAS das = DAS.FACTORY.createDAS(in, conn); + Command read = das.getCommand("getAccountByID"); + read.setParameter(1, Integer.valueOf(id)); + + root = read.executeQuery(); + + // This is just testing to see if the call to das.applyChanges works + // This doesn't work + + DataObject account = root.getDataObject("ACCOUNT[1]"); + account.set("ACCOUNT_NAME", "TestNode2"); + System.out.println("findOrganization data graph -> " + root.getDataGraph()); + System.out.println("findOrganization data graph root -> " + root.getDataGraph().getRootObject()); + + das.applyChanges(root); + + return root; + } + + public void updateOrganization(DataObject organization, SchemaInfoType schemaInfo) { + InputStream in = getClass().getClassLoader().getResourceAsStream("dasConfiguration.xml"); + + java.sql.Connection conn = getConnection(schemaInfo); + + DAS das = DAS.FACTORY.createDAS(in, conn); + + das.applyChanges(organization); + } +} diff --git a/sandbox/lresende/sca/samples/organization-das/src/main/java/util/ConnectionHelper.java b/sandbox/lresende/sca/samples/organization-das/src/main/java/util/ConnectionHelper.java new file mode 100644 index 0000000000..43903b3a11 --- /dev/null +++ b/sandbox/lresende/sca/samples/organization-das/src/main/java/util/ConnectionHelper.java @@ -0,0 +1,28 @@ +package util; + +import java.sql.Connection; +import java.sql.DriverManager; + +import org.soa.types.SchemaInfoType; + +public class ConnectionHelper { + public static java.sql.Connection getConnection(SchemaInfoType schemaInfo) + { + Connection conn = null; + + // schemaInfo should be your SID. Something like xe (for Oracle Personal Edition) + String url = "jdbc:derby:target/organization_db; create = true"; + String driver = "org.apache.derby.jdbc.EmbeddedDriver"; + + try { + Class.forName(driver); + conn = DriverManager.getConnection(url, schemaInfo.getUSERNAME(), schemaInfo.getPASSWORD()); + conn.setAutoCommit(false); + } + catch (Exception e) { + e.printStackTrace(); + } + + return conn; + } +} diff --git a/sandbox/lresende/sca/samples/organization-das/src/main/resources/organization.composite b/sandbox/lresende/sca/samples/organization-das/src/main/resources/organization.composite new file mode 100644 index 0000000000..e19441aa5d --- /dev/null +++ b/sandbox/lresende/sca/samples/organization-das/src/main/resources/organization.composite @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + targetNamespace="http://org.soa.services" + xmlns:soa="http://org.soa.services" + name="Organization-Service-Composite"> + + <component name="OrganizationServiceComponent"> + <implementation.spring location="Organization-spring-context.xml"/> + <service name="OrganizationService"/> + </component> + + <service name="OrganizationService" promote="OrganizationServiceComponent/OrganizationService"> + <binding.ws/> + </service> + + <component name="OrganizationDataServiceComponent"> + <implementation.spring location="Organization-spring-context.xml"/> + </component> + + +</composite> diff --git a/sandbox/lresende/sca/samples/organization-das/src/main/resources/organizationConfiguration.xml b/sandbox/lresende/sca/samples/organization-das/src/main/resources/organizationConfiguration.xml new file mode 100644 index 0000000000..2104c37404 --- /dev/null +++ b/sandbox/lresende/sca/samples/organization-das/src/main/resources/organizationConfiguration.xml @@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="ASCII"?> +<Config xmlns="http:///org.apache.tuscany.das.rdb/config.xsd"> + + <!--ConnectionInfo> + <ConnectionProperties + driverClass="org.apache.derby.jdbc.EmbeddedDriver" + databaseURL="jdbc:derby:target/organization_db; create = true" + loginTimeout="600000"/> + </ConnectionInfo--> + + + <Command name="getAllOrganizations" SQL="select * from ORGANIZATIONTYPELIST" kind="Select"> + <ResultDescriptor columnName="ORGANIZATIONTYPEID" tableName="ORGANIZATIONTYPELIST" columnType="commonj.sdo.IntObject"/> + <ResultDescriptor columnName="CODE" tableName="ORGANIZATIONTYPELIST" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="DISPLAYVALUE" tableName="ORGANIZATIONTYPELIST" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="DESCRIPTION" tableName="ORGANIZATIONTYPELIST" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="ISEDITABLE" tableName="ORGANIZATIONTYPELIST" columnType="commonj.sdo.Type"/> + </Command> + + <Command name="findOrganization" SQL="select * from ORGANIZATIONTYPELIST where ORGANIZATIONTYPEID = ? " kind="Select"> + <ResultDescriptor columnName="ORGANIZATIONTYPEID" tableName="ORGANIZATIONTYPELIST" columnType="commonj.sdo.IntObject"/> + <ResultDescriptor columnName="CODE" tableName="ORGANIZATIONTYPELIST" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="DISPLAYVALUE" tableName="ORGANIZATIONTYPELIST" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="DESCRIPTION" tableName="ORGANIZATIONTYPELIST" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="ISEDITABLE" tableName="ORGANIZATIONTYPELIST" columnType="commonj.sdo.Integer"/> + </Command> + + <Command name="getAllAccounts" SQL="select * from ACCOUNT" kind="Select"> + <ResultDescriptor columnName="ACCOUNT_ID" tableName="ACCOUNT" columnType="commonj.sdo.IntObject"/> + <ResultDescriptor columnName="ACCOUNTTYPE_CD" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="ACCOUNT_NAME" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="WEB_SITE_ADDRESS" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="STREET_ADDRESS_1" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="STREET_ADDRESS_2" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="STREET_ADDRESS_3" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="CITY" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="STATE_CD" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="POSTAL_CD" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="COUNTRY_CD" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="PHONE_NUMBER" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="FAX_NUMBER" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="NOTE" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + </Command> + + <Command name="getAccountByID" SQL="select * from ACCOUNT where ACCOUNT_ID = ?" kind="Select"> + <ResultDescriptor columnName="ACCOUNT_ID" tableName="ACCOUNT" columnType="commonj.sdo.IntObject"/> + <ResultDescriptor columnName="ACCOUNTTYPE_CD" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="ACCOUNT_NAME" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="WEB_SITE_ADDRESS" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="STREET_ADDRESS_1" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="STREET_ADDRESS_2" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="STREET_ADDRESS_3" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="CITY" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="STATE_CD" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="POSTAL_CD" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="COUNTRY_CD" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="PHONE_NUMBER" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="FAX_NUMBER" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + <ResultDescriptor columnName="NOTE" tableName="ACCOUNT" columnType="commonj.sdo.String"/> + </Command> + + <Table tableName="ORGANIZATIONTYPELIST"> + <Column columnName="ORGANIZATIONTYPEID" primaryKey="true" generated="true"/> + <Column columnName="CODE" /> + <Column columnName="DISPLAYVALUE" /> + <Column columnName="DESCRIPTION" /> + <Column columnName="ISEDITABLE" /> + </Table> + + <Table tableName="ACCOUNT"> + <Column columnName="ACCOUNT_ID" primaryKey="true" generated="true"/> + <Column columnName="ACCOUNTTYPE_CD" /> + <Column columnName="ACCOUNT_NAME" /> + <Column columnName="WEB_SITE_ADDRESS" /> + <Column columnName="STREET_ADDRESS_1" /> + <Column columnName="STREET_ADDRESS_2" /> + <Column columnName="STREET_ADDRESS_3" /> + <Column columnName="CITY" /> + <Column columnName="STATE_CD" /> + <Column columnName="POSTAL_CD" /> + <Column columnName="COUNTRY_CD" /> + <Column columnName="PHONE_NUMBER" /> + <Column columnName="FAX_NUMBER" /> + <Column columnName="NOTE" /> + </Table> + +</Config>
\ No newline at end of file diff --git a/sandbox/lresende/sca/samples/organization-das/src/main/resources/sdo-types.xsd b/sandbox/lresende/sca/samples/organization-das/src/main/resources/sdo-types.xsd new file mode 100644 index 0000000000..0b287bda24 --- /dev/null +++ b/sandbox/lresende/sca/samples/organization-das/src/main/resources/sdo-types.xsd @@ -0,0 +1,66 @@ + +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://org/soa/types" + xmlns:tns="http://org/soa/types" + elementFormDefault="qualified"> + + <xsd:element name="Organization" type="OrganizationType"/> + + <xsd:complexType name="OrganizationType"> + <xsd:sequence> + <xsd:element name="ORGANIZATIONTYPEID" type="xsd:int" /> + <xsd:element name="CODE" type="xsd:string" /> + <xsd:element name="DISPLAYVALUE" type="xsd:string" /> + <xsd:element name="DESCRIPTION" type="xsd:string" /> + <xsd:element name="ISEDITABLE" type="xsd:int" /> + </xsd:sequence> + </xsd:complexType> + + <xsd:element name="Address" type="AddressType"/> + + <xsd:complexType name="AddressType"> + <xsd:sequence> + <xsd:element name="ADDRESS_ID" type="xsd:int" /> + <xsd:element name="ADDRESSTYPE_CD" type="xsd:string" /> + <xsd:element name="STREET_ADDRESS_1" type="xsd:string" /> + <xsd:element name="STREET_ADDRESS_2" type="xsd:string" /> + <xsd:element name="STREET_ADDRESS_3" type="xsd:string" /> + <xsd:element name="CITY" type="xsd:string" /> + <xsd:element name="STATE_CD" type="xsd:string" /> + <xsd:element name="POSTAL_CD" type="xsd:string" /> + <xsd:element name="COUNTRY_CD" type="xsd:string" /> + </xsd:sequence> + </xsd:complexType> + + <xsd:element name="SchemaInfo" type="SchemaInfoType"/> + + <xsd:complexType name="SchemaInfoType"> + <xsd:sequence> + <xsd:element name="USERNAME" type="xsd:string" /> + <xsd:element name="PASSWORD" type="xsd:string" /> + <xsd:element name="SCHEMA" type="xsd:string" /> + </xsd:sequence> + </xsd:complexType> + + <xsd:element name="Account" type="AccountType"/> + + <xsd:complexType name="AccountType"> + <xsd:sequence> + <xsd:element name="ACCOUNT_ID" type="xsd:string"/> + <xsd:element name="ACCOUNTTYPE_CD" type="xsd:string"/> + <xsd:element name="ACCOUNT_NAME" type="xsd:string"/> + <xsd:element name="WEB_SITE_ADDRESS" type="xsd:string"/> + <xsd:element name="STREET_ADDRESS_1" type="xsd:string"/> + <xsd:element name="STREET_ADDRESS_2" type="xsd:string"/> + <xsd:element name="STREET_ADDRESS_3" type="xsd:string"/> + <xsd:element name="CITY" type="xsd:string"/> + <xsd:element name="STATE_CD" type="xsd:string"/> + <xsd:element name="POSTAL_CD" type="xsd:string"/> + <xsd:element name="COUNTRY_CD" type="xsd:string"/> + <xsd:element name="PHONE_NUMBER" type="xsd:string"/> + <xsd:element name="FAX_NUMBER" type="xsd:string"/> + <xsd:element name="NOTE" type="xsd:string"/> + </xsd:sequence> + </xsd:complexType> + +</xsd:schema>
\ No newline at end of file |