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/02 09:44:30 UTC
svn commit: r534339 - in /incubator/tuscany/cpp/das:
VSExpress/tuscany_das/das_lite/ VSExpress/tuscany_das/das_runtime/
runtime/das_lite/src/
Author: adrianocrestani
Date: Wed May 2 00:44:29 2007
New Revision: 534339
URL: http://svn.apache.org/viewvc?view=rev&rev=534339
Log:
Added composite relationship, implementation of GraphBuilder to populate the sdo graph and some others minor changes
Added:
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/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
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/Config.cpp
incubator/tuscany/cpp/das/runtime/das_lite/src/Config.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/ReadCommandImpl.cpp
incubator/tuscany/cpp/das/runtime/das_lite/src/Relationship.cpp
incubator/tuscany/cpp/das/runtime/das_lite/src/Relationship.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/Table.cpp
incubator/tuscany/cpp/das/runtime/das_lite/src/Table.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=534339&r1=534338&r2=534339
==============================================================================
--- 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 Wed May 2 00:44:29 2007
@@ -151,6 +151,10 @@
>
</File>
<File
+ RelativePath="..\..\..\runtime\das_lite\src\ColumnData.h"
+ >
+ </File>
+ <File
RelativePath="..\..\..\runtime\das_lite\src\Command.h"
>
</File>
@@ -238,6 +242,10 @@
RelativePath="..\..\..\runtime\das_lite\src\Table.h"
>
</File>
+ <File
+ RelativePath="..\..\..\runtime\das_lite\src\TableData.h"
+ >
+ </File>
</Filter>
<Filter
Name="Resource Files"
@@ -259,6 +267,10 @@
>
</File>
<File
+ RelativePath="..\..\..\runtime\das_lite\src\ColumnData.cpp"
+ >
+ </File>
+ <File
RelativePath="..\..\..\runtime\das_lite\src\CommandImpl.cpp"
>
</File>
@@ -336,6 +348,10 @@
</File>
<File
RelativePath="..\..\..\runtime\das_lite\src\Table.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\..\..\runtime\das_lite\src\TableData.cpp"
>
</File>
</Filter>
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=534339&r1=534338&r2=534339
==============================================================================
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=534339&r1=534338&r2=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Column.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Column.cpp Wed May 2 00:44:29 2007
@@ -59,7 +59,7 @@
}
bool Column::isFK(void) const {
- return (keyPairs == 0 || keyPairs->size() > 0);
+ return (keyPairs != 0 && keyPairs->size() > 0);
}
void Column::setMappedName(std::string mappedName) {
@@ -79,3 +79,56 @@
keyPairs->push_back(&keyPair);
}
+
+//void Column::populateDataGraph(commonj::sdo::DataObjectPtr dataObject, ResultSet& resultSet) const {
+//
+// switch (sqlType) {
+//
+// case SQL_INTEGER :
+// dataObject->setInteger(columnName.c_str(), resultSet.getSQLInteger(
+// containerTable->getTableName(), columnName));
+// break;
+//
+// case SQL_CHAR :
+// dataObject->setCharacter(columnName.c_str(), resultSet.getSQLChar(
+// containerTable->getTableName(), columnName));
+// break;
+//
+// case SQL_DOUBLE :
+// dataObject->setDouble(columnName.c_str(), resultSet.getSQLDouble(
+// containerTable->getTableName(), columnName));
+// break;
+//
+// case SQL_FLOAT :
+// dataObject->setDouble(columnName.c_str(), resultSet.getSQLFloat(
+// containerTable->getTableName(), columnName));
+// break;
+//
+// case SQL_REAL :
+// dataObject->setFloat(columnName.c_str(), resultSet.getSQLReal(
+// containerTable->getTableName(), columnName));
+// break;
+//
+// case SQL_VARCHAR :
+// {
+// std::string varchar = resultSet.getSQLVarchar(containerTable->getTableName(),
+// columnName);
+//
+// unsigned int size = varchar.size();
+// wchar_t* aux = new wchar_t[size];
+// for (int i = 0 ; i < varchar.size() ; i++) {
+// aux[i] = (wchar_t) varchar[i];
+// }
+//
+// dataObject->setString(columnName.c_str(), aux, varchar.size());
+// delete [] aux;
+// }
+//
+// break;
+//
+// default :
+// throw std::logic_error("Invalid sql type!");
+//
+// }
+//
+//}
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=534339&r1=534338&r2=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Column.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Column.h Wed May 2 00:44:29 2007
@@ -59,9 +59,8 @@
SQLSMALLINT getSQLType(void) const;
Table* getContainerTable(void) const;
std::list<KeyPair*>& getKeyPairs(void) const;
-
std::string getName(void) const;
-
+
};
#endif //COLUMN_H
Added: 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=auto&rev=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.cpp Wed May 2 00:44:29 2007
@@ -0,0 +1,175 @@
+/*
+ * 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 "ColumnData.h"
+
+ColumnData::ColumnData(Column& column, ResultSet& resultSet, commonj::sdo::DataObjectPtr dataObjectContainer) {
+ this->column = &column;
+
+ switch (column.getSQLType()) {
+
+ case SQL_INTEGER :
+ {
+ long sqlInteger = resultSet.getSQLInteger(
+ column.getContainerTable()->getTableName(), column.getName());
+
+ data = new int;
+ int* aux = (int*) data;
+ *aux = sqlInteger;
+ dataObjectContainer->setInteger(column.getName().c_str(), sqlInteger);
+ }
+
+ break;
+
+ case SQL_CHAR :
+ {
+ 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(),
+ 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(),
+ 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(),
+ 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(),
+ 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;
+
+ default :
+ throw std::logic_error("Invalid sql type!");
+
+ }
+
+}
+
+ColumnData::~ColumnData(void) {
+ delete data;
+}
+
+bool ColumnData::operator==(ColumnData& columnData) const {
+
+ if (column->getSQLType() != columnData.column->getSQLType()) {
+ return false;
+ }
+
+ 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 {
+ return !(*this == columnData);
+}
Added: 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=auto&rev=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ColumnData.h Wed May 2 00:44:29 2007
@@ -0,0 +1,46 @@
+/*
+ * 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 COLUMN_DATA_H
+#define COLUMN_DATA_H
+
+#include <windows.h>
+#include <sql.h>
+#include <sqlext.h>
+#include <string>
+
+#include "Column.h"
+
+#include "commonj/sdo/DataObject.h"
+
+class ColumnData {
+
+ private:
+ Column* column;
+ void* data;
+
+ public:
+ ColumnData(Column& column, ResultSet& resultSet, commonj::sdo::DataObjectPtr dataObjectContainer);
+ virtual ~ColumnData(void);
+
+ bool operator==(ColumnData& columnData) const;
+ bool operator!=(ColumnData& columnData) const;
+
+};
+
+#endif //COLUMN_DATA_H
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=534339&r1=534338&r2=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Config.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Config.cpp Wed May 2 00:44:29 2007
@@ -47,6 +47,14 @@
void Config::addTable(Table& table) {
+ std::list<Relationship*>* relationships = getRelationships(table.getTableName());
+ std::list<Relationship*>::iterator it;
+
+ for (it = relationships->begin() ; it != relationships->end() ; it++) {
+ table.addRelationship(**it);
+ }
+
+ delete relationships;
tables->insert(std::make_pair(table.getTableName(), &table));
//load PKs
@@ -103,11 +111,21 @@
}
+std::map<std::string, Relationship*>& Config::getRelationships(void) const {
+ return *relationships;
+}
+
void Config::addRelationship(Relationship& relationship) {
relationships->insert(std::make_pair(relationship.getPKTableName() + relationship.getFKTableName(),
&relationship));
relationship.setConfig(this);
+ Table* table = getTable(relationship.getPKTableName());
+
+ if (table != 0) {
+ table->addRelationship(relationship);
+ }
+
}
std::list<Relationship*>* Config::getRelationships(std::string tableName, bool pkTable) const {
@@ -145,10 +163,6 @@
return it->second;
-}
-
-std::map<std::string, Relationship*>& Config::getRelationships(void) const {
- return *relationships;
}
std::map<std::string, Table*>& Config::getTables(void) const {
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=534339&r1=534338&r2=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Config.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Config.h Wed May 2 00:44:29 2007
@@ -55,7 +55,7 @@
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;
-
+
};
#endif //CONFIG_H
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=534339&r1=534338&r2=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilder.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilder.cpp Wed May 2 00:44:29 2007
@@ -18,33 +18,217 @@
*/
#include "GraphBuilder.h"
+//test
+#include "commonj/sdo/TypeList.h"
+#include "commonj/sdo/Type.h"
+#include <iostream>
+#include <sstream>
+#include <queue>
+
+void printDataGraphMetaData(commonj::sdo::DataFactoryPtr dataFactory) {
+ const commonj::sdo::TypeList& typeList = dataFactory->getTypes();
+
+ for (int i = 0 ; i < typeList.size() ; i++) {
+ std::cout << "\n[" << typeList[i].getName() << "]\n";
+ commonj::sdo::PropertyList propertyList = typeList[i].getProperties();
+
+ for (int j = 0 ; j < propertyList.size() ; j++) {
+
+ std::cout << propertyList[j].getName();
+
+ if (propertyList[j].isReference()) {
+ std::cout << "-> ";
+ } else {
+ std::cout << " - ";
+ }
+
+ std::cout << propertyList[j].getType().getName() << "\n";
+
+ }
+
+ }
+
+}
+int tabCount = 0;
+std::string getTab(int count) {
+ std::string ret = "\n";
+ ret.append(count* 3, ' ');
+ return ret;
+
+}
+
+#include <sstream>
+
+std::string to_string (const int& t)
+{
+ std::stringstream ss;
+ ss << t;
+ return ss.str();
+}
+
+void printDataGraph(commonj::sdo::DataObjectPtr dataObject) {
+ commonj::sdo::PropertyList& propertyList = dataObject->getType().getProperties();
+ std::cout << getTab(tabCount) << "[" << dataObject->getType().getName() << "]";
+ tabCount++;
+
+ for (int i = 0 ; i < propertyList.size() ; i++) {
+
+ if (propertyList[i].isMany()) {
+ std::cout << getTab(tabCount) << "[LIST]";
+ tabCount++;
+ commonj::sdo::DataObjectList& objectList = dataObject->getList(propertyList[i]);
+
+ for (int j = 0 ; j < objectList.size() ; j++) {
+
+ if (objectList[i]->getType().isDataType()) {
+ std::string typeName = objectList[j]->getType().getName();
+
+ if (typeName == "String") {
+ wchar_t* buf = new wchar_t[200];
+ int copied = dataObject->getString((((std::string) propertyList[j].getName()) + "[" + to_string(j) + "]").c_str(), buf, 200);
+ buf[copied] = 0;
+ std::wstring wstr = buf;
+ std::string str(wstr.begin(), wstr.end());
+ str.assign(wstr.begin(), wstr.end());
+
+
+ std::cout << getTab(tabCount) << str << " : " << objectList[j]->getType().getName();
+ delete [] buf;
+ } else if (typeName == "Integer") {
+ std::cout << getTab(tabCount) << dataObject->getInteger((((std::string) propertyList[j].getName()) + "[" + to_string(j) + "]").c_str()) << " : " << objectList[j]->getType().getName();
+ }
+
+ } else {
+ printDataGraph(objectList[j]);
+ }
+
+ }
+
+ if (objectList.size() == 0) {
+ std::cout << getTab(tabCount) << "--empty--";
+ }
+
+ tabCount--;
+
+ } else {
+ commonj::sdo::DataObjectPtr actual = dataObject->getDataObject(propertyList[i]);
+ std::string typeName = actual->getType().getName();
+ if (typeName == "String") {
+ wchar_t* buf = new wchar_t[200];
+ int copied = dataObject->getString(propertyList[i], buf, 200);
+ buf[copied] = 0;
+ std::wstring wstr = buf;
+ std::string str(wstr.begin(), wstr.end());
+ str.assign(wstr.begin(), wstr.end());
+
+
+ std::cout << getTab(tabCount) << str << " : " << actual->getType().getName();
+ delete [] buf;
+ } else if (typeName == "Integer") {
+ std::cout << getTab(tabCount) << dataObject->getInteger(propertyList[i]) << " : " << actual->getType().getName();
+ }
+
+ }
+
+ if (propertyList.size() == 0) {
+ std::cout << getTab(tabCount) << "--empty--";
+ }
+
+ /*for (int j = 0 ; j < propertyList.size() ; j++) {
+
+ std::cout << propertyList[j].getName();
+
+ if (propertyList[j].isReference()) {
+ std::cout << "-> ";
+ } else {
+ std::cout << " - ";
+ }
+
+ std::cout << propertyList[j].getType().getName() << "\n";
+
+ }*/
+
+ }
+
+ tabCount--;
+
+}
+
GraphBuilder::GraphBuilder(Config& config, ResultSet& resultSet) {
graphBuilderMetaData = new GraphBuilderMetaData(config, resultSet.getResultSetMetaData()) ;
commonj::sdo::DataFactoryPtr dataFactory = graphBuilderMetaData->createGraph();
+
+ printDataGraphMetaData(dataFactory);
this->resultSet = &resultSet;
- /*root = dataFactory->create(DAS_NAMESPACE, DAS_ROOT_NAME);
+ root = dataFactory->create(DAS_NAMESPACE, DAS_ROOT_NAME);
- const std::map<std::string, Table*> tables = graphBuiderMetaData.getTables();
+ const std::map<std::string, Table*> tables = graphBuilderMetaData->getTables();
std::map<std::string, Table*>::const_iterator it;
while (resultSet.next()) {
- for (it = tables.begin() ; it != tables.end() ; i++) {
+ for (it = tables.begin() ; it != tables.end() ; it++) {
Table* table = it->second;
- DataObjectPtr tableDataObject = root->create(DAS_NAMESPACE,
- table->getTableName());
-
+ std::list<TableData*>* tableList;
+ TableData* tableData = new TableData(*table, *this, resultSet);
+
+ if (!tableData->hasPK()) {
+ delete tableData;
+ continue;
+ }
+
+ std::map<std::string, std::list<TableData*>*>::iterator it2 =
+ tablesData.find(table->getTableName());
+
+ if (it2 == tablesData.end()) {
+ tableList = new std::list<TableData*>();
+ tablesData.insert(std::make_pair(table->getTableName(), tableList));
+ } else {
+ tableList = it2->second;
+ }
+
+ std::list<TableData*>::const_iterator it3;
+
+ for (it3 = tableList->begin() ; it3 != tableList->end() ; it3++) {
+
+ if (*tableData == **it3) {
+ delete tableData;
+ continue;
+
+ }
+
+ }
+
+ tableList->push_back(tableData);
+
}
- }*/
+ }
+
+ printDataGraph(root);
}
GraphBuilder::~GraphBuilder(void) {
+ std::map<std::string, std::list<TableData*>*>::iterator it;
+ std::list<TableData*>::iterator it2;
+
+ for (it = tablesData.begin() ; it != tablesData.end() ; it++) {
+ std::list<TableData*>* tableList = it->second;
+
+ for (it2 = tableList->begin() ; it2 != tableList->end() ; it2++) {
+ delete *it2;
+ }
+
+ delete tableList;
+
+ }
+
delete root;
delete graphBuilderMetaData;
+
}
commonj::sdo::DataObjectPtr GraphBuilder::getRoot(void) const {
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=534339&r1=534338&r2=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilder.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilder.h Wed May 2 00:44:29 2007
@@ -21,22 +21,27 @@
#include "ResultSet.h"
#include "Config.h"
+#include "TableData.h"
#include "GraphBuilderMetaData.h"
#include "commonj/sdo/DataFactory.h"
#include "commonj/sdo/DataObject.h"
#include "das_constants.h"
+class TableData;
+
class GraphBuilder {
private:
ResultSet* resultSet;
GraphBuilderMetaData* graphBuilderMetaData;
commonj::sdo::DataObjectPtr root;
-
+ std::map<std::string, std::list<TableData*>*> tablesData;
+
public:
GraphBuilder(Config& config, ResultSet& 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=534339&r1=534338&r2=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilderMetaData.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilderMetaData.cpp Wed May 2 00:44:29 2007
@@ -22,6 +22,9 @@
this->resultSetMetaData = &resultSetMetaData;
this->config = &config;
graphTables = new std::map<std::string, Table*>();
+ std::map<std::string, Relationship*>& configRelationships = config.getRelationships();
+ relationships = new std::list<Relationship*>();
+ std::map<std::string, Relationship*>::iterator relationshipIterator;
unsigned int colCount = resultSetMetaData.getColumnCount();
std::map<std::string, std::list<Column*>*> tablesColumns;
@@ -33,7 +36,7 @@
Table* table = config.getTable(columnTableName);
if (table == 0) {
- Table* newTable = new Table(config, columnTableName);
+ Table* newTable = new Table(*this, columnTableName);
config.addTable(*newTable);
table = newTable;
@@ -54,6 +57,33 @@
}
+ for (relationshipIterator = configRelationships.begin() ;
+ relationshipIterator != configRelationships.end() ; relationshipIterator++) {
+
+ Relationship& relationship = *relationshipIterator->second;
+ std::map<std::string, KeyPair*>& keyPairs = relationship.getKeyPairs();
+ std::map<std::string, KeyPair*>::iterator keyPairIterator;
+
+ for (keyPairIterator = keyPairs.begin() ; keyPairIterator != keyPairs.end() ;
+ keyPairIterator++) {
+
+ KeyPair& keyPair = *keyPairIterator->second;
+
+ if (!resultSetMetaData.containsColumn(relationship.getPKTableName(),
+ keyPair.getPKColumnName()) ||
+ resultSetMetaData.containsColumn(relationship.getFKTableName(),
+ keyPair.getFKColumnName())) {
+
+ continue;
+
+ }
+
+ }
+
+ relationships->push_back(&relationship);
+
+ }
+
std::map<std::string, Table*>::iterator it;
for (it = graphTables->begin() ; it != graphTables->end() ; it++) {
@@ -70,13 +100,16 @@
GraphBuilderMetaData::~GraphBuilderMetaData(void) {
delete graphTables;
+ delete relationships;
+
}
commonj::sdo::DataFactoryPtr GraphBuilderMetaData::createGraph(void) const {
commonj::sdo::DataFactoryPtr dataFactory = commonj::sdo::DataFactory::getDataFactory();
dataFactory->addType(DAS_NAMESPACE, DAS_ROOT_NAME);
-
+
std::map<std::string, Table*>::const_iterator it;
+ std::list<Relationship*>::const_iterator it2;
for (it = graphTables->begin() ; it != graphTables->end() ; it++) {
Table& table = *(it->second);
@@ -92,6 +125,15 @@
it->second->createGraph(*this, dataFactory);
}
+ for (it2 = relationships->begin() ; it2 != relationships->end() ; it2++) {
+ const Relationship& relationship = **it2;
+
+ dataFactory->addPropertyToType(DAS_NAMESPACE, relationship.getPKTableName().c_str(),
+ relationship.getName().c_str(), DAS_NAMESPACE,
+ relationship.getFKTableName().c_str(), true, false, false);
+
+ }
+
return dataFactory;
}
@@ -116,5 +158,35 @@
}
return it->second;
+
+}
+
+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=534339&r1=534338&r2=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilderMetaData.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/GraphBuilderMetaData.h Wed May 2 00:44:29 2007
@@ -26,6 +26,8 @@
#include "ResultSet.h"
#include "Table.h"
#include "Config.h"
+#include "Relationship.h"
+#include "KeyPair.h"
#include "ResultSetMetaData.h"
#include "commonj/sdo/DataFactory.h"
#include "das_constants.h"
@@ -37,6 +39,7 @@
private:
ResultSetMetaData* resultSetMetaData;
std::map<std::string, Table*>* graphTables;
+ std::list<Relationship*>* relationships;
Config* config;
public:
@@ -47,7 +50,8 @@
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;
};
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=534339&r1=534338&r2=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ReadCommandImpl.cpp Wed May 2 00:44:29 2007
@@ -102,40 +102,9 @@
}
-//test
-#include "commonj/sdo/TypeList.h"
-#include "commonj/sdo/Type.h"
-#include <iostream>
-
-void printDataGraph(commonj::sdo::DataFactoryPtr dataFactory) {
- const commonj::sdo::TypeList& typeList = dataFactory->getTypes();
-
- for (int i = 0 ; i < typeList.size() ; i++) {
- std::cout << "\n[" << typeList[i].getName() << "]\n";
- commonj::sdo::PropertyList propertyList = typeList[i].getProperties();
-
- for (int j = 0 ; j < propertyList.size() ; j++) {
-
- if (propertyList[j].isReference()) {
- std::cout << "-> ";
- }
-
- if (propertyList[j].getType().isDataType()) {
- std::cout << propertyList[j].getName() << " - ";
- }
-
- std::cout << propertyList[j].getType().getName();
-
- std::cout << "\n";
-
- }
-
- }
-
-}
-
commonj::sdo::DataObjectPtr ReadCommandImpl::buildGraph(ResultSet& resultSet) { /*throws SQLException*/
GraphBuilder graphBuilder(((DASImpl*) das)->getConfig(), resultSet);
+
//printDataGraph(dataFactory);
//commonj::sdo::ChangeSummaryPtr changeSummary = rootDataObject->getChangeSummary();
Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/Relationship.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/Relationship.cpp?view=diff&rev=534339&r1=534338&r2=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Relationship.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Relationship.cpp Wed May 2 00:44:29 2007
@@ -19,6 +19,7 @@
#include "Relationship.h"
Relationship::Relationship(std::string pkTableName, std::string fkTableName) {
+ this->relationshipName = pkTableName + fkTableName;
this->pkTableName = pkTableName;
this->fkTableName = fkTableName;
keyPairs = new std::map<std::string, KeyPair*>();
@@ -26,6 +27,20 @@
}
+Relationship::Relationship(std::string pkTableName, std::string fkTableName,
+ std::string relationshipName) {
+ this->relationshipName = relationshipName;
+ this->pkTableName = pkTableName;
+ this->fkTableName = fkTableName;
+ keyPairs = new std::map<std::string, KeyPair*>();
+ config = 0;
+
+}
+
+std::string Relationship::getName(void) const {
+ return relationshipName;
+}
+
Relationship::~Relationship(void) {
delete keyPairs;
}
@@ -77,4 +92,53 @@
void Relationship::setConfig(Config* config) {
this->config = config;
+}
+
+std::list<KeyPair*>* Relationship::getKeyPair(std::string columnName, bool pkColumn) const {
+ std::map<std::string, KeyPair*>::const_iterator it;
+ std::list<KeyPair*>* ret = new std::list<KeyPair*>();
+
+ for (it = keyPairs->begin() ; it != keyPairs->end() ; it++) {
+ std::string actualColumnName;
+
+ if (pkColumn) {
+ actualColumnName = it->second->getPKColumnName();
+ } else {
+ actualColumnName = it->second->getFKColumnName();
+ }
+
+ if (columnName == actualColumnName) {
+ ret->push_back(it->second);
+ }
+
+ }
+
+ return ret;
+
+}
+
+
+bool Relationship::containsColumn(std::string columnName, bool pkColumn) const {
+ std::map<std::string, KeyPair*>::const_iterator it;
+
+ for (it = keyPairs->begin() ; it != keyPairs->end() ; it++) {
+
+ if (pkColumn) {
+
+ if (it->second->getPKColumnName() == columnName) {
+ return true;
+ }
+
+ } else {
+
+ if (it->second->getFKColumnName() == columnName) {
+ return true;
+ }
+
+ }
+
+ }
+
+ return false;
+
}
Modified: incubator/tuscany/cpp/das/runtime/das_lite/src/Relationship.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/das_lite/src/Relationship.h?view=diff&rev=534339&r1=534338&r2=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Relationship.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Relationship.h Wed May 2 00:44:29 2007
@@ -30,6 +30,7 @@
friend class Config;
private:
+ std::string relationshipName;
std::string pkTableName;
std::string fkTableName;
std::map<std::string, KeyPair*>* keyPairs;
@@ -39,15 +40,19 @@
public:
Relationship(std::string pkTableName, std::string fkTableName);
+ Relationship(std::string pkTableName, std::string fkTableName, std::string relationshipName);
virtual ~Relationship(void);
void addKeyPair(KeyPair& keyPair);
std::string getPKTableName(void) const;
std::string getFKTableName(void) const;
+ std::string getName(void) const;
std::map<std::string, KeyPair*>& getKeyPairs(void) const;
KeyPair* getKeyPair(std::string pkColumnName, std::string fkColumnName) const;
+ std::list<KeyPair*>* getKeyPair(std::string columnName, bool pkColumn = true) const;
+ bool containsColumn(std::string columnName, bool pkColumn = true) const;
};
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=534339&r1=534338&r2=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSet.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSet.cpp Wed May 2 00:44:29 2007
@@ -36,6 +36,21 @@
return *stmt;
}
+long ResultSet::getSQLInteger(unsigned int columnIndex) const {
+ SQLCHAR strAux[1];
+ SQLINTEGER sqlPtr = 0;
+ SQLSMALLINT length = 0;
+ SQLINTEGER aux = 0;
+ SQLGetData(stmt->getODBCStatement(), columnIndex + 1, SQL_C_LONG, &sqlPtr, 0, &aux);
+
+ return (long) sqlPtr;
+
+}
+
+long ResultSet::getSQLInteger(std::string tableName, std::string columnName) const {
+ return getSQLInteger(metaData->getColumnIndex(tableName, columnName));
+}
+
wchar_t ResultSet::getSQLChar(unsigned int columnIndex) const {
wchar_t ret = 0;
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=534339&r1=534338&r2=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSet.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/ResultSet.h Wed May 2 00:44:29 2007
@@ -61,6 +61,9 @@
std::string getSQLDecimal(unsigned int columnIndex) const;
std::string getSQLDecimal(std::string tableName, std::string columnName) const;
+ long getSQLInteger(unsigned int columnIndex) const;
+ long getSQLInteger(std::string tableName, std::string columnName) const;
+
bool isNull(unsigned int columnIndex) const;
bool isNull(std::string tableName, std::string columnName) const;
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=534339&r1=534338&r2=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Table.cpp (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Table.cpp Wed May 2 00:44:29 2007
@@ -18,20 +18,27 @@
*/
#include "Table.h"
-Table::Table(Config& config, std::string tableName) {
- this->config = &config;
+Table::Table(GraphBuilderMetaData& graphBuilderMetaData, std::string tableName) {
+ this->graphBuilderMetaData = &graphBuilderMetaData;
this->tableName = tableName;
this->mappedName = tableName;
+ columns = new std::map<std::string, Column*>();
}
Table::~Table(void) {
std::map<std::string, Column*>::iterator it;
- for (it = columns.begin() ; it != columns.end() ; it++) {
+ for (it = columns->begin() ; it != columns->end() ; it++) {
delete it->second;
}
+ delete columns;
+
+}
+
+void Table::addRelationship(Relationship& relationship) {
+ relationships.push_back(&relationship);
}
std::string Table::getTableName(void) const {
@@ -41,12 +48,12 @@
void Table::addColumns(std::list<Column*>& columns) {
std::list<Column*>::iterator it;
for (it = columns.begin() ; it != columns.end() ;) {
- std::map<std::string, Column*>::iterator it2 = this->columns.
+ std::map<std::string, Column*>::iterator it2 = this->columns->
find((*it)->getName());
- if (it2 == this->columns.end()) {
+ if (it2 == this->columns->end()) {
(*it)->setContainerTable(this);
- this->columns.insert(std::make_pair((*it)->getName(), *it));
+ this->columns->insert(std::make_pair((*it)->getName(), *it));
it++;
} else {
@@ -58,7 +65,7 @@
}
- if (config->isConvOverConfig()) {
+ if (graphBuilderMetaData->getConfig().isConvOverConfig()) {
for (it == columns.begin() ; it != columns.end() ; it++) {
Column* column = *it;
@@ -71,11 +78,11 @@
} else if (columnName.substr(columnName.size() - 4, 3) == "_id") {
std::string referencedTable = columnName.substr(0, columnName.size() - 3);
std::string tableName = column->getContainerTable()->getTableName();
- Relationship* relationship = config->getRelationship(tableName, referencedTable);
+ Relationship* relationship = graphBuilderMetaData->getConfig().getRelationship(tableName, referencedTable);
if (relationship == 0) {
relationship = new Relationship(tableName, referencedTable);
- config->addRelationship(*relationship);
+ graphBuilderMetaData->getConfig().addRelationship(*relationship);
}
@@ -101,7 +108,7 @@
}
- std::list<Relationship*>* relationships = config->getRelationships(tableName, false);
+ std::list<Relationship*>* relationships = graphBuilderMetaData->getRelationships(tableName, false);
std::list<Relationship*>::const_iterator it2;
for (it2 = relationships->begin() ; it2 != relationships->end() ; it2++) {
@@ -109,8 +116,8 @@
std::map<std::string, KeyPair*>& keyPairs = relationship.getKeyPairs();
std::map<std::string, KeyPair*>::const_iterator it3;
- for (it3 == keyPairs.begin() ; it3 != keyPairs.end() ; it3++) {
- for (it == columns.begin() ; it != columns.end() ; it++) {
+ for (it3 = keyPairs.begin() ; it3 != keyPairs.end() ; it3++) {
+ for (it = columns.begin() ; it != columns.end() ; it++) {
Column& column = **it;
if (column.getName() == it3->second->getFKColumnName()) {
@@ -126,8 +133,8 @@
}
-Config& Table::getConfig(void) const {
- return *config;
+GraphBuilderMetaData& Table::getGraphBuilderMetaData(void) const {
+ return *graphBuilderMetaData;
}
void Table::addPKColumn(std::string columnName) {
@@ -136,35 +143,46 @@
void Table::createGraph(const GraphBuilderMetaData& graphBuilderMetaData, commonj::sdo::DataFactoryPtr dataFactory) const {
std::map<std::string, Column*>::const_iterator it;
+ std::list<Relationship*>& relationships = graphBuilderMetaData.getRelationships();
+ std::list<Relationship*>::const_iterator relationshipIterator;
+ std::list<Relationship*> tablePKRelationships;
+ std::list<Relationship*> tableFKRelationships;
+ std::list<std::string> relationshipColumns;
- for (it = columns.begin() ; it != columns.end() ; it++) {
- Column& column = *(it->second);
-
- if (column.isFK()) {
- std::list<KeyPair*>& keyPairs = column.getKeyPairs();
- std::list<KeyPair*>::const_iterator it2;
-
- for (it2 = keyPairs.begin() ; it2 != keyPairs.end() ; it2++) {
- KeyPair& keyPair = **it2;
- Table* referecedTable = graphBuilderMetaData.getTable(
- keyPair.getRelationship()->getPKTableName());
-
- if (referecedTable != 0) {
- dataFactory->addPropertyToType(DAS_NAMESPACE, tableName.c_str(),
- column.getName().c_str(), DAS_NAMESPACE,
- keyPair.getRelationship()->getPKTableName().c_str(), true, false, false);
+ for (relationshipIterator = relationships.begin() ; relationshipIterator !=
+ relationships.end() ; relationshipIterator++) {
+
+ if ((*relationshipIterator)->getFKTableName() == tableName) {
+ std::map<std::string, KeyPair*>& keyPairs = (*relationshipIterator)->getKeyPairs();
+ std::map<std::string, KeyPair*>::const_iterator keyPairIterator;
+
+ for (keyPairIterator = keyPairs.begin() ; keyPairIterator !=
+ keyPairs.end() ; keyPairIterator++) {
+
+ relationshipColumns.push_back(keyPairIterator->second->
+ getFKColumnName());
}
}
+
+ }
- } else {
- dataFactory->addType(DAS_NAMESPACE, column.getName());
- dataFactory->addPropertyToType(DAS_NAMESPACE, tableName.c_str(),
- column.getName().c_str(), SDO_NAMESPACE,
- ODBCTypeHelper::getSDOType(column.getSQLType()).c_str() , false,
- false, true);
+ for (it = columns->begin() ; it != columns->end() ; it++) {
+ Column& column = *(it->second);
+
+ if (graphBuilderMetaData.getResultSetMetaData().containsColumn(tableName, column.getName())) {
+ std::list<std::string>::const_iterator it2 = std::find(relationshipColumns.begin(),
+ relationshipColumns.end(), column.getName());
+
+ if (it2 == relationshipColumns.end()) {
+ dataFactory->addPropertyToType(DAS_NAMESPACE, tableName.c_str(),
+ column.getName().c_str(), SDO_NAMESPACE,
+ ODBCTypeHelper::getSDOType(column.getSQLType()).c_str() , false,
+ false, true);
+
+ }
}
@@ -172,28 +190,37 @@
}
-void Table::populateGraph(commonj::sdo::DataObjectPtr dataObject/*, ResultSet& resultSet*/) const {
-
- /*std::map<std::string, Column*>::iterator it;
- for (it = columns.begin() ; it != columns.end() ; it++) {
- Column* column = it->second;
-
- if (column->isFK()) {
-
- }
-
- }*/
-
-}
+//void Table::populateGraph(commonj::sdo::DataObjectPtr dataObject, ResultSet& resultSet) const {
+//
+// std::map<std::string, Column*>::const_iterator it;
+// for (it = columns->begin() ; it != columns->end() ; it++) {
+// Column& column = *it->second;
+//
+// if (resultSet.getResultSetMetaData().containsColumn(tableName, column.getName())) {
+// const commonj::sdo::Property* prop = 0;
+//
+// try {
+// prop = &dataObject->getProperty(it->second->getName().c_str());
+// } catch (SDOPropertyNotFoundException e) {}
+//
+// if (prop != 0 && prop->isContainment()) {
+// it->second->populateDataGraph(dataObject, resultSet);
+// }
+//
+// }
+//
+// }
+//
+//}
void Table::setMappedName(std::string mappedName) {
this->mappedName = mappedName;
}
Column* Table::getColumn(std::string columnName) const {
- std::map<std::string, Column*>::const_iterator it = columns.find(columnName);
+ std::map<std::string, Column*>::const_iterator it = columns->find(columnName);
- if (it == columns.end()) {
+ if (it == columns->end()) {
return 0;
}
@@ -203,4 +230,12 @@
std::string Table::getMappedName(void) const {
return mappedName;
+}
+
+const std::map<std::string, Column*>& Table::getColumns(void) const {
+ return *columns;
+}
+
+unsigned int Table::getPKColumnCount(void) const {
+ return pkColumns.size();
}
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=534339&r1=534338&r2=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/Table.h (original)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/Table.h Wed May 2 00:44:29 2007
@@ -23,10 +23,12 @@
#include <list>
#include <string>
#include <stdexcept>
+#include <algorithm>
#include "das_constants.h"
#include "Relationship.h"
#include "Config.h"
+#include "KeyPair.h"
#include "ResultSet.h"
#include "Column.h"
#include "DASImpl.h"
@@ -42,28 +44,31 @@
class Table {
private:
- std::map<std::string, Column*> columns;
+ std::map<std::string, Column*>* columns;
std::list<std::string> pkColumns;
- Config* config;
+ std::list<Relationship*> relationships;
+ GraphBuilderMetaData* graphBuilderMetaData;
std::string tableName;
std::string mappedName;
public:
- Table(Config& config, std::string tableName);
+ Table(GraphBuilderMetaData& graphBuilderMetaData, std::string tableName);
virtual ~Table(void);
void addColumns(std::list<Column*>& columns);
void setMappedName(std::string mappedName);
void addPKColumn(std::string columnName);
+ void addRelationship(Relationship& relationship);
std::string getMappedName(void) const;
- Config& getConfig(void) const;
+ GraphBuilderMetaData& getGraphBuilderMetaData(void) const;
std::string getTableName(void) const;
Column* getColumn(std::string columnName) const;
+ const std::map<std::string, Column*>& getColumns(void) const;
+ unsigned int getPKColumnCount(void) const;
void createGraph(const GraphBuilderMetaData& graphBuilderMetaData, commonj::sdo::DataFactoryPtr dataFactory) const;
- void populateGraph(commonj::sdo::DataObjectPtr dataObject/*, ResultSet& resultSet*/) const;
-
+
};
#endif //TABLE_H
Added: 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=auto&rev=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.cpp Wed May 2 00:44:29 2007
@@ -0,0 +1,89 @@
+/*
+ * 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 "TableData.h"
+
+TableData::TableData(Table& table, GraphBuilder& graphBuilder, ResultSet& resultSet) {
+ this->table = &table;
+ 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());
+
+ for (columnIterator = columns.begin() ; columnIterator != columns.end() ;
+ columnIterator++) {
+
+ Column& column = *columnIterator->second;
+ std::string columnName = column.getName();
+
+ if (metaData.containsColumn(table.getTableName(), columnName)) {
+ ColumnData* columnData = new ColumnData(column, resultSet, dataObject);
+
+ columnsData.insert(std::make_pair(columnName, columnData));
+
+ if (column.isPK()) {
+ primaryKeys.push_back(columnData);
+ }
+
+ }
+
+ }
+
+}
+
+TableData::~TableData(void) {
+ std::map<std::string, ColumnData*>::iterator it;
+
+ for (it = columnsData.begin() ; it != columnsData.end() ; it++) {
+ delete it->second;
+ }
+
+}
+
+Table& TableData::getTable(void) const {
+ return *table;
+}
+
+bool TableData::operator==(TableData& tableData) const {
+
+ if (tableData.table->getTableName() != table->getTableName()) {
+ return false;
+ }
+
+ std::list<ColumnData*>::const_iterator it;
+ std::list<ColumnData*>::const_iterator it2;
+ for (it = primaryKeys.begin(), it2 = tableData.primaryKeys.begin() ;
+ it != primaryKeys.end(), it2 != tableData.primaryKeys.end() ; it++, it2++) {
+
+ if (**it != **it2) {
+ return false;
+ }
+
+ }
+
+ return true;
+
+}
+
+bool TableData::hasPK(void) const {
+ return (primaryKeys.size() == table->getPKColumnCount());
+}
+
+bool TableData::operator!=(TableData& tableData) const {
+ return !(*this == tableData);
+}
Added: 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=auto&rev=534339
==============================================================================
--- incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.h (added)
+++ incubator/tuscany/cpp/das/runtime/das_lite/src/TableData.h Wed May 2 00:44:29 2007
@@ -0,0 +1,56 @@
+/*
+ * 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 TABLE_DATA_H
+#define TABLE_DATA_H
+
+#include <list>
+#include <map>
+#include <string>
+
+#include "Table.h"
+#include "ResultSet.h"
+#include "ColumnData.h"
+#include "GraphBuilder.h"
+#include "ResultSetMetaData.h"
+
+#include "commonj/sdo/DataObject.h"
+
+class GraphBuilder;
+
+class TableData {
+
+ private:
+ Table* table;
+ commonj::sdo::DataObjectPtr dataObject;
+ std::map<std::string, ColumnData*> columnsData;
+ std::list<ColumnData*> primaryKeys;
+
+ public:
+ TableData(Table& table, GraphBuilder& graphBuilder, ResultSet& resultSet);
+ virtual ~TableData(void);
+
+ Table& getTable(void) const;
+ bool hasPK(void) const;
+
+ bool operator==(TableData& tableData) const;
+ bool operator!=(TableData& tableData) const;
+
+};
+
+#endif //TABLE_DATA_H
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org