summaryrefslogtreecommitdiffstats
path: root/sandbox/amita/sca/modules/implementation-data-sdo/main/java/org/apache/tuscany/sca/implementation/sdo/provider/SDOInvoker.java
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/amita/sca/modules/implementation-data-sdo/main/java/org/apache/tuscany/sca/implementation/sdo/provider/SDOInvoker.java')
-rw-r--r--sandbox/amita/sca/modules/implementation-data-sdo/main/java/org/apache/tuscany/sca/implementation/sdo/provider/SDOInvoker.java87
1 files changed, 87 insertions, 0 deletions
diff --git a/sandbox/amita/sca/modules/implementation-data-sdo/main/java/org/apache/tuscany/sca/implementation/sdo/provider/SDOInvoker.java b/sandbox/amita/sca/modules/implementation-data-sdo/main/java/org/apache/tuscany/sca/implementation/sdo/provider/SDOInvoker.java
new file mode 100644
index 0000000000..776541869c
--- /dev/null
+++ b/sandbox/amita/sca/modules/implementation-data-sdo/main/java/org/apache/tuscany/sca/implementation/sdo/provider/SDOInvoker.java
@@ -0,0 +1,87 @@
+/*
+ * 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.sca.implementation.sdo.provider;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tuscany.sca.data.engine.DataAccessEngine;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+
+import commonj.sdo.DataObject;
+
+public class SDOInvoker implements Invoker {
+ private final Operation operation;
+ private final String table;
+ private final String key;
+ private final DataAccessEngine dataAccessEngine;
+
+ public SDOInvoker(Operation operation, String table, String key, DataAccessEngine dataAccessEngine) {
+ this.operation = operation;
+ this.table = table;
+ this.key = key;
+ this.dataAccessEngine = dataAccessEngine;
+ }
+
+ public Message invoke(Message msg) {
+ try {
+ Object[] args = msg.getBody();
+ Object resp = doTheWork(args);
+ msg.setBody(resp);
+ } catch (InvocationTargetException e) {
+ msg.setFaultBody(e.getCause());
+ }
+ return msg;
+ }
+
+ public Object doTheWork(Object[] args) throws InvocationTargetException {
+ if (operation.getName().equals("get")) {
+ ArrayList id = (ArrayList) args[0];
+
+ //simple execute command by name
+ return this.dataAccessEngine.executeGet(id, table, key);
+ } else if (operation.getName().equals("getAll")) {
+ return this.dataAccessEngine.executeGetAll(table, key);
+ } else if (operation.getName().equals("query")) {
+ String queryString = (String) args[0];
+ return this.dataAccessEngine.executeQuery(queryString, table, key);
+ } else if (operation.getName().equals("put")) {
+ ArrayList keys = (ArrayList) args[0];//TODO this will be ignored
+ DataObject origDataObject = (DataObject)args[1];
+ this.dataAccessEngine.executePut(origDataObject);
+ return null;
+ } else if (operation.getName().equals("post")) {
+ DataObject origDataObject = (DataObject)args[0];
+ return this.dataAccessEngine.executePost(origDataObject, table, key);
+ } else if (operation.getName().equals("delete")) {
+ ArrayList keyVals = (ArrayList)args[0];
+ this.dataAccessEngine.executeDelete(keyVals, table, key);
+ return null;
+ } else {
+ return null;
+ }
+ }
+}