tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From am...@apache.org
Subject svn commit: r610715 - in /incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main: ./ java/ java/org/ java/org/apache/ java/org/apache/tuscany/ java/org/apache/tuscany/sca/ java/org/apache/tuscany/sca/data/ java/org/apache/tuscany/sca/data/...
Date Thu, 10 Jan 2008 08:37:46 GMT
Author: amita
Date: Thu Jan 10 00:37:44 2008
New Revision: 610715

URL: http://svn.apache.org/viewvc?rev=610715&view=rev
Log:
Tuscany- implementation-data-sdo

Added:
    incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/
    incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/
    incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/
    incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/
    incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/
    incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/
    incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/
    incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/
    incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/ConnectionInfoArtifactProcessor.java
    incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngine.java
    incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngineManager.java
    incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/MissingConfigFileException.java
    incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/config/
    incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/config/ConnectionInfo.java
    incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/config/ConnectionProperties.java

Added: incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/ConnectionInfoArtifactProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/ConnectionInfoArtifactProcessor.java?rev=610715&view=auto
==============================================================================
--- incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/ConnectionInfoArtifactProcessor.java
(added)
+++ incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/ConnectionInfoArtifactProcessor.java
Thu Jan 10 00:37:44 2008
@@ -0,0 +1,176 @@
+/*
+ * 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.data.engine;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.data.engine.config.ConnectionInfo;
+import org.apache.tuscany.sca.data.engine.config.ConnectionProperties;
+
+/**
+ * Implements a STAX artifact processor for ConnectionInfo.
+ * This processor is shared between implementation.das and implementation.data component
type  implementations,
+ * and can be used for other applications that require database connectivity information.
+ * 
+ * The artifact processor is responsible for processing <ConnectionInfo>
+ * elements in SCA assembly XML composite files.
+ * 
+ * @version $Rev: 572267 $ $Date: 2007-09-03 15:16:41 +0530 (Mon, 03 Sep 2007) $
+ */
+public class ConnectionInfoArtifactProcessor implements StAXArtifactProcessor<ConnectionInfo>
{
+    public static final QName CONNECTION_INFO = new QName(Constants.SCA10_TUSCANY_NS, "connectionInfo");
+    private static final QName CONNECTION_PROPERTIES = new QName(Constants.SCA10_TUSCANY_NS,
"connectionProperties");
+    
+    public ConnectionInfoArtifactProcessor(ModelFactoryExtensionPoint modelFactories) {
+
+    }
+
+    public QName getArtifactType() {
+        // Returns the qname of the XML element processed by this processor
+        return CONNECTION_INFO;
+    }
+
+    public Class<ConnectionInfo> getModelType() {
+        // Returns the type of model processed by this processor
+        return ConnectionInfo.class;
+    }
+
+    /*
+     * <component name="CompanyDataComponent">
+     *   <implementation.data table="company">
+     *
+     *      <connectionInfo>
+     *         <connectionProperties 
+     *          driverClass="org.apache.derby.jdbc.EmbeddedDriver" 
+     *          databaseURL="jdbc:derby:target/test-classes/dastest; create = true" 
+     *          loginTimeout="600000"/>
+     *      </connectionInfo>
+     *
+     *   </implementation.data>
+     * </component>
+     */
+    public ConnectionInfo read(XMLStreamReader reader) throws ContributionReadException {
+        assert CONNECTION_INFO.equals(reader.getName());
+
+        // Create a ConnectionInfo from the component type model
+        ConnectionInfo connectionInfo = new ConnectionInfo();
+
+        /* 
+         *  <connectionInfo dataSource="jdbc:derby:target/test-classes/dastest; create
= true"/>
+         */
+        String dataSource = reader.getAttributeValue(null, "datasource"); // exclusive with
connection properties
+        if (dataSource != null && dataSource.length() > 0) {
+            connectionInfo.setDataSource(dataSource);
+        } else {
+            try {
+                int event = reader.next();
+                while (event == XMLStreamConstants.CHARACTERS) {
+                    event = reader.next();
+                }
+            } catch (XMLStreamException e) {
+                throw new ContributionReadException(e);
+            }
+
+            QName element = reader.getName();
+            
+            assert CONNECTION_PROPERTIES.equals(element);
+            
+            /*
+             * <connectionProperties 
+             *  driverClass="org.apache.derby.jdbc.EmbeddedDriver" 
+             *  databaseURL="jdbc:derby:target/test-classes/dastest; create = true"
+             *  username=""
+             *  password="" 
+             *  loginTimeout="600000"/>
+             */
+            
+            String driverClass = reader.getAttributeValue(null, "driverClass");
+            String databaseURL = reader.getAttributeValue(null, "databaseURL");
+            String username = reader.getAttributeValue(null, "username");
+            String password = reader.getAttributeValue(null, "password");
+            String loginTimeout = reader.getAttributeValue(null, "loginTimeout");
+
+            // FIXME: validation sending info to monitor....
+            ConnectionProperties connectionProperties = new ConnectionProperties();
+            connectionProperties.setDriverClass(driverClass);
+            connectionProperties.setDatabaseURL(databaseURL);
+            connectionProperties.setUsername(username);
+            connectionProperties.setPassword(password);
+            if (loginTimeout != null) {
+                connectionProperties.setLoginTimeout(Integer.parseInt(loginTimeout));
+            }
+
+            connectionInfo.setConnectionProperties(connectionProperties);
+        }
+        
+        return connectionInfo;
+    }
+
+    public void resolve(ConnectionInfo impl, ModelResolver resolver) throws ContributionResolveException
{
+
+    }
+
+    public void write(ConnectionInfo connectionInfo, XMLStreamWriter writer) throws ContributionWriteException,
XMLStreamException {
+
+        writer.writeStartElement(CONNECTION_INFO.getNamespaceURI(), CONNECTION_INFO.getLocalPart());
+
+        if (connectionInfo.getDataSource() != null) {
+            writer.writeAttribute("dataSource", connectionInfo.getDataSource());
+        }
+        
+        ConnectionProperties connectionProperties = connectionInfo.getConnectionProperties();
+        if (connectionProperties != null) {
+            writer.writeStartElement(CONNECTION_PROPERTIES.getNamespaceURI(), CONNECTION_PROPERTIES.getLocalPart());
+            
+            if (connectionProperties.getDriverClass() != null) {
+                writer.writeAttribute("driverClass", connectionProperties.getDriverClass());
+            }
+            if (connectionProperties.getDatabaseURL() != null) {
+                writer.writeAttribute("databaseURL", connectionProperties.getDatabaseURL());
+            }
+            if (connectionProperties.getUsername() != null) {
+                writer.writeAttribute("username", connectionProperties.getUsername());
+            }
+            if (connectionProperties.getPassword() != null) {
+                writer.writeAttribute("password", connectionProperties.getPassword());
+            }
+            if (connectionProperties.getLoginTimeout() != null) {
+                writer.writeAttribute("loginTimeout", String.valueOf(connectionProperties.getLoginTimeout()));
+            }
+            
+            writer.writeEndElement();
+        }
+        
+        
+        writer.writeEndElement();
+        
+    }
+}

Added: incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngine.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngine.java?rev=610715&view=auto
==============================================================================
--- incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngine.java
(added)
+++ incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngine.java
Thu Jan 10 00:37:44 2008
@@ -0,0 +1,287 @@
+/*
+ * 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.data.engine;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.das.rdb.Command;
+import org.apache.tuscany.das.rdb.DAS;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
+import commonj.sdo.helper.XMLHelper;
+
+/**
+ * Facade to hide DAS implementation details of handling commands
+ * 
+ * @version $Rev$ $Date$
+ */
+public class DataAccessEngine {
+    private final DAS das;
+
+    public DataAccessEngine(DAS das) {
+        this.das = das;
+    }
+
+    public DataObject executeGet(ArrayList keyVals, String table, String key) {//TODO need
to consider compound keys
+        try {
+            String sqlQuery = "select * from " + table.toUpperCase();
+            List<String> keys = null;
+            
+            if(key == null) {
+                if(keyVals != null && keyVals.size() == 1) {
+                    sqlQuery += " where ID = " + keyVals.get(0);
+                }            	
+            } else {//can be other than ID , can be compount keys
+            	keys = getKeys(key);
+            	if(keyVals.size() != keys.size()) {
+            		throw new RuntimeException("One or more PK values missing");
+            	}
+            	            	
+            	sqlQuery += " where ";
+            	
+            	for(int i=0; i<keys.size(); i++) {
+            		sqlQuery += keys.get(i)+" = ? AND ";
+            	}
+            	
+            	sqlQuery = sqlQuery.substring(0, sqlQuery.lastIndexOf(" AND "));
+            }
+            
+            Command command = this.das.createCommand(sqlQuery);
+            
+            if(key != null) {
+            	for(int i=1; i<=keyVals.size(); i++) {
+            		command.setParameter(i, keyVals.get(i-1));
+            	}
+            }
+            
+            DataObject returnDO = command.executeQuery();          
+            return returnDO;
+        } catch (Exception e) {
+            //e.printStackTrace();
+            throw new RuntimeException(e);
+        }
+    }
+    
+    /**
+     * 
+     * @param table table'e Type name - should be same as table name
+     * @param key column's Property name - should be same as column name
+     * @return
+     */
+    public Map<Object, DataObject> executeGetAll(String table, String key) {
+        try {
+            String sqlQuery = "select * from " + table.toUpperCase();
+            Command command = this.das.createCommand(sqlQuery);
+            DataObject result = command.executeQuery();
+            List<String> keys = getKeys(key);
+            List<DataObject> resultDataObjects = result.getList(table);
+            
+            return getMappedDataObjects(resultDataObjects, keys);
+        } catch (Exception e) {
+            //e.printStackTrace();
+        	throw new RuntimeException(e);
+        }
+    }
+    
+    public Map<Object, DataObject> executeQuery(String queryString, String table, String
key) {
+        try {
+            Command command = this.das.createCommand(queryString);
+            DataObject result = command.executeQuery();
+            List<String> keys = getKeys(key);
+            List<DataObject> resultDataObjects = result.getList(table);
+            
+            return getMappedDataObjects(resultDataObjects, keys);
+        } catch (Exception e) {
+            //e.printStackTrace();
+        	throw new RuntimeException(e);
+        }
+    }
+    
+    //origDataObject should be with change summary. table, pk is already known to DAS, so
no need to have these here
+    public void executePut(DataObject origDataObject) {
+    	this.das.applyChanges(origDataObject);
+    	return;
+    }
+    
+    //return PK/s
+    public ArrayList executePost(DataObject origDataObject, String table, String key){
+    	//TODO check that PKs are present before insert - this is not correct for auto incr
PKs, so let it be upto user whether to send PK or not
+    	/*List<String> keys = getKeys(key);
+    	for(int i=0; i<keys.size(); i++) {
+    		String currentKey = keys.get(i);
+    		Object currentKeyValue = origDataObject.get(currentKey);
+    		if(currentKeyValue == null) {
+    			throw new RuntimeException("PK missing during INSERT");
+    		}
+    	}*/
+    	
+    	String sqlString = "insert into "+table+" (";
+    	List props = origDataObject.getType().getProperties();
+    	if(props.size() != 0) {
+	    	for(int i=0; i<props.size(); i++) {
+	    		String currPropName = ((Property)props.get(i)).getName();
+	    		if(origDataObject.get(currPropName) != null) {
+	    			sqlString += currPropName+",";
+	    		}
+	    	}
+	    	sqlString = sqlString.substring(0, sqlString.length()-1);
+	    	sqlString += ") values (";
+	    	for(int i=0; i<props.size(); i++) {
+	    		String currPropName = ((Property)props.get(i)).getName();
+	    		if(origDataObject.get(currPropName) != null) {
+	    			sqlString += "?,";
+	    		}
+	    	}
+
+	    	sqlString = sqlString.substring(0, sqlString.length()-1);
+	    	sqlString += ")";
+	    	
+	    	Command insertCommand = this.das.createCommand(sqlString);
+	    	int paramIdx = 1;
+	    	for(int i=1; i<=props.size(); i++) {
+	    		String currPropName = ((Property)props.get(i-1)).getName();
+	    		if(origDataObject.get(currPropName) != null) {
+	    			insertCommand.setParameter(paramIdx, origDataObject.get(currPropName));
+	    			paramIdx++;
+	    		}
+	    	}
+	    	
+	    	insertCommand.execute();
+	    	
+	    	//there can be different possibilities
+	    	//1- there is autogen key - insertCommand.getGeneratedKey() will return value and not
exception
+	    	//2- there is no autogen key - insertCommand.getGeneratedKey() will return exception
and value needs to be taken from origDataObject
+	    	//for 2 it is straight forward to know the column name same as property name
+	    	//for 1 it is possible for only 1 column so no question of compound PK
+
+	    	//now get the PK/s to be returned
+	    	ArrayList pks = new ArrayList();
+
+	    	try {
+	    		int newId = insertCommand.getGeneratedKey();
+	    		pks.add(newId);
+	    		return pks;
+	    	} catch(Exception e) {
+		    	List<String> keys = getKeys(key);
+		    	for(int i=0; i<keys.size(); i++) {
+		    		String currentKey = keys.get(i);
+		    		Object currentKeyValue = origDataObject.get(currentKey);
+		    		if(currentKeyValue == null) {
+		    			throw new RuntimeException("PK missing during INSERT");
+		    		}
+		    		pks.add(currentKeyValue);
+		    	}
+		    	return pks;
+	    	}
+
+    	}
+    	return null;
+    }
+    
+    //when keyVal is null can be used as deleteAll
+    public void executeDelete(ArrayList keyVals, String table, String key) {
+        try {
+            String sqlQuery = "select * from " + table.toUpperCase();
+            List<String> keys = null;
+            
+            if(key == null) {
+                if(keyVals != null && keyVals.size() == 1) {
+                    sqlQuery += " where ID = " + keyVals.get(0);
+                }            	
+            } else {//can be other than ID , can be compount keys
+            	keys = getKeys(key);
+            	if(keyVals.size() != keys.size()) {
+            		throw new RuntimeException("One or more PK values missing");
+            	}
+            	            	
+            	sqlQuery += " where ";
+            	
+            	for(int i=0; i<keys.size(); i++) {
+            		sqlQuery += keys.get(i)+" = ? AND ";
+            	}
+            	
+            	sqlQuery = sqlQuery.substring(0, sqlQuery.lastIndexOf(" AND "));
+            }
+            
+            Command command = this.das.createCommand(sqlQuery);
+            
+            if(key != null) {
+            	for(int i=1; i<=keyVals.size(); i++) {
+            		command.setParameter(i, keyVals.get(i-1));
+            	}
+            }
+            
+            DataObject result = command.executeQuery();
+            List<DataObject> resultDOs = result.getList(table);
+            if(resultDOs != null) {
+            	for(int i=0; i<resultDOs.size(); i++) {
+            		((DataObject)resultDOs.get(i)).delete();
+            	}
+            }
+            this.das.applyChanges(result);
+        } catch (Exception e) {
+            //e.printStackTrace();
+            throw new RuntimeException(e);
+        }
+    }
+    
+    public Map<Object, DataObject> getMappedDataObjects(List<DataObject> resultDataObjects,
List<String> keys) {
+    	Map<Object, DataObject> resultMap = new HashMap<Object, DataObject>();
+    	ArrayList<Object> keyCols = null;
+        for(int j=0; j<resultDataObjects.size(); j++) {
+        	DataObject currentDO = resultDataObjects.get(j);
+        	
+            keyCols = new ArrayList<Object>();
+        	for(int i=0; i<keys.size(); i++) {
+        		String currentKey = keys.get(i);
+        		Object currentKeyValue = currentDO.get(currentKey);
+        		keyCols.add(currentKeyValue);
+        	}
+        	
+        	resultMap.put(keyCols, currentDO);          	
+        }
+        return resultMap;
+    }
+    
+    public static List<String> getKeys(String key) {
+    	String[] keys = key.split(",");
+    	return Arrays.asList(keys);
+    }
+    
+    public DataObject executeCommand(String commandName) {
+        try {
+            Command command = this.das.getCommand(commandName);
+            return command.executeQuery();
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    public DataObject executeCommand(String commandName, String xPath) {
+        DataObject root = executeCommand(commandName);
+        return root.getDataObject(xPath);
+    }
+}

Added: incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngineManager.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngineManager.java?rev=610715&view=auto
==============================================================================
--- incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngineManager.java
(added)
+++ incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngineManager.java
Thu Jan 10 00:37:44 2008
@@ -0,0 +1,141 @@
+/*
+ * 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.data.engine;
+
+import java.io.InputStream;
+import java.util.List;
+
+import org.apache.tuscany.das.rdb.ConfigHelper;
+import org.apache.tuscany.das.rdb.DAS;
+import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper;
+import org.apache.tuscany.sca.data.engine.config.ConnectionInfo;
+
+/**
+ * The DataAccessEngineManager acts like a registry and factory for DAS instances
+ * It holds DAS by it's config file name, reusing the same DAS for all components 
+ * using the same config file.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class DataAccessEngineManager {
+    //private final Map<String, DAS> registry = new HashMap<String, DAS>();
+    
+    public DataAccessEngineManager() {
+        super();
+    }
+    
+    protected DAS initializeDAS(String config, ConnectionInfo connectionInfo, String table,
String pkColumns) throws MissingConfigFileException {
+        //load the config file
+        //System.out.println("Initializing DAS");
+        
+        ConfigHelper configHelper;
+        
+        if(config == null) {
+            //no config information
+            configHelper = new ConfigHelper();    
+        } else {
+            //initialize the config helper by loading config file
+            configHelper = new ConfigHelper(this.getConfigStream(config));
+        }
+        
+        //add additional connectionInfo if provided in the SCA Composite file
+        if( connectionInfo != null) {
+            String dataSource = connectionInfo.getDataSource();
+            if(dataSource != null && dataSource.length() > 0) {
+                configHelper.addConnectionInfo(dataSource);
+            } else {
+                String driverClass = connectionInfo.getConnectionProperties().getDriverClass();
+                String connectionURL = connectionInfo.getConnectionProperties().getDatabaseURL();
+                String userName = connectionInfo.getConnectionProperties().getUsername();
+                String password = connectionInfo.getConnectionProperties().getPassword();
+                int loginTimeout = connectionInfo.getConnectionProperties().getLoginTimeout();
+
+                configHelper.addConnectionInfo(driverClass, connectionURL, userName, password,
loginTimeout);
+            }
+            
+        }
+        
+        if(table != null && pkColumns != null) {
+            MappingWrapper configWrapper = new MappingWrapper(configHelper.getConfig());
+            List<String> pkColsList = DataAccessEngine.getKeys(pkColumns);
+            for(int i=0; i<pkColsList.size(); i++) {
+            	configWrapper.addPrimaryKey(table+"."+pkColsList.get(i), pkColsList.get(i));
+            }                	
+        }
+        
+        DAS das = DAS.FACTORY.createDAS(configHelper.getConfig());
+        
+        return das;    	
+    }
+    
+/*
+    public DAS getDAS(String config) throws MissingConfigFileException {
+        //DAS das = registry.get(config);
+        //if ( das == null) {
+        //    das = this.initializeDAS(config);
+        //    this.registry.put(config, das);
+        //}
+        return initializeDAS(config, null);
+    }
+
+    public DAS getDAS(ConnectionInfo connectionInfo) {
+        assert connectionInfo != null;
+        
+        //FIXME: cache the das, we need to define the keys to use (datasource and databaseurl
+ hashed(username + password))
+        DAS das = null;
+        try {
+            das =  initializeDAS(null, connectionInfo);
+        }catch (MissingConfigFileException e) {
+            //this should never happen, as configFile == null
+        }
+        
+        return das;
+    }
+*/
+    public DAS getDAS(String config, ConnectionInfo connectionInfo) throws MissingConfigFileException
{
+        assert connectionInfo != null;
+        
+        //FIXME: cache the das, we need to define the keys to use (datasource and databaseurl
+ hashed(username + password))
+        
+        return initializeDAS(config, connectionInfo, null, null);
+    }
+    
+    public DAS getDAS(String config, ConnectionInfo connectionInfo, String table, String
pkColumns) throws MissingConfigFileException {
+        assert connectionInfo != null;
+        
+        //FIXME: cache the das, we need to define the keys to use (datasource and databaseurl
+ hashed(username + password))
+        
+        return initializeDAS(config, connectionInfo, table, pkColumns);
+    }
+    
+    protected InputStream getConfigStream(String config) throws MissingConfigFileException{
+        InputStream configStream = null;
+        
+        try {
+            configStream = this.getClass().getClassLoader().getResourceAsStream(config);

+        } catch (Exception e) {
+            throw new MissingConfigFileException(config); 
+        }
+        
+        return configStream;
+    }
+    
+
+}

Added: incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/MissingConfigFileException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/MissingConfigFileException.java?rev=610715&view=auto
==============================================================================
--- incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/MissingConfigFileException.java
(added)
+++ incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/MissingConfigFileException.java
Thu Jan 10 00:37:44 2008
@@ -0,0 +1,44 @@
+/*
+ * 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.data.engine;
+
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+
+
+/**
+ * Exception to be used when DAS configuration side file is not available
+ * 
+ * @version $Rev$ $Date$
+ */
+public class MissingConfigFileException extends ContributionReadException {
+
+    private static final long serialVersionUID = -2616590185174691724L;
+
+    public MissingConfigFileException(String message) {
+        super(message);
+    }
+
+    public MissingConfigFileException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public MissingConfigFileException(Throwable cause) {
+        super(cause);
+    }
+}

Added: incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/config/ConnectionInfo.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/config/ConnectionInfo.java?rev=610715&view=auto
==============================================================================
--- incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/config/ConnectionInfo.java
(added)
+++ incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/config/ConnectionInfo.java
Thu Jan 10 00:37:44 2008
@@ -0,0 +1,47 @@
+/*
+ * 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.data.engine.config;
+
+/**
+ * Database connection information to be used for implementation.data
+ * 
+ * @version $Rev$ $Date$
+ */
+public class ConnectionInfo {
+    private ConnectionProperties connectionProperties;
+
+    private String dataSource;
+
+    public String getDataSource() {
+        return this.dataSource;
+    }
+
+    public void setDataSource(String dataSource) {
+        this.dataSource = dataSource;
+    }
+
+    public ConnectionProperties getConnectionProperties() {
+        return this.connectionProperties;
+    }
+
+    public void setConnectionProperties(ConnectionProperties connectionProperties) {
+        this.connectionProperties = connectionProperties;
+    }
+
+}

Added: incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/config/ConnectionProperties.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/config/ConnectionProperties.java?rev=610715&view=auto
==============================================================================
--- incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/config/ConnectionProperties.java
(added)
+++ incubator/tuscany/sandbox/amita/sca/modules/data-engine-helper/main/java/org/apache/tuscany/sca/data/engine/config/ConnectionProperties.java
Thu Jan 10 00:37:44 2008
@@ -0,0 +1,78 @@
+/*
+ * 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.data.engine.config;
+
+/**
+ * Database connection properties to be used for implementation.data
+ * 
+ * @version $Rev$ $Date$
+ */
+public class ConnectionProperties {
+
+    private String driverClass;
+
+    private String databaseURL;
+
+    private String userName;
+
+    private String password;
+
+    private Integer loginTimeOut;
+
+    public String getDriverClass() {
+        return this.driverClass;
+    }
+
+    public void setDriverClass(String driverClass) {
+        this.driverClass = driverClass;
+    }
+
+    public String getDatabaseURL() {
+        return this.databaseURL;
+    }
+
+    public void setDatabaseURL(String databaseURL) {
+        this.databaseURL = databaseURL;
+    }
+
+    public String getUsername() {
+        return this.userName;
+    }
+
+    public void setUsername(String userName) {
+        this.userName = userName;
+    }
+
+    public String getPassword() {
+        return this.password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public Integer getLoginTimeout() {
+        return this.loginTimeOut;
+    }
+
+    public void setLoginTimeout(Integer loginTimeOut) {
+        this.loginTimeOut = loginTimeOut;
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message