summaryrefslogtreecommitdiffstats
path: root/sandbox/amita/das/api/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/amita/das/api/src/main/java/org')
-rw-r--r--sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/Command.java69
-rw-r--r--sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/ConfigHelper.java0
-rw-r--r--sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/Converter.java54
-rw-r--r--sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/DAS.java65
-rw-r--r--sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/DASFactory.java134
-rw-r--r--sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/Implementation.java17
-rw-r--r--sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/Pager.java64
-rw-r--r--sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/service/ServiceLoader.java92
-rw-r--r--sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/service/ServiceProvider.java92
9 files changed, 587 insertions, 0 deletions
diff --git a/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/Command.java b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/Command.java
new file mode 100644
index 0000000000..1ce4bab622
--- /dev/null
+++ b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/Command.java
@@ -0,0 +1,69 @@
+/*
+ * 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.das;
+
+import commonj.sdo.DataObject;
+
+/**
+ * A Command is used to execute a read or write to a database
+ */
+public interface Command {
+
+ /**
+ * Performs the function defined by the command
+ */
+ void execute();
+
+ /**
+ * Performs the function defined by the command and return the results in the root DataObject
+ *
+ * @return the root DataObject
+ */
+ DataObject executeQuery();
+
+ /**
+ * Sets the value of the associated Parameter
+ *
+ * @param index
+ * the index of the Parameter
+ * @param value
+ * the value for the Parameter
+ */
+ void setParameter(int index, Object value);
+
+ /**
+ * Returns the value of the associated Parameter
+ *
+ * @param index
+ * the index of the Parameter
+ * @return the value of the Parameter
+ */
+ Object getParameter(int index);
+
+ /**
+ * Returns the value of the database-generated key. This method is specific
+ * to an "insert" command and will be valid only after the command has
+ * been executed. This methos is only relevant when database is data source.
+ *
+ * @return the generated key
+ */
+ int getGeneratedKey();
+
+ public void setDataSourceConnection(DataSourceConnection con);
+}
diff --git a/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/ConfigHelper.java b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/ConfigHelper.java
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/ConfigHelper.java
diff --git a/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/Converter.java b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/Converter.java
new file mode 100644
index 0000000000..dde6e81771
--- /dev/null
+++ b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/Converter.java
@@ -0,0 +1,54 @@
+/*
+ * 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.das;
+
+/**
+ * A lightweight Table-column <--> DataObject-property converter framework. Converters
+ * allow a user to insert a transformation between a column value
+ * and is destination DataObject property value. For example, by default, a VARCHAR
+ * column will be represented as a String in its corresponding
+ * DataObject property. A user could insert a converter that transforms the the VARCHAR
+ * value to an Integer. If this is done then although the column
+ * returns character data, the DataObject property will be an Integer
+ *
+ *
+ */
+public interface Converter {
+
+ /**
+ * Transform the columnData object to a new value and possibly
+ * new type. This should be the invers operation of #getColumnValue
+ *
+ * @param columnData
+ * The column value to transorm
+ * @return Returns the transformed value
+ */
+ Object getPropertyValue(Object columnData);
+
+ /**
+ * Transform the columnData object to a new value and possibly new
+ * type. This should be the invers operation of #getPropertyValue
+ *
+ * @param propertyData
+ * The property value to transform
+ * @return Returns the transformed value
+ */
+ Object getColumnValue(Object propertyData);
+
+}
diff --git a/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/DAS.java b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/DAS.java
new file mode 100644
index 0000000000..4f0eab6701
--- /dev/null
+++ b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/DAS.java
@@ -0,0 +1,65 @@
+/*
+ * 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.das;
+
+import commonj.sdo.DataObject;
+
+/**
+ * A CommandGroup represents a set of {@link Command} and single {@link ApplyChangesCommand}
+ * that are created from a common config file.
+ *
+ */
+public interface DAS {
+ //hook to specify - e.g. say for XQuery DAS - are we using Saxon/DB2 Express/...
+ public void setImplementationFactory(ImplementationFactory implFactory);
+
+ /**
+ * The change history is scanned and modifications to the graph of data objects are flushed to the database.
+ *
+ * @param root
+ * the topmost containing data object
+ */
+ void applyChanges(DataObject root);
+
+ /**
+ * Gets the named command from this factory's inventory
+ *
+ * @param name
+ * The identifying name of the requested command
+ * @return Returns the identified command
+ */
+ Command getCommand(String name);
+
+ /**
+ * If the CommandGroup is managing connections then this method must be called
+ * when the client is done with the instance.
+ *
+ */
+ void releaseResources();
+
+ /**
+ * Creates a Command based on the provided Query statement
+ *
+ * @param queryStr
+ * The Query statement
+ * @return returns a Command instance
+ */
+ Command createCommand(String queryStr);
+
+}
diff --git a/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/DASFactory.java b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/DASFactory.java
new file mode 100644
index 0000000000..c5130460eb
--- /dev/null
+++ b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/DASFactory.java
@@ -0,0 +1,134 @@
+/*
+ * 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.das;
+
+import java.io.InputStream;
+import java.sql.Connection;
+import java.util.Iterator;
+
+//import org.apache.tuscany.das.config.Config;
+
+import sun.misc.Service;
+
+/**
+ * A DASFactory produces {@link DAS} instances.
+ *
+ *
+ */
+public abstract class DASFactory {
+
+ /**
+ * Return a concrete factory based on specific implementation namespace
+ * @param implementationNamespace
+ * @return
+ */
+ public static DASFactory getInstance(String implementationNamespace){
+ return DASFactory.getInstance(implementationNamespace, DASFactory.class.getClassLoader());
+ }
+
+ /**
+ * Return a concrete factory based on specific implementation namespace and consider a given classloader
+ * @param implementationNamespace
+ * @param cl
+ * @return
+ */
+ public static DASFactory getInstance(String implementationNamespace, ClassLoader cl){
+ DASFactory factoryInstance = null;
+ Iterator ps = Service.providers(DASFactory.class);
+ while(ps.hasNext()){
+ DASFactory factory = (DASFactory) ps.next();
+ if(factory.getNamespace().equalsIgnoreCase(implementationNamespace)) {
+ factoryInstance = factory;
+ break;
+ }
+ }
+
+ return factoryInstance;
+ }
+
+ /**
+ * Namespace that identifies the implementation
+ * @return
+ */
+ public abstract String getNamespace();
+
+ /**
+ * Creates a DAS based on the provided config file stream
+ *
+ * @param configStream
+ * A stream over a DAS config file
+ * @return returns a DAS instance
+ */
+ public abstract DAS createDAS(InputStream configStream);
+
+ /**
+ * Creates a DAS based on the provide config file stream and connection
+ * @param configStream
+ * @param connection
+ * @return
+ */
+ //TODO this should not be directly used, instead createDAS(InputStream configStream, DataSourceConnection connection)
+ //should be used
+ public abstract DAS createDAS(InputStream configStream, Connection connection);
+
+ /**
+ * Creates a DAS based on the provided config
+ *
+ * @param config
+ * A DAS config object
+ * @return returns a DAS instance
+ */
+ //TODO why to have Config here? Let it be only in Impls
+ //public abstract DAS createDAS(Config config);
+
+ /**
+ * Creates a DAS based on the provided config and connection
+ * @param config
+ * @param connection
+ * @return
+ */
+ //TODO this should not be directly used, instead createDAS(Object config, DataSourceConnection connection)
+ //should be used
+ //public abstract DAS createDAS(Config config, Connection connection);
+
+ /**
+ * Creates a DAS based on the provided connection
+ * @param connection
+ * @return
+ */
+ //TODO this should not be directly used, instead createDAS(DataSourceConnection connection)
+ //should be used
+ //public abstract DAS createDAS(Connection connection);
+
+ /**
+ * Connection needs to be generic and not only tied to database connection
+ * as in RDB-DAS, thus introduced DataSourceConnection and used here
+ */
+ public abstract DAS createDAS(DataSourceConnection connection);
+
+ public abstract DAS createDAS(Object config, DataSourceConnection connection);
+
+ public abstract DAS createDAS(InputStream configStream, DataSourceConnection connection);
+
+ public abstract DAS createDAS(Object config);
+
+}
+
+
+
diff --git a/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/Implementation.java b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/Implementation.java
new file mode 100644
index 0000000000..5f999a30cf
--- /dev/null
+++ b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/Implementation.java
@@ -0,0 +1,17 @@
+package org.apache.tuscany.das;
+
+public enum Implementation {
+ RDB ("das://rdb"),
+ LDAP ("das://ldap"),
+ XQUERY ("das://xquery");
+
+ private final String key;
+
+ Implementation(String key){
+ this.key = key;
+ }
+
+ public String getKey(){
+ return this.key;
+ }
+}
diff --git a/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/Pager.java b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/Pager.java
new file mode 100644
index 0000000000..4a4ac1cae7
--- /dev/null
+++ b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/Pager.java
@@ -0,0 +1,64 @@
+/*
+ * 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.das;
+
+import commonj.sdo.DataObject;
+
+/**
+ * An iterator-like interface to conveniently move through chunks of data. The
+ * idea is that a Pager works with a read Command. The read command
+ * returns a large amount of data and the client wants to work with chunks
+ * of it at a time. So the Pager is created on the command and each call to
+ * next returns the next chunk of data. This is done completely disconnected.
+ * No cursor is maintained between calls to #next.
+ *
+ * TODO - This is very preliminary. We need to look at this interface
+ * in the context of disonnected scenarios such as a web app. The Pager instance
+ * will probably be saved in session so it must be very light and cannot
+ * reference a connection. Also, we probably need to define a factory or add a
+ * method to set page size.
+ *
+ *
+ */
+public interface Pager {
+
+ /**
+ * Get the next page of data
+ *
+ * @return the next page of data
+ */
+ DataObject next();
+
+ /**
+ * Get the page prior to the last page returned
+ *
+ * @return the previous page
+ */
+ DataObject previous();
+
+ /**
+ * Return a specific identified page.
+ *
+ * @param page
+ * The number of the page to return
+ * @return the indicated page
+ */
+ DataObject getPage(int page);
+
+}
diff --git a/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/service/ServiceLoader.java b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/service/ServiceLoader.java
new file mode 100644
index 0000000000..a84c386f6a
--- /dev/null
+++ b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/service/ServiceLoader.java
@@ -0,0 +1,92 @@
+/*
+ * 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.das.service;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.*;
+/**
+ * This class loads services present in the class path.
+ */
+public class ServiceLoader {
+
+ private static Map providerMap = new java.util.Hashtable();
+ static Logger log = Logger.getLogger("ServiceLoader.class");
+
+ public static synchronized Iterator providers(Class cls) {
+ ClassLoader cl = cls.getClassLoader();
+ // null if loaded by bootstrap class loader
+ if (cl == null) {
+ cl = ClassLoader.getSystemClassLoader();
+ }
+ String serviceFile = "META-INF/services/" + cls.getName();
+
+ log.debug("File: " + serviceFile);
+
+ List lst = (List)providerMap.get(serviceFile);
+ if (lst != null) {
+ log.debug("file in map returning ");
+ return lst.iterator();
+ }
+
+ lst = new java.util.Vector();
+ providerMap.put(serviceFile, lst);
+
+ //Enumeration e=null;
+ FileInputStream fis=null;
+ InputStream is = null;
+ try {
+ log.debug("getting resource");
+ is = cl.getResourceAsStream(serviceFile);
+ log.debug("is class "+is.getClass().getName());
+ }catch(Exception ex){
+ ex.printStackTrace();
+ log.debug("other exception");
+ }
+
+ log.debug("am here");
+
+ if(is != null)
+ log.debug("found resource");
+ else
+ log.debug("not found resource");
+
+ try {
+ byte[] byt=new byte[is.available()];
+ is.read(byt);
+ String line = new String(byt);
+ log.debug("Line: " + line);
+ lst.add(line);
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ return lst.iterator();
+ }
+ }
diff --git a/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/service/ServiceProvider.java b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/service/ServiceProvider.java
new file mode 100644
index 0000000000..db3b92a238
--- /dev/null
+++ b/sandbox/amita/das/api/src/main/java/org/apache/tuscany/das/service/ServiceProvider.java
@@ -0,0 +1,92 @@
+/*
+ * 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.das.service;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.tuscany.das.DASFactory;
+
+import sun.misc.Service;
+
+
+public class ServiceProvider {
+ private static final ServiceProvider instance = new ServiceProvider();
+
+ protected ServiceProvider() {
+
+ }
+
+ public static ServiceProvider getInstance(){
+ return instance;
+ }
+
+ public static DASFactory getDASFactory(){
+ try{
+ Iterator ps = ServiceLoader.providers(DASFactory.class);
+ while(ps.hasNext()){
+ String className = (String) ps.next();
+ DASFactory factory = (DASFactory) Class.forName(className).newInstance();
+ System.out.println( factory.getClass().getName() );
+ return factory;
+ }
+ }catch(Exception e){
+ e.printStackTrace();
+ return null;
+ }
+ return null;
+ }
+
+ public static void Something(){
+ //Second, try to find a service by using the JDK1.3 jar
+ // discovery mechanism. This will allow users to plug a logger
+ // by just placing it in the lib/ directory of the webapp ( or in
+ // CLASSPATH or equivalent ). This is similar with the second
+ // step, except that it uses the (standard?) jdk1.3 location in the jar.
+
+ Iterator ps = Service.providers(DASFactory.class);
+ while(ps.hasNext()){
+ DASFactory factory = (DASFactory) ps.next();
+ System.out.println( factory.getClass().getName());
+ }
+ }
+
+ public static void Anotherthing() throws Exception{
+ //Second, try to find a service by using the JDK1.3 jar
+ // discovery mechanism. This will allow users to plug a logger
+ // by just placing it in the lib/ directory of the webapp ( or in
+ // CLASSPATH or equivalent ). This is similar with the second
+ // step, except that it uses the (standard?) jdk1.3 location in the jar.
+
+ Iterator ps = ServiceLoader.providers(DASFactory.class);
+ while(ps.hasNext()){
+ String className = (String) ps.next();
+ DASFactory factory = (DASFactory) Class.forName(className).newInstance();
+ System.out.println( factory.getClass().getName() );
+ }
+ }
+
+ public static void main(String[] args) throws Exception{
+ //DASFactory factory = ServiceProvider.getInstance().getFactory(Implementation.LDAP);
+ //ServiceProvider.Something();
+ //ServiceProvider.Anotherthing();
+ ServiceProvider.getDASFactory();
+ }
+}