You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by lr...@apache.org on 2006/11/16 08:31:20 UTC
svn commit: r475609 [2/2] - in /incubator/tuscany/sandbox/lresende: ./
container.das/ container.das/src/ container.das/src/main/
container.das/src/main/java/ container.das/src/main/java/org/
container.das/src/main/java/org/apache/ container.das/src/mai...
Added: incubator/tuscany/sandbox/lresende/container.das/src/main/java/org/apache/tuscany/container/dataaccessscript/DataAccessInstanceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/lresende/container.das/src/main/java/org/apache/tuscany/container/dataaccessscript/DataAccessInstanceImpl.java?view=auto&rev=475609
==============================================================================
--- incubator/tuscany/sandbox/lresende/container.das/src/main/java/org/apache/tuscany/container/dataaccessscript/DataAccessInstanceImpl.java (added)
+++ incubator/tuscany/sandbox/lresende/container.das/src/main/java/org/apache/tuscany/container/dataaccessscript/DataAccessInstanceImpl.java Wed Nov 15 23:31:18 2006
@@ -0,0 +1,206 @@
+/*
+ * 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.container.dataaccessscript;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.apache.tuscany.container.dataaccess.DataAccessInstance;
+import org.apache.tuscany.das.rdb.Command;
+import org.apache.tuscany.das.rdb.DAS;
+
+import commonj.sdo.DataObject;
+/**
+ * An invokeable instance of a DataAccessScript script.
+ */
+public class DataAccessInstanceImpl implements DataAccessInstance {
+
+ private DAS dasInstance;
+ private String dataAccessType;
+
+ public DataAccessInstanceImpl(DAS das, String dataAccessType){
+ this.dasInstance = das;
+ this.dataAccessType = dataAccessType;
+ }
+
+ public Object invokeFunction(String functionName, Object[] args, Class returnType) {
+ Command cmd = null;
+ System.out.println("functionName:"+functionName);
+
+ ArrayList paramsList = null;
+ if(args != null){
+ paramsList = (ArrayList)args[0];
+ }
+
+ //if any of the 3 below - its dynamic way , else , its static way
+ if(!functionName.equals("execute") &&
+ !functionName.equals("executeQuery") &&
+ !functionName.equals("applyChanges")){
+ //try for static way
+ String commandName = CommandMapper.getCommandName(functionName);
+ System.out.println("commandName:"+commandName);
+ cmd = dasInstance.getCommand(commandName);
+ }
+ else{
+ //upto below statement is generic DAS..but select,etc..are particular
+ //to RDBDAS
+ cmd = dasInstance.getCommand((String)paramsList.get(0));
+ }
+
+ //Particular to RDBDAS
+ if(this.dataAccessType.equals(DataAccessEngine.RDB)){
+ DataObject dataObj = null;
+ dataObj = invokeRDBDASFunction(cmd, paramsList);
+ return dataObj;
+ }
+
+ //TODO ...implement for other than RDB
+ return null;
+ }
+
+ private DataObject invokeRDBDASSelect(Command cmd, ArrayList paramsList){
+ DataObject dObject = null;
+
+ if(paramsList != null){
+ if(paramsList.size()>=3){
+ Map<Integer, Object> inParams = new Hashtable<Integer, Object>();
+ inParams = (Map<Integer, Object>)paramsList.get(2);
+ DataAccessUtils.fromJavaToRDBDASPositionBased(inParams, cmd);
+ }
+ }
+ dObject = cmd.executeQuery();
+ if(dObject == null){
+ System.out.println("null result returned in select");
+ }
+ return dObject;
+ }
+
+ private void invokeRDBDASDelete(Command cmd, ArrayList paramsList){
+ if(paramsList != null){
+ if(paramsList.size()>=3){
+ Map<Integer, Object> inParams = new Hashtable<Integer, Object>();
+ inParams = (Map<Integer, Object>)paramsList.get(2);
+ DataAccessUtils.fromJavaToRDBDASPositionBased(inParams, cmd);
+ }
+ }
+ cmd.execute();
+ }
+
+ private void invokeRDBDASInsert(Command cmd, ArrayList paramsList){
+ if(paramsList != null){
+ if(paramsList.size()>=3){
+ Map<Integer, Object> inParams = new Hashtable<Integer, Object>();
+ inParams = (Map<Integer, Object>)paramsList.get(2);
+ DataAccessUtils.fromJavaToRDBDASPositionBased(inParams, cmd);
+ }
+ }
+ cmd.execute();
+ }
+
+ private void invokeRDBDASUpdate(Command cmd, ArrayList paramsList){
+ if(paramsList != null){
+ if(paramsList.size()>=4){
+
+ String paramsTableName = paramsList.get(1).toString();
+ int idx = paramsTableName.indexOf(DataAccessEngine.SEPARATOR);
+ String tableName = paramsTableName.substring(idx+1);
+
+ String genericSelectForRoot = "select * from "+ tableName;
+
+ System.out.println("genericSelectForRoot:"+genericSelectForRoot);
+ cmd = dasInstance.createCommand(genericSelectForRoot);
+
+ //set UPD and WHERE params
+ if(paramsList.get(2) instanceof Map){
+ Map<String, Object> updParams = (Map<String, Object>)paramsList.get(2);
+
+ if(paramsList.get(3) instanceof Map){
+ Map<String, Object> whereParams = (Map<String, Object>)paramsList.get(3);
+ DataObject root = DataAccessUtils.fromJavaToRDBDASNameBased(updParams, whereParams, cmd, tableName);
+ dasInstance.applyChanges(root);
+ }
+ }
+ }
+ }
+ }
+
+ private DataObject invokeRDBDASProcedure(Command cmd, ArrayList paramsList){
+ DataObject dataObj = null;
+ if(paramsList != null){
+ //set IN params
+ if(paramsList.size()>=3){
+ if(paramsList.get(2) instanceof Map){
+ Map<Integer, Object> inParams = (Map<Integer, Object>)paramsList.get(2);
+ DataAccessUtils.fromJavaToRDBDASPositionBased(inParams, cmd);
+ }
+
+ }
+
+ dataObj = cmd.executeQuery();
+
+ if(paramsList.size()>=4){
+ if(paramsList.get(3) instanceof Map){
+ Map<Integer, Object> outParams = (Map<Integer, Object>)paramsList.get(3);
+ DataAccessUtils.fromRDBDASToJavaPositionBased(outParams, cmd);
+ paramsList.add(3, outParams);
+ }
+ }
+
+ System.out.println("executed SP..");
+ }
+ return dataObj;
+ }
+
+ private DataObject invokeRDBDASFunction(Command cmd, ArrayList paramsList){
+ String commandKind = null;
+ //TODO
+ commandKind = (String)paramsList.get(1);
+
+ System.out.println("commandKind:"+commandKind);
+
+ if(commandKind.equals(DataAccessEngine.SELECT)){
+ DataObject dataObj = invokeRDBDASSelect(cmd, paramsList);
+ return dataObj;
+ }
+
+ if(commandKind.equals(DataAccessEngine.DELETE)){
+ invokeRDBDASDelete(cmd, paramsList);
+ return null;
+ }
+
+ if(commandKind.equals(DataAccessEngine.INSERT)){
+ invokeRDBDASInsert(cmd, paramsList);
+ return null;
+ }
+
+ if(commandKind.startsWith(DataAccessEngine.UPDATE)){
+ invokeRDBDASUpdate(cmd, paramsList);
+ return null;
+ }
+
+ if(commandKind.equals(DataAccessEngine.PROCEDURE)){
+ DataObject dataObj = invokeRDBDASProcedure(cmd, paramsList);
+ return dataObj;
+ }
+
+ //TODO..need to implement for UPDATE, CREATE etc.
+ return null;
+ }
+}
Added: incubator/tuscany/sandbox/lresende/container.das/src/main/java/org/apache/tuscany/container/dataaccessscript/DataAccessUtils.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/lresende/container.das/src/main/java/org/apache/tuscany/container/dataaccessscript/DataAccessUtils.java?view=auto&rev=475609
==============================================================================
--- incubator/tuscany/sandbox/lresende/container.das/src/main/java/org/apache/tuscany/container/dataaccessscript/DataAccessUtils.java (added)
+++ incubator/tuscany/sandbox/lresende/container.das/src/main/java/org/apache/tuscany/container/dataaccessscript/DataAccessUtils.java Wed Nov 15 23:31:18 2006
@@ -0,0 +1,75 @@
+/*
+ * 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.container.dataaccessscript;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.tuscany.das.rdb.Command;
+
+import commonj.sdo.DataObject;
+
+public class DataAccessUtils {
+ public static void fromRDBDASToJavaPositionBased(Map outParams, Command cmd){
+ for (Iterator i = outParams.keySet().iterator(); i.hasNext();) {
+ Integer odx = (Integer)i.next();
+
+ //result can be of any Object type
+ Object outRes = null;
+ outRes = cmd.getParameter(odx);
+
+ outParams.put(odx, outRes);
+ }
+ }
+
+ public static void fromJavaToRDBDASPositionBased(Map inParams, Command cmd){
+ for (Iterator i = inParams.keySet().iterator(); i.hasNext();) {
+ Integer idx = (Integer)i.next();
+
+ Object val = inParams.get(idx);
+ cmd.setParameter(idx, val);
+ }
+ }
+
+ public static DataObject fromJavaToRDBDASNameBased(Map updParams, Map whereParams, Command cmd, String tableName){
+ //currently where clause is only for PKs - by convention
+ String whereStr = null;
+
+ for (Iterator i = whereParams.keySet().iterator(); i.hasNext();) {
+ String idx = (String)i.next();
+
+ Object val = whereParams.get(idx);
+ whereStr = tableName+"["+val+"]";
+ System.out.println("whereStr:"+whereStr);
+ }
+ DataObject root = cmd.executeQuery();
+ DataObject dObj = root.getDataObject(whereStr);
+
+ for (Iterator i = updParams.keySet().iterator(); i.hasNext();) {
+ String idx = (String)i.next();
+
+ Object val = updParams.get(idx);
+ dObj.set(idx, val);
+ }
+
+ return root;
+ }
+
+ //TODO ..similarly there will be fromJavaToXQueryDAS()..and revese etc.
+}
Added: incubator/tuscany/sandbox/lresende/container.das/src/main/resources/META-INF/sca/das.system.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/lresende/container.das/src/main/resources/META-INF/sca/das.system.scdl?view=auto&rev=475609
==============================================================================
--- incubator/tuscany/sandbox/lresende/container.das/src/main/resources/META-INF/sca/das.system.scdl (added)
+++ incubator/tuscany/sandbox/lresende/container.das/src/main/resources/META-INF/sca/das.system.scdl Wed Nov 15 23:31:18 2006
@@ -0,0 +1,44 @@
+<?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.
+-->
+<!--
+ JavaScript configuration for the launcher environment.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.launcher.DataAccessImplementation">
+
+ <component name="dataaccess.implementationLoader">
+ <system:implementation.system class="org.apache.tuscany.container.dataaccess.DataAccessImplementationLoader"/>
+ </component>
+
+ <component name="dataaccess.componentTypeLoader">
+ <system:implementation.system class="org.apache.tuscany.container.dataaccess.DataAccessComponentTypeLoader"/>
+ </component>
+
+ <component name="dataaccess.componentBuilder">
+ <system:implementation.system class="org.apache.tuscany.container.dataaccess.DataAccessComponentBuilder"/>
+ </component>
+
+ <!-- Xml Instance Registry service -->
+<!-- <component name="xmlInstRegistry">
+ <system:implementation.system class="org.apache.tuscany.container.dataaccess.utils.xmlfromxsd.XmlInstanceRegistryImpl"/>
+ </component>-->
+
+</composite>
Added: incubator/tuscany/sandbox/lresende/container.das/src/main/resources/META-INF/sca/default.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/lresende/container.das/src/main/resources/META-INF/sca/default.scdl?view=auto&rev=475609
==============================================================================
--- incubator/tuscany/sandbox/lresende/container.das/src/main/resources/META-INF/sca/default.scdl (added)
+++ incubator/tuscany/sandbox/lresende/container.das/src/main/resources/META-INF/sca/default.scdl Wed Nov 15 23:31:18 2006
@@ -0,0 +1,50 @@
+<?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.
+-->
+<!--
+ JavaScript configuration for the launcher environment.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+ name="org.apache.tuscany.launcher.DataAccessImplementation">
+
+ <dependency xmlns="http://tuscany.apache.org/xmlns/1.0-SNAPSHOT">
+ <group>org.apache.tuscany.sca.services.containers</group>
+ <name>dataaccess</name>
+ <version>1.0-incubator-M2-SNAPSHOT</version>
+ </dependency>
+
+ <component name="dataaccess.implementationLoader">
+ <system:implementation.system class="org.apache.tuscany.container.dataaccess.DataAccessImplementationLoader"/>
+ </component>
+
+ <component name="dataaccess.componentTypeLoader">
+ <system:implementation.system class="org.apache.tuscany.container.dataaccess.DataAccessComponentTypeLoader"/>
+ </component>
+
+ <component name="dataaccess.componentBuilder">
+ <system:implementation.system class="org.apache.tuscany.container.dataaccess.DataAccessComponentBuilder"/>
+ </component>
+
+ <!-- Xml Instance Registry service -->
+ <!--<component name="xmlInstRegistry">
+ <system:implementation.system class="org.apache.tuscany.container.dataaccess.utils.xmlfromxsd.XmlInstanceRegistryImpl"/>
+ </component>-->
+
+</composite>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org