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/10 08:32:04 UTC

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

Author: adrianocrestani
Date: Wed May  9 23:32:02 2007
New Revision: 536753

URL: http://svn.apache.org/viewvc?view=rev&rev=536753
Log:
 - relationship on db is now being converted to reference on sdo graph
 - duplicate table data is being detected on resultset and only added a single table on sdo graph

Modified:
    incubator/tuscany/cpp/das/VSExpress/tuscany_das/das_runtime/das_runtime.suo
    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/Config.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/Connection.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilder.cpp
    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/RelationshipWrapper.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/RelationshipWrapper.h
    incubator/tuscany/cpp/das/runtime/das_lite/src/Table.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.h
    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/Statement.cpp
    incubator/tuscany/cpp/das/runtime/das_lite/src/das/Statement.h

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=536753&r1=536752&r2=536753
==============================================================================
Binary files - no diff available.

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=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.cpp Wed May  9 23:32:02 2007
@@ -108,6 +108,10 @@
 
 void ColumnData::populateDataGraph(TableData& tableData) const {
 
+	if (!tableData.getGraphObject()->hasProperty(column->getName().c_str())) {
+		return;
+	}
+
 	switch (column->getSQLType()) {
 
 		case SQL_INTEGER :
@@ -154,7 +158,7 @@
 bool ColumnData::operator==(ColumnData& columnData) const {
 
 	if (column->getSQLType() != columnData.column->getSQLType()) {
-		return false;
+		throw std::invalid_argument("Different sql types!");
 	}
 
 	switch (column->getSQLType()) {
@@ -210,4 +214,122 @@
 
 bool ColumnData::operator!=(ColumnData& columnData) const {
 	return !(*this == columnData);
+}
+
+Column& ColumnData::getColumn(void) const {
+	return *column;
+}
+
+bool ColumnData::operator<(ColumnData& columnData) const {
+
+	if (column->getSQLType() != columnData.column->getSQLType()) {
+		throw std::invalid_argument("Different sql types!");
+	}
+
+	switch (column->getSQLType()) {
+
+		case SQL_INTEGER :
+			
+			if (*((long*) columnData.data) > *((long*) data)) {
+				return true;
+			}
+
+			break;
+
+		case SQL_CHAR :	
+			
+			if (*((wchar_t*) columnData.data) > *((wchar_t*) data)) {
+				return true;
+			}
+
+			break;
+
+		case SQL_DOUBLE :
+		case SQL_FLOAT :
+			
+			if (*((double*) columnData.data) > *((double*) data)) {
+				return true;
+			}
+
+			break;
+
+		case SQL_REAL :
+			
+			if (*((float*) columnData.data) > *((float*) data)) {
+				return true;
+			}
+
+			break;
+
+		case SQL_VARCHAR :
+			if (*((std::wstring*) columnData.data) > *((std::wstring*) data)) {
+				return true;
+			}
+
+			break;
+		
+		default :
+			throw std::logic_error("Invalid sql type!");
+
+	}
+
+	return false;
+
+}
+
+bool ColumnData::operator>(ColumnData& columnData) const {
+
+	if (column->getSQLType() != columnData.column->getSQLType()) {
+		throw std::invalid_argument("Different sql types!");
+	}
+
+	switch (column->getSQLType()) {
+
+		case SQL_INTEGER :
+			
+			if (*((long*) columnData.data) < *((long*) data)) {
+				return true;
+			}
+
+			break;
+
+		case SQL_CHAR :	
+			
+			if (*((wchar_t*) columnData.data) < *((wchar_t*) data)) {
+				return true;
+			}
+
+			break;
+
+		case SQL_DOUBLE :
+		case SQL_FLOAT :
+			
+			if (*((double*) columnData.data) < *((double*) data)) {
+				return true;
+			}
+
+			break;
+
+		case SQL_REAL :
+			
+			if (*((float*) columnData.data) < *((float*) data)) {
+				return true;
+			}
+
+			break;
+
+		case SQL_VARCHAR :
+			if (*((std::wstring*) columnData.data) < *((std::wstring*) data)) {
+				return true;
+			}
+
+			break;
+		
+		default :
+			throw std::logic_error("Invalid sql type!");
+
+	}
+
+	return false;
+
 }

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=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.h Wed May  9 23:32:02 2007
@@ -43,6 +43,9 @@
 
 		bool operator==(ColumnData& columnData) const;
 		bool operator!=(ColumnData& columnData) const;
+		bool operator<(ColumnData& columnData) const;
+		bool operator>(ColumnData& columnData) const;
+		Column& getColumn(void) const;
 
 		void populateDataGraph(TableData& tableData) const;
 

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=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Config.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Config.cpp Wed May  9 23:32:02 2007
@@ -48,7 +48,7 @@
 
 void Config::addTable(Table& table) {
 	std::list<Relationship*>* relationships = RelationshipWrapper::
-		getRelationships(*this->relationships, table.getTableName());
+		getRelationshipsByTableName(*this->relationships, table.getTableName());
 	std::list<Relationship*>::iterator it;
 
 	for (it = relationships->begin() ; it != relationships->end() ; it++) {

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=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Connection.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Connection.cpp Wed May  9 23:32:02 2007
@@ -148,7 +148,7 @@
 
 	}
 
-	das::Statement* stmt = new das::Statement(statementHandle);
+	das::Statement* stmt = new das::Statement(*this, statementHandle);
 	statements.push_back(*(new StatementPtr(stmt, false)));
 
 	return stmt;

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=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilder.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilder.cpp Wed May  9 23:32:02 2007
@@ -66,7 +66,7 @@
 	return ss.str();
 }
 
-void printDataGraph(commonj::sdo::DataObjectPtr dataObject) {
+void printDataGraph(commonj::sdo::DataObjectPtr dataObject, bool ref = false) {
 	commonj::sdo::PropertyList& propertyList = dataObject->getType().getProperties();
 	std::cout << getTab(tabCount) << "[" << dataObject->getType().getName() << "]";
 	tabCount++;
@@ -74,13 +74,13 @@
 	for (int i = 0 ; i < propertyList.size() ; i++) {
 		
 		if (propertyList[i].isMany()) {
-			std::cout << getTab(tabCount) << "[LIST]";
+			std::cout << getTab(tabCount) << ((propertyList[i].isReference()) ? "-> " : "") << "[LIST]";
 			tabCount++;
 			commonj::sdo::DataObjectList& objectList = dataObject->getList(propertyList[i]);
 		
 			for (int j = 0 ; j < objectList.size() ; j++) {
 
-				if (objectList[i]->getType().isDataType()) {
+				if (objectList[j]->getType().isDataType()) {
 					std::string typeName = objectList[j]->getType().getName();
 
 					if (typeName == "String") {
@@ -98,8 +98,8 @@
 						std::cout << getTab(tabCount) << dataObject->getInteger((((std::string) propertyList[j].getName()) + "[" + to_string(j) + "]").c_str()) << " : " << objectList[j]->getType().getName();
 					}
 					
-				} else {
-					printDataGraph(objectList[j]);
+				} else if (!ref) {
+					printDataGraph(objectList[j], propertyList[i].isReference());
 				}
 
 			}
@@ -122,7 +122,7 @@
 				str.assign(wstr.begin(), wstr.end());
 
 
-				std::cout << getTab(tabCount) << str << " : " << actual->getType().getName();
+				std::cout << getTab(tabCount) << ((propertyList[i].isReference()) ? "-> " : "") << str << " : " << actual->getType().getName();
 				delete [] buf;
 			} else if (typeName == "Integer") {
 				std::cout << getTab(tabCount) << dataObject->getInteger(propertyList[i]) << " : " << actual->getType().getName();
@@ -222,10 +222,91 @@
 
 	}
 
+	std::map<std::string, Table*>::const_iterator it2;
+	std::list<Relationship*>& relationships = graphBuilderMetaData->getRelationships();
+	std::map<std::string, std::map<KeyDataList*, TableData*, KeyDataCmp>*> tablesDataByPK;
+	std::map<std::string, std::list<TableData*>*>::iterator it3;
+	KeyDataCmp keyDataCmp;
+	for (it3 = tablesData.begin() ; it3 != tablesData.end() ; it3++) {
+		std::map<KeyDataList*, TableData*, KeyDataCmp>* tableList = new std::map<KeyDataList*, TableData*, KeyDataCmp>();
+		std::list<TableData*>::iterator it4;
+
+		for (it4 = it3->second->begin() ; it4 != it3->second->end() ; it4++) {
+			TableData* tableData = *it4;
+			tableList->insert(std::make_pair(&tableData->getPrimaryKeys(), tableData));
 
+		}
+
+		tablesDataByPK.insert(std::make_pair(it3->first, tableList));
+
+	}
+		
+	for (it2 = tables.begin() ; it2 != tables.end() ; it2++) {
+		std::list<Relationship*>* fkTableRelationships = RelationshipWrapper::
+			getRelationshipsByTableName(relationships, it2->first, false);
+
+		std::list<Relationship*>::iterator relationshipIterator;
+		for (relationshipIterator = fkTableRelationships->begin() ; 
+			relationshipIterator != fkTableRelationships->end() ; relationshipIterator++) {
+
+				std::list<TableData*>& fkTablesList = 
+					*((std::map<std::string, std::list<TableData*>*>::iterator) tablesData.find(
+					(*relationshipIterator)->getFKTableName()))->second;
+
+				std::map<KeyDataList*, TableData*, KeyDataCmp>& pkTablesData = 
+						*((std::map<std::string, std::map<KeyDataList*, TableData*, KeyDataCmp>*>::iterator) 
+						tablesDataByPK.find((*relationshipIterator)->getPKTableName()))->second;
+
+				std::list<TableData*>::iterator tableDataIterator;
+				for (tableDataIterator = fkTablesList.begin() ; tableDataIterator != 
+					fkTablesList.end() ; tableDataIterator++) {
+
+					TableData& fkTableData = **tableDataIterator;
+					std::map<std::string, KeyPair*>& keyPairs = (*relationshipIterator)->getKeyPairs();
+					std::map<std::string, KeyPair*>::iterator keyPairIterator;
+					KeyDataList fksColumnList;
+
+					for (keyPairIterator = keyPairs.begin() ; keyPairIterator != keyPairs.end() ;
+						keyPairIterator++) {
+					
+							KeyPair& keyPair = *keyPairIterator->second;
+							ColumnData* columnData = fkTableData.
+								getColumnData(keyPair.getFKColumnName());
+
+							fksColumnList.insert(std::make_pair(keyPair.getPKColumnName(),
+								columnData));
+		
+					}
+
+					std::map<KeyDataList*, TableData*, KeyDataCmp>::iterator pkTablaDataIterator = 
+						pkTablesData.find(&fksColumnList);
+
+					if (pkTablaDataIterator != pkTablesData.end()) {
+						TableData& pkTableData = *pkTablaDataIterator->second;
+					
+						pkTableData.getGraphObject()->getList((*relationshipIterator)->getName().c_str()).
+							append(fkTableData.getGraphObject());
+
+					}
+
+				}
+
+		}
+
+		delete fkTableRelationships;
+
+	}
+
+	std::map<std::string, std::map<KeyDataList*, TableData*, KeyDataCmp>*>::iterator tablesDataByPKIterator;
+	for (tablesDataByPKIterator = tablesDataByPK.begin() ; tablesDataByPKIterator != 
+		tablesDataByPK.end() ; tablesDataByPKIterator++) {
+
+			delete tablesDataByPKIterator->second;
+
+	}
 
 	printDataGraph(root);
-	
+
 }
 
 GraphBuilder::~GraphBuilder(void) {
@@ -243,7 +324,6 @@
 
 	}
 
-	delete root;
 	delete graphBuilderMetaData;
 
 }

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=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/PreparedStatement.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/PreparedStatement.cpp Wed May  9 23:32:02 2007
@@ -18,8 +18,8 @@
  */
 #include "PreparedStatement.h"
 
-PreparedStatement::PreparedStatement(SQLHSTMT statementHandle, string sql)
-	:das::Statement(statementHandle){
+PreparedStatement::PreparedStatement(Connection& connection, SQLHSTMT statementHandle, string sql)
+	:das::Statement(connection, statementHandle){
 		this->sql = sql;
 
 		for(int i = 0; i < sql.size(); i++){

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=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/PreparedStatement.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/PreparedStatement.h Wed May  9 23:32:02 2007
@@ -33,7 +33,7 @@
 		vector<int> positions;
 
 	public:
-		PreparedStatement(SQLHSTMT statementHandle, string sql);
+		PreparedStatement(Connection& connection, 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=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.cpp Wed May  9 23:32:02 2007
@@ -104,12 +104,13 @@
 
 commonj::sdo::DataObjectPtr ReadCommandImpl::buildGraph(ResultSetPtr resultSet) { /*throws SQLException*/
 	GraphBuilder graphBuilder(((DASImpl*) das)->getConfig(), resultSet); 
-	
+	commonj::sdo::DataObjectPtr root = graphBuilder.getRoot();
+	root->getChangeSummary()->beginLogging();
 	
 	//printDataGraph(dataFactory);
 	//commonj::sdo::ChangeSummaryPtr changeSummary = rootDataObject->getChangeSummary();
 	
-	return 0;
+	return root;
 
 	/*int columnCount = getColumnCount(statement);
 	int col;

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=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.h Wed May  9 23:32:02 2007
@@ -26,6 +26,7 @@
 
 #include "commonj/sdo/DataFactory.h"
 #include "commonj/sdo/DataObject.h"
+#include "commonj/sdo/ChangeSummary.h"
 
 #include "das_constants.h"
 

Modified: 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=diff&rev=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/RelationshipWrapper.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/RelationshipWrapper.cpp Wed May  9 23:32:02 2007
@@ -18,7 +18,7 @@
  */
 #include "RelationshipWrapper.h"
 
-std::list<Relationship*>* RelationshipWrapper::getRelationships(
+std::list<Relationship*>* RelationshipWrapper::getRelationshipsByTableName(
 	const std::map<std::string, Relationship*>& relationships, std::string tableName, 
 			bool pkTable) {
 
@@ -47,7 +47,7 @@
 
 }
 
-std::list<Relationship*>* RelationshipWrapper::getRelationships(const std::list<
+std::list<Relationship*>* RelationshipWrapper::getRelationshipsByTableName(const std::list<
 			Relationship*>& relationships, std::string tableName, 
 			bool pkTable) {
 

Modified: 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=diff&rev=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/RelationshipWrapper.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/RelationshipWrapper.h Wed May  9 23:32:02 2007
@@ -28,11 +28,11 @@
 class RelationshipWrapper {
 		
 	public:
-		static std::list<Relationship*>* getRelationships(const std::map<std::string,
+		static std::list<Relationship*>* getRelationshipsByTableName(const std::map<std::string,
 			Relationship*>& relationships, std::string tableName, 
 			bool pkTable = true);
 
-		static std::list<Relationship*>* getRelationships(const std::list<
+		static std::list<Relationship*>* getRelationshipsByTableName(const std::list<
 			Relationship*>& relationships, std::string tableName, 
 			bool pkTable = true);
 		

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=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Table.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Table.cpp Wed May  9 23:32:02 2007
@@ -108,7 +108,7 @@
 
 	}
 
-	std::list<Relationship*>* relationships = RelationshipWrapper::getRelationships(
+	std::list<Relationship*>* relationships = RelationshipWrapper::getRelationshipsByTableName(
 		graphBuilderMetaData->getRelationships(), tableName, false);
 
 	std::list<Relationship*>::const_iterator it2;

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=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.cpp Wed May  9 23:32:02 2007
@@ -20,6 +20,7 @@
 
 TableData::TableData(Table& table, ResultSetPtr resultSet) {
 	this->table = &table;
+	primaryKeys = new KeyDataList();
 	dataObject = 0;
 	const std::map<std::string, Column*>& columns = table.getColumns();
 	std::map<std::string, Column*>::const_iterator columnIterator;
@@ -37,7 +38,7 @@
 				columnsData.insert(std::make_pair(columnName, columnData));
 
 				if (column.isPK()) {
-					primaryKeys.push_back(columnData);
+					primaryKeys->insert(std::make_pair(columnName, columnData));
 				}
 
 			}
@@ -59,35 +60,64 @@
 	return *table;
 }
 
-bool TableData::operator==(TableData& tableData) const {
+bool TableData::operator==(const KeyDataList* primaryKeyList) const {
 	
-	if (tableData.table->getTableName() != table->getTableName()) {
+	if (primaryKeys->size() != primaryKeyList->size()) {
 		return false;
 	}
 
-	std::list<ColumnData*>::const_iterator it;
-	std::list<ColumnData*>::const_iterator it2;
+	KeyDataList::const_iterator it, primaryKeyIterator;
+	
+	for (it = primaryKeyList->begin() ; it != primaryKeyList->end() ; it++) {
+		primaryKeyIterator = primaryKeys->find(it->first);
+
+		if (primaryKeyIterator == primaryKeys->end())  {
+			return false;
+
+		} else if (*it->second != *primaryKeyIterator->second) {
+			return false;
+
+		}
+
+	}
+
+	return true;
+	
+	/*if (tableData.table->getTableName() != table->getTableName()) {
+		return false;
+	}
+
+	std::map<std::string, ColumnData*>::const_iterator it;
+	std::map<std::string, ColumnData*>::const_iterator it2;
 	for (it = primaryKeys.begin(), it2 = tableData.primaryKeys.begin() ;
 		it != primaryKeys.end(), it2 != tableData.primaryKeys.end() ; it++, it2++) {
 
-			if (**it != **it2) {
+			if (*it->second != *it2->second) {
 				return false;
 			}
 
 	}
 
-	return true;
+	return true;*/
 	
 }
 
-bool TableData::hasPK(void) const {
-	return (primaryKeys.size() == table->getPKColumnCount());
+bool TableData::operator==(const TableData& tableData) const {
+	return (*this == tableData.primaryKeys);
 }
 
-bool TableData::operator!=(TableData& tableData) const {
+bool TableData::operator!=(const TableData& tableData) const {
 	return !(*this == tableData);
 }
 
+bool TableData::operator!=(const KeyDataList* primaryKeyList) const {
+	return !(*this == primaryKeyList);
+}
+
+bool TableData::hasPK(void) const {
+	return (primaryKeys->size() == table->getPKColumnCount());
+}
+
 commonj::sdo::DataObjectPtr TableData::getGraphObject(void) const {
 	return dataObject;
 }
@@ -100,4 +130,92 @@
 		it->second->populateDataGraph(*this);
 	}
 
+}
+
+KeyDataList& TableData::getPrimaryKeys(void) const {
+	return *primaryKeys;
+}
+
+void TableData::addFK(std::string columnName) {
+	std::map<std::string, ColumnData*>::iterator it = columnsData.find(columnName);
+
+	if (it == columnsData.end()) {
+		throw std::invalid_argument("Column " + columnName + " does not exist!");
+	}
+
+	foreignKeys.insert(std::make_pair(columnName, it->second));
+
+}
+
+ColumnData* TableData::getColumnData(std::string columnName) const {
+	std::map<std::string, ColumnData*>::const_iterator it = columnsData.find(columnName);
+
+	if (it == columnsData.end()) {
+		return 0;
+	}
+
+	return it->second;
+
+}
+
+bool TableData::operator<(const TableData& tableData) const {
+	return (*this < tableData.primaryKeys);
+}
+
+bool TableData::operator<(const KeyDataList* primaryKeyList) const {
+	
+	if (primaryKeys->size() < primaryKeyList->size()) {
+		return true;
+	} else if (primaryKeys->size() > primaryKeyList->size()) {
+		return false;
+	}
+
+	KeyDataList::const_iterator it;
+	
+	for (it = primaryKeyList->begin() ; it != primaryKeyList->end() ; it++) {
+		KeyDataList::const_iterator primaryKeyIterator = 
+			primaryKeys->find(it->first);
+
+		if (primaryKeyIterator != primaryKeys->end()) {
+
+			if (*it->second < *primaryKeyIterator->second) {
+				return true;
+			} else if (*it->second > *primaryKeyIterator->second) {
+				return false;
+			}
+
+		}
+
+	}
+
+	return false;
+
+}
+
+bool KeyDataCmp::operator() ( const KeyDataList* keyDataList1, const KeyDataList* keyDataList2 ) const {
+	if (keyDataList1->size() < keyDataList2->size()) {
+		return true;
+	} else if (keyDataList1->size() > keyDataList2->size()) {
+		return false;
+	}
+
+	KeyDataList::const_iterator it;
+	
+	for (it = keyDataList2->begin() ; it != keyDataList2->end() ; it++) {
+		KeyDataList::const_iterator primaryKeyIterator = 
+			keyDataList1->find(it->first);
+
+		if (primaryKeyIterator != keyDataList1->end()) {
+
+			if (*it->second < *primaryKeyIterator->second) {
+				return true;
+			} else if (*it->second > *primaryKeyIterator->second) {
+				return false;
+			}
+
+		}
+
+	}
+
+	return false;
 }

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=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.h Wed May  9 23:32:02 2007
@@ -22,6 +22,7 @@
 #include <list>
 #include <map>
 #include <string>
+#include <stdexcept>
 
 #include "ColumnData.h"
 #include "GraphBuilder.h"
@@ -33,13 +34,16 @@
 class ColumnData;
 class ResultSet;
 
+typedef std::map<std::string, ColumnData*> KeyDataList;
+
 class TableData {
 
 	private:
 		Table* table;
 		commonj::sdo::DataObjectPtr dataObject;
 		std::map<std::string, ColumnData*> columnsData;
-		std::list<ColumnData*> primaryKeys;
+		KeyDataList* primaryKeys;
+		std::map<std::string, ColumnData*> foreignKeys;
 
 	public:
 		TableData(Table& table, ResultSetPtr resultSet);
@@ -49,11 +53,23 @@
 		bool hasPK(void) const;
 		commonj::sdo::DataObjectPtr getGraphObject(void) const;
 
-		bool operator==(TableData& tableData) const;
-		bool operator!=(TableData& tableData) const;
+		bool operator==(const TableData& tableData) const;
+		bool operator==(const KeyDataList* primaryKeyList) const;
+		bool operator!=(const TableData& tableData) const;
+		bool operator!=(const KeyDataList* primaryKeyList) const;
+		bool operator<(const TableData& tableData) const;
+		bool operator<(const KeyDataList* primaryKeyList) const;
+
+		ColumnData* getColumnData(std::string columnName) const;
+		KeyDataList& getPrimaryKeys(void) const;
 
+		void addFK(std::string columnName);
 		void populateDataGraph(GraphBuilder& graphBuilder);
 		
 };
 
+class KeyDataCmp {
+	public:
+		bool operator() (const KeyDataList* keyDataList1, const KeyDataList* keyDataList2 ) const;
+};
 #endif //TABLE_DATA_H

Modified: 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=diff&rev=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingObject.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingObject.cpp Wed May  9 23:32:02 2007
@@ -24,7 +24,7 @@
 {
 	refCount = 0;
 	freed = false;
-    refPtrs = new std::map<das::RefCountingPointer<T>*, das::RefCountingPointer<T>*>();
+    refPtrs = new std::list<das::RefCountingPointer<T>*>();
 }
 
 template <class T>
@@ -32,7 +32,7 @@
 {
 	refCount = 0;
 	freed = false;
-    refPtrs = new std::map<das::RefCountingPointer<T>*, das::RefCountingPointer<T>*>();
+    refPtrs = new std::list<das::RefCountingPointer<T>*>();
 }
 template <class T>
 T& das::RefCountingObject<T>::operator=(const T& rc)
@@ -52,12 +52,10 @@
 
 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);
-
+	std::list<das::RefCountingPointer<T>*>::iterator it;
+	
 	while (!refPtrs->empty()) {
-		das::RefCountingPointer<T>* aux = refPtrs->begin()->second;
+		das::RefCountingPointer<T>* aux = *refPtrs->begin();
 		refPtrs->erase(refPtrs->begin());
 		*aux = 0;
 
@@ -75,17 +73,28 @@
 		refCount++;
 	}
 
-	refPtrs->insert(std::make_pair(refPtr, refPtr));
+	refPtrs->push_front(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);
+	std::list<das::RefCountingPointer<T>*>::iterator it;
+	bool found = false;
+
+	for (it = refPtrs->begin() ; it != refPtrs->end() ; it++) {
+
+		if (refPtr == *it) {
+			found = true;
+			break;
+
+		}
+
+	}
 	
-	if (refPtrs->end() != it) {
+	if (found) {
 
-		if ((*it->second).isObjectOwner()) {
+		if ((*it)->isObjectOwner()) {
 			refCount--;
 		}
 
@@ -124,7 +133,7 @@
 			Connection conn("", "", "");
             StatementObject* fptr = new StatementObject();
 			StatementObject statement;
-			das::Statement* s = new das::Statement(0);
+			das::Statement* s = new das::Statement(conn, 0);
 			delete s;
 			StatementObject* fptr2 = new StatementObject(statement);
 			fptr->releaseRef(0);

Modified: 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=diff&rev=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingObject.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingObject.h Wed May  9 23:32:02 2007
@@ -21,7 +21,7 @@
 #define REF_COUNTING_OBJECT_H
 
 #include <iostream>
-#include <map>
+#include <list>
 
 #include "das/RefCountingPointer.h"
 
@@ -61,7 +61,7 @@
         private:
 			bool freed;
 			unsigned int refCount;
-			std::map<das::RefCountingPointer<T>*, das::RefCountingPointer<T>*>* refPtrs;
+			std::list<das::RefCountingPointer<T>*>* refPtrs;
        
     };
 

Modified: 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=diff&rev=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingPointer.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/das/RefCountingPointer.cpp Wed May  9 23:32:02 2007
@@ -114,8 +114,8 @@
             /* 1) construct */
 			Connection* conn = new Connection("","","");
             StatementPtr fptr = conn->createStatement();
-			StatementPtr a(new Statement(0));
-			Statement& st = *(new Statement(0));
+			StatementPtr a(new Statement(*conn, 0));
+			Statement& st = *(new Statement(*conn, 0));
 			StatementPtr* c = new StatementPtr(st);
 			c->isObjectOwner();
             

Modified: 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=diff&rev=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/das/Statement.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/das/Statement.cpp Wed May  9 23:32:02 2007
@@ -18,8 +18,10 @@
  */
 #include "das/Statement.h"
 
-das::Statement::Statement(SQLHSTMT statementHandle) : resultSet(false) {
+das::Statement::Statement(Connection& connection, SQLHSTMT statementHandle) : resultSet(false) {
 	this->statementHandle = statementHandle;
+	this->connection = &connection;
+
 }
 
 das::Statement::~Statement(void) {
@@ -30,6 +32,10 @@
 	SQLFreeHandle(SQL_HANDLE_STMT, statementHandle);
 	StatementObject::free();
 
+}
+
+Connection& das::Statement::getConnection(void) const {
+	return *connection;
 }
 
 ResultSetPtr das::Statement::executeQuery(std::string sql) { /*throws SQLException*/

Modified: 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=diff&rev=536753&r1=536752&r2=536753
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/das/Statement.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/das/Statement.h Wed May  9 23:32:02 2007
@@ -49,6 +49,7 @@
 	private:
 		SQLHSTMT statementHandle;
 		ResultSetPtr resultSet;
+		Connection* connection;
 		
 	protected:
 		string queryString;
@@ -56,11 +57,12 @@
 		ResultSetPtr createResultSet(void);
 		
 	public:
-		Statement(SQLHSTMT statementHandle);
+		Statement(Connection& connection, SQLHSTMT statementHandle);
 		virtual ~Statement(void);
 		virtual SQLHSTMT getODBCStatement(void) const;
 		virtual ResultSetPtr executeQuery(string sql); /*throws SQLException*/
 		virtual void close(void);
+		virtual Connection& getConnection(void) const;
 		
 };
 



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