diff options
Diffstat (limited to 'sandbox/lresende/das/api/src/main/java/org')
9 files changed, 646 insertions, 0 deletions
diff --git a/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/Command.java b/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/Command.java new file mode 100644 index 0000000000..0d82b839ab --- /dev/null +++ b/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/Command.java @@ -0,0 +1,68 @@ +/* + * 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. + * + * @return the generated key + */ + int getGeneratedKey(); + +} diff --git a/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/ConfigHelper.java b/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/ConfigHelper.java new file mode 100644 index 0000000000..c9117a5d0a --- /dev/null +++ b/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/ConfigHelper.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; + + +import org.apache.tuscany.das.config.Config; +import org.apache.tuscany.das.config.ConfigFactory; + +/** + * A ConfigHelper is used as an aid in programmatic construction of Config instances. + * Manual contrution fo COnfig is an alternative to providing needed configuration + * information in an XML file + * + */ +public class ConfigHelper { + + private Config config; + + //private MappingWrapper configWrapper; + + private ConfigFactory factory = ConfigFactory.INSTANCE; + + public ConfigHelper() { + config = factory.createConfig(); + //configWrapper = new MappingWrapper(config); + } + + public ConfigHelper(Config config) { + this.config = config; + //configWrapper = new MappingWrapper(config); + } + + + public Config getConfig() { + return config; + } + +} diff --git a/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/Converter.java b/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/Converter.java new file mode 100644 index 0000000000..dde6e81771 --- /dev/null +++ b/sandbox/lresende/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/lresende/das/api/src/main/java/org/apache/tuscany/das/DAS.java b/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/DAS.java new file mode 100644 index 0000000000..bdbab71bb8 --- /dev/null +++ b/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/DAS.java @@ -0,0 +1,68 @@ +/* + * 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 org.apache.tuscany.das.rdb.impl.DASFactoryImpl; + +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 { + + //DASFactory FACTORY = new DASFactoryImpl(); + + + /** + * 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 SQL statement + * + * @param sql + * The SQL statement + * @return returns a Command instance + */ + Command createCommand(String sql); + +} diff --git a/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/DASFactory.java b/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/DASFactory.java new file mode 100644 index 0000000000..25be55db96 --- /dev/null +++ b/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/DASFactory.java @@ -0,0 +1,114 @@ +/* + * 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 + */ + 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 + */ + public abstract DAS createDAS(Config config); + + /** + * Creates a DAS based on the provided config and connection + * @param config + * @param connection + * @return + */ + public abstract DAS createDAS(Config config, Connection connection); + + /** + * Creates a DAS based on the provided connection + * @param connection + * @return + */ + public abstract DAS createDAS(Connection connection); + + +} + diff --git a/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/Implementation.java b/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/Implementation.java new file mode 100644 index 0000000000..5f999a30cf --- /dev/null +++ b/sandbox/lresende/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/lresende/das/api/src/main/java/org/apache/tuscany/das/Pager.java b/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/Pager.java new file mode 100644 index 0000000000..4a4ac1cae7 --- /dev/null +++ b/sandbox/lresende/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/lresende/das/api/src/main/java/org/apache/tuscany/das/service/ServiceLoader.java b/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/service/ServiceLoader.java new file mode 100644 index 0000000000..34466778df --- /dev/null +++ b/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/service/ServiceLoader.java @@ -0,0 +1,110 @@ +/*
+ * 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.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;
+
+/**
+ * This class loads services present in the class path.
+ */
+public class ServiceLoader {
+
+ private static Map providerMap = new java.util.Hashtable();
+
+ 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) {
+ return lst.iterator();
+ }
+
+ lst = new java.util.Vector();
+ providerMap.put(serviceFile, lst);
+
+ Enumeration e;
+ try {
+ e = cl.getResources(serviceFile);
+ } catch (IOException ioe) {
+ return lst.iterator();
+ }
+
+ while (e.hasMoreElements()) {
+ try {
+ java.net.URL u = (java.net.URL)e.nextElement();
+ //log.debug("URL: " + u);
+
+ InputStream is = u.openStream();
+ Reader r = new InputStreamReader(is, "UTF-8");
+ BufferedReader br = new BufferedReader(r);
+
+ String line = br.readLine();
+ while (line != null) {
+ try {
+ // First strip any comment...
+ int idx = line.indexOf('#');
+ if (idx != -1) {
+ line = line.substring(0, idx);
+ }
+
+ // Trim whitespace.
+ line = line.trim();
+
+ // If nothing left then loop around...
+ if (line.length() == 0) {
+ line = br.readLine();
+ continue;
+ }
+ // log.debug("Line: " + line);
+
+ // Try and load the class
+ // Object obj = cl.loadClass(line).newInstance();
+ // stick it into our vector...
+ lst.add(line);
+ } catch (Exception ex) {
+ // Just try the next line
+ }
+
+ line = br.readLine();
+ }
+ } catch (Exception ex) {
+ // Just try the next file...
+ }
+
+ }
+ return lst.iterator();
+ }
+
+ }
diff --git a/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/service/ServiceProvider.java b/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/service/ServiceProvider.java new file mode 100644 index 0000000000..37f7183130 --- /dev/null +++ b/sandbox/lresende/das/api/src/main/java/org/apache/tuscany/das/service/ServiceProvider.java @@ -0,0 +1,97 @@ +/*
+ * 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 {
+ /**
+ * The name of the property used to identify the LogFactory implementation class name.
+ */
+ public static final String FACTORY_PROPERTY = "org.apache.tuscany.das.DASFactory";
+
+ /**
+ * 'Service Provider' specification ( http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html )
+ */
+ protected static final String SERVICE_ID = "META-INF/services/org.apache.tuscany.das.DASFactory";
+
+
+ private static final String FACTORY_RESOURCE = "org.apache.tuscany.das.das";
+
+
+ private Map<String, String> registry = new HashMap<String, String>();
+
+ private static final ServiceProvider instance = new ServiceProvider();
+
+ protected ServiceProvider() {
+
+ }
+
+ public static ServiceProvider getInstance(){
+ return instance;
+ }
+
+
+ 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();
+ }
+}
|