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/11 23:36:57 UTC
svn commit: r537297 [9/10] - in /incubator/tuscany/cpp/das:
VSExpress/tuscany_das/ VSExpress/tuscany_das/das_lite/
VSExpress/tuscany_das/das_runtime/ das_java_classes/
das_java_classes/config/ runtime/core/include/ runtime/core/include/apache/
runtime/...
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/CommandImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/CommandImpl.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/CommandImpl.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/CommandImpl.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,60 @@
+/*
+ * 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 "apache/das/rdb/CommandImpl.h"
+#include "apache/das/rdb/DASImpl.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+CommandImpl::CommandImpl(DASImpl& das, std::string sqlString) {
+ this->das = &das;
+ statement = das.getConnection()->createStatement();
+ sql = sqlString;
+
+ //statement = new Statement();
+
+ //try {
+ /*URL url = getClass().getResource("/xml/sdoJava.xsd");
+ if (url == null) {
+ //throw new RuntimeException("Could not find resource: xml/sdoJava.xsd");
+ }
+
+ InputStream inputStream = url.openStream();
+ XSDHelper.INSTANCE.define(inputStream, url.toString());
+ inputStream.close();*/
+ //} catch (IOException ex) {
+ // throw new RuntimeException(ex);
+ //}
+
+}
+
+CommandImpl::~CommandImpl() {}
+
+DASImpl& CommandImpl::getDAS(void) {
+ return *das;
+}
+
+void CommandImpl::close(void) {
+ statement->close();
+}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Config.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Config.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Config.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Config.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,185 @@
+/*
+ * 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 "apache/das/rdb/Config.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+Config::Config(DAS& das) {
+ relationships = new std::map<std::string, Relationship*>();
+ tables = new std::map<std::string, Table*>();
+ this->das = &das;
+ convOverConfig = false;
+
+}
+
+Config::~Config(void) {
+ std::map<std::string, Table*>::iterator tableIterator;
+ std::map<std::string, Relationship*>::iterator relationshipIterator;
+
+ for (tableIterator = tables->begin() ; tableIterator != tables->end() ;
+ tableIterator++) {
+ delete tableIterator->second;
+ }
+
+ for (relationshipIterator = relationships->begin() ;
+ relationshipIterator != relationships->end() ; relationshipIterator++) {
+ delete relationshipIterator->second;
+ }
+
+ delete relationships;
+ delete tables;
+
+}
+
+
+void Config::addTable(Table& table) {
+ std::list<Relationship*>* relationships = RelationshipWrapper::
+ getRelationshipsByTableName(*this->relationships, 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
+ ResultSetPtr pksResultSet = 0;
+ Connection* conn = ((DASImpl*) das)->getConnection();
+
+ try {
+ pksResultSet = conn->getDatabase().getPKs(table.getTableName());
+ } catch (std::runtime_error& e) {
+ convOverConfig = true;
+ return;
+
+ }
+
+ if (pksResultSet) {
+
+ while (pksResultSet->next()) {
+ table.addPKColumn(pksResultSet->getSQLVarchar(3));
+ }
+
+ }
+
+ //load FKs
+ ResultSetPtr fksResultSet = 0;
+
+ try {
+ fksResultSet = conn->getDatabase().getFKs(table.getTableName());
+ } catch (std::runtime_error& e) {
+ convOverConfig = true;
+ return;
+
+ }
+
+ while (fksResultSet->next()) {
+ std::string fkColumnName = fksResultSet->getSQLVarchar(7);
+ std::string pkTableName = fksResultSet->getSQLVarchar(2);
+ std::string pkColumnName = fksResultSet->getSQLVarchar(3);
+
+ fkColumnName = fkColumnName.substr(1, fkColumnName.size() - 2);
+ pkColumnName = pkColumnName.substr(1, pkColumnName.size() - 2);
+
+ Relationship* relationship = getRelationship(pkTableName, table.getTableName());
+
+ if (relationship == 0) {
+ relationship = new Relationship(pkTableName, table.getTableName());
+ addRelationship(*relationship);
+
+ }
+
+ KeyPair* keyPair = new KeyPair(pkColumnName, fkColumnName);
+ relationship->addKeyPair(*keyPair);
+
+ }
+
+}
+
+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);
+ }
+
+}
+
+Relationship* Config::getRelationship(std::string tableName, std::string referencedTableName) const {
+ std::map<std::string, Relationship*>::iterator it = relationships->find(tableName + referencedTableName);
+
+ if (it == relationships->end()) {
+ return 0;
+ }
+
+ return it->second;
+
+}
+
+std::map<std::string, Table*>& Config::getTables(void) const {
+ return *tables;
+}
+
+bool Config::isConvOverConfig(void) const {
+ return convOverConfig;
+}
+
+Table* Config::getTable(std::string tableName) const {
+ std::map<std::string, Table*>::iterator tableIterator = tables->find(tableName);
+
+ if (tableIterator == tables->end()) {
+ return 0;
+ }
+
+ return tableIterator->second;
+
+}
+
+DAS& Config::getDAS(void) const {
+ return *das;
+}
+
+void Config::loadConvOverConfigFKs(std::list<Column*>& columns) {
+ std::list<Column*>::iterator it;
+
+ for (it == columns.begin() ; it != columns.end() ; it++) {
+ Column* column = *it;
+ std::string columnName = column->getName();
+
+
+
+ }
+
+}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Connection.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Connection.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Connection.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Connection.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,167 @@
+/*
+ * 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 "apache/das/rdb/Connection.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+Connection::Connection(string dns, string user, string password) throw (SqlException){
+ database = new Database(*this);
+
+ SQLRETURN result;
+
+ SQLSMALLINT autoCommit;
+ SQLINTEGER strLen;
+
+ SQLINTEGER error;
+ SQLCHAR sqlStat;
+ SQLCHAR * message = 0;
+ SQLSMALLINT messageLength;
+
+ //Alloc environment handle
+ result = SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&environment);
+
+ if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
+ throw SqlException("Error to alloc the environment handle - SQLHENV");
+
+ //Set the environment
+ result = SQLSetEnvAttr(environment, SQL_ATTR_ODBC_VERSION,(void*)SQL_OV_ODBC3, 0);
+
+ if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)){
+ SQLFreeHandle(SQL_HANDLE_ENV, environment);
+ throw SqlException("Error to set the environment handle - SQLHENV");
+ }
+
+ //Allocate connection handle
+ result = SQLAllocHandle(SQL_HANDLE_DBC, environment, &connection);
+
+ if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)){
+ SQLFreeHandle(SQL_HANDLE_ENV, environment);
+ throw SqlException("Error to alloc the connection handle - SQLHDBC");
+ }
+
+ setAutoCommit(false);
+
+ //Connect to the datasource
+ result = SQLConnect(connection, reinterpret_cast<SQLCHAR *>(const_cast<char *> (dns.c_str())), SQL_NTS,
+ reinterpret_cast<SQLCHAR *>(const_cast<char *> (user.c_str())), SQL_NTS,
+ reinterpret_cast<SQLCHAR *>(const_cast<char *> (password.c_str())), SQL_NTS);
+
+ if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)){
+
+ SQLGetDiagRec(SQL_HANDLE_DBC, connection,1,
+ &sqlStat, &error,message,100,&messageLength);
+
+ SQLFreeHandle(SQL_HANDLE_DBC, connection);
+ SQLFreeHandle(SQL_HANDLE_ENV, environment);
+
+ string error("Error to establish the connection.\nSQLSTATE: ");
+ error += reinterpret_cast<char*>(&sqlStat);
+ throw SqlException(error.c_str());
+ }
+
+ database = new Database(*this);
+
+}
+
+Connection::~Connection(void){
+ std::list<StatementPtr*>::iterator it;
+
+ for (it = statements.begin() ; it != statements.end() ; it++) {
+
+ if (**it) {
+ delete **it;
+ delete *it;
+
+ }
+
+ }
+
+ delete database;
+
+ SQLDisconnect(connection);
+ SQLFreeHandle(SQL_HANDLE_DBC,connection);
+ SQLFreeHandle(SQL_HANDLE_ENV, environment);
+
+}
+
+SQLHDBC Connection::getODBCConnection(void) const{
+ return connection;
+}
+
+void Connection::commit(void){
+ SQLEndTran(SQL_HANDLE_DBC, connection, SQL_COMMIT);
+}
+
+void Connection::rollback(void){
+ SQLEndTran(SQL_HANDLE_DBC, connection, SQL_ROLLBACK);
+}
+
+void Connection::setAutoCommit(bool autoCommit){
+ if(autoCommit)
+ SQLSetConnectAttr(connection,SQL_ATTR_AUTOCOMMIT,reinterpret_cast<SQLPOINTER>(SQL_AUTOCOMMIT_ON), SQL_IS_INTEGER );
+ else
+ SQLSetConnectAttr(connection,SQL_ATTR_AUTOCOMMIT,SQL_AUTOCOMMIT_OFF, SQL_IS_INTEGER );
+}
+
+Database& Connection::getDatabase(void) const {
+ return *database;
+}
+
+StatementPtr Connection::createStatement(void) throw (SqlException){
+ SQLHSTMT statementHandle;
+ SQLRETURN result = SQLAllocHandle(SQL_HANDLE_STMT, connection, &statementHandle);
+
+ if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)){
+
+ SQLDisconnect(connection);
+ SQLFreeHandle(SQL_HANDLE_DBC, connection);
+ SQLFreeHandle(SQL_HANDLE_ENV, environment);
+
+ throw SqlException("Error to alloc the statement handle - SQLSTMT");
+ }
+
+ std::list<StatementPtr*>::iterator it;
+
+ for (it = statements.begin() ; it != statements.end() ; ) {
+
+ if (**it) {
+ it++;
+
+ } else {
+ std::list<StatementPtr*>::iterator aux = it;
+ it++;
+ statements.erase(aux);
+
+ }
+
+ }
+
+ Statement* stmt = new Statement(*this, statementHandle);
+ StatementPtr ret(stmt);
+ statements.push_back(new StatementPtr(stmt, false));
+
+ return ret;
+
+}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/DASFactoryImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/DASFactoryImpl.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/DASFactoryImpl.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/DASFactoryImpl.cpp Fri May 11 14:36:45 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.
+ */
+#include "apache/das/rdb/DASFactoryImpl.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+DASFactoryImpl::DASFactoryImpl(void) {}
+
+DASFactoryImpl::~DASFactoryImpl(void) {}
+
+DAS* DASFactoryImpl::createDAS(Connection& connection) {
+ return new DASImpl(connection);
+}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/DASImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/DASImpl.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/DASImpl.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/DASImpl.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,99 @@
+/*
+ * 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 "apache/das/rdb/DASImpl.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+DASImpl::DASImpl(Connection& inConnection) {
+ createdCommands = new std::list<Command*>();
+ setConnection(&inConnection);
+ config = new Config(*this);
+
+}
+
+DASImpl::~DASImpl() {
+ std::list<Command*>::iterator it;
+
+ for (it = createdCommands->begin() ; it != createdCommands->end() ; it++) {
+ delete *it;
+ }
+
+ delete createdCommands;
+ delete config;
+
+}
+
+
+void DASImpl::setConnection(Connection* aConnection) {
+ connection = aConnection;
+}
+
+Connection* DASImpl::getConnection(void) {
+ return connection;
+}
+
+void DASImpl::releaseResources(void) {
+ closeConnection();
+}
+
+Command& DASImpl::createCommand(std::string sql) {
+ return baseCreateCommand(sql);
+}
+
+Command& DASImpl::baseCreateCommand(std::string inSql) {
+ CommandImpl* returnCmd = NULL;
+ //trim(inSql);
+ char firstChar = toupper(inSql[0]);
+
+ switch (firstChar) {
+ case 'S':
+ returnCmd = new ReadCommandImpl(*this, inSql);
+ break;
+
+ }
+
+ createdCommands->push_back(returnCmd);
+ return *returnCmd;
+
+}
+
+void DASImpl::closeConnection(void) {
+
+ if (connection != NULL) {
+
+ //try {
+ SQLDisconnect(connection);
+ connection = NULL;
+ //} catch (SQLException e) {
+ // throw new RuntimeException(e);
+ //}
+
+ }
+
+}
+
+Config& DASImpl::getConfig(void) const {
+ return *config;
+}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/GraphBuilder.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/GraphBuilder.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/GraphBuilder.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/GraphBuilder.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,341 @@
+/*
+ * 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 "apache/das/rdb/GraphBuilder.h"
+
+//test
+#include "commonj/sdo/TypeList.h"
+#include "commonj/sdo/Type.h"
+#include <iostream>
+#include <sstream>
+#include <queue>
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+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, bool ref = false) {
+ 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) << ((propertyList[i].isReference()) ? "-> " : "") << "[LIST]";
+ tabCount++;
+ commonj::sdo::DataObjectList& objectList = dataObject->getList(propertyList[i]);
+
+ for (int j = 0 ; j < objectList.size() ; j++) {
+
+ if (objectList[j]->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 if (!ref) {
+ printDataGraph(objectList[j], propertyList[i].isReference());
+ }
+
+ }
+
+ 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) << ((propertyList[i].isReference()) ? "-> " : "") << 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, ResultSetPtr resultSet) {
+ graphBuilderMetaData = new GraphBuilderMetaData(config, resultSet->getResultSetMetaData()) ;
+ commonj::sdo::DataFactoryPtr dataFactory = graphBuilderMetaData->createGraph();
+
+ printDataGraphMetaData(dataFactory);
+ this->resultSet = resultSet;
+ const std::map<std::string, Table*> tables = graphBuilderMetaData->getTables();
+
+ 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, 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;
+ bool duplicated = false;
+
+ for (it3 = tableList->begin() ; it3 != tableList->end() ; it3++) {
+
+ if (*tableData == **it3) {
+ delete tableData;
+ duplicated = true;
+ break;
+
+ }
+
+ }
+
+ 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);
+ }
+
+ }
+
+ 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) {
+ 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 graphBuilderMetaData;
+
+}
+
+commonj::sdo::DataObjectPtr GraphBuilder::getRoot(void) const {
+ return root;
+}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/GraphBuilderMetaData.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/GraphBuilderMetaData.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/GraphBuilderMetaData.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/GraphBuilderMetaData.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,178 @@
+/*
+ * 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 "apache/das/rdb/GraphBuilderMetaData.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+GraphBuilderMetaData::GraphBuilderMetaData(Config& config, ResultSetMetaData& resultSetMetaData) {
+ 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;
+
+ for (int i = 0 ; i < colCount ; i++) {
+ std::string columnName = resultSetMetaData.getColumnName(i);
+ SQLSMALLINT columnSQLType = resultSetMetaData.getSQLType(i);
+ std::string columnTableName = resultSetMetaData.getTableName(i);
+ Table* table = config.getTable(columnTableName);
+
+ if (table == 0) {
+ Table* newTable = new Table(*this, columnTableName);
+ config.addTable(*newTable);
+ table = newTable;
+
+ }
+
+ std::map<std::string, std::list<Column*>*>::iterator it = tablesColumns.
+ find(columnTableName);
+
+ if (it == tablesColumns.end()) {
+ std::list<Column*>* columnsList = new std::list<Column*>();
+ columnsList->push_back(new Column(columnName, columnSQLType));
+ tablesColumns.insert(std::make_pair(columnTableName, columnsList));
+ graphTables->insert(std::make_pair(table->getTableName(), table));
+
+ } else {
+ tablesColumns[columnTableName]->push_back(new Column(columnName, columnSQLType));
+ }
+
+ }
+
+ 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;
+ bool contains = true;
+
+ 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())) {
+
+ contains = false;
+ break;
+
+ }
+
+ }
+
+ if (contains) {
+ relationships->push_back(&relationship);
+ }
+
+ }
+
+ std::map<std::string, Table*>::iterator it;
+
+ for (it = graphTables->begin() ; it != graphTables->end() ; it++) {
+ Table* table = it->second;
+ std::string tableName = table->getTableName();
+ std::list<Column*>* columns = tablesColumns[tableName];
+
+ table->addColumns(*columns);
+ delete columns;
+
+ }
+
+}
+
+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);
+ std::string tableName = table.getTableName();
+
+ dataFactory->addType(DAS_NAMESPACE, tableName.c_str());
+ dataFactory->addPropertyToType(DAS_NAMESPACE, DAS_ROOT_NAME,
+ tableName.c_str(), DAS_NAMESPACE, tableName.c_str(), true, false, true);
+
+ }
+
+ for (it = graphTables->begin() ; it != graphTables->end() ; it++) {
+ 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;
+
+}
+
+ResultSetMetaData& GraphBuilderMetaData::getResultSetMetaData(void) const {
+ return *resultSetMetaData;
+}
+
+Config& GraphBuilderMetaData::getConfig(void) const {
+ return *config;
+}
+
+std::map<std::string, Table*>& GraphBuilderMetaData::getTables(void) const {
+ return *graphTables;
+}
+
+Table* GraphBuilderMetaData::getTable(std::string tableName) const {
+ std::map<std::string, Table*>::iterator it = graphTables->find(tableName);
+
+ if (it == graphTables->end()) {
+ return 0;
+ }
+
+ return it->second;
+
+}
+
+std::list<Relationship*>& GraphBuilderMetaData::getRelationships(void) const {
+ return *relationships;
+}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/KeyPair.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/KeyPair.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/KeyPair.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/KeyPair.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,52 @@
+/*
+ * 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 "apache/das/rdb/KeyPair.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+KeyPair::KeyPair(std::string pkColumnName, std::string fkColumnName) {
+ this->pkColumnName = pkColumnName;
+ this->fkColumnName = fkColumnName;
+ relationship = 0;
+
+}
+
+KeyPair::~KeyPair(void) {}
+
+std::string KeyPair::getPKColumnName(void) const {
+ return pkColumnName;
+}
+
+std::string KeyPair::getFKColumnName(void) const {
+ return fkColumnName;
+}
+
+void KeyPair::setRelationship(Relationship* relationship) {
+ this->relationship = relationship;
+}
+
+Relationship* KeyPair::getRelationship(void) const {
+ return relationship;
+}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/ODBCTypeHelper.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/ODBCTypeHelper.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/ODBCTypeHelper.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/ODBCTypeHelper.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,48 @@
+/*
+ * 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 "apache/das/rdb/ODBCTypeHelper.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+const std::string ODBCTypeHelper::getSDOType(SQLSMALLINT sqlType) {
+
+ switch (sqlType) {
+
+ case SQL_CHAR :
+ return "Integer";
+
+ case SQL_REAL :
+ return "Float";
+
+ case SQL_FLOAT :
+ case SQL_DOUBLE :
+ return "Double";
+
+ default :
+ return "String";
+
+ }
+
+}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/PreparedStatement.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/PreparedStatement.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/PreparedStatement.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/PreparedStatement.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,42 @@
+/*
+ * 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 "apache/das/rdb/PreparedStatement.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+PreparedStatement::PreparedStatement(Connection& connection, SQLHSTMT statementHandle, string sql)
+ : Statement(connection, statementHandle){
+ this->sql = sql;
+
+ for(int i = 0; i < sql.size(); i++){
+ if(sql.at(i) == '?')
+ positions.push_back(i);
+ }
+}
+
+
+PreparedStatement::~PreparedStatement(){
+ Statement::~Statement();
+}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/ReadCommandImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/ReadCommandImpl.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/ReadCommandImpl.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/ReadCommandImpl.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,111 @@
+/*
+ * 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 "apache/das/rdb/ReadCommandImpl.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+ReadCommandImpl::ReadCommandImpl(DASImpl& das, std::string sqlString) : CommandImpl(das, sqlString) {}
+
+ReadCommandImpl::~ReadCommandImpl(void) {}
+
+commonj::sdo::DataObjectPtr ReadCommandImpl::executeQuery(void) {
+ ResultSetPtr results = statement->executeQuery(sql);
+ commonj::sdo::DataObjectPtr root = buildGraph(results);
+
+ return root;
+
+}
+
+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 root;
+
+ /*int columnCount = getColumnCount(statement);
+ int col;
+ int i;
+ SQLSMALLINT sqlType = 0;
+ std::list<SQLSMALLINT> columnTypes;
+ std::string columnName;
+
+ dataFactory->addType(DAS_NAMESPACE, DAS_ROOT);
+ const commonj::sdo::Type& dasType = dataFactory->getType(DAS_NAMESPACE, DAS_ROOT);
+ const commonj::sdo::Type& intType = dataFactory->getType("commonj.sdo","Integer");
+ const commonj::sdo::Type& stringType = dataFactory->getType("commonj.sdo","String");*/
+
+ //for (col = 1 ; col <= columnCount ; col++) {
+ // sqlType = getSQLColumnType(statement, col);
+ // columnName = getColumnName(statement, col);
+ // columnTypes.push_back(sqlType);
+ //
+ // switch (sqlType) {
+
+ // case SQL_INTEGER :
+ // dataFactory->addPropertyToType(dasType, columnName, intType);
+ // break;
+
+ // case SQL_CHAR :
+ // dataFactory->addPropertyToType(dasType, columnName, stringType);
+ // break;
+
+ // default :
+ // ;
+ // //throw exception
+
+ // }
+ //
+ //}
+
+ /*commonj::sdo::DataObjectPtr rootDataObject = dataFactory->create(DAS_NAMESPACE, DAS_ROOT);
+ SQLRETURN sqlRet = SQLFetch(statement);
+
+ while (sqlRet == SQL_SUCCESS) {
+ std::list<SQLSMALLINT>::iterator it = columnTypes.begin();
+ int col = 0;
+
+ while (it != columnTypes.end()) {
+ SQLSMALLINT sqlType = *it;
+
+ if (sqlType == SQL_INTEGER) {
+ rootDataObject->setInteger(col, getIntegerData(statement, col + 1));
+
+ } else if (sqlType == SQL_CHAR) {
+ rootDataObject->setCString(col, getStringData(statement, col + 1));
+ }
+
+ sqlRet = SQLFetch(statement);
+ col++;
+ it++;
+
+ }
+
+ }*/
+
+}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Relationship.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Relationship.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Relationship.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Relationship.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,152 @@
+/*
+ * 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 "apache/das/rdb/Relationship.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+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*>();
+ config = 0;
+
+}
+
+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;
+}
+
+std::string Relationship::getPKTableName(void) const {
+ return pkTableName;
+}
+
+std::string Relationship::getFKTableName(void) const {
+ return fkTableName;
+}
+
+std::map<std::string, KeyPair*>& Relationship::getKeyPairs(void) const {
+ return *keyPairs;
+}
+
+KeyPair* Relationship::getKeyPair(std::string pkColumnName, std::string fkColumnName) const {
+ std::map<std::string, KeyPair*>::iterator it = keyPairs->
+ find(pkColumnName + fkColumnName);
+
+ if (it == keyPairs->end()) {
+ return 0;
+ }
+
+ return it->second;
+
+}
+
+void Relationship::addKeyPair(KeyPair& keyPair) {
+ keyPair.setRelationship(this);
+ keyPairs->insert(
+ std::make_pair(keyPair.getPKColumnName() + keyPair.getFKColumnName(), &keyPair));
+
+ if (config != 0) {
+ Table* table = config->getTable(fkTableName);
+
+ if (table != 0) {
+ Column* column = table->getColumn(keyPair.getFKColumnName());
+
+ if (column != 0) {
+ column->addKeyPair(keyPair);
+ }
+
+ }
+
+ }
+
+}
+
+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;
+
+}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/RelationshipWrapper.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/RelationshipWrapper.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/RelationshipWrapper.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/RelationshipWrapper.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,85 @@
+/*
+ * 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 "apache/das/rdb/RelationshipWrapper.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+std::list<Relationship*>* RelationshipWrapper::getRelationshipsByTableName(
+ 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::getRelationshipsByTableName(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/core/src/apache/das/rdb/ResultSet.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/ResultSet.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/ResultSet.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/ResultSet.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,219 @@
+/*
+ * 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 "apache/das/rdb/ResultSet.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+ResultSet::ResultSet(StatementPtr aStmt) {
+ stmt = aStmt;
+ metaData = new ResultSetMetaData(this);
+
+}
+
+ResultSet::~ResultSet(void) {
+ ResultSetObject::free();
+ delete metaData;
+
+}
+
+ResultSetMetaData& ResultSet::getResultSetMetaData(void) const {
+ return *metaData;
+}
+
+StatementPtr ResultSet::getStatement(void) const {
+ 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;
+
+ if (metaData->getSQLType(columnIndex) == SQL_CHAR) {
+ SQLWCHAR strAux = 0;
+ SQLINTEGER length = 0;
+ SQLGetData(stmt->getODBCStatement(), columnIndex + 1, SQL_C_WCHAR, &strAux, 1, &length);
+
+ ret = (wchar_t) strAux;
+
+ } else {
+ //throw an exception if the column type is not the requested
+ }
+
+ return ret;
+
+}
+
+wchar_t ResultSet::getSQLChar(std::string tableName, std::string columnName) const {
+ return getSQLChar(metaData->getColumnIndex(tableName, columnName));
+}
+
+float ResultSet::getSQLReal(unsigned int columnIndex) const {
+ float ret = 0;
+
+ if (metaData->getSQLType(columnIndex) == SQL_REAL) {
+ SQLFLOAT real = 0;
+ SQLINTEGER length = 0;
+ SQLGetData(stmt->getODBCStatement(), columnIndex + 1, SQL_C_FLOAT, &real, 1, &length);
+
+ ret = (float) real;
+
+ } else {
+ //throw an exception if the column type is not the requested
+ }
+
+ return ret;
+
+}
+
+float ResultSet::getSQLReal(std::string tableName, std::string columnName) const {
+ return getSQLReal(metaData->getColumnIndex(tableName, columnName));
+}
+
+double ResultSet::getSQLFloat(unsigned int columnIndex) const {
+ double ret = 0;
+
+ if (metaData->getSQLType(columnIndex) == SQL_FLOAT) {
+ SQLDOUBLE data = 0;
+ SQLINTEGER length = 0;
+ SQLGetData(stmt->getODBCStatement(), columnIndex + 1, SQL_C_DOUBLE, &data, 1, &length);
+
+ ret = (double) data;
+
+ } else {
+ //throw an exception if the column type is not the requested
+ }
+
+ return ret;
+
+}
+
+double ResultSet::getSQLFloat(std::string tableName, std::string columnName) const {
+ return getSQLFloat(metaData->getColumnIndex(tableName, columnName));
+}
+
+double ResultSet::getSQLDouble(unsigned int columnIndex) const {
+ double ret = 0;
+
+ if (metaData->getSQLType(columnIndex) == SQL_DOUBLE) {
+ SQLDOUBLE data = 0;
+ SQLINTEGER length = 0;
+ SQLGetData(stmt->getODBCStatement(), columnIndex + 1, SQL_C_DOUBLE, &data, 1, &length);
+
+ ret = (double) data;
+
+ } else {
+ //throw an exception if the column type is not the requested
+ }
+
+ return ret;
+
+}
+
+double ResultSet::getSQLDouble(std::string tableName, std::string columnName) const {
+ return getSQLDouble(metaData->getColumnIndex(tableName, columnName));
+}
+
+std::string ResultSet::getSQLDecimal(unsigned int columnIndex) const {
+ //std::string ret;
+
+ //if (metaData.getSQLType(columnIndex) == SQL_DECIMAL) {
+ // SQLPOINTER sqlPtr = 0;
+ // SQLCHAR strAux[1];
+ // SQLINTEGER length = 0;
+ // SQLGetData(statement, columnIndex + 1, SQL_C_CHAR, &strAux, 1, &length);
+ // length++;
+ // sqlPtr = (SQLCHAR*) malloc(length*sizeof(SQLCHAR));
+ // SQLINTEGER aux = 0;
+ // SQLGetData(statement, columnIndex + 1, SQL_C_CHAR, sqlPtr, length, &aux);
+ //
+ // std::string ret = (char*) sqlPtr);
+ // delete [] sqlPtr;
+ // ret = &((double) strAux);
+ //
+ //} else {
+ // //throw an exception if the column type is not the requested
+ //}
+
+ //return ret;
+ return "";
+
+}
+
+std::string ResultSet::getSQLDecimal(std::string tableName, std::string columnName) const {
+ return getSQLDecimal(metaData->getColumnIndex(tableName, columnName));
+}
+
+bool ResultSet::isNull(unsigned int columnIndex) const {
+ return false;
+}
+
+bool ResultSet::isNull(std::string tableName, std::string columnName) const {
+ return false;
+}
+
+bool ResultSet::next(void) {
+ return (SQL_SUCCESS == SQLFetch(stmt->getODBCStatement()));
+}
+
+unsigned int ResultSet::rowCount(void) const {
+ SQLINTEGER columnCount = 0;
+ SQLRETURN ret = SQLColAttribute(stmt->getODBCStatement(), NULL, SQL_DESC_COUNT, NULL, NULL, NULL, &columnCount);
+
+ return (unsigned int) columnCount;
+
+}
+
+std::string ResultSet::getSQLVarchar(unsigned int columnIndex) const {
+ SQLPOINTER sqlPtr = 0;
+ SQLCHAR strAux[1];
+ SQLINTEGER length = 0;
+ SQLGetData(stmt->getODBCStatement(), columnIndex + 1, SQL_C_CHAR, &strAux, 1, &length);
+ length++;
+ sqlPtr = (SQLCHAR*) malloc(length*sizeof(SQLCHAR));
+ SQLINTEGER aux = 0;
+ SQLGetData(stmt->getODBCStatement(), columnIndex + 1, SQL_C_CHAR, sqlPtr, length, &aux);
+
+ std::string ret = (char*) sqlPtr;
+ return ret;
+
+}
+
+std::string ResultSet::getSQLVarchar(std::string tableName, std::string columnName) const {
+ return getSQLVarchar(metaData->getColumnIndex(tableName, columnName));
+}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/ResultSetMetaData.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/ResultSetMetaData.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/ResultSetMetaData.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/ResultSetMetaData.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,215 @@
+/*
+ * 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 "apache/das/rdb/ResultSetMetaData.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+ResultSetMetaData::ResultSetMetaData(ResultSet* aResultSet) {
+ resultSet = aResultSet;
+ unsigned int columnCount = getColumnCount();
+
+ for (unsigned int i = 0 ; i < columnCount ; i++) {
+ std::string columnName = getColumnName(i);
+ std::string tableName = getTableName(i);
+ columnsIndexes.insert(std::make_pair(tableName + columnName, i));
+
+ }
+
+}
+
+ResultSetMetaData::~ResultSetMetaData(void) {}
+
+SQLSMALLINT ResultSetMetaData::getSQLCType(SQLSMALLINT sqlType) {
+
+ switch (sqlType) {
+
+ case SQL_CHAR :
+ return SQL_C_CHAR;
+
+ case SQL_BINARY :
+ return SQL_C_BINARY;
+
+ case SQL_TYPE_DATE :
+ return SQL_C_TYPE_DATE;
+
+ case SQL_DECIMAL :
+ return SQL_C_CHAR;
+
+ case SQL_DOUBLE :
+ return SQL_C_DOUBLE;
+
+ case SQL_FLOAT :
+ return SQL_C_DOUBLE;
+
+ case SQL_INTEGER :
+ return SQL_C_LONG;
+
+ case SQL_LONGVARCHAR :
+ return SQL_C_CHAR;
+
+ case SQL_LONGVARBINARY :
+ return SQL_C_BINARY;
+
+ case SQL_NUMERIC :
+ return SQL_C_CHAR;
+
+ case SQL_REAL :
+ return SQL_C_FLOAT;
+
+ case SQL_SMALLINT :
+ return SQL_C_SHORT;
+
+ case SQL_TYPE_TIME :
+ return SQL_C_TYPE_TIME;
+
+ case SQL_TYPE_TIMESTAMP :
+ return SQL_C_TYPE_TIMESTAMP;
+
+ case SQL_VARCHAR :
+ return SQL_C_CHAR;
+
+ case SQL_VARBINARY :
+ return SQL_C_BINARY;
+
+ default :
+ throw std::invalid_argument("Illegal SQL type!");
+
+ }
+
+}
+
+SQLSMALLINT ResultSetMetaData::getSQLType(unsigned int columnIndex) const {
+ SQLSMALLINT sqlType = 0;
+ SQLColAttribute(resultSet->getStatement()->getODBCStatement(), columnIndex + 1, SQL_DESC_TYPE, NULL, NULL, NULL, &sqlType);
+
+ return sqlType;
+
+}
+
+SQLSMALLINT ResultSetMetaData::getSQLType(std::string tableName, std::string columnName) const {
+ return getSQLType(getColumnIndex(tableName, columnName));
+}
+
+
+std::string ResultSetMetaData::getSQLTypeName(unsigned int columnIndex) const {
+ SQLCHAR* sqlPtr = 0;
+ char strAux[1];
+ SQLSMALLINT length = 0;
+ 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);
+
+ std::string ret((char*) sqlPtr);
+ delete [] sqlPtr;
+
+ return ret;
+
+}
+
+std::string ResultSetMetaData::getSQLTypeName(std::string tableName, std::string columnName) const {
+ return getSQLTypeName(getColumnIndex(tableName, columnName));
+}
+
+
+std::string ResultSetMetaData::getColumnName(unsigned int columnIndex) const {
+ 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);
+ length++;
+ sqlPtr = (SQLCHAR*) new SQLCHAR[length];
+ SQLColAttributeA(resultSet->getStatement()->getODBCStatement(), columnIndex + 1, SQL_DESC_BASE_COLUMN_NAME, sqlPtr, length, (SQLSMALLINT*) &length, NULL);
+
+ std::string ret((char*) sqlPtr);
+ delete [] sqlPtr;
+
+ return ret;
+
+}
+
+unsigned int ResultSetMetaData::getColumnIndex(std::string tableName, std::string columnName) const {
+ std::map<std::string, unsigned int>::const_iterator it = columnsIndexes.find(tableName + columnName);
+
+ if (it == columnsIndexes.end()) {
+ throw std::invalid_argument("No such column name: " + columnName);
+ }
+
+ return it->second;
+
+}
+
+
+std::string ResultSetMetaData::getTableName(unsigned int columnIndex) const {
+ SQLCHAR* sqlPtr = 0;
+ char strAux[1];
+ SQLSMALLINT length = 0;
+ 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);
+
+ std::string ret((char*) sqlPtr);
+ delete [] sqlPtr;
+
+ return ret;
+
+}
+
+std::string ResultSetMetaData::getTableName(std::string tableName, std::string columnName) const {
+ return getTableName(getColumnIndex(tableName, columnName));
+}
+
+
+SQLSMALLINT ResultSetMetaData::getSQLCType(unsigned int columnIndex) const {
+ return getSQLCType(getSQLType(columnIndex));
+}
+
+SQLSMALLINT ResultSetMetaData::getSQLCType(std::string tableName, std::string columnName) const {
+ return getSQLCType(getSQLType(getColumnIndex(tableName, columnName)));
+}
+
+unsigned int ResultSetMetaData::getColumnCount(void) const {
+ SQLUINTEGER columnCount = 0;
+ SQLRETURN ret = SQLColAttribute(resultSet->getStatement()->getODBCStatement(), NULL, SQL_DESC_COUNT, NULL, NULL, NULL, &columnCount);
+
+ return (unsigned int) columnCount;
+
+}
+
+bool ResultSetMetaData::containsColumn(std::string tableName, std::string columnName) const {
+ std::map<std::string, unsigned int>::const_iterator it = columnsIndexes.find(tableName + columnName);
+
+ if (it == columnsIndexes.end()) {
+ return false;
+ }
+
+ return true;
+
+}
+
+const ResultSet& ResultSetMetaData::getResultSet(void) const {
+ return *resultSet;
+}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/SqlException.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/SqlException.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/SqlException.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/SqlException.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,33 @@
+/*
+ * 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 "apache/das/rdb/SqlException.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+SqlException::SqlException(string errorText)
+ :exception(errorText.c_str()){}
+
+SqlException::~SqlException(){}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Statement.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Statement.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Statement.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Statement.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,74 @@
+/*
+ * 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 "apache/das/rdb/Statement.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+Statement::Statement(Connection& connection, SQLHSTMT statementHandle) : resultSet(0, false) {
+ this->statementHandle = statementHandle;
+ this->connection = &connection;
+
+}
+
+Statement::~Statement(void) {
+ if (!resultSet) {
+ delete resultSet;
+ }
+
+ SQLFreeHandle(SQL_HANDLE_STMT, statementHandle);
+ StatementObject::free();
+
+}
+
+Connection& Statement::getConnection(void) const {
+ return *connection;
+}
+
+ResultSetPtr Statement::executeQuery(std::string sql) { /*throws SQLException*/
+ SQLExecDirect(statementHandle, (SQLCHAR*) (char*) sql.c_str(), SQL_NTS);
+
+ return createResultSet();
+
+}
+
+ResultSetPtr Statement::createResultSet(void) {
+ if (resultSet) {
+ delete resultSet;
+ }
+
+ ResultSetPtr ret = new ResultSet((StatementPtr) *this);
+ resultSet = ret;
+
+ return ret;
+
+}
+
+void Statement::close(void) {
+ delete this;
+}
+
+HSTMT Statement::getODBCStatement(void) const {
+ return statementHandle;
+}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Table.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Table.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Table.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/Table.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,251 @@
+/*
+ * 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 "apache/das/rdb/Table.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+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++) {
+ delete it->second;
+ }
+
+ delete columns;
+
+}
+
+void Table::addRelationship(Relationship& relationship) {
+ relationships.push_back(&relationship);
+}
+
+std::string Table::getTableName(void) const {
+ return tableName;
+}
+
+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->
+ find((*it)->getName());
+
+ if (it2 == this->columns->end()) {
+ (*it)->setContainerTable(this);
+ this->columns->insert(std::make_pair((*it)->getName(), *it));
+ it++;
+
+ } else {
+ std::list<Column*>::iterator aux = it;
+ it++;
+ columns.erase(aux);
+
+ }
+
+ }
+
+ if (graphBuilderMetaData->getConfig().isConvOverConfig()) {
+
+ for (it == columns.begin() ; it != columns.end() ; it++) {
+ Column* column = *it;
+ std::string columnName = column->getName();
+
+ if (columnName == "id") {
+ column->setPK(true);
+ pkColumns.push_back(columnName);
+
+ } 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 = graphBuilderMetaData->getConfig().getRelationship(tableName, referencedTable);
+
+ if (relationship == 0) {
+ relationship = new Relationship(tableName, referencedTable);
+ graphBuilderMetaData->getConfig().addRelationship(*relationship);
+
+ }
+
+ KeyPair* keyPair = new KeyPair("id", column->getName());
+ relationship->addKeyPair(*keyPair);
+
+ }
+
+ }
+
+ } else {
+ std::list<std::string>::iterator it2;
+
+ for (it2 = pkColumns.begin() ; it2 != pkColumns.end() ; it2++) {
+ for (it = columns.begin() ; it != columns.end() ; it++) {
+
+ if ((*it)->getName() == *it2) {
+ (*it)->setPK(true);
+ }
+
+ }
+ }
+
+ }
+
+ std::list<Relationship*>* relationships = RelationshipWrapper::getRelationshipsByTableName(
+ graphBuilderMetaData->getRelationships(), tableName, false);
+
+ std::list<Relationship*>::const_iterator it2;
+
+ for (it2 = relationships->begin() ; it2 != relationships->end() ; it2++) {
+ Relationship& relationship = **it2;
+ 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++) {
+ Column& column = **it;
+
+ if (column.getName() == it3->second->getFKColumnName()) {
+ column.addKeyPair(*(it3->second));
+ }
+
+ }
+ }
+
+ }
+
+ delete relationships;
+
+}
+
+GraphBuilderMetaData& Table::getGraphBuilderMetaData(void) const {
+ return *graphBuilderMetaData;
+}
+
+void Table::addPKColumn(std::string columnName) {
+ pkColumns.push_back(columnName);
+}
+
+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 (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());
+
+ }
+
+ }
+
+ }
+
+ 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);
+
+ }
+
+ }
+
+ }
+
+}
+
+//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);
+
+ if (it == columns->end()) {
+ return 0;
+ }
+
+ return it->second;
+
+}
+
+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();
+}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/TableData.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/TableData.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/TableData.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/TableData.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,229 @@
+/*
+ * 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 "apache/das/rdb/TableData.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+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;
+ ResultSetMetaData& metaData = resultSet->getResultSetMetaData();
+
+ 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);
+
+ columnsData.insert(std::make_pair(columnName, columnData));
+
+ if (column.isPK()) {
+ primaryKeys->insert(std::make_pair(columnName, 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==(const KeyDataList* primaryKeyList) const {
+
+ if (primaryKeys->size() != primaryKeyList->size()) {
+ return false;
+ }
+
+ 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->second != *it2->second) {
+ return false;
+ }
+
+ }
+
+ return true;*/
+
+}
+
+bool TableData::operator==(const TableData& tableData) const {
+ return (*this == tableData.primaryKeys);
+}
+
+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;
+}
+
+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);
+ }
+
+}
+
+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;
+}
+
+ };
+ };
+};
Added: incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/database.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/database.cpp?view=auto&rev=537297
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/database.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/apache/das/rdb/database.cpp Fri May 11 14:36:45 2007
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include "apache/das/rdb/Database.h"
+
+namespace apache {
+ namespace das {
+ namespace rdb {
+
+Database::Database(Connection& connection) {
+ this->connection = &connection;
+}
+
+Database::~Database(void) {}
+
+ResultSetPtr Database::getPKs(std::string tableName) const {
+ StatementPtr statement = connection->createStatement();
+ SQLPrimaryKeysA(statement->getODBCStatement(), 0,0,0,0, (SQLCHAR*) (char*) tableName.c_str(), tableName.size());
+
+ return statement->createResultSet();
+
+}
+
+ResultSetPtr Database::getFKs(std::string tableName) const {
+ 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 statement->createResultSet();
+
+}
+
+ };
+ };
+};
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org