You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ad...@apache.org on 2007/05/07 10:13:43 UTC

svn commit: r535777 - in /incubator/tuscany/cpp/das: VSExpress/tuscany_das/das_lite/ VSExpress/tuscany_das/das_runtime/ runtime/das_lite/src/ runtime/das_lite/src/das/

Author: adrianocrestani
Date: Mon May  7 01:13:37 2007
New Revision: 535777

URL: http://svn.apache.org/viewvc?view=rev&rev=535777
Log:
- fixed deleted objects bug
- added a object reference control

Added:
    incubator/tuscany/cpp/das/runtime/das_lite/src/NullPointerException.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/NullPointerException.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/RelationshipWrapper.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/RelationshipWrapper.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/das/
    incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingObject.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingObject.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingPointer.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingPointer.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/das/Statement.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/das/Statement.h
Removed:
    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/Statement.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/Statement.h
Modified:
    incubator/tuscany/cpp/das/VSExpress/tuscany_das/das_lite/das_lite.vcproj
    incubator/tuscany/cpp/das/VSExpress/tuscany_das/das_runtime/das_runtime.suo
    incubator/tuscany/cpp/das/runtime/das_lite/src/Column.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/Column.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.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/Config.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/Config.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/Connection.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/Connection.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/Database.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/Database.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilder.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilder.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilderMetaData.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilderMetaData.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/PreparedStatement.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/PreparedStatement.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/ResultSet.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSet.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSetMetaData.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/Table.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/Table.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.h

Modified: incubator/tuscany/cpp/das/VSExpress/tuscany_das/das_lite/das_lite.vcproj
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/VSExpress/tuscany_das/das_lite/das_lite.vcproj?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/VSExpress/tuscany_das/das_lite/das_lite.vcproj (original)
+++ incubator/tuscany/cpp/das/VSExpress/tuscany_das/das_lite/das_lite.vcproj Mon May  7 01:13:37 2007
@@ -143,10 +143,6 @@
 			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
 			>
 			<File
-				RelativePath="..\..\..\runtime\das_lite\src\BaseCommandImpl.h"
-				>
-			</File>
-			<File
 				RelativePath="..\..\..\runtime\das_lite\src\Column.h"
 				>
 			</File>
@@ -207,6 +203,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\..\runtime\das_lite\src\NullPointerException.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\..\runtime\das_lite\src\ODBCTypeHelper.h"
 				>
 			</File>
@@ -219,10 +219,22 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\..\runtime\das_lite\src\das\RefCountingObject.h"
+				>
+			</File>
+			<File
+				RelativePath="..\..\..\runtime\das_lite\src\das\RefCountingPointer.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\..\runtime\das_lite\src\Relationship.h"
 				>
 			</File>
 			<File
+				RelativePath="..\..\..\runtime\das_lite\src\RelationshipWrapper.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\..\runtime\das_lite\src\ResultSet.h"
 				>
 			</File>
@@ -235,7 +247,7 @@
 				>
 			</File>
 			<File
-				RelativePath="..\..\..\runtime\das_lite\src\Statement.h"
+				RelativePath="..\..\..\runtime\das_lite\src\das\Statement.h"
 				>
 			</File>
 			<File
@@ -259,10 +271,6 @@
 			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
 			>
 			<File
-				RelativePath="..\..\..\runtime\das_lite\src\BaseCommandImpl.cpp"
-				>
-			</File>
-			<File
 				RelativePath="..\..\..\runtime\das_lite\src\Column.cpp"
 				>
 			</File>
@@ -315,6 +323,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\..\runtime\das_lite\src\NullPointerException.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\..\runtime\das_lite\src\ODBCTypeHelper.cpp"
 				>
 			</File>
@@ -327,10 +339,22 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\..\runtime\das_lite\src\das\RefCountingObject.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\..\..\runtime\das_lite\src\das\RefCountingPointer.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\..\runtime\das_lite\src\Relationship.cpp"
 				>
 			</File>
 			<File
+				RelativePath="..\..\..\runtime\das_lite\src\RelationshipWrapper.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\..\runtime\das_lite\src\ResultSet.cpp"
 				>
 			</File>
@@ -343,7 +367,7 @@
 				>
 			</File>
 			<File
-				RelativePath="..\..\..\runtime\das_lite\src\Statement.cpp"
+				RelativePath="..\..\..\runtime\das_lite\src\das\Statement.cpp"
 				>
 			</File>
 			<File

Modified: incubator/tuscany/cpp/das/VSExpress/tuscany_das/das_runtime/das_runtime.suo
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/VSExpress/tuscany_das/das_runtime/das_runtime.suo?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
Binary files - no diff available.

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/Column.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/Column.cpp?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Column.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Column.cpp Mon May  7 01:13:37 2007
@@ -73,7 +73,7 @@
 void Column::addKeyPair(KeyPair& keyPair) {
 
 	if (keyPairs == 0) {
-		keyPairs= new std::list<KeyPair*>();
+		keyPairs = new std::list<KeyPair*>();
 	}
 
 	keyPairs->push_back(&keyPair);

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/Column.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/Column.h?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Column.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Column.h Mon May  7 01:13:37 2007
@@ -28,6 +28,8 @@
 #include "Table.h"
 #include "das_constants.h"
 
+class KeyPair;
+
 class Column {
 
 	friend class Table;

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.cpp?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.cpp Mon May  7 01:13:37 2007
@@ -18,86 +18,79 @@
  */
 #include "ColumnData.h"
 
-ColumnData::ColumnData(Column& column, ResultSet& resultSet, commonj::sdo::DataObjectPtr dataObjectContainer) {
+ColumnData::ColumnData(Column& column, ResultSetPtr resultSet) {
 	this->column = &column;
 
 	switch (column.getSQLType()) {
 
 		case SQL_INTEGER :
 			{
-				long sqlInteger = resultSet.getSQLInteger(
+				long sqlInteger = resultSet->getSQLInteger(
 					column.getContainerTable()->getTableName(), column.getName());
 				
-				data = new int;
-				int* aux = (int*) data;
+				data = new long;
+				long* aux = (long*) data;
 				*aux = sqlInteger;
-				dataObjectContainer->setInteger(column.getName().c_str(), sqlInteger);
 			}
 
 			break;
 
 		case SQL_CHAR :	
 			{
-				wchar_t sqlChar = resultSet.getSQLChar(column.getContainerTable()->getTableName(), 
+				wchar_t sqlChar = resultSet->getSQLChar(column.getContainerTable()->getTableName(), 
 					column.getName());
 
 				data = new wchar_t;
 				wchar_t* aux = (wchar_t*) data;
 				*aux= sqlChar;
-				dataObjectContainer->setCharacter(column.getName().c_str(), sqlChar);
 			}
 
 			break;
 
 		case SQL_DOUBLE :
 			{
-				double sqlDouble = resultSet.getSQLDouble(column.getContainerTable()->getTableName(), 
+				double sqlDouble = resultSet->getSQLDouble(column.getContainerTable()->getTableName(), 
 					column.getName());
 
 				data = new double;
 				double* aux = (double*) data;
 				*aux = sqlDouble;
-				dataObjectContainer->setDouble(column.getName().c_str(), sqlDouble);
 			}
 
 			break;
 
 		case SQL_FLOAT :
 			{
-				double sqlFloat = resultSet.getSQLFloat(column.getContainerTable()->getTableName(), 
+				double sqlFloat = resultSet->getSQLFloat(column.getContainerTable()->getTableName(), 
 					column.getName());
 
 				data = new double;
 				double* aux = (double*) data;
 				*aux = sqlFloat;
-				dataObjectContainer->setDouble(column.getName().c_str(), sqlFloat);
 			}
 
 			break;
 
 		case SQL_REAL :
 			{
-				float sqlReal = resultSet.getSQLReal(column.getContainerTable()->getTableName(), 
+				float sqlReal = resultSet->getSQLReal(column.getContainerTable()->getTableName(), 
 				column.getName());
 
 				data = new float;
 				float* aux = (float*) data;
 				*aux = sqlReal;
-				dataObjectContainer->setFloat(column.getName().c_str(), sqlReal);
 			}
 
 			break;
 
 		case SQL_VARCHAR :
 			{
-				std::string varchar = resultSet.getSQLVarchar(column.getContainerTable()->getTableName(),
+				std::string varchar = resultSet->getSQLVarchar(column.getContainerTable()->getTableName(),
 					column.getName());
 
 				data = new std::wstring(varchar.begin(), varchar.end());
 				std::wstring* aux = (std::wstring*) data;
 				(*aux).assign(varchar.begin(), varchar.end());
-				
-				dataObjectContainer->setString(column.getName().c_str(), (*aux).c_str(), varchar.size());
 			}
 
 			break;
@@ -111,6 +104,51 @@
 
 ColumnData::~ColumnData(void) {
 	delete data;
+}
+
+void ColumnData::populateDataGraph(TableData& tableData) const {
+
+	switch (column->getSQLType()) {
+
+		case SQL_INTEGER :
+			tableData.getGraphObject()->setInteger(column->getName().c_str(), *((long*) data));
+
+			break;
+
+		case SQL_CHAR :	
+			tableData.getGraphObject()->setCharacter(column->getName().c_str(), *((wchar_t*) data));
+
+			break;
+
+		case SQL_DOUBLE :
+			tableData.getGraphObject()->setDouble(column->getName().c_str(), *((double*) data));
+
+			break;
+
+		case SQL_FLOAT :
+			tableData.getGraphObject()->setDouble(column->getName().c_str(), *((double*) data));
+			
+			break;
+
+		case SQL_REAL :
+			tableData.getGraphObject()->setFloat(column->getName().c_str(), *((float*) data));
+			
+			break;
+
+		case SQL_VARCHAR :
+			{
+				std::wstring* varchar = (std::wstring*) data;
+				tableData.getGraphObject()->setString(column->getName().c_str(), 
+					(*varchar).c_str(), (*varchar).size());
+			}
+
+			break;
+		
+		default :
+			throw std::logic_error("Invalid sql type!");
+
+	}
+
 }
 
 bool ColumnData::operator==(ColumnData& columnData) const {

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.h?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.h Mon May  7 01:13:37 2007
@@ -25,9 +25,12 @@
 #include <string>
 
 #include "Column.h"
+#include "TableData.h"
 
 #include "commonj/sdo/DataObject.h"
 
+class TableData;
+
 class ColumnData {
 
 	private:
@@ -35,11 +38,13 @@
 		void* data;
 
 	public:
-		ColumnData(Column& column, ResultSet& resultSet, commonj::sdo::DataObjectPtr dataObjectContainer);
+		ColumnData(Column& column, ResultSetPtr resultSet);
 		virtual ~ColumnData(void);
 
 		bool operator==(ColumnData& columnData) const;
 		bool operator!=(ColumnData& columnData) const;
+
+		void populateDataGraph(TableData& tableData) const;
 
 };
 

Modified: 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=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/CommandImpl.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/CommandImpl.cpp Mon May  7 01:13:37 2007
@@ -18,9 +18,9 @@
  */
 #include "CommandImpl.h"
 
-CommandImpl::CommandImpl(DAS& das, std::string sqlString) {
+CommandImpl::CommandImpl(DASImpl& das, std::string sqlString) {
 	this->das = &das;
-	statement = &(((DASImpl&) das).getConnection()->createStatement());
+	statement = das.getConnection()->createStatement();
 	sql = sqlString;
 	
 	//statement = new Statement();
@@ -40,8 +40,10 @@
 
 }
 
-CommandImpl::~CommandImpl() {
-	delete statement;
+CommandImpl::~CommandImpl() {}
+
+DASImpl& CommandImpl::getDAS(void) {
+	return *das;
 }
 
 void CommandImpl::close(void) {

Modified: 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=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/CommandImpl.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/CommandImpl.h Mon May  7 01:13:37 2007
@@ -24,27 +24,24 @@
 #include "Command.h"
 #include "DAS.h"
 #include "DASImpl.h"
-#include "Statement.h"
 #include "Connection.h"
-#include "BaseCommandImpl.h"
 
 #include "commonj/sdo/DataObject.h"
 
 class DASImpl;
 
-class CommandImpl : public Command, public BaseCommandImpl {
+class CommandImpl : public Command {
 
 	protected:
-		DAS* das;
+		DASImpl* das;
 		std::string sql;
-		Statement *statement;
-
-		Connection* getConnection(void);
+		StatementPtr statement;
 		
 	public:
-		CommandImpl(DAS& das, std::string sqlString);
+		CommandImpl(DASImpl& das, std::string sqlString);
 		virtual ~CommandImpl(void);
 		virtual commonj::sdo::DataObjectPtr executeQuery(void) = 0;
+		virtual DASImpl& getDAS(void);
 		virtual void close(void);
 
 };

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/Config.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/Config.cpp?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Config.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Config.cpp Mon May  7 01:13:37 2007
@@ -36,7 +36,7 @@
 	}
 	
 	for (relationshipIterator = relationships->begin() ; 
-		relationshipIterator != relationships->end() ; tableIterator++) {
+		relationshipIterator != relationships->end() ; relationshipIterator++) {
 			delete relationshipIterator->second;
 	}
 
@@ -47,7 +47,8 @@
 
 
 void Config::addTable(Table& table) {
-	std::list<Relationship*>* relationships = getRelationships(table.getTableName());
+	std::list<Relationship*>* relationships = RelationshipWrapper::
+		getRelationships(*this->relationships, table.getTableName());
 	std::list<Relationship*>::iterator it;
 
 	for (it = relationships->begin() ; it != relationships->end() ; it++) {
@@ -125,32 +126,6 @@
 	if (table != 0) {
 		table->addRelationship(relationship);
 	}
-
-}
-
-std::list<Relationship*>* Config::getRelationships(std::string tableName, bool pkTable) const {
-	std::list<Relationship*>* relationshipList = new std::list<Relationship*>();
-	std::map<std::string, Relationship*>::const_iterator it;
-
-	for (it = relationships->begin() ; it != relationships->end() ; it++) {
-		
-		if (pkTable) {
-
-			if (it->second->getPKTableName() == tableName) {
-				relationshipList->push_back(it->second);
-			}
-
-		} else {
-
-			if (it->second->getFKTableName() == tableName) {
-				relationshipList->push_back(it->second);
-			}
-
-		}
-
-	}
-
-	return relationshipList;
 
 }
 

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/Config.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/Config.h?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Config.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Config.h Mon May  7 01:13:37 2007
@@ -26,6 +26,7 @@
 #include "Table.h"
 #include "Column.h"
 #include "Relationship.h"
+#include "RelationshipWrapper.h"
 
 class Table;
 class Column;
@@ -54,7 +55,6 @@
 		void loadConvOverConfigFKs(std::list<Column*>& columns);
 		Table* getTable(std::string tableName) const;
 		Relationship* getRelationship(std::string tableName, std::string referencedTableName) const;
-		std::list<Relationship*>* getRelationships(std::string tableName, bool pkTable = true) const;
 		
 };
 		

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/Connection.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/Connection.cpp?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Connection.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Connection.cpp Mon May  7 01:13:37 2007
@@ -77,17 +77,23 @@
 }
 
 Connection::~Connection(void){
+	std::list<StatementPtr>::iterator it;
 
-	std::list<Statement*>::iterator it;
+	for (it = statements.begin() ; it != statements.end() ; it++) {
+		
+		if (*it) {
+			delete *it;
 
-	for(it=statements.begin(); it != statements.end(); it++)
-		delete *it;
+		}
+
+	}
 
 	delete database;
 
 	SQLDisconnect(connection);
     SQLFreeHandle(SQL_HANDLE_DBC,connection);
     SQLFreeHandle(SQL_HANDLE_ENV, environment);
+
 }
 
 SQLHDBC Connection::getODBCConnection(void) const{
@@ -113,7 +119,7 @@
 	return *database;
 }
 
-Statement& Connection::createStatement(void) throw (SqlException){
+StatementPtr Connection::createStatement(void) throw (SqlException){
 	SQLHSTMT statementHandle;
 	SQLRETURN result = SQLAllocHandle(SQL_HANDLE_STMT, connection, &statementHandle);
 
@@ -126,18 +132,26 @@
 		throw SqlException("Error to alloc the statement handle - SQLSTMT");
 	}
 
-	Statement* statement = new Statement(*this, statementHandle);
-	statements.push_back(statement);
+	std::list<StatementPtr>::iterator it;
 
-	return *statement;
+	for (it = statements.begin() ; it != statements.end() ; ) {
+		
+		if (*it) {
+			it++;
+
+		} else {
+			std::list<StatementPtr>::iterator aux = it;
+			it++;
+			statements.erase(aux);
 
-}
+		}
 
-void Connection::freeStatement(Statement& statement){
-	std::list<Statement*>::iterator it;
+	}
+
+	das::Statement* stmt = new das::Statement(statementHandle);
+	statements.push_back(*(new StatementPtr(stmt, false)));
 
-	it = std::find(statements.begin(), statements.end(), &statement);
+	return stmt;
 
-	if(it != statements.end() )
-		statements.erase(it);
 }
+

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/Connection.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/Connection.h?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Connection.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Connection.h Mon May  7 01:13:37 2007
@@ -28,26 +28,21 @@
 #include <iostream>
 #include <algorithm>
 
-#include "Statement.h"
 #include "Database.h"
 #include "SqlException.h"
+#include "das/Statement.h"
 
 using std::string;
 using std::exception;
 class Database;
-class Statement;
 
 class Connection {
-	
-	friend class Statement;
 
 	private:
 		SQLHDBC connection;
 		SQLHENV environment;
 		Database* database;
-		std::list<Statement*> statements;
-
-		void freeStatement(Statement& statement);
+		std::list<StatementPtr> statements;
 		
 	public:
 		Connection(string dns, string user, string password) throw (SqlException);
@@ -57,7 +52,7 @@
 		void rollback(void);
 		void setAutoCommit(bool autoCommit);
 		Database& getDatabase(void) const;
-		Statement& createStatement(void) throw (exception);
+		StatementPtr createStatement(void) throw (exception);
 		//PreparedStatement& prepareStatement(string sql);
 		
 };

Modified: 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=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/DASImpl.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/DASImpl.cpp Mon May  7 01:13:37 2007
@@ -19,48 +19,8 @@
 #include "DASImpl.h"
 #include "ReadCommandImpl.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(Connection& inConnection) {
+	createdCommands = new std::list<Command*>();
     setConnection(&inConnection);
 	config = new Config(*this);
 
@@ -69,11 +29,12 @@
 DASImpl::~DASImpl() {
 	std::list<Command*>::iterator it;
 
-	for (it = createdCommands.begin() ; it != createdCommands.end() ; it++) {
+	for (it = createdCommands->begin() ; it != createdCommands->end() ; it++) {
 		delete *it;
 	}
 
-	delete connection;
+	delete createdCommands;
+	delete config;
 
 }
 
@@ -90,13 +51,13 @@
 	closeConnection();
 }
 
-Command* DASImpl::createCommand(std::string sql) {
+Command& DASImpl::createCommand(std::string sql) {
 	return baseCreateCommand(sql);
 }
 
-Command* DASImpl::baseCreateCommand(std::string inSql) {
+Command& DASImpl::baseCreateCommand(std::string inSql) {
 	CommandImpl* returnCmd = NULL;
-    trim(inSql); // Remove leading white space
+    //trim(inSql);
     char firstChar = toupper(inSql[0]);
 
     switch (firstChar) {
@@ -106,9 +67,8 @@
      
     }
 
-	returnCmd->setConnection(getConnection());
-	createdCommands.push_back(returnCmd);
-    return returnCmd;
+	createdCommands->push_back(returnCmd);
+    return *returnCmd;
 
 }
 

Modified: 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=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/DASImpl.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/DASImpl.h Mon May  7 01:13:37 2007
@@ -41,10 +41,10 @@
 
 	private:
 		Connection* connection;
-		std::list<Command*> createdCommands;
+		std::list<Command*>* createdCommands;
 		Config* config;
 		
-		Command* baseCreateCommand(std::string inSql);
+		Command& baseCreateCommand(std::string inSql);
 		
 	public:
 		DASImpl(Connection& inConnection);
@@ -53,7 +53,7 @@
 		Config& getConfig(void) const;
 		void setConnection(Connection* aConnection);
 		void releaseResources(void);
-		Command* createCommand(std::string sql);
+		Command& createCommand(std::string sql);
 		void closeConnection(void);
 		
 };

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/Database.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/Database.cpp?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Database.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Database.cpp Mon May  7 01:13:37 2007
@@ -25,16 +25,16 @@
 Database::~Database(void) {}
 
 ResultSet* Database::getPKs(std::string tableName) const {
-	Statement& statement = connection->createStatement();
-	SQLPrimaryKeysA(statement.getODBCStatement(), 0,0,0,0, (SQLCHAR*) (char*) tableName.c_str(), tableName.size());
+	StatementPtr statement = connection->createStatement();
+	SQLPrimaryKeysA(statement->getODBCStatement(), 0,0,0,0, (SQLCHAR*) (char*) tableName.c_str(), tableName.size());
 
 	return new ResultSet(statement);
 	
 }
 
 ResultSet* Database::getFKs(std::string tableName) const {
-	Statement& statement = connection->createStatement();
-	SQLForeignKeysA(statement.getODBCStatement(), 0,0,0,0,0,0, 0,0,0,0,(SQLCHAR*) (char*) tableName.c_str(), tableName.size());
+	StatementPtr statement = connection->createStatement();
+	SQLForeignKeysA(statement->getODBCStatement(), 0,0,0,0,0,0, 0,0,0,0,(SQLCHAR*) (char*) tableName.c_str(), tableName.size());
 
 	return new ResultSet(statement);
 

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/Database.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/Database.h?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Database.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Database.h Mon May  7 01:13:37 2007
@@ -24,9 +24,7 @@
 #include <sqlext.h>
 #include <string>
 
-#include "Connection.h"
-#include "ResultSet.h"
-#include "Statement.h"
+#include "das/Statement.h"
 
 class Connection;
 class ResultSet;

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilder.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilder.cpp?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilder.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilder.cpp Mon May  7 01:13:37 2007
@@ -154,24 +154,22 @@
 
 }
 
-GraphBuilder::GraphBuilder(Config& config, ResultSet& resultSet) {
-	graphBuilderMetaData = new GraphBuilderMetaData(config, resultSet.getResultSetMetaData()) ;
+GraphBuilder::GraphBuilder(Config& config, ResultSetPtr resultSet) {
+	graphBuilderMetaData = new GraphBuilderMetaData(config, resultSet->getResultSetMetaData()) ;
 	commonj::sdo::DataFactoryPtr dataFactory = graphBuilderMetaData->createGraph();
 
 	printDataGraphMetaData(dataFactory);
-	this->resultSet = &resultSet;
+	this->resultSet = resultSet;
+	const std::map<std::string, Table*> tables = graphBuilderMetaData->getTables();
 	
-	root = dataFactory->create(DAS_NAMESPACE, DAS_ROOT_NAME);
+	while (resultSet->next()) {
 	
-	const std::map<std::string, Table*> tables = graphBuilderMetaData->getTables();
-	std::map<std::string, Table*>::const_iterator it;
-	while (resultSet.next()) {
-
+		std::map<std::string, Table*>::const_iterator it;
 		for (it = tables.begin() ; it != tables.end() ; it++) {
 			Table* table = it->second;
 			
 			std::list<TableData*>* tableList;
-			TableData* tableData = new TableData(*table, *this, resultSet);
+			TableData* tableData = new TableData(*table, resultSet);
 
 			if (!tableData->hasPK()) {
 				delete tableData;
@@ -190,22 +188,41 @@
 			}
 
 			std::list<TableData*>::const_iterator it3;
+			bool duplicated = false;
 
 			for (it3 = tableList->begin() ; it3 != tableList->end() ; it3++) {
 
 				if (*tableData == **it3) {
 					delete tableData;
-					continue;
+					duplicated = true;
+					break;
 
 				}
 
 			}
 
-			tableList->push_back(tableData);
+			if (!duplicated) {
+				tableList->push_back(tableData);
+			}
 			
 		}
 
 	}
+
+	root = dataFactory->create(DAS_NAMESPACE, DAS_ROOT_NAME);
+	std::map<std::string, std::list<TableData*>*>::iterator it;
+
+	for (it = tablesData.begin() ; it != tablesData.end() ; it++) {
+		std::list<TableData*>& tableList = *it->second;
+		std::list<TableData*>::iterator it2;
+
+		for (it2 = tableList.begin() ; it2 != tableList.end() ; it2++) {
+			(*it2)->populateDataGraph(*this);
+		}
+
+	}
+
+
 
 	printDataGraph(root);
 	

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilder.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilder.h?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilder.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilder.h Mon May  7 01:13:37 2007
@@ -37,7 +37,7 @@
 		std::map<std::string, std::list<TableData*>*> tablesData;
 
 	public:
-		GraphBuilder(Config& config, ResultSet& resultSet);
+		GraphBuilder(Config& config, ResultSetPtr resultSet);
 		virtual ~GraphBuilder(void);
 
 		commonj::sdo::DataObjectPtr getRoot(void) const;

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilderMetaData.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilderMetaData.cpp?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilderMetaData.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilderMetaData.cpp Mon May  7 01:13:37 2007
@@ -63,6 +63,7 @@
 			Relationship& relationship = *relationshipIterator->second;
 			std::map<std::string, KeyPair*>& keyPairs = relationship.getKeyPairs();
 			std::map<std::string, KeyPair*>::iterator keyPairIterator;
+			bool contains = true;
 
 			for (keyPairIterator = keyPairs.begin() ; keyPairIterator != keyPairs.end() ; 
 				keyPairIterator++) {
@@ -71,16 +72,19 @@
 
 					if (!resultSetMetaData.containsColumn(relationship.getPKTableName(), 
 						keyPair.getPKColumnName()) || 
-						resultSetMetaData.containsColumn(relationship.getFKTableName(), 
+						!resultSetMetaData.containsColumn(relationship.getFKTableName(), 
 						keyPair.getFKColumnName())) {
-
-							continue;
+							
+							contains = false;
+							break;
 
 					}
 
 			}
 
-			relationships->push_back(&relationship);
+			if (contains) {
+				relationships->push_back(&relationship);
+			}
 
 	}
 
@@ -163,30 +167,4 @@
 
 std::list<Relationship*>& GraphBuilderMetaData::getRelationships(void) const {
 	return *relationships;
-}
-
-std::list<Relationship*>* GraphBuilderMetaData::getRelationships(std::string tableName, bool pkTable) const {
-	std::list<Relationship*>* relationshipList = new std::list<Relationship*>();
-	std::list<Relationship*>::const_iterator it;
-
-	for (it = relationships->begin() ; it != relationships->end() ; it++) {
-		
-		if (pkTable) {
-
-			if ((*it)->getPKTableName() == tableName) {
-				relationshipList->push_back(*it);
-			}
-
-		} else {
-
-			if ((*it)->getFKTableName() == tableName) {
-				relationshipList->push_back(*it);
-			}
-
-		}
-
-	}
-
-	return relationshipList;
-
 }

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilderMetaData.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilderMetaData.h?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilderMetaData.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilderMetaData.h Mon May  7 01:13:37 2007
@@ -50,7 +50,6 @@
 		std::map<std::string, Table*>& getTables(void) const;
 		Config& getConfig(void) const;
 		Table* getTable(std::string tableName) const;
-		std::list<Relationship*>* getRelationships(std::string tableName, bool pkTable = true) const;
 		std::list<Relationship*>& getRelationships(void) const;
 		commonj::sdo::DataFactoryPtr createGraph(void) const;
 

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/NullPointerException.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/NullPointerException.cpp?view=auto&rev=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/NullPointerException.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/NullPointerException.cpp Mon May  7 01:13:37 2007
@@ -0,0 +1,24 @@
+/*
+ * 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 "NullPointerException.h"
+
+NullPointerException::NullPointerException(void) {}
+
+NullPointerException::~NullPointerException(void) {}
\ No newline at end of file

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/NullPointerException.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/NullPointerException.h?view=auto&rev=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/NullPointerException.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/NullPointerException.h Mon May  7 01:13:37 2007
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+/* $Rev: 452786 $ $Date: 2006-10-04 08:57:36 +0100 (Wed, 04 Oct 2006) $ */
+
+#ifndef NULL_POINTER_EXCEPTION_H
+#define NULL_POINTER_EXCEPTION_H
+
+#include <stdexcept>
+
+class NullPointerException : public std::exception {
+
+	public:
+		NullPointerException(void);
+		virtual ~NullPointerException(void);
+
+};
+
+#endif //NULL_POINTER_EXCEPTION_H

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/PreparedStatement.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/PreparedStatement.cpp?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/PreparedStatement.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/PreparedStatement.cpp Mon May  7 01:13:37 2007
@@ -18,8 +18,8 @@
  */
 #include "PreparedStatement.h"
 
-PreparedStatement::PreparedStatement(Connection& connection, SQLHSTMT statementHandle, string sql)
-	:Statement(connection,statementHandle){
+PreparedStatement::PreparedStatement(SQLHSTMT statementHandle, string sql)
+	:das::Statement(statementHandle){
 		this->sql = sql;
 
 		for(int i = 0; i < sql.size(); i++){
@@ -30,5 +30,5 @@
 
 
 PreparedStatement::~PreparedStatement(){
-	Statement::~Statement();
+	das::Statement::~Statement();
 }

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/PreparedStatement.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/PreparedStatement.h?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/PreparedStatement.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/PreparedStatement.h Mon May  7 01:13:37 2007
@@ -20,20 +20,20 @@
 #ifndef PREPARED_STATEMENT_H
 #define PREPARED_STATEMENT_H
 
-#include "Statement.h";
-
 #include<vector>
 
+#include "das/Statement.h"
+
 using std::vector;
 
-class PreparedStatement : Statement{
+class PreparedStatement : das::Statement {
 
 	private:
 		string sql;
 		vector<int> positions;
 
 	public:
-		PreparedStatement(Connection& connection, SQLHSTMT statementHandle, string sql);
+		PreparedStatement(SQLHSTMT statementHandle, string sql);
 		~PreparedStatement(void);
 
 		void setInt(int index, int elem);

Modified: 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=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.cpp Mon May  7 01:13:37 2007
@@ -90,19 +90,19 @@
 //
 //}
 
-ReadCommandImpl::ReadCommandImpl(DAS& das, std::string sqlString) : CommandImpl(das, sqlString) {}
+ReadCommandImpl::ReadCommandImpl(DASImpl& das, std::string sqlString) : CommandImpl(das, sqlString) {}
 
 ReadCommandImpl::~ReadCommandImpl(void) {}
 
 commonj::sdo::DataObjectPtr ReadCommandImpl::executeQuery(void) {
-	ResultSet& results = statement->executeQuery(sql);
+	ResultSetPtr results = statement->executeQuery(sql);
     commonj::sdo::DataObjectPtr root = buildGraph(results);
 	
     return root;
 
 }
 
-commonj::sdo::DataObjectPtr ReadCommandImpl::buildGraph(ResultSet& resultSet) { /*throws SQLException*/
+commonj::sdo::DataObjectPtr ReadCommandImpl::buildGraph(ResultSetPtr resultSet) { /*throws SQLException*/
 	GraphBuilder graphBuilder(((DASImpl*) das)->getConfig(), resultSet); 
 	
 	

Modified: 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=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.h Mon May  7 01:13:37 2007
@@ -36,10 +36,10 @@
 		unsigned int endRow;
 
 	public:
-		commonj::sdo::DataObjectPtr buildGraph(ResultSet& resultSet); /*throws SQLException*/
+		commonj::sdo::DataObjectPtr buildGraph(ResultSetPtr resultSet); /*throws SQLException*/
 		
 	
-		ReadCommandImpl(DAS& das, std::string sqlString);
+		ReadCommandImpl(DASImpl& das, std::string sqlString);
 		~ReadCommandImpl(void);
 		commonj::sdo::DataObjectPtr executeQuery(void);
 

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/RelationshipWrapper.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/RelationshipWrapper.cpp?view=auto&rev=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/RelationshipWrapper.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/RelationshipWrapper.cpp Mon May  7 01:13:37 2007
@@ -0,0 +1,77 @@
+/*
+ * 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 "RelationshipWrapper.h"
+
+std::list<Relationship*>* RelationshipWrapper::getRelationships(
+	const std::map<std::string, Relationship*>& relationships, std::string tableName, 
+			bool pkTable) {
+
+	std::list<Relationship*>* relationshipList = new std::list<Relationship*>();
+	std::map<std::string, Relationship*>::const_iterator it;
+
+	for (it = relationships.begin() ; it != relationships.end() ; it++) {
+		
+		if (pkTable) {
+
+			if (it->second->getPKTableName() == tableName) {
+				relationshipList->push_back(it->second);
+			}
+
+		} else {
+
+			if (it->second->getFKTableName() == tableName) {
+				relationshipList->push_back(it->second);
+			}
+
+		}
+
+	}
+
+	return relationshipList;
+
+}
+
+std::list<Relationship*>* RelationshipWrapper::getRelationships(const std::list<
+			Relationship*>& relationships, std::string tableName, 
+			bool pkTable) {
+
+	std::list<Relationship*>* relationshipList = new std::list<Relationship*>();
+	std::list<Relationship*>::const_iterator it;
+
+	for (it = relationships.begin() ; it != relationships.end() ; it++) {
+		
+		if (pkTable) {
+
+			if ((*it)->getPKTableName() == tableName) {
+				relationshipList->push_back(*it);
+			}
+
+		} else {
+
+			if ((*it)->getFKTableName() == tableName) {
+				relationshipList->push_back(*it);
+			}
+
+		}
+
+	}
+
+	return relationshipList;
+
+}

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/RelationshipWrapper.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/RelationshipWrapper.h?view=auto&rev=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/RelationshipWrapper.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/RelationshipWrapper.h Mon May  7 01:13:37 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.    
+ */
+#ifndef RELATIONSHIP_WRAPPER_H
+#define RELATIONSHIP_WRAPPER_H
+
+#include <string>
+#include <map>
+#include <list>
+
+#include "Relationship.h"
+
+class RelationshipWrapper {
+		
+	public:
+		static std::list<Relationship*>* getRelationships(const std::map<std::string,
+			Relationship*>& relationships, std::string tableName, 
+			bool pkTable = true);
+
+		static std::list<Relationship*>* getRelationships(const std::list<
+			Relationship*>& relationships, std::string tableName, 
+			bool pkTable = true);
+		
+};
+
+#endif //RELATIONSHIP_WRAPPER_H

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSet.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSet.cpp?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSet.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSet.cpp Mon May  7 01:13:37 2007
@@ -18,22 +18,24 @@
  */
 #include "ResultSet.h"
 
-ResultSet::ResultSet(Statement& aStmt) {
-	stmt = &aStmt;
+ResultSet::ResultSet(StatementPtr aStmt) {
+	stmt = aStmt;
 	metaData = new ResultSetMetaData(this);
 
 }
 
 ResultSet::~ResultSet(void) {
+	ResultSetObject::free();
 	delete metaData;
+
 }
 
 ResultSetMetaData& ResultSet::getResultSetMetaData(void) const {
 	return *metaData;
 }
 
-Statement& ResultSet::getStatement(void) const {
-	return *stmt;
+StatementPtr ResultSet::getStatement(void) const {
+	return stmt;
 }
 
 long ResultSet::getSQLInteger(unsigned int columnIndex) const {

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSet.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSet.h?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSet.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSet.h Mon May  7 01:13:37 2007
@@ -24,24 +24,28 @@
 #include <sqlext.h>
 #include <string>
 
+#include "das/Statement.h"
 #include "ResultSetMetaData.h"
-#include "Statement.h"
 
-class Statement;
+class das::Statement;
 class ResultSetMetaData;
+class ResultSet;
 
-class ResultSet {
+typedef das::RefCountingPointer<ResultSet> ResultSetPtr;
+typedef das::RefCountingObject<ResultSet> ResultSetObject;
+
+class ResultSet : public ResultSetObject {
 
 	private:
 		ResultSetMetaData* metaData;
-		Statement* stmt;
+		StatementPtr stmt;
 
 	public:
-		ResultSet(Statement& aStmt);
+		ResultSet(StatementPtr aStmt);
 		virtual ~ResultSet(void);
 
 		ResultSetMetaData& getResultSetMetaData(void) const;
-		Statement& getStatement(void) const;
+		StatementPtr getStatement(void) const;
 		
 		wchar_t getSQLChar(unsigned int columnIndex) const;
 		wchar_t getSQLChar(std::string tableName, std::string columnName) const;

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSetMetaData.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSetMetaData.cpp?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSetMetaData.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSetMetaData.cpp Mon May  7 01:13:37 2007
@@ -94,7 +94,7 @@
 
 SQLSMALLINT ResultSetMetaData::getSQLType(unsigned int columnIndex) const {
 	SQLSMALLINT sqlType = 0;
-	SQLColAttribute(resultSet->getStatement().getODBCStatement(), columnIndex + 1, SQL_DESC_TYPE, NULL, NULL, NULL, &sqlType);
+	SQLColAttribute(resultSet->getStatement()->getODBCStatement(), columnIndex + 1, SQL_DESC_TYPE, NULL, NULL, NULL, &sqlType);
 		
 	return sqlType;
 
@@ -109,10 +109,10 @@
 	SQLCHAR* sqlPtr = 0;
 	char strAux[1];
 	SQLSMALLINT length = 0;
-	SQLColAttribute(resultSet->getStatement().getODBCStatement(), columnIndex + 1, SQL_DESC_TYPE_NAME, &strAux, 1, (SQLSMALLINT*) &length, NULL);
+	SQLColAttribute(resultSet->getStatement()->getODBCStatement(), columnIndex + 1, SQL_DESC_TYPE_NAME, &strAux, 1, (SQLSMALLINT*) &length, NULL);
 	length++;
 	sqlPtr = (SQLCHAR*) new SQLCHAR[length];
-	SQLColAttributeA(resultSet->getStatement().getODBCStatement(), columnIndex + 1, SQL_DESC_TYPE_NAME, sqlPtr, length, (SQLSMALLINT*) &length, NULL);
+	SQLColAttributeA(resultSet->getStatement()->getODBCStatement(), columnIndex + 1, SQL_DESC_TYPE_NAME, sqlPtr, length, (SQLSMALLINT*) &length, NULL);
 
 	std::string ret((char*) sqlPtr);
 	delete [] sqlPtr;
@@ -130,10 +130,10 @@
 	SQLCHAR* sqlPtr = 0;
 	char strAux[1];
 	SQLSMALLINT length = 0;
-	SQLColAttribute(resultSet->getStatement().getODBCStatement(), columnIndex + 1, SQL_DESC_BASE_COLUMN_NAME, &strAux, 1, (SQLSMALLINT*) &length, NULL);
+	SQLColAttribute(resultSet->getStatement()->getODBCStatement(), columnIndex + 1, SQL_DESC_BASE_COLUMN_NAME, &strAux, 1, (SQLSMALLINT*) &length, NULL);
 	length++;
 	sqlPtr = (SQLCHAR*) new SQLCHAR[length];
-	SQLColAttributeA(resultSet->getStatement().getODBCStatement(), columnIndex + 1, SQL_DESC_BASE_COLUMN_NAME, sqlPtr, length, (SQLSMALLINT*) &length, NULL);
+	SQLColAttributeA(resultSet->getStatement()->getODBCStatement(), columnIndex + 1, SQL_DESC_BASE_COLUMN_NAME, sqlPtr, length, (SQLSMALLINT*) &length, NULL);
 
 	std::string ret((char*) sqlPtr);
 	delete [] sqlPtr;
@@ -158,10 +158,10 @@
 	SQLCHAR* sqlPtr = 0;
 	char strAux[1];
 	SQLSMALLINT length = 0;
-	SQLColAttribute(resultSet->getStatement().getODBCStatement(), columnIndex + 1, SQL_DESC_TABLE_NAME, &strAux, 1, (SQLSMALLINT*) &length, NULL);
+	SQLColAttribute(resultSet->getStatement()->getODBCStatement(), columnIndex + 1, SQL_DESC_TABLE_NAME, &strAux, 1, (SQLSMALLINT*) &length, NULL);
 	length++;
 	sqlPtr = (SQLCHAR*) new SQLCHAR[length];
-	SQLColAttributeA(resultSet->getStatement().getODBCStatement(), columnIndex + 1, SQL_DESC_TABLE_NAME, sqlPtr, length, (SQLSMALLINT*) &length, NULL);
+	SQLColAttributeA(resultSet->getStatement()->getODBCStatement(), columnIndex + 1, SQL_DESC_TABLE_NAME, sqlPtr, length, (SQLSMALLINT*) &length, NULL);
 
 	std::string ret((char*) sqlPtr);
 	delete [] sqlPtr;
@@ -185,7 +185,7 @@
 
 unsigned int ResultSetMetaData::getColumnCount(void) const {
 	SQLUINTEGER columnCount = 0;
-	SQLRETURN ret = SQLColAttribute(resultSet->getStatement().getODBCStatement(), NULL, SQL_DESC_COUNT, NULL, NULL, NULL, &columnCount);
+	SQLRETURN ret = SQLColAttribute(resultSet->getStatement()->getODBCStatement(), NULL, SQL_DESC_COUNT, NULL, NULL, NULL, &columnCount);
 	
 	return (unsigned int) columnCount;
 

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/Table.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/Table.cpp?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Table.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Table.cpp Mon May  7 01:13:37 2007
@@ -108,7 +108,9 @@
 
 	}
 
-	std::list<Relationship*>* relationships = graphBuilderMetaData->getRelationships(tableName, false);
+	std::list<Relationship*>* relationships = RelationshipWrapper::getRelationships(
+		graphBuilderMetaData->getRelationships(), tableName, false);
+
 	std::list<Relationship*>::const_iterator it2;
 
 	for (it2 = relationships->begin() ; it2 != relationships->end() ; it2++) {

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/Table.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/Table.h?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Table.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Table.h Mon May  7 01:13:37 2007
@@ -26,6 +26,7 @@
 #include <algorithm>
 
 #include "das_constants.h"
+#include "RelationshipWrapper.h"
 #include "Relationship.h"
 #include "Config.h"
 #include "KeyPair.h"

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.cpp?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.cpp Mon May  7 01:13:37 2007
@@ -18,13 +18,13 @@
  */
 #include "TableData.h"
 
-TableData::TableData(Table& table, GraphBuilder& graphBuilder, ResultSet& resultSet) {
+TableData::TableData(Table& table, ResultSetPtr resultSet) {
 	this->table = &table;
+	dataObject = 0;
 	const std::map<std::string, Column*>& columns = table.getColumns();
 	std::map<std::string, Column*>::const_iterator columnIterator;
-	ResultSetMetaData& metaData = resultSet.getResultSetMetaData();
-	dataObject = graphBuilder.getRoot()->createDataObject(table.getTableName().c_str());
-
+	ResultSetMetaData& metaData = resultSet->getResultSetMetaData();
+	
 	for (columnIterator = columns.begin() ; columnIterator != columns.end() ; 
 		columnIterator++) {
 
@@ -32,7 +32,7 @@
 			std::string columnName = column.getName();
 
 			if (metaData.containsColumn(table.getTableName(), columnName)) {
-				ColumnData* columnData = new ColumnData(column, resultSet, dataObject);
+				ColumnData* columnData = new ColumnData(column, resultSet);
 
 				columnsData.insert(std::make_pair(columnName, columnData));
 
@@ -86,4 +86,18 @@
 
 bool TableData::operator!=(TableData& tableData) const {
 	return !(*this == tableData);
+}
+
+commonj::sdo::DataObjectPtr TableData::getGraphObject(void) const {
+	return dataObject;
+}
+
+void TableData::populateDataGraph(GraphBuilder& graphBuilder) {
+	dataObject = graphBuilder.getRoot()->createDataObject(table->getTableName().c_str());
+	std::map<std::string, ColumnData*>::iterator it;
+
+	for (it = columnsData.begin() ; it != columnsData.end() ; it++) {
+		it->second->populateDataGraph(*this);
+	}
+
 }

Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.h?view=diff&rev=535777&r1=535776&r2=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.h Mon May  7 01:13:37 2007
@@ -23,8 +23,6 @@
 #include <map>
 #include <string>
 
-#include "Table.h"
-#include "ResultSet.h"
 #include "ColumnData.h"
 #include "GraphBuilder.h"
 #include "ResultSetMetaData.h"
@@ -32,6 +30,8 @@
 #include "commonj/sdo/DataObject.h"
 
 class GraphBuilder;
+class ColumnData;
+class ResultSet;
 
 class TableData {
 
@@ -42,14 +42,17 @@
 		std::list<ColumnData*> primaryKeys;
 
 	public:
-		TableData(Table& table, GraphBuilder& graphBuilder, ResultSet& resultSet);
+		TableData(Table& table, ResultSetPtr resultSet);
 		virtual ~TableData(void);
 
 		Table& getTable(void) const;
 		bool hasPK(void) const;
+		commonj::sdo::DataObjectPtr getGraphObject(void) const;
 
 		bool operator==(TableData& tableData) const;
 		bool operator!=(TableData& tableData) const;
+
+		void populateDataGraph(GraphBuilder& graphBuilder);
 		
 };
 

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingObject.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingObject.cpp?view=auto&rev=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingObject.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingObject.cpp Mon May  7 01:13:37 2007
@@ -0,0 +1,213 @@
+/*
+ * 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 "RefCountingObject.h"
+
+template <class T>
+das::RefCountingObject<T>::RefCountingObject()
+{
+	refCount = 0;
+	freed = false;
+    refPtrs = new std::map<das::RefCountingPointer<T>*, das::RefCountingPointer<T>*>();
+}
+
+template <class T>
+das::RefCountingObject<T>::RefCountingObject(const das::RefCountingObject<T>& rc)
+{
+	refCount = 0;
+	freed = false;
+    refPtrs = new std::map<das::RefCountingPointer<T>*, das::RefCountingPointer<T>*>();
+}
+template <class T>
+T& das::RefCountingObject<T>::operator=(const T& rc)
+{
+    return *this;
+}
+template <class T>
+das::RefCountingObject<T>::~RefCountingObject()
+{
+	if (!freed) {
+		throw std::logic_error("Function RefCountingObjec<T>::free() must be invoked before deleting this object!");
+	}
+
+	delete refPtrs;
+
+}
+
+template <class T>
+void das::RefCountingObject<T>::free(void) {
+	std::map<das::RefCountingPointer<T>*, das::RefCountingPointer<T>*>::iterator it;
+	//std::map<das::RefCountingPointer<T>*, das::RefCountingPointer<T>*>* copiedMap
+	//	= new std::map<das::RefCountingPointer<T>*, das::RefCountingPointer<T>*>(*refPtrs);
+
+	while (!refPtrs->empty()) {
+		das::RefCountingPointer<T>* aux = refPtrs->begin()->second;
+		refPtrs->erase(refPtrs->begin());
+		*aux = 0;
+
+	}
+
+	freed = true;
+
+}
+
+template <class T>
+void das::RefCountingObject<T>::addRef(das::RefCountingPointer<T>* refPtr)
+
+{
+	if ((*refPtr).isObjectOwner()) {
+		refCount++;
+	}
+
+	refPtrs->insert(std::make_pair(refPtr, refPtr));
+}
+template <class T>
+void das::RefCountingObject<T>::releaseRef(das::RefCountingPointer<T>* refPtr)
+{
+	std::map<das::RefCountingPointer<T>*, das::RefCountingPointer<T>*>::iterator it = 
+		refPtrs->find(refPtr);
+	
+	if (refPtrs->end() != it) {
+
+		if ((*it->second).isObjectOwner()) {
+			refCount--;
+		}
+
+		refPtrs->erase(it);
+
+		if (refCount == 0) {
+			free();
+			delete this;
+
+		}
+
+	}
+
+}
+
+template <class T>
+std::ostream& das::RefCountingObject<T>::printSelf(std::ostream &os) 
+{
+	os << "RefCountingObject: reference count = " << refPtrs->size() << std::endl;
+    return os;
+}
+
+#include "Connection.h"
+#include "das/Statement.h"
+
+namespace das{
+        
+        // officially, there is nothing here- but if I dont use the overrides in
+        // the templates, then they dont get generated.
+        void Test ()
+        {
+            
+#if defined(WIN32) || defined (_WINDOWS)
+            /* 1) construct */
+			    
+			Connection conn("", "", "");
+            StatementObject* fptr = new StatementObject();
+			StatementObject statement;
+			das::Statement* s = new das::Statement(0);
+			delete s;
+			StatementObject* fptr2 = new StatementObject(statement);
+			fptr->releaseRef(0);
+			fptr->addRef(0);
+			delete fptr;
+
+			StatementPtr stmt = conn.createStatement();
+			ResultSetObject* rs1 = new ResultSetObject();
+            ResultSetObject rs2;
+			delete rs1;
+			rs2.releaseRef(0);
+			rs2.addRef(0);
+			
+            ///* Use the T*  and  * */
+            //DataObject* dof = dptr;
+            //DataObject& dor = *dptr;
+            //
+            //if (dptr2 == dptr || !dptr){}
+            //
+            //
+            //ChangeSummaryPtr cptr = dptr->getChangeSummary();
+            //cptr = dptr->getChangeSummary();
+            //ChangeSummaryPtr cptr2 = cptr;
+            //
+            //ChangeSummary* cof = cptr;
+            //ChangeSummary& cop = *cptr;
+            //
+            //
+            //if (cptr2 == cptr || !cptr){}
+            //
+            //cptr->endLogging();
+            //
+            //SequencePtr sptr = dptr->getSequence();
+            //sptr = dptr->getSequence();
+            //SequencePtr sptr2 = sptr;
+            //
+            //Sequence* sof = sptr;
+            //Sequence& sop = *sptr;
+            //
+            //
+            //if (sptr2 == sptr || !sptr){}
+            //
+            //sptr->getBooleanValue(0);
+            //
+            //
+            //// Generate code for XMLDocumentPtr
+            //XMLDocumentPtr xmldocptr1 = 0;
+            //XMLDocumentPtr xmldocptr2 = xmldocptr1;
+            //xmldocptr1 = xmldocptr2;
+            //if (xmldocptr2 == xmldocptr1 || !xmldocptr1){}
+            //XMLDocument* xmldocp = xmldocptr1;
+            //XMLDocument& xmldocref = *xmldocptr2;
+            //xmldocptr1->getEncoding();
+
+            //// Generate code for XSDHelperPtr
+            //XSDHelperPtr xsdhptr1 = 0;
+            //XSDHelperPtr xsdhptr2 = xsdhptr1;
+            //xsdhptr1 = xsdhptr2;
+            //if (xsdhptr2 == xsdhptr1 || !xsdhptr1){}
+            //XSDHelper* xsdhp = xsdhptr1;
+            //XSDHelper& xsdhref = *xsdhptr2;
+            //xsdhptr1->define("dummy");
+
+            //// Generate code for XMLHelperPtr
+            //XMLHelperPtr xmlhptr1 = 0;
+            //XMLHelperPtr xmlhptr2 = xmlhptr1;
+            //xmlhptr1 = xmlhptr2;
+            //if (xmlhptr2 == xmlhptr1 || !xmlhptr1){}
+            //XMLHelper* xmlhp = xmlhptr1;
+            //XMLHelper& xmlhref = *xmlhptr2;
+            //xmlhptr1->load("dummy");
+
+            //// Generate code for DataGraphPtr
+            //DataGraphPtr dgptr1 = 0;
+            //DataGraphPtr dgptr2 = dgptr1;
+            //dgptr1 = dgptr2;
+            //if (dgptr2 == dgptr1 || !dgptr1){}
+            //DataGraph* dghp = dgptr1;
+            //DataGraph& dgref = *dgptr2;
+            //dgptr1->getRootObject();
+
+#endif
+            
+        }
+    };
+

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingObject.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingObject.h?view=auto&rev=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingObject.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingObject.h Mon May  7 01:13:37 2007
@@ -0,0 +1,71 @@
+/*
+ * 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 REF_COUNTING_OBJECT_H
+#define REF_COUNTING_OBJECT_H
+
+#include <iostream>
+#include <map>
+
+#include "das/RefCountingPointer.h"
+
+namespace das {
+	
+/**
+ * RefcountingObject is the base class for all objects in SDO
+ * These objects keep a count of references to themselves, then
+ * free themselves when they are unused.
+ */
+template <class T>
+    class RefCountingObject
+    {
+		
+        public:
+        RefCountingObject();
+		RefCountingObject(const das::RefCountingObject<T>& rc);
+        T& operator=(const T& rc);
+        virtual ~RefCountingObject();
+/**
+ * Add to the reference count - a new pointer has been created.
+ */
+        void addRef(das::RefCountingPointer<T>* refPtr);
+/**
+ * Subtract from the the reference count - a reference has dropped.
+ */
+        virtual void releaseRef(das::RefCountingPointer<T>* refPtr);
+
+/**
+ * Print contents to stream
+ */
+        virtual std::ostream& printSelf(std::ostream &os);
+
+	protected:
+		virtual void free(void);
+
+        private:
+			bool freed;
+			unsigned int refCount;
+			std::map<das::RefCountingPointer<T>*, das::RefCountingPointer<T>*>* refPtrs;
+       
+    };
+
+};
+
+
+#endif //REF_COUNTING_OBJECT_H

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingPointer.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingPointer.cpp?view=auto&rev=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingPointer.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingPointer.cpp Mon May  7 01:13:37 2007
@@ -0,0 +1,198 @@
+/*
+ * 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/RefCountingPointer.h"
+#include "das/Statement.h"
+#include "Connection.h"
+
+template<class T>
+void das::RefCountingPointer<T>::init()
+{
+    if (pointee == 0) return;
+    pointee->addRef(this);
+}
+
+template<class T>
+/*SDO_API*/ das::RefCountingPointer<T>::RefCountingPointer(T* realPtr, bool objectOwner)
+:pointee(realPtr)
+{
+	this->objectOwner = objectOwner;
+    init();
+}
+
+template<class T>
+/*SDO_API*/ das::RefCountingPointer<T>::RefCountingPointer(T& realPtr, bool objectOwner)
+:pointee(&realPtr)
+{
+	this->objectOwner = objectOwner;
+    init();
+}
+
+template<class T>
+das::RefCountingPointer<T>::RefCountingPointer(const das::RefCountingPointer<T>& rhs, bool objectOwner)
+: pointee(rhs.pointee)
+{
+	this->objectOwner = objectOwner;
+    init();
+}
+
+template<class T>
+/*SDO_API*/ das::RefCountingPointer<T>::~RefCountingPointer(void)
+{
+    if (pointee)pointee->releaseRef(this);
+}
+
+template<class T>
+/*SDO_API*/ das::RefCountingPointer<T>& das::RefCountingPointer<T>::operator=(const das::RefCountingPointer<T>& rhs)
+{
+    if (pointee != rhs.pointee)
+    {
+        T *oldP = pointee;
+        pointee = rhs.pointee;
+        init();
+        if (oldP) oldP->releaseRef(this);
+    }
+    return *this;
+}
+
+template<class T>
+/*SDO_API*/ bool das::RefCountingPointer<T>::operator!() const
+{
+    return (pointee == 0);
+}
+
+template<class T>
+/*SDO_API*/ bool das::RefCountingPointer<T>::operator==(das::RefCountingPointer<T>& test) const
+{
+    return (pointee == test.pointee);
+}
+
+template<class T>
+/*SDO_API*/ T* das::RefCountingPointer<T>::operator->() const 
+{
+    if (pointee == 0)
+        throw NullPointerException();
+    return pointee;
+}
+
+template<class T>
+/*SDO_API*/ T& das::RefCountingPointer<T>::operator*() const
+{
+    return *pointee;
+}
+
+template<class T>
+bool das::RefCountingPointer<T>::isObjectOwner(void) const {
+	return objectOwner;
+}
+
+namespace das{
+        
+        // officially, there is nothing here- but if I dont use the overrides in
+        // the templates, then they dont get generated.
+        void Test2()
+        {
+            
+#if defined(WIN32) || defined (_WINDOWS)
+			{
+            /* 1) construct */
+			Connection* conn = new Connection("","","");
+            StatementPtr fptr = conn->createStatement();
+			StatementPtr a(new Statement(0));
+			Statement& st = *(new Statement(0));
+			StatementPtr* c = new StatementPtr(st);
+			c->isObjectOwner();
+            
+            /* 2) use the & operator= */
+            fptr = conn->createStatement();
+            
+            /* 3) copy */
+            StatementPtr fptr2 = fptr;
+            
+            /* 4) use the == and ! */
+            if (fptr2 == fptr || !fptr){}
+            
+            /* 5) Use the T*  and  * */
+            Statement* dmsf = fptr;
+            Statement& dmsr = *fptr;
+            
+            /* 1) construct */
+            StatementPtr dfptr(fptr);
+            
+            /* 3) copy */
+            StatementPtr dfptr2 = dfptr;
+            
+            /* 2) use the & operator= */
+            dfptr = dfptr2;
+            
+            /* 4) use the == and ! */
+            if (dfptr2 == dfptr || !dfptr){}
+            
+            /* 5) Use the T*  and  * */
+            Statement* ddmsf = dfptr;
+            Statement& ddmsr = *dfptr;
+            
+            /* 6) Use the -> */
+			dfptr->close(); 
+            
+            /* and again to catch the = */
+			fptr = conn->createStatement();
+			delete fptr2;
+
+		}
+			{
+			/* 1) construct */
+			Connection* conn = new Connection("","","");
+            StatementPtr fptr = conn->createStatement();
+			ResultSetPtr a(new ResultSet(fptr));
+			ResultSetPtr b(new ResultSet(fptr));
+			ResultSet& st = *(new ResultSet(fptr));
+			ResultSetPtr* c = new ResultSetPtr(st);
+			c->isObjectOwner();
+            /* 2) use the & operator= */
+            a = b;
+            
+            /* 3) copy */
+            ResultSetPtr d = a;
+            
+            /* 4) use the == and ! */
+            if (a == b || !b){}
+            
+            /* 5) Use the T*  and  * */
+            ResultSet* dmsf = a;
+            ResultSet& dmsr = *b;
+
+			/* 6) Use the -> */
+			a->getStatement(); 
+            
+            /* and again to catch the = */
+			delete c;
+            
+         
+			}
+        
+            
+#endif
+            
+        }
+    };
+
+
+
+

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingPointer.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingPointer.h?view=auto&rev=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingPointer.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingPointer.h Mon May  7 01:13:37 2007
@@ -0,0 +1,103 @@
+/*
+ * 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 REF_COUNTING_POINTER_H
+#define REF_COUNTING_POINTER_H
+
+#include <iostream>
+
+#include "NullPointerException.h"
+
+namespace das {
+
+	template <class T>
+class RefCountingPointer {
+	
+    public:
+        /*SDO_API*/ RefCountingPointer(T* realPtr = 0, bool objectOwner = true);
+					RefCountingPointer(const das::RefCountingPointer<T>& rhs, bool objectOwner = true);
+        /*SDO_API*/ RefCountingPointer(T& rhs, bool objectOwner = true);
+        /*SDO_API*/ virtual ~RefCountingPointer(void);
+        /*SDO_API*/ RefCountingPointer& operator=(const das::RefCountingPointer<T>& rhs);
+        /*SDO_API*/ bool operator==(das::RefCountingPointer<T>& test) const;
+        /*SDO_API*/ T* operator->() const;
+        /*SDO_API*/ T& operator*() const;
+        /*SDO_API*/ bool operator!() const;
+					bool isObjectOwner(void) const;
+
+#ifdef MFT
+        // MFT == member function templates
+        // Notes on the items below.
+        // In our code, we use subclasses to expose the API, and super
+        // classes to implement. E,g DataObject and DataObjectImpl.
+        // In some cases, we know that the DataObject given to us is a 
+        // DataObjectImpl, and cast it. With RefCountingPointers, however,
+        // the cast cannot work, as the RefCountingPointer to the superclass
+        // is not related to the RCP to the subclass. Recent changes in the
+        // C++ language allow this to work by defining an operator which 
+        // causes a pointer of the other type to be returned, as long as pointee
+        // is acceptable as a parameter to the cosntructor of the other type 
+        // of pointer. This works in C++.NET, but not in C++6:
+        operator RefCountingPointer<otherType>()
+        { 
+             return RefCountingPointer<otherType>(pointee);
+        }
+
+        // Since we are using C6, a possible workround is to provide a method
+        // which returns the dumb pointer, then construct a pointer to the 
+        // base class from the pointer returned. This is that the operator T* does.
+        // The code in DataObject could be simpler if we used C7,and we should
+        // discusss changing.
+#else 
+        operator T*() {return pointee;}
+#endif
+
+        template <class otherType>
+        operator RefCountingPointer<otherType>()
+        {
+            return RefCountingPointer<otherType>(pointee);
+        }
+
+        friend std::ostream& operator<< (std::ostream &os, const das::RefCountingPointer<T>& ptr)
+        {
+            if (!ptr)
+            {
+                os << "NULL" << std::endl;
+            }
+            else
+            {
+                ptr->printSelf(os);
+            }
+
+            return os;
+        }
+
+    private:
+        T *pointee;
+		bool objectOwner;
+        void init();
+
+};
+
+};
+
+class ResultSet;
+typedef das::RefCountingPointer<ResultSet> ResultSetPtr;
+
+#endif

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/das/Statement.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/das/Statement.cpp?view=auto&rev=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/das/Statement.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/das/Statement.cpp Mon May  7 01:13:37 2007
@@ -0,0 +1,59 @@
+/*
+ * 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/Statement.h"
+
+das::Statement::Statement(SQLHSTMT statementHandle) : resultSet(false) {
+	this->statementHandle = statementHandle;
+}
+
+das::Statement::~Statement(void) {
+	if (!resultSet) {
+		delete resultSet;
+	}
+
+	SQLFreeHandle(SQL_HANDLE_STMT, statementHandle);
+	StatementObject::free();
+
+}
+
+ResultSetPtr das::Statement::executeQuery(std::string sql) { /*throws SQLException*/
+	SQLExecDirect(statementHandle, (SQLCHAR*) (char*) sql.c_str(), SQL_NTS);
+
+    return createResultSet();
+
+}
+
+ResultSetPtr das::Statement::createResultSet(void) {
+	if (resultSet) {
+		delete resultSet;
+	}
+
+	resultSet = new ResultSet((StatementPtr) *this);
+
+	return resultSet;
+
+}
+
+void das::Statement::close(void) {
+	delete this;
+}
+
+HSTMT das::Statement::getODBCStatement(void) const {
+	return statementHandle;
+}

Added: incubator/tuscany/cpp/das/runtime/das_lite/src/das/Statement.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/das/Statement.h?view=auto&rev=535777
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/das/Statement.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/das/Statement.h Mon May  7 01:13:37 2007
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+#ifndef STATEMENT_H
+#define STATEMENT_H
+
+#include <list>
+#include <windows.h>
+#include <sql.h>
+
+#include "das/RefCountingObject.h"
+
+namespace das {
+	class Statement;
+};
+
+typedef das::RefCountingPointer<das::Statement> StatementPtr;
+typedef das::RefCountingObject<das::Statement> StatementObject;
+
+#include "Connection.h"
+#include "ResultSet.h"
+
+class Connection;
+class ResultSet;
+
+using std::string;
+
+namespace das {
+
+class Statement : public StatementObject {
+
+	friend class ResultSet;
+	
+	private:
+		SQLHSTMT statementHandle;
+		ResultSetPtr resultSet;
+		
+	protected:
+		string queryString;
+
+		ResultSetPtr createResultSet(void);
+		
+	public:
+		Statement(SQLHSTMT statementHandle);
+		virtual ~Statement(void);
+		virtual SQLHSTMT getODBCStatement(void) const;
+		virtual ResultSetPtr executeQuery(string sql); /*throws SQLException*/
+		virtual void close(void);
+		
+};
+
+};
+
+#endif //STATEMENT_H



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