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 2007/03/16 09:10:16 UTC

svn commit: r518884 - in /incubator/tuscany/cpp/das/runtime/das_lite: ./ src/

Author: lresende
Date: Fri Mar 16 01:10:15 2007
New Revision: 518884

URL: http://svn.apache.org/viewvc?view=rev&rev=518884
Log:
TUSCANY-1140 - Applying Adriano Crestani's patch

Added:
    incubator/tuscany/cpp/das/runtime/das_lite/
    incubator/tuscany/cpp/das/runtime/das_lite/src/
    incubator/tuscany/cpp/das/runtime/das_lite/src/BaseCommandImpl.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/BaseCommandImpl.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/Command.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/CommandImpl.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/CommandImpl.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/ConnectionImpl.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/ConnectionImpl.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/DAS.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/DAS.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactory.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactory.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactoryImpl.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactoryImpl.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/DASImpl.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/DASImpl.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/Statement.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/Statement.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/das_constants.h

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/BaseCommandImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/BaseCommandImpl.cpp?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/BaseCommandImpl.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/BaseCommandImpl.cpp Fri Mar 16 01:10:15 2007
@@ -0,0 +1,30 @@
+/*
+ * 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.    
+ */
+#include "BaseCommandImpl.h"
+
+BaseCommandImpl::BaseCommandImpl(void) {}
+
+BaseCommandImpl::~BaseCommandImpl(void) {}
+
+void BaseCommandImpl::setConnection(HENV* env, HDBC* hdbc) {
+	setConnection(env, hdbc);
+}
+
+void BaseCommandImpl::setConnection(ConnectionImpl* c) {
+}

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/BaseCommandImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/BaseCommandImpl.h?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/BaseCommandImpl.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/BaseCommandImpl.h Fri Mar 16 01:10:15 2007
@@ -0,0 +1,37 @@
+/*
+ * 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.    
+ */
+#ifndef BASE_COMMAND_IMPL_H
+#define BASE_COMMAND_IMPL_H
+
+#include <windows.h>
+#include <sql.h>
+
+#include "ConnectionImpl.h"
+
+class BaseCommandImpl {
+
+	public:
+		BaseCommandImpl(void);
+		virtual ~BaseCommandImpl(void);
+		void setConnection(HENV* env, HDBC* hdbc);
+		virtual void setConnection(ConnectionImpl* c);
+		
+};
+
+#endif //BASE_COMMAND_IMPL_H

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/Command.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/Command.h?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Command.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Command.h Fri Mar 16 01:10:15 2007
@@ -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.    
+ */
+#ifndef COMMAND_H
+#define COMMAND_H
+
+#include "commonj/sdo/DataObject.h"
+
+#include <string>
+
+/**
+ * A Command is used to execute a read or write to a database
+ */
+virtual class Command {
+
+	public:
+
+		/**
+		 * Performs the function defined by the command
+		 */
+		//void execute(void);
+
+		/**
+		 * Performs the function defined by the command and return the results in the root DataObject
+		 * 
+		 * @return the root DataObject
+		 */
+		commonj::sdo::DataObjectPtr executeQuery(void);
+		
+};
+
+#endif //COMMAND_H

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/CommandImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/CommandImpl.cpp?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/CommandImpl.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/CommandImpl.cpp Fri Mar 16 01:10:15 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.    
+ */
+#include "CommandImpl.h"
+
+CommandImpl::CommandImpl(std::string sqlString) {
+	statement = new Statement(sqlString);
+
+    //try {
+        /*URL url = getClass().getResource("/xml/sdoJava.xsd");
+        if (url == null) {
+            //throw new RuntimeException("Could not find resource: xml/sdoJava.xsd");
+        }
+
+        InputStream inputStream = url.openStream();
+        XSDHelper.INSTANCE.define(inputStream, url.toString());
+        inputStream.close();*/
+    //} catch (IOException ex) {
+      //  throw new RuntimeException(ex);
+    //}
+
+}
+
+CommandImpl::~CommandImpl() {
+	delete statement;
+}
+
+void CommandImpl::setConnection(ConnectionImpl* connection) {
+	statement->setConnection(connection);
+}
+
+void CommandImpl::close(void) {
+	statement->close();
+}
+
+commonj::sdo::DataObjectPtr CommandImpl::executeQuery(void) {
+	return 0;
+}

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/CommandImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/CommandImpl.h?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/CommandImpl.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/CommandImpl.h Fri Mar 16 01:10:15 2007
@@ -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.    
+ */
+#ifndef COMMAND_IMPL_H
+#define COMMAND_IMPL_H
+
+#include <vector>
+
+#include "Command.h"
+#include "Statement.h"
+#include "ConnectionImpl.h"
+#include "BaseCommandImpl.h"
+
+#include "commonj/sdo/DataObject.h"
+
+class CommandImpl : public Command, public BaseCommandImpl {
+
+	protected:
+		Statement *statement;
+
+		ConnectionImpl* getConnection(void);
+
+	public:
+		CommandImpl(std::string sqlString);
+		virtual ~CommandImpl(void);
+		virtual commonj::sdo::DataObjectPtr executeQuery(void);
+		virtual void setConnection(ConnectionImpl* connection);
+		virtual void close(void);
+
+};
+
+#endif //COMMAND_IMPL_H

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/ConnectionImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/ConnectionImpl.cpp?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ConnectionImpl.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ConnectionImpl.cpp Fri Mar 16 01:10:15 2007
@@ -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.    
+ */
+#include "ConnectionImpl.h"
+
+ConnectionImpl::ConnectionImpl(HENV* aEnvironment, HDBC* aConnection) {
+	connection = aConnection;
+	environment = aEnvironment;
+
+   //try {
+		SQLCHAR sqlDbmsName[255];
+		SQLSMALLINT strLen;
+		SQLINTEGER strLen2;
+		SQLGetInfo(connection, SQL_DBMS_NAME, sqlDbmsName, sizeof(sqlDbmsName), &strLen);
+		std::string dbmsName = (char*) sqlDbmsName;
+
+        if (dbmsName.find("Oracle") < 0) {
+//            boolUseGetGeneratedKeys = false;
+        } else {
+  //          boolUseGetGeneratedKeys = true;
+        }
+
+		SQLSMALLINT autoCommit;
+		if (SQLGetConnectAttr(connection, SQL_ATTR_AUTOCOMMIT, &autoCommit, sizeof(autoCommit), &strLen2) == SQL_AUTOCOMMIT_ON) {
+            //throw new RuntimeException("AutoCommit must be off");
+        }
+
+//    } catch (SQLException e) {
+  //      throw new RuntimeException(e);
+    //}
+
+}
+
+ConnectionImpl::~ConnectionImpl(void) {
+}
+
+HDBC* ConnectionImpl::getODBCConnection(void) {
+	return connection;
+}
+
+void ConnectionImpl::cleanUp(void) {
+	SQLEndTran(SQL_HANDLE_DBC, connection, SQL_COMMIT);
+}
+
+void ConnectionImpl::errorCleanUp(void) {
+	SQLTransact(environment, connection, SQL_ROLLBACK);
+}
+
+HSTMT* ConnectionImpl::prepareStatement(std::string queryString) {
+
+	/*if (this.logger.isDebugEnabled()) {
+		this.logger.debug("Preparing Statement: " + queryString);
+	}*/
+	HSTMT statement;
+	SQLAllocStmt( connection, &statement);
+	SQLPrepare(statement, (SQLCHAR*) queryString.c_str(), SQL_NTS);
+	
+	return &statement;
+
+}

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/ConnectionImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/ConnectionImpl.h?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ConnectionImpl.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ConnectionImpl.h Fri Mar 16 01:10:15 2007
@@ -0,0 +1,43 @@
+/*
+ * 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.    
+ */
+#ifndef CONNECTION_IMPL_H
+#define CONNECTION_IMPL_H
+
+#include <windows.h>
+#include <sql.h>
+#include <sqlext.h>
+#include <string>
+
+class ConnectionImpl {
+
+	private:
+		HDBC* connection;
+		HENV* environment;
+		
+	public:
+		ConnectionImpl(HENV* aEnvironment, HDBC* aConnection);
+		virtual ~ConnectionImpl(void);
+		HDBC* getODBCConnection(void);
+		void cleanUp(void);
+		void errorCleanUp(void);
+		HSTMT* prepareStatement(std::string queryString);
+		
+};
+
+#endif //CONNECTION_IMPL_H

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/DAS.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/DAS.cpp?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/DAS.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/DAS.cpp Fri Mar 16 01:10:15 2007
@@ -0,0 +1,30 @@
+/*
+ * 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.    
+ */
+#include "DAS.h"
+#include "DASFactoryImpl.h"
+
+DASFactory* DAS::FACTORY = new DASFactoryImpl();
+
+DAS::DAS(void) {}
+
+DASFactory* DAS::getFACTORY(void) {
+	return FACTORY;
+}
+
+DAS::~DAS(void) {}

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/DAS.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/DAS.h?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/DAS.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/DAS.h Fri Mar 16 01:10:15 2007
@@ -0,0 +1,43 @@
+/*
+ * 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.    
+ */
+
+#ifndef D_A_S_H
+#define D_A_S_H
+
+#include "DASFactory.h"
+#include "Command.h"
+
+#include "commonj/sdo/DataObject.h"
+
+class DASFactory;
+
+class DAS {
+
+	private:
+		static DASFactory* FACTORY;
+
+	public:
+		static DASFactory* getFACTORY(void);
+
+		DAS(void);
+		virtual ~DAS(void);
+		
+};
+
+#endif //D_A_S_H

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactory.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactory.cpp?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactory.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactory.cpp Fri Mar 16 01:10:15 2007
@@ -0,0 +1,28 @@
+/*
+ * 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.    
+ */
+
+#include "DASFactory.h"
+
+DASFactory::DASFactory(void) {}
+
+DASFactory::~DASFactory(void) {}
+
+DAS* DASFactory::createDAS(HDBC* connection) {
+	return 0;
+}

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactory.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactory.h?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactory.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactory.h Fri Mar 16 01:10:15 2007
@@ -0,0 +1,39 @@
+/*
+ * 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.    
+ */
+#ifndef D_A_S_FACTORY_H
+#define D_A_S_FACTORY_H
+
+#include <windows.h>
+#include <sql.h>
+#include <string>
+
+#include "DAS.h"
+
+class DAS;
+
+virtual class DASFactory {
+
+	public:
+		DASFactory(void);
+		virtual ~DASFactory(void);
+		DAS* createDAS(HDBC* connection);
+
+};
+
+#endif //D_A_S_FACTORY_H

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactoryImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactoryImpl.cpp?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactoryImpl.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactoryImpl.cpp Fri Mar 16 01:10:15 2007
@@ -0,0 +1,27 @@
+/*
+ * 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.    
+ */
+#include "DASFactoryImpl.h"
+
+DASFactoryImpl::DASFactoryImpl(void) {}
+
+DASFactoryImpl::~DASFactoryImpl(void) {}
+
+DAS* DASFactoryImpl::createDAS(ConnectionImpl* connection) {
+	return new DASImpl(connection);
+}

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactoryImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactoryImpl.h?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactoryImpl.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/DASFactoryImpl.h Fri Mar 16 01:10:15 2007
@@ -0,0 +1,39 @@
+/*
+ * 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.    
+ */
+#ifndef D_A_S_FACTORY_IMPL_H
+#define D_A_S_FACTORY_IMPL_H
+
+#include <windows.h>
+#include <sql.h>
+#include <sqlext.h>
+
+#include "DAS.h"
+#include "DASImpl.h"
+#include "DASFactory.h"
+
+class DASFactoryImpl : public DASFactory {	
+
+	public:
+		DASFactoryImpl(void);
+		virtual ~DASFactoryImpl(void);
+		DAS* createDAS(ConnectionImpl* connection);
+
+};
+
+#endif //D_A_S_FACTORY_IMPL_H

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/DASImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/DASImpl.cpp?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/DASImpl.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/DASImpl.cpp Fri Mar 16 01:10:15 2007
@@ -0,0 +1,125 @@
+/*
+ * 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.    
+ */
+#include "DASImpl.h"
+
+void toLower(std::string str) {
+	int i;
+	int stringSize = str.size();
+
+	for (i = 0 ; i < stringSize ; i++) {
+		str[i] = tolower(str[i]);
+	}
+
+}
+
+void trim(std::string str) {
+	int stringSize = str.size();
+	int stringBegin = 0;
+	int stringEnd = str.size() - 1;
+	char actual = str[0];
+
+	while (actual != ' ') {
+		stringBegin++;
+		actual = str[stringBegin];
+
+	}
+
+	actual = str[stringEnd];
+	while (actual != ' ') {
+		stringEnd--;
+		actual = str[stringBegin];
+
+	}
+
+	int i;
+	int j = 0;
+	for (i = stringBegin ; i <= stringEnd ; i++) {
+		str[j] = str[i];
+		j++;
+
+	}
+
+	str[j] = 0;
+
+}
+
+DASImpl::DASImpl(ConnectionImpl* inConnection) {
+    setConnection(inConnection);
+}
+
+DASImpl::~DASImpl() {
+	std::list<Command*>::iterator it;
+
+	for (it = createdCommands.begin() ; it != createdCommands.end() ; it++) {
+		delete *it;
+	}
+
+	delete connection;
+
+}
+
+
+void DASImpl::setConnection(ConnectionImpl* aConnection) {
+	connection = aConnection;
+}
+
+ConnectionImpl* DASImpl::getConnection(void) {
+	return connection;
+}
+
+void DASImpl::releaseResources(void) {
+	closeConnection();
+}
+
+Command* DASImpl::createCommand(std::string sql) {
+	return baseCreateCommand(sql);
+}
+
+Command* DASImpl::baseCreateCommand(std::string inSql) {
+	CommandImpl* returnCmd = NULL;
+    trim(inSql); // Remove leading white space
+    char firstChar = toupper(inSql[0]);
+
+    switch (firstChar) {
+        case 'S':
+            returnCmd = new ReadCommandImpl(inSql);
+            break;
+     
+    }
+
+	returnCmd->setConnection(getConnection());
+	createdCommands.push_back(returnCmd);
+    return returnCmd;
+
+}
+
+void DASImpl::closeConnection(void) {
+	
+	if (connection != NULL) {
+
+        //try {
+            SQLDisconnect(connection);
+            connection = NULL;
+        //} catch (SQLException e) {
+          //  throw new RuntimeException(e);
+        //}
+
+    }
+
+}

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/DASImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/DASImpl.h?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/DASImpl.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/DASImpl.h Fri Mar 16 01:10:15 2007
@@ -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.    
+ */
+#ifndef D_A_S_IMPL_H
+#define D_A_S_IMPL_H
+
+#include <windows.h>
+#include <sql.h>
+#include <map>
+#include <string>
+#include <cctype>
+#include <list>
+
+#include "DAS.h"
+#include "Command.h"
+#include "ReadCommandImpl.h"
+
+#include "commonj/sdo/DataFactory.h"
+
+class DASImpl : public DAS {
+
+	private:
+		ConnectionImpl* connection;
+		std::list<Command*> createdCommands;
+		
+		Command* baseCreateCommand(std::string inSql);
+		
+	public:
+		DASImpl(ConnectionImpl* inConnection);
+		virtual ~DASImpl(void);
+		ConnectionImpl* getConnection(void);
+		void setConnection(ConnectionImpl* aConnection);
+		void releaseResources(void);
+		Command* createCommand(std::string sql);
+		void closeConnection(void);
+		
+};
+
+#endif //D_A_S_IMPL_H

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.cpp?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.cpp Fri Mar 16 01:10:15 2007
@@ -0,0 +1,179 @@
+/*
+ * 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.    
+ */
+#include "ReadCommandImpl.h"
+
+
+int getColumnCount(HSTMT statement) {
+	SQLINTEGER columnCount = 0;
+	SQLRETURN ret = SQLColAttribute(statement, NULL, SQL_DESC_COUNT, NULL, NULL, NULL, &columnCount);
+	
+	return columnCount;
+
+}
+
+std::string getColumnName(HSTMT statement, int column) {
+	SQLCHAR* sqlPtr = 0;
+	char strAux[1];
+	SQLSMALLINT length = 0;
+	SQLColAttributeA(statement, column, SQL_DESC_BASE_COLUMN_NAME, &strAux, 1, (SQLSMALLINT*) &length, NULL);
+	length++;
+	sqlPtr = (SQLCHAR*) new char(length);
+	SQLColAttributeA(statement, column, SQL_DESC_BASE_COLUMN_NAME, sqlPtr, length, (SQLSMALLINT*) &length, NULL);
+
+	std::string ret((char*) sqlPtr);
+	return ret;
+
+}
+
+std::string getStringData(HSTMT statement, int column) {
+	SQLPOINTER sqlPtr = 0;
+	SQLCHAR strAux[1];
+	SQLINTEGER length = 0;
+	SQLGetData(statement, column, SQL_C_CHAR, &strAux, 1, &length);
+	length++;
+	sqlPtr = (SQLCHAR*) malloc(length*sizeof(SQLCHAR));
+	SQLINTEGER aux = 0;
+	SQLGetData(statement, column, SQL_C_CHAR, sqlPtr, length, &aux);
+		
+	std::string ret = (char*) sqlPtr;
+	return ret;
+
+}
+
+int getIntegerData(HSTMT statement, int column) {
+	SQLCHAR strAux[1];
+	SQLINTEGER sqlPtr = 0;
+	SQLSMALLINT length = 0;
+	SQLINTEGER aux = 0;
+	SQLGetData(statement, column, SQL_C_ULONG, &sqlPtr, 0, &aux);
+		
+	return (int) sqlPtr;
+
+}
+
+int getSQLColumnType(HSTMT statement, int column) {
+	SQLSMALLINT sqlType = 0;
+	SQLColAttribute(statement, column, SQL_DESC_TYPE, NULL, NULL, NULL, &sqlType);
+		
+	return (int) sqlType;
+
+}
+
+
+ReadCommandImpl::ReadCommandImpl(std::string sqlString) : CommandImpl(sqlString) {}
+
+ReadCommandImpl::~ReadCommandImpl(void) {}
+
+commonj::sdo::DataObjectPtr ReadCommandImpl::executeQuery(void) {
+
+	if (statement->getConnection() == NULL) {
+		//throw new RuntimeException("A DASConnection object must be specified before executing the query.");
+    }
+
+    int success = 0;
+
+    //try {
+        HSTMT& results = statement->executeQuery();
+        success = 1;
+
+        return buildGraph(results);
+
+    //} catch (SQLException e) {
+      //  throw new RuntimeException(e);
+    //} finally {
+        if (success) {
+            statement->getConnection()->cleanUp();
+        } else {
+            statement->getConnection()->errorCleanUp();
+        }
+    //}
+}
+
+commonj::sdo::DataObjectPtr ReadCommandImpl::buildGraph(HSTMT& statement) { /*throws SQLException*/
+	commonj::sdo::DataFactoryPtr dataFactory = commonj::sdo::DataFactory::getDataFactory();
+	
+	int columnCount = getColumnCount(statement);
+	int col;
+	int i;
+	SQLSMALLINT sqlType = 0;
+	std::list<SQLSMALLINT> columnTypes;
+	std::string columnName;
+
+	dataFactory->addType(DAS_NAMESPACE, DAS_ROOT);
+	const commonj::sdo::Type& type = dataFactory->getType(DAS_NAMESPACE, DAS_ROOT);
+	const commonj::sdo::Type& typeInt = dataFactory->getType("commonj.sdo","Integer");
+	std::string str1 = "adriano";
+	str1 = "crestani";
+	int t = -1;
+	
+	for (col = 1 ; col <= columnCount ; col++) {
+		sqlType = getSQLColumnType(statement, col);
+		columnName = getColumnName(statement, col);
+		columnTypes.push_back(sqlType);
+		std::string aux = getColumnName(statement, col);
+		//std::string* aux = new std::string();
+
+	t = -1;
+		//if (sqlType == SQL_INTEGER) {
+			dataFactory->addPropertyToType(type, aux, typeInt);
+			t = type.getProperties().size();
+		//} else if (sqlType == SQL_CHAR) {
+		//	dataFactory->addPropertyToType(DAS_NAMESPACE, DAS_ROOT, columnName, commonj::sdo::Type::SDOTypeNamespaceURI, "String", false);
+		//	t = dataFactory->getType(DAS_NAMESPACE, DAS_ROOT).getProperties().size();
+		//}
+//			delete aux;
+		
+	}
+
+	int m;
+	commonj::sdo::PropertyList list = type.getProperties();
+	for (m = 0 ; m < list.size() ; m++) {
+		std::string aux = list[m].getName();
+	}
+
+	commonj::sdo::DataObjectPtr rootDataObject = dataFactory->create(DAS_NAMESPACE, DAS_ROOT);
+	SQLRETURN sqlRet = SQLFetch(statement);
+	t = dataFactory->getType(DAS_NAMESPACE, DAS_ROOT).getProperties().size();
+	while (sqlRet == SQL_SUCCESS) {
+		std::list<SQLSMALLINT>::iterator it = columnTypes.begin();
+		int col = 0;
+
+		while (it != columnTypes.end()) {
+			SQLSMALLINT sqlType = *it;
+
+			if (sqlType == SQL_INTEGER) {
+				rootDataObject->setInteger(col + 1, getIntegerData(statement, col + 1));
+
+			} else if (sqlType == SQL_CHAR) {
+				rootDataObject->setCString(col + 1, getStringData(statement, col + 1));
+			}
+
+			sqlRet = SQLFetch(statement);
+			col++;
+			it++;
+	
+		}
+
+	}
+
+	commonj::sdo::ChangeSummaryPtr changeSummary = rootDataObject->getChangeSummary();
+	
+	return rootDataObject;
+
+}

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.h?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.h Fri Mar 16 01:10:15 2007
@@ -0,0 +1,49 @@
+/*
+ * 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.    
+ */
+#ifndef READ_COMMAND_IMPL_H
+#define READ_COMMAND_IMPL_H
+
+#include <vector>
+#include <list>
+
+#include "CommandImpl.h"
+
+#include "commonj/sdo/DataFactory.h"
+#include "commonj/sdo/DataObject.h"
+
+#include "das_constants.h"
+
+class ReadCommandImpl : public CommandImpl {
+
+	private:
+		unsigned int startRow;
+		unsigned int endRow;
+
+	protected:
+		public:
+		commonj::sdo::DataObjectPtr buildGraph(HSTMT& statement); /*throws SQLException*/
+		
+	
+		ReadCommandImpl(std::string sqlString);
+		~ReadCommandImpl(void);
+		commonj::sdo::DataObjectPtr executeQuery(void);
+
+};
+
+#endif //READ_COMMAND_IMPL_H

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/Statement.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/Statement.cpp?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Statement.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Statement.cpp Fri Mar 16 01:10:15 2007
@@ -0,0 +1,41 @@
+/*
+ * 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.    
+ */
+#include "Statement.h"
+
+Statement::Statement(std::string sqlString) {
+	queryString = sqlString;	
+}
+
+Statement::~Statement(void) {
+}
+
+HSTMT& Statement::executeQuery(void) { /*throws SQLException*/
+    return *(new HSTMT);
+}
+
+void Statement::setConnection(ConnectionImpl* connection) {
+}
+
+ConnectionImpl* Statement::getConnection(void) {
+	return connection;
+}
+
+void Statement::close(void) {
+
+}

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/Statement.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/Statement.h?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Statement.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Statement.h Fri Mar 16 01:10:15 2007
@@ -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.    
+ */
+#ifndef STATEMENT_H
+#define STATEMENT_H
+
+#include <list>
+#include <windows.h>
+#include <sql.h>
+
+#include "ConnectionImpl.h"
+
+class Statement {
+	
+	private:
+		HSTMT preparedStatement;
+		
+	protected:
+		std::string queryString;
+		ConnectionImpl* connection;
+		
+	public:
+		Statement(std::string sqlString);
+		~Statement(void);
+		HSTMT& executeQuery(); /*throws SQLException*/
+		void setConnection(ConnectionImpl* jdbcConnection);
+		ConnectionImpl* getConnection(void);
+		void close(void);
+		
+};
+
+#endif //STATEMENT_H

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/das_constants.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/das_constants.h?view=auto&rev=518884
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/das_constants.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/das_constants.h Fri Mar 16 01:10:15 2007
@@ -0,0 +1,2 @@
+#define DAS_ROOT "DAS_ROOT"
+#define DAS_NAMESPACE "das.lite"



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