From f21ed5242ed195c2bfc082765c9a5ec95a26348c Mon Sep 17 00:00:00 2001 From: lresende Date: Sat, 9 Aug 2008 22:58:07 +0000 Subject: 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 --- .../org/osoa/services/OrganizationDataService.java | 31 ++++++ .../osoa/services/OrganizationDataServiceImpl.java | 106 +++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 sandbox/lresende/sca/samples/organization-das/src/main/java/org/osoa/services/OrganizationDataService.java create mode 100644 sandbox/lresende/sca/samples/organization-das/src/main/java/org/osoa/services/OrganizationDataServiceImpl.java (limited to 'sandbox/lresende/sca/samples/organization-das/src/main/java/org') 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); + } +} -- cgit v1.2.3