You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by lr...@apache.org on 2007/01/13 00:33:57 UTC
svn commit: r495788 [5/5] - in /incubator/tuscany/cpp/das: ./ VSExpress/
VSExpress/tuscany_das/ VSExpress/tuscany_das/Build/
VSExpress/tuscany_das/Build/Debug/ VSExpress/tuscany_das/das_runtime/
runtime/ runtime/core/ runtime/core/src/
Added: incubator/tuscany/cpp/das/runtime/core/src/ResultMetadata.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/ResultMetadata.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/ResultMetadata.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/ResultMetadata.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,290 @@
+/*
+ * 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 "ResultMetadata.h"
+
+ResultMetadata::ResultMetadata(ResultSet& rs, MappingWrapper& cfgWrapper, ResultSetShape& shape) {
+ resultSet = rs;
+ configWrapper = cfgWrapper;
+
+ if (shape == NULL) {
+ resultSetShape = *(new ResultSetShape(rs.getMetaData()));
+ } else {
+ resultSetShape = shape;
+ }
+
+ converters = new Converter[resultSetShape.getColumnCount()];
+
+ map<string, string> impliedRelationships;
+
+ for (int i = 1; i <= resultSetShape.getColumnCount(); i++) {
+ string tableName = resultSetShape.getTableName(i);
+
+ if (( tableName == NULL ) || ( tableName[0] == '\0')) {
+ //throw new RuntimeException("Unable to obtain table information from JDBC. DAS configuration must specify ResultDescriptors");
+ }
+
+ string typeName = configWrapper->getTableTypeName(tableName);
+ string columnName = resultSetShape->getColumnName(i);
+ string lower = columnName.c_str();
+ toLower(lower);
+
+ if (columnName.find("_ID", 0) != string::npos) {
+ impliedRelationships.insert(make_pair(columnName, tableName));
+
+ } else if (strcmp(lower, "id") == 0) {
+ configWrapper->addImpliedPrimaryKey(tableName, columnName);
+ }
+
+ string propertyName = configWrapper->getColumnPropertyName(tableName, columnName);
+ string converterName = configWrapper->getConverter(tableName, resultSetShape.getColumnName(i));
+
+ converters[i - 1] = loadConverter(converterName);
+
+ typeNames.insert(typeName.c_str());
+ propertyNames.insert(propertyName.c_str());
+
+ map<string, list<string>*> i = tableToPropertyMap.find(typeName);
+ list<string>& properties = NULL;
+
+ if (i == tableToPropertyMap.end()) {
+ properties = *(new list<string>);
+ } else {
+ properties = i->second;
+ }
+
+ properties.insert(propertyName);
+ tableToPropertyMap.insert(make_pair(typeName, properties));
+
+ }
+
+ map<string, string>::iterator j;
+ Iterator i = impliedRelationships.keySet().iterator();
+
+ for (j = impliedRelationships.begin() ; j != impliedRelationships.end() ; j++) {
+ string columnName = (string) j->fist;
+
+ string pkTableName = columnName.substr(0, columnName.find("_ID"));
+ string fkTableName = j->second;
+
+ map<string, list<string>*> mapIter = tableToPropertyMap.find(pkTableName);
+ list<string>& pkTableProperties = NULL;
+
+ if (mapIter != tableToPropertyMap.end()) {
+ pkTableProperties = mapIter->second;
+
+ if (pkTableProperties.find("ID") != string::npos) {
+ configWrapper.addImpliedRelationship(pkTableName, fkTableName, columnName);
+ }
+
+ }
+
+ }
+ // Add any tables defined in the model but not included in the ResultSet
+ // to the list of propertyNames
+ Config model = configWrapper.getConfig();
+ if (model != NULL) {
+
+ list<Table*>& tablesFromModel = model.getTable();
+ list<Table*>::iterator i;
+
+ for (i = tablesFromModel.begin() ; i != tablesFromModel.end() ; i++) {
+ TableWrapper t(*i);
+ list<string> emptyList;
+
+ if (tableToPropertyMap.find(t.getTypeName()) == tableToPropertyMap.end()) {
+ tableToPropertyMap.insert(make_pair(t.getTypeName(), emptyList));
+ }
+
+ }
+
+ }
+
+}
+
+ResultMetadata::~ResultMetadata(void) {
+}
+
+string ResultMetadata::getColumnPropertyName(int i) {
+ return propertyNames.at(i - 1);
+}
+
+string ResultMetadata::getDatabaseColumnName(int i) {
+ return resultSetShape.getColumnName(i);
+}
+
+string ResultMetadata::getTableName(string columnName) {
+ list<string>::iterator i;
+ int index = -1;
+ int j;
+
+ for (j = 0, i = propertyNames.begin() ; i != propertyNames.end() ; i++, j++) {
+
+ if (strcmp(columnName, *i) == 0) {
+ index = j;
+ break;
+
+ }
+
+ }
+
+ if (index == -1) {
+ return NULL;
+ }
+
+ return *(typeNames.at(index));
+
+}
+
+int ResultMetadata::getTableSize(string tableName) {
+ return (((map<string, list<string>*>::iterator) tableToPropertyMap.find(tableName))->second).size();
+}
+
+Type& ResultMetadata::getDataType(string columnName) {
+ list<string>::iterator i;
+ int index = -1;
+ int j;
+
+ for (j = 0, i = propertyNames.begin() ; i != propertyNames.end() ; i++, j++) {
+
+ if (strcmp(columnName, *i) == 0) {
+ index = j;
+ break;
+
+ }
+
+ }
+
+ if (index == -1) {
+ return NULL;
+ }
+
+ return resultSetShape.getColumnType(index);
+
+}
+
+string ResultMetadata::getTablePropertyName(int i) {
+ return typeNames.at(i - 1);
+}
+
+list<string>& ResultMetadata::getAllTablePropertyNames(void) {
+ list<string> res;
+ map<string, list<string>*>::iterator i;
+
+ for (i = tableToPropertyMap.begin() ; i != tableToPropertyMap.end() ; i++) {
+ res.insert(i->second);
+ }
+
+ return res;
+
+}
+
+//string ResultMetadata::toString(void) {}
+
+int ResultMetadata::getNumberOfTables(void) {
+ return tableToPropertyMap.size();
+}
+
+bool ResultMetadata::isPKColumn(int i) {
+ Table& t = configWrapper.getTableByTypeName(getTablePropertyName(i));
+
+ if (t == NULL) {
+ return true;
+ }
+
+ // If no Columns have been defined, consider every column to be part of
+ // the PK
+ if (t.getColumn().size() == 0) {
+ return true;
+ }
+
+ Column& c = configWrapper.getColumn(t, getDatabaseColumnName(i));
+
+ if (c == NULL) {
+ return false;
+ }
+
+ if (c.isPrimaryKey()) {
+ return true;
+ }
+
+ return false;
+
+}
+
+Type& ResultMetadata::getDataType(int i) {
+ return resultSetShape.getColumnType(i);
+}
+
+list<string>& ResultMetadata::getPropertyNames(string tableName) {
+ return ((map<string, list<string>*>::iterator) tableToPropertyMap.find(tableName))->second;
+}
+
+ResultSet& ResultMetadata::getResultSet(void) {
+ return resultSet;
+}
+
+int ResultMetadata::getResultSetSize(void) {
+ return resultSetShape.getColumnCount();
+}
+
+bool ResultMetadata::isRecursive(void) {
+ return configWrapper.hasRecursiveRelationships();
+}
+
+Converter& ResultMetadata::getConverter(int i) {
+ return converters[i - 1];
+}
+
+Converter& ResultMetadata::loadConverter(string converterName) {
+ if (converterName != NULL) {
+
+ //try {
+ //Class converterClazz = Class.forName(converterName, true,
+ // Thread.currentThread().getContextClassLoader());
+ if (NULL != converterClazz) {
+ //return (Converter) converterClazz.newInstance();
+ }
+
+ //converterClazz = Class.forName(converterName);
+ if (converterClazz != NULL) {
+ //return (Converter) converterClazz.newInstance();
+ }
+ //} catch (ClassNotFoundException ex) {
+ // throw new RuntimeException(ex);
+ //} catch (IllegalAccessException ex) {
+ // throw new RuntimeException(ex);
+ //} catch (InstantiationException ex) {
+ // throw new RuntimeException(ex);
+ //}
+
+ }
+
+ return *(new DefaultConverter());
+
+}
+
+void DASImpl::toLower(string string) {
+ int i;
+ int stringSize = strlen(string);
+
+ for (i = 0 ; i < stringSize ; i++) {
+ string[i] = tolower(string[i]);
+ }
+
+}
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/ResultMetadata.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/ResultMetadata.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/ResultMetadata.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/ResultMetadata.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#ifndef RESULT_METADATA_H
+#define RESULT_METADATA_H
+
+class ResultMetadata {
+
+ private:
+ map<string, list<string>*> tableToPropertyMap;
+ list<string> typeNames;
+ list<string> propertyNames;
+ ResultSet* resultSet
+ ResultSetShape* resultSetShape;
+ MappingWrapper* configWrapper;
+ Converter** converters;
+ int convertersCount;
+
+ Converter* loadConverter(string converterName);
+ void DASImpl::toLower(string string);
+
+ public:
+ ResultMetadata(ResultSet* rs, MappingWrapper* cfgWrapper, ResultSetShape* shape);
+ ~ResultMetadata(void);
+ string getColumnPropertyName(int i);
+ string getDatabaseColumnName(int i);
+ string getTableName(string columnName);
+ int getTableSize(string tableName);
+ Type* getDataType(string columnName);
+ string getTablePropertyName(int i);
+ list<string>* getAllTablePropertyNames(void);
+ //string toString(void);
+ int getNumberOfTables(void);
+ bool isPKColumn(int i);
+ Type* getDataType(int i);
+ list<string>* getPropertyNames(string tableName);
+ ResultSet* getResultSet(void);
+ int getResultSetSize(void);
+ bool isRecursive(void);
+ Converter* getConverter(int i);
+
+};
+
+#endif //RESULT_METADATA_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/ResultSet.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/ResultSet.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/ResultSet.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/ResultSet.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,25 @@
+/*
+ * 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 RESULT_SET_H
+#define RESULT_SET_H
+
+class ResultSet {
+};
+
+#endif
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/ResultSetMetaData.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/ResultSetMetaData.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/ResultSetMetaData.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/ResultSetMetaData.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,25 @@
+/*
+ * 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 RESULT_SET_META_DATA_H
+#define RESULT_SET_META_DATA_H
+
+class ResultSetMetaData {
+};
+
+#endif
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/ResultSetShape.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/ResultSetShape.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/ResultSetShape.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/ResultSetShape.cpp Fri Jan 12 15:33:46 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 "ResultSetShape.h"
+
+//ResultSetShape::ResultSetShape(ResultSetMetaData* metadata) { /*throws SQLException*/
+// columnsLength = metadata->getColumnCount();
+// columns = char[columnsLength]*;
+//
+// tablesLength = metadata->getColumnCount();
+// tables = char[tablesLength]*;
+//
+// typesLength = metadata->getColumnCount();
+// types = Type[typesLength]*;
+//
+// ResultSetTypeMap typeMap = ResultSetTypeMap.INSTANCE;
+// for (int i = 1; i <= metadata->getColumnCount(); i++) {
+// tables[i - 1] = metadata->getTableName(i);
+// columns[i - 1] = metadata->getColumnName(i);
+// types[i - 1] = typeMap.getType(metadata->getColumnType(i), 1);
+//
+// }
+//
+//}
+
+ResultSetShape::ResultSetShape(vector<ResultDescriptor*>* resultDescriptor) {
+ TypeHelper helper = TypeHelper.INSTANCE;
+ int size = resultDescriptor->size();
+ columnsLength = size;
+ tablesLength = size;
+ typesLength = size;
+ columns = char[size]*;
+ tables = char[size]*;
+ types = Type[size]*;
+
+ for (int i = 0; i < size; i++) {
+ ResultDescriptor* desc = (ResultDescriptor*) resultDescriptor.at(i);
+ tables[i] = desc->getTableName();
+ columns[i] = desc->getColumnName();
+
+ int idx = ((string) desc->getColumnType()).find_last_of('.');
+ string uri = (string) ((string) desc->getColumnType()).substr(0, idx);
+ string typeName = (string) ((string) desc->getColumnType()).substr(idx + 1);
+
+ types[i] = helper->getType(uri, typeName);
+ if (types[i] == NULL) {
+ //throw new RuntimeException("Could not find type " + desc.getColumnType()
+ // + " for column " + desc.getColumnName());
+ }
+
+ }
+
+}
+
+ResultSetShape::~ResultSetShape() {
+}
+
+int ResultSetShape::getColumnCount(void) {
+ columnsLength;
+}
+
+string ResultSetShape::getTableName(int i) {
+ return tables[i - 1];
+}
+
+string ResultSetShape::getColumnName(int i) {
+ return columns[i - 1];
+}
+
+Type* ResultSetShape::getColumnType(int i) {
+ return types[i - 1];
+}
+
+//string ResultSetShape::toString(void) {}
Added: incubator/tuscany/cpp/das/runtime/core/src/ResultSetShape.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/ResultSetShape.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/ResultSetShape.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/ResultSetShape.h Fri Jan 12 15:33:46 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 RESULT_SET_SHAPE_H
+#define RESULT_SET_SHAPE_H
+
+#include <vector>
+#include <sql.h>
+
+#include "ResultSetMetaData.h"
+#include "ResultDescriptor.h"
+//#include "ResultSetTypeMap.h"
+//#include "TypeHelper.h"
+
+using namespace std;
+
+class ResultSetShape {
+
+ private:
+ string* columns;
+ string* tables;
+ Type** types;
+ int columnsLength;
+ int tablesLength;
+ int typesLength;
+
+
+ public:
+ //ResultSetShape(ResultSetMetaData* metadata); /*throws SQLException*/
+ ResultSetShape(vector<ResultDescriptor*>* resultDescriptor);
+ ~ResultSetShape();
+ int getColumnCount(void);
+ string getTableName(int i);
+ string getColumnName(int i);
+ Type* getColumnType(int i);
+ //string toString(void);
+
+
+};
+
+#endif //RESULT_SET_SHAPE_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/SDODataTypeHelper.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/SDODataTypeHelper.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/SDODataTypeHelper.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/SDODataTypeHelper.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,90 @@
+/*
+ * 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 "SDODataTypeHelper.h"
+
+#include <sql>
+
+static int SDODataTypeHelper::sqlTypeFor(Type* sdoType) {
+
+ if (sdoType == NULL) {
+ return SQL_C_DEFAULT;
+ }
+
+ switch (sdoType) {
+
+ case Types::BigDecimalType :
+ return SQL_C_DEFAULT;
+
+ case Types::BigIntegerType :
+ return SQL_C_SBIGINT;
+
+ case Types::BooleanType :
+ return SQL_C_DEFAULT;
+
+ case Types::ByteType :
+ return SQL_C_BINARY;
+
+ case Types::BytesType :
+ return SQL_C_DEFAULT;
+
+ case Types::CharacterType :
+ return SQL_C_CHAR;
+
+ case Types::DateType :
+ return SQL_C_DATE;
+
+ case Types::DoubleType :
+ return SQL_C_DOUBLE;
+
+ case Types::FloatType :
+ return SQL_C_FLOAT;
+
+ case Types::IntegerType :
+ return SQL_C_DEFAULT;
+
+ case Types::LongType :
+ return SQL_C_LONG;
+
+ case Types::ShortType :
+ return SQL_C_SHORT;
+
+ case Types::StringType :
+ return SQL_C_CHAR;
+
+ case Types::UriType :
+ return SQL_C_DEFAULT;
+
+ case Types::DataObjectType :
+ return SQL_C_DEFAULT;
+
+ case ChangeSummaryType :
+ return SQL_C_DEFAULT;
+
+ case TextType :
+ return SQL_C_DEFAULT;
+
+ case OpenDataObjectType :
+ return SQL_C_DEFAULT;
+
+ default:
+ return SQL_C_DEFAULT;
+
+ }
+
+}
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/SDODataTypeHelper.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/SDODataTypeHelper.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/SDODataTypeHelper.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/SDODataTypeHelper.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#ifndef S_D_O_DATA_TYPE_HELPER_H
+#define S_D_O_DATA_TYPE_HELPER_H
+
+#include <sql.h>
+
+#include "commonj/sdo/DataFactory.h"
+
+#include "SDODataTypes.h"
+
+using namespace commonj::sdo;
+
+class SDODataTypeHelper {
+
+ public:
+ static int sqlTypeFor(Type* sdoType);
+
+};
+
+#endif //S_D_O_DATA_TYPE_HELPER_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/SDODataTypes.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/SDODataTypes.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/SDODataTypes.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/SDODataTypes.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,97 @@
+/*
+ * 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 S_D_O_DATA_TYPES_H
+#define S_D_O_DATA_TYPES_H
+
+#include <sql.h>
+
+class SDODataTypes {
+
+ public:
+ /*static TypeHelper TYPE_HELPER = TypeHelper.INSTANCE;
+
+ static Type BOOLEAN = TYPE_HELPER.getType("commonj.sdo", "Boolean");
+
+ static Type BYTE = TYPE_HELPER.getType("commonj.sdo", "Byte");
+
+ static Type BYTES = TYPE_HELPER.getType("commonj.sdo", "Bytes");
+
+ static Type CHARACTER = TYPE_HELPER.getType("commonj.sdo", "Character");
+
+ static Type DATE = TYPE_HELPER.getType("commonj.sdo", "Date");
+
+ static Type DATETIME = TYPE_HELPER.getType("commonj.sdo", "Date");
+
+ static Type DAY = TYPE_HELPER.getType("commonj.sdo", "Date");
+
+ static Type DECIMAL = TYPE_HELPER.getType("commonj.sdo", "Float");
+
+ static Type DOUBLE = TYPE_HELPER.getType("commonj.sdo", "Double");
+
+ static Type DURATION = TYPE_HELPER.getType("commonj.sdo", "Date");
+
+ static Type FLOAT = TYPE_HELPER.getType("commonj.sdo", "Float");
+
+ static Type INT = TYPE_HELPER.getType("commonj.sdo", "Int");
+
+ static Type INTEGER = TYPE_HELPER.getType("commonj.sdo", "Integer");
+
+ static Type LONG = TYPE_HELPER.getType("commonj.sdo", "Long");
+
+ static Type MONTH = TYPE_HELPER.getType("commonj.sdo", "Date");
+
+ static Type MONTHDAY = TYPE_HELPER.getType("commonj.sdo", "Date");
+
+ static Type OBJECT = TYPE_HELPER.getType("commonj.sdo", "Object");
+
+ static Type SHORT = TYPE_HELPER.getType("commonj.sdo", "Short");
+
+ static Type STRING = TYPE_HELPER.getType("commonj.sdo", "String");
+
+ static Type STRINGS = TYPE_HELPER.getType("commonj.sdo", "String");
+
+ static Type TIME = TYPE_HELPER.getType("commonj.sdo", "Date");
+
+ static Type URI = TYPE_HELPER.getType("commonj.sdo", "String");
+
+ static Type YEAR = TYPE_HELPER.getType("commonj.sdo", "Date");
+
+ static Type YEARMONTH = TYPE_HELPER.getType("commonj.sdo", "Date");
+
+ static Type YEARMONTHDAY = TYPE_HELPER.getType("commonj.sdo", "Date");
+
+ static Type BOOLEANOBJECT = TYPE_HELPER.getType("commonj.sdo", "BooleanObject");
+
+ static Type BYTEOBJECT = TYPE_HELPER.getType("commonj.sdo", "ByteObject");
+
+ static Type CHARACTEROBJECT = TYPE_HELPER.getType("commonj.sdo", "CharacterObject");
+
+ static Type DOUBLEOBJECT = TYPE_HELPER.getType("commonj.sdo", "DoubleObject");
+
+ static Type FLOATOBJECT = TYPE_HELPER.getType("commonj.sdo", "FloatObject");
+
+ static Type INTEGEROBJECT = TYPE_HELPER.getType("commonj.sdo", "IntObject");
+
+ static Type LONGOBJECT = TYPE_HELPER.getType("commonj.sdo", "LongObject");
+
+ static Type SHORTOBJECT = TYPE_HELPER.getType("commonj.sdo", "ShortObject");*/
+
+};
+
+#endif //S_D_O_DATA_TYPES_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/SPCommandImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/SPCommandImpl.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/SPCommandImpl.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/SPCommandImpl.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include "SPCommandImpl.h"
+
+SPCommandImpl::SPCommandImpl(string sqlString, MappingWrapper* config, list<Parameter*>* params) {
+ super(sqlString, config, NULL);
+
+ list<Parameter*>::iterator i;
+ for (i = params->begin() ; i != params->end() ; i++) {
+
+ int index = ((string) *i->getColumnType()).find_last_of('.');
+ string pkg = (string) ((string) *i->getColumnType()).substr(0, index);
+ string typeName = (string) ((string) *i->getColumnType()).substr(index + 1);
+
+ Type* sdoType = TypeHelper.INSTANCE.getType(pkg, typeName);
+
+ int direction = ParameterImpl.IN;
+ if (strcmp("OUT", toLower(*i->getDirection())) == 0) {
+ direction = ParameterImpl.OUT;
+ } else if (strcmp("INOUT", toLower(*i->getDirection())) == 0) {
+ direction = ParameterImpl.IN_OUT;
+ }
+
+ parameters.findOrCreateParameterWithIndex(p->getIndex(), direction, sdoType);
+
+ }
+
+}
+
+SPCommandImpl::~SPCommandImpl(void) {
+}
+
+DataObject* SPCommandImpl::executeQuery(void) {
+ int success = 0;
+
+ //try {
+ list<ResultSet*>* results = statement->executeCall(parameters);
+ success = 1;
+
+ return buildGraph(results);
+
+ //} catch (SQLException e) {
+
+ /*if (this.logger.isDebugEnabled()) {
+ this.logger.debug(e);
+ }*/
+
+ // throw new RuntimeException(e);
+ //} finally {
+ if (success) {
+ statement->getConnection()->cleanUp();
+ } else {
+ statement->getConnection()->errorCleanUp();
+ }
+
+ //}
+
+}
+
+void SPCommandImpl::execute(void) {
+ int success = 0;
+ //try {
+ statement->executeUpdateCall(parameters);
+ success = 1;
+
+ //} catch (SQLException e) {
+ //throw new RuntimeException(e);
+ //} finally {
+ if (success) {
+ statement->getConnection()->cleanUp();
+ } else {
+ statement->getConnection()->errorCleanUp();
+ }
+
+ //}
+
+}
+
+void DASImpl::toLower(string string) {
+ int i;
+ int stringSize = strlen(string);
+
+ for (i = 0 ; i < stringSize ; i++) {
+ string[i] = tolower(string[i]);
+ }
+
+}
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/SPCommandImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/SPCommandImpl.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/SPCommandImpl.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/SPCommandImpl.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,50 @@
+/*
+ * 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 S_P_COMMAND_IMPL_H
+#define S_P_COMMAND_IMPL_H
+
+#include <list>
+#include <string>
+
+#include "ReadCommandImpl.h"
+#include "MappingWrapper.h"
+#include "Parameter.h"
+#include "TypeHelper.h"
+#include "Type.h"
+#include "Parameter.h"
+
+#include "commonj/sdo/DataFactory.h"
+
+using namespace commonj::sdo;
+using namespace std;
+
+class SPCommandImpl : public ReadCommandImpl {
+
+ private:
+ void toLower(string string);
+
+ public:
+ SPCommandImpl(string sqlString, MappingWrapper* config, list<Parameter*>* params);
+ ~SPCommandImpl(void);
+ DataObject* executeQuery(void);
+ void execute(void);
+
+};
+
+#endif //S_P_COMMAND_IMPL_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/Statement.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/Statement.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/Statement.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/Statement.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,258 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include "Statement.h"
+
+Statement::Statement(string sqlString) {
+ queryString = sqlString;
+}
+
+Statement::~Statement(void) {
+}
+
+list<ResultSet*>* Statement::executeQuery(Parameters* parameters) { /*throws SQLException*/
+ PreparedStatement* ps = getPreparedStatement(NULL, 0);
+ ps = setParameters(ps, parameters);
+ ResultSet* rs = ps->executeQuery();
+ list<ResultSet*> resultSetList;
+ resultSetList.insert(rs);
+
+ return &resultSetList;
+
+}
+
+list<ResultSet*>* Statement::executeCall(Parameters* parameters) { /*throws SQLException*/
+ CallableStatement* cs = jdbcConnection.prepareCall(queryString);
+
+ list<ParameterImpl*>* params = parameters->inParams();
+ list<ParameterImpl*>::iterator i;
+ for (i = params->begin() ; i != params->end() ; i++) {
+ cs->setObject(*i->getIndex(), *i->getValue());
+ }
+
+ // register out parameters
+ list<ParameterImpl*>* outParams = parameters->outParams();
+ for (i = outParams->begin() ; i != outParams->end() ; i++) {
+
+ /*if (this.logger.isDebugEnabled()) {
+ this.logger.debug("Registering parameter " + param.getName());
+ }*/
+
+ cs->registerOutParameter(*i->getIndex(), SDODataTypeHelper.sqlTypeFor(*i->getType()));
+
+ }
+
+ // Using execute because Derby does not currenlty support
+ // executeQuery
+ // for SP
+ cs->execute();
+ list<ResultSet*> results;
+ results.add(cs->getResultSet());
+
+ while (cs->getMoreResults(java.sql.Statement.KEEP_CURRENT_RESULT)) {
+ results.add(cs->getResultSet());
+ }
+
+ for (i = outParams->begin() ; i != outParams->end() ; i++) {
+ *i->setValue(cs->getObject(*i->getIndex()));
+
+ }
+
+ return &results;
+
+}
+
+void Statement::executeUpdateCall(Parameters* parameters) { /*throws SQLException*/
+ CallableStatement* cs = odbcConnection.prepareCall(queryString);
+
+ list<ParameterImpl*>* inParams = parameters->inParams();
+ list<ParameterImpl*>::iterator i;
+ for (i = inParams->begin() ; i != inParams->end() ; i++) {
+ cs->setObject(*i->getIndex(), *i->getValue());
+ }
+
+ // register out parameters
+ list<ParameterImpl*>* outParams = parameters->outParams();
+ for (i = outParams->begin() ; i != outParams->end() ; i++) {
+
+ /*if (this.logger.isDebugEnabled()) {
+ this.logger.debug("Registering parameter " + param.getName());
+ }*/
+
+ cs->registerOutParameter(*i->getIndex(), SDODataTypeHelper.sqlTypeFor(*i->getType()));
+
+ }
+
+ cs->execute();
+
+ for (i = outParams->begin() ; i != outParams->end() ; i++) {
+ *i->setValue(cs->getObject(*i->getIndex()));
+ }
+
+}
+
+int Statement::executeUpdate(Parameters* parameters, string* generatedKeys, int keyCount) { /*throws SQLException*/
+ return executeUpdate(getPreparedStatement(generatedKeys, keyCount), parameters);
+}
+
+int Statement::executeUpdate(Parameters* parameters) { /*throws SQLException*/
+ return executeUpdate(parameters, NULL, 0);
+}
+
+void Statement::setConnection(ConnectionImpl* jdbcConnection) {
+ /*if (this.logger.isDebugEnabled()) {
+ this.logger.debug("Executing statement " + queryString);
+ }*/
+
+ list<ParameterImpl*>* inParams = parameters->inParams();
+ list<ParameterImpl*>::iterator i;
+ for (i = inParams->begin() ; i != inParams->end() ; i++) {
+ DASObject value = *i->getValue();
+
+ /*if (this.logger.isDebugEnabled()) {
+ this.logger.debug("Setting parameter " + param.getIndex() + " to " + value);
+ }*/
+
+ if (value == NULL) {
+ if (*i->getType() == NULL) {
+
+ //try {
+ ParameterMetaData* pmd = ps->getParameterMetaData();
+ ps->setNull(param->getIndex(), pmd->getParameterType(*i->getIndex()));
+
+ //} catch (SQLException ex) {
+ ps->setNull(*i->getIndex(), SDODataTypeHelper.sqlTypeFor(NULL));
+ //}
+
+ } else {
+ ps->setNull(*i->getIndex(), SDODataTypeHelper.sqlTypeFor(*i->getType()));
+ }
+
+ } else {
+ ps->setObject(*i->getIndex(), value);
+ }
+
+ }
+
+ return ps->executeUpdate();
+
+}
+ConnectionImpl* Statement::getConnection(void) {
+ return odbcConnection;
+}
+
+int Statement::getGeneratedKey(void) { /*throws SQLException*/
+
+ if (getConnection()->useGetGeneratedKeys()) {
+ ResultSet* rs = preparedStatement->getGeneratedKeys();
+
+ if (rs->next()) {
+ return rs.getInt(1);
+ }
+
+ }
+
+ return NULL;
+
+}
+
+void Statement::close(void) {
+
+ if (preparedStatement != NULL) {
+
+ //try {
+ preparedStatement->close();
+ //} catch (SQLException e) {
+ //throw new RuntimeException(e);
+ //}
+
+ }
+
+}
+
+PreparedStatement* Statement::setParameters(PreparedStatement* ps, Parameters* parameters) { /*throws SQLException*/
+ list<ParameterImpl*>* inParams = parameters->inParams();
+ list<ParameterImpl*>::iterator i;
+
+ for (i = inParams->begin() ; i != inParams->end() ; i++) {
+ ps->setObject(*i->getIndex(), *i->getValue());
+ }
+
+ return ps;
+
+}
+
+void Statement::enablePaging(void) {
+ isPaging = 1;
+}
+
+int Statement::executeUpdate(PreparedStatement* ps, Parameters* parameters) { /*throws SQLException*/
+ /*if (this.logger.isDebugEnabled()) {
+ this.logger.debug("Executing statement " + queryString);
+ }*/
+
+ list<ParameterImpl*>* inParams = parameters->inParams();
+ list<ParameterImpl*>::iterator i;
+ for (i = inParams->begin() ; i != inParams->end() ; i++) {
+ DASObject value = *i->getValue();
+
+ /*if (this.logger.isDebugEnabled()) {
+ this.logger.debug("Setting parameter " + param.getIndex() + " to " + value);
+ }*/
+
+ if (value == NULL) {
+
+ if (*i->getType() == NULL) {
+
+ //try {
+ ParameterMetaData pmd = ps->getParameterMetaData();
+ ps->setNull(*i->getIndex(), pmd->getParameterType(*i->getIndex()));
+
+ //} catch (SQLException ex) {
+ ps->setNull(*i->getIndex(), SDODataTypeHelper.sqlTypeFor(NULL));
+ //}
+
+ } else {
+ ps->setNull(*i->getIndex(), SDODataTypeHelper.sqlTypeFor(*i->getType()));
+ }
+
+ } else {
+ ps->setObject(*i->getIndex(), value);
+ }
+
+ }
+
+ return ps->executeUpdate();
+
+}
+
+PreparedStatement* Statement::getPreparedStatement(string* returnKeys, int keyCount) { /*throws SQLException*/
+
+ if (preparedStatement == NULL) {
+
+ if (isPaging) {
+ preparedStatement = jdbcConnection->preparePagedStatement(queryString);
+ } else {
+ preparedStatement = jdbcConnection->prepareStatement(queryString, returnKeys);
+ }
+
+ }
+
+ return preparedStatement;
+
+}
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/Statement.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/Statement.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/Statement.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/Statement.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#ifndef STATEMENT_H
+#define STATEMENT_H
+
+#include <list>
+#include <windows.h>
+#include <sql.h>
+
+#include "PreparedStatement.h"
+#include "Parameters.h"
+#include "PreparedStatement.h"
+#include "ConnectionImpl.h"
+#include "ResultSet.h"
+#include "CallableStatement.h"
+#include "ParameterImpl.h"
+#include "SDODataTypeHelper.h"
+#include "DASObject.h"
+#include "SDODataTypeHelper.h"
+
+using namespace std;
+
+class Statement {
+
+ private:
+ PreparedStatement* preparedStatement;
+ int isPaging;
+
+ int executeUpdate(PreparedStatement* ps, Parameters* parameters); /*throws SQLException*/
+ PreparedStatement* getPreparedStatement(string* returnKeys, int keyCount); /*throws SQLException*/
+
+ protected:
+ string queryString;
+ ConnectionImpl* odbcConnection;
+
+ PreparedStatement* setParameters(PreparedStatement* ps, Parameters* parameters); /*throws SQLException*/
+ void enablePaging(void);
+
+ public:
+ Statement(string sqlString);
+ ~Statement(void);
+ list<ResultSet*>* executeQuery(Parameters* parameters); /*throws SQLException*/
+ list<ResultSet*>* executeCall(Parameters* parameters); /*throws SQLException*/
+ void executeUpdateCall(Parameters* parameters); /*throws SQLException*/
+ int executeUpdate(Parameters* parameters, string* generatedKeys, int keyCount); /*throws SQLException*/
+ int executeUpdate(Parameters* parameters); /*throws SQLException*/
+ void setConnection(ConnectionImpl* jdbcConnection);
+ ConnectionImpl* getConnection(void);
+ int getGeneratedKey(void); /*throws SQLException*/
+ void close(void);
+
+};
+
+#endif //STATEMENT_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/Table.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/Table.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/Table.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/Table.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,159 @@
+/*
+ * 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_H
+#define TABLE_H
+
+#include <list>
+
+#include "Delete.h"
+#include "Update.h"
+#include "Create.h"
+#include "Column.h"
+
+using namespace std;
+
+virtual class Table {
+
+ public:
+ /**
+ * Returns the value of the '<em><b>Column</b></em>' containment reference list.
+ * The list contents are of type {@link org.apache.tuscany.das.rdb.config.Column}.
+ * <!-- begin-user-doc -->
+ * <p>
+ * If the meaning of the '<em>Column</em>' containment reference list isn't clear,
+ * there really should be more of a description here...
+ * </p>
+ * <!-- end-user-doc -->
+ * @return the value of the '<em>Column</em>' containment reference list.
+ * @generated
+ */
+ list<Column*>* getColumn(void);
+
+ /**
+ * Returns the value of the '<em><b>Create</b></em>' containment reference.
+ * <!-- begin-user-doc -->
+ * <p>
+ * If the meaning of the '<em>Create</em>' containment reference isn't clear,
+ * there really should be more of a description here...
+ * </p>
+ * <!-- end-user-doc -->
+ * @return the value of the '<em>Create</em>' containment reference.
+ * @see #setCreate(Create)
+ * @generated
+ */
+ Create* getCreate(void);
+
+ /**
+ * Sets the value of the '{@link org.apache.tuscany.das.rdb.config.Table#getCreate <em>Create</em>}' containment reference.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @param value the new value of the '<em>Create</em>' containment reference.
+ * @see #getCreate()
+ * @generated
+ */
+ void setCreate(Create* value);
+
+ /**
+ * Returns the value of the '<em><b>Update</b></em>' containment reference.
+ * <!-- begin-user-doc -->
+ * <p>
+ * If the meaning of the '<em>Update</em>' containment reference isn't clear,
+ * there really should be more of a description here...
+ * </p>
+ * <!-- end-user-doc -->
+ * @return the value of the '<em>Update</em>' containment reference.
+ * @see #setUpdate(Update)
+ * @generated
+ */
+ Update* getUpdate(void);
+
+ /**
+ * Sets the value of the '{@link org.apache.tuscany.das.rdb.config.Table#getUpdate <em>Update</em>}' containment reference.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @param value the new value of the '<em>Update</em>' containment reference.
+ * @see #getUpdate()
+ * @generated
+ */
+ void setUpdate(Update* value);
+
+ Delete* getDelete(void);
+
+ /**
+ * Sets the value of the '{@link org.apache.tuscany.das.rdb.config.Table#getDelete <em>Delete</em>}' containment reference.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @param value the new value of the '<em>Delete</em>' containment reference.
+ * @see #getDelete()
+ * @generated
+ */
+ void setDelete(Delete* value);
+
+ /**
+ * Returns the value of the '<em><b>Table Name</b></em>' attribute.
+ * <!-- begin-user-doc -->
+ * <p>
+ * If the meaning of the '<em>Table Name</em>' attribute isn't clear,
+ * there really should be more of a description here...
+ * </p>
+ * <!-- end-user-doc -->
+ * @return the value of the '<em>Table Name</em>' attribute.
+ * @see #setTableName(String)
+ * @generated
+ */
+ string getTableName(void);
+
+ /**
+ * Sets the value of the '{@link org.apache.tuscany.das.rdb.config.Table#getTableName <em>Table Name</em>}' attribute.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @param value the new value of the '<em>Table Name</em>' attribute.
+ * @see #getTableName()
+ * @generated
+ */
+ void setTableName(string value);
+
+ /**
+ * Returns the value of the '<em><b>Type Name</b></em>' attribute.
+ * <!-- begin-user-doc -->
+ * <p>
+ * If the meaning of the '<em>Type Name</em>' attribute isn't clear,
+ * there really should be more of a description here...
+ * </p>
+ * <!-- end-user-doc -->
+ * @return the value of the '<em>Type Name</em>' attribute.
+ * @see #setTypeName(String)
+ * @generated
+ */
+ string getTypeName(void);
+
+ /**
+ * Sets the value of the '{@link org.apache.tuscany.das.rdb.config.Table#getTypeName <em>Type Name</em>}' attribute.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @param value the new value of the '<em>Type Name</em>' attribute.
+ * @see #getTypeName()
+ * @generated
+ */
+ void setTypeName(string value);
+
+}; // Table
+
+
+#endif //TABLE_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/TableWrapper.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/TableWrapper.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/TableWrapper.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/TableWrapper.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,174 @@
+/*
+ * 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 "TableWrapper.h"
+
+TableWrapper::TableWrapper(void) {
+ table = NULL;
+}
+
+TableWrapper::TableWrapper(Table* table) {
+ this->table = table;
+}
+
+TableWrapper::~TableWrapper(void) {
+}
+
+string TableWrapper::getTypeName(void) {
+ return table->getTypeName() == NULL ? table->getTableName() : table->getTypeName();
+}
+
+string TableWrapper::getTableName(void) {
+ return table->getTableName();
+}
+
+list<string>* TableWrapper::getPrimaryKeyNames(void) {
+ list<string> pkNames;
+ list<Column*>* columnList = table->getColumn();
+ list<Column*>::itrator i;
+
+ for (i = columnList.begin() ; i != columnList.end() ; i++) {
+
+ if (i->isPrimaryKey()) {
+ pkNames.insert(i->getColumnName());
+ }
+
+ }
+
+ return pkNames;
+
+}
+
+list<string>* TableWrapper::getPrimaryKeyProperties(void) {
+ list<string> keyProperties;
+ list<Column*>* columnList = table->getColumn();
+ list<Column*>::iterator i;
+
+ for (i = columnList.begin() ; i != columnList.end() ; i++) {
+
+ if (i->isPrimaryKey()) {
+ keyProperties.insert(getColumnPropertyName(i));
+ }
+
+ }
+
+ return keyProperties;
+
+}
+
+string TableWrapper::getColumnPropertyName(Column* c) {
+
+ if (c->getPropertyName() != NULL) {
+ return c->getPropertyName();
+ }
+
+ return c->getColumnName();
+
+}
+
+bool TableWrapper::isGeneratedColumnProperty(string name) {
+ Column* c = getColumnByPropertyName(name);
+
+ return c == NULL ? false : c->isGenerated();
+
+}
+
+string TableWrapper::getConverter(string propertyName) {
+ Column* c = getColumnByPropertyName(propertyName);
+
+ return (c == NULL) ? NULL : c->getConverterClassName();
+
+}
+
+Column* TableWrapper::getColumnByPropertyName(string propertyName) {
+ list<Column*>* columnList = table->getColumn();
+ list<Column*>::iterator i;
+ for (i = columnList->begin() ; i != columnList->end() i++) {
+ string propert = i->getPropertyName();
+
+ if (propert == NULL) {
+ propert = i->getColumnName();
+ }
+
+ if (strcmp(propertyName, propert) == 0) {
+ return i;
+ }
+
+ }
+
+ return NULL;
+
+}
+
+Column* TableWrapper::getCollisionColumn(void) {
+ list<Column*>* columnList = table->getColumn();
+ list<Column*>::iterator i;
+ for (i = columnList->begin() ; i != columnList->end() i++) {
+
+ if (i->isCollision()) {
+ return i;
+ }
+
+ }
+
+ return NULL;
+
+}
+
+string TableWrapper::getCollisionColumnPropertyName(void) {
+ Column* c = getCollisionColumn();
+
+ if (c->getPropertyName() != NULL) {
+ return c->getPropertyName();
+ }
+
+ return c->getColumnName();
+
+}
+
+string TableWrapper::getManagedColumnPropertyName(void) {
+ list<Column*>* columnList = table->getColumn();
+ list<Column*>::iterator i;
+
+ for (i = columnList->begin() ; i != columnList->end() i++) {
+
+ if (i->isCollision() && i->isManaged()) {
+ return i->getPropertyName() == NULL ? i->getColumnName() : i->getPropertyName();
+ }
+
+ }
+
+ return NULL;
+
+}
+
+Column* TableWrapper::getManagedColumn(void) {
+ list<Column*>* columnList = table->getColumn();
+ list<Column*>::iterator i;
+
+ for (i = columnList->begin() ; i != columnList->end() i++) {
+
+ if (i->isCollision() && i->isManaged()) {
+ return i;
+ }
+
+ }
+
+ return NULL;
+
+}
Added: incubator/tuscany/cpp/das/runtime/core/src/TableWrapper.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/TableWrapper.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/TableWrapper.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/TableWrapper.h Fri Jan 12 15:33:46 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 TABLE_WRAPPER_H
+#define TABLE_WRAPPER_H
+
+class TableWrapper {
+
+ private:
+ Table* table;
+
+ public:
+ TableWrapper(void);
+ TableWrapper(Table* table);
+ ~TableWrapper(void);
+ string getTypeName(void);
+ string getTableName(void);
+ list<string>* getPrimaryKeyNames(void);
+ list<string>* getPrimaryKeyProperties(void);
+ string getColumnPropertyName(Column* c);
+ bool isGeneratedColumnProperty(string name);
+ string getConverter(string propertyName);
+ Column* getColumnByPropertyName(string propertyName);
+ Column* getCollisionColumn(void);
+ string getCollisionColumnPropertyName(void);
+ string getManagedColumnPropertyName(void);
+ Column* getManagedColumn(void);
+
+};
+
+#endif //TABLE_WRAPPER_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/Update.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/Update.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/Update.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/Update.h Fri Jan 12 15:33:46 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.
+ */
+#ifndef UPDATE_H
+#define UPDATE_H
+
+virtual class Update {
+ /**
+ * Returns the value of the '<em><b>Sql</b></em>' attribute.
+ * <!-- begin-user-doc -->
+ * <p>
+ * If the meaning of the '<em>Sql</em>' attribute isn't clear,
+ * there really should be more of a description here...
+ * </p>
+ * <!-- end-user-doc -->
+ * @return the value of the '<em>Sql</em>' attribute.
+ * @see #setSql(String)
+ * @generated
+ */
+ string getSql(void);
+
+ /**
+ * Sets the value of the '{@link org.apache.tuscany.das.rdb.config.Update#getSql <em>Sql</em>}' attribute.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @param value the new value of the '<em>Sql</em>' attribute.
+ * @see #getSql()
+ * @generated
+ */
+ void setSql(string value);
+
+ /**
+ * Returns the value of the '<em><b>Parameters</b></em>' attribute.
+ * <!-- begin-user-doc -->
+ * <p>
+ * If the meaning of the '<em>Parameters</em>' attribute isn't clear,
+ * there really should be more of a description here...
+ * </p>
+ * <!-- end-user-doc -->
+ * @return the value of the '<em>Parameters</em>' attribute.
+ * @see #setParameters(String)
+ * @generated
+ */
+ string getParameters(void);
+
+ /**
+ * Sets the value of the '{@link org.apache.tuscany.das.rdb.config.Update#getParameters <em>Parameters</em>}' attribute.
+ * <!-- begin-user-doc -->
+ * <!-- end-user-doc -->
+ * @param value the new value of the '<em>Parameters</em>' attribute.
+ * @see #getParameters()
+ * @generated
+ */
+ void setParameters(string value);
+
+}; // Update
+
+
+#endif //UPDATE_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/UpdateCommandImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/UpdateCommandImpl.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/UpdateCommandImpl.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/UpdateCommandImpl.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,32 @@
+/*
+ * 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 "UpdateCommandImpl.h"
+
+UpdateCommandImpl::UpdateCommandImpl(string sqlString) {
+ super(sqlString);
+}
+
+UpdateCommandImpl::UpdateCommandImpl(Update* update) {
+ super(update->getSql());
+ addParameters(update->getParameters());
+
+}
+
+UpdateCommandImpl::~UpdateCommandImpl(void) {
+}
Added: incubator/tuscany/cpp/das/runtime/core/src/UpdateCommandImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/UpdateCommandImpl.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/UpdateCommandImpl.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/UpdateCommandImpl.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,34 @@
+/*
+ * 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 UPDATE_COMMAND_IMPL_H
+#define UPDATE_COMMAND_IMPL_H
+
+#include "WriteCommandImpl.h"
+#include "Update.h"
+
+class UpdateCommandImpl : public WriteCommandImpl {
+
+ public:
+ UpdateCommandImpl(string sqlString);
+ UpdateCommandImpl(Update* update);
+ ~UpdateCommandImpl(void);
+
+};
+
+#endif //UPDATE_COMMAND_IMPL_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/UpdateGenerator.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/UpdateGenerator.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/UpdateGenerator.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/UpdateGenerator.cpp Fri Jan 12 15:33:46 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 "UpdateGenerator.h"
+
+UpdateGenerator::UpdateGenerator(void) {}
+
+UpdateGenerator::~UpdateGenerator(void) {
+}
+
+UpdateCommandImpl& UpdateGenerator::getUpdateCommand(MappingWrapper& mapping, DataObject& changedObject, Table& table); {
+ list<ParameterImpl*> parameters;
+ Type& type = changedObject.getType();
+ TableWrapper tableWrapper(table);
+ string statement = "update ";
+ statement += table.getTableName();
+ statement += " set ";
+
+ ChangeSummary& summary = changedObject.getDataGraph().getChangeSummary();
+ map<Property&, Property*>& changedFields = getChangedFields(mapping, summary, changedObject, tableWrapper);
+ map<Property&, Property*>::iterator it;
+
+ int idx = 1;
+ for (it = changedFields.begin() ; it != changedFields.end() ; it++) {
+
+ Column& c = tableWrapper.getColumnByPropertyName(it->getName());
+
+ if ((c == NULL) || !c.isCollision() || !c.isPrimaryKey()) {
+ string columnName = (c == NULL) ? it->getName() : c.getColumnName();
+ appendFieldSet(statement, idx > 1, columnName);
+ parameters.insert(createParameter(tableWrapper, *it, idx++));
+
+ }
+
+ }
+
+ Column& c = tableWrapper.getManagedColumn();
+ if (c != NULL) {
+ appendFieldSet(statement, idx > 1, c.getColumnName());
+ string propertyName = (c.getPropertyName()) == NULL ? c.getColumnName() : c.getPropertyName();
+ parameters.insert(createManagedParameter(tableWrapper,
+ changedObject.getProperty(propertyName), idx++));
+
+ }
+
+ statement += " where ";
+
+ list<string>& pkNames = tableWrapper.getPrimaryKeyNames();
+ list<string>::iterator pkColumnNames = pkNammes.iterator();
+
+ list<string>& pkNamesProperties = tableWrapper.getPrimaryKeyProperties();
+ list<string>::iterator pkPropertyNames = pkNamesProperties.iterator();
+
+ while (pkNames.end() != pkColumnNames && pkNamesProperties.end() != pkPropertyNames) {
+ string columnName = *pkColumnNames;
+ pkColumnNames++;
+
+ string propertyName = *pkPropertyNames;
+ pkPropertyNames++;
+
+ statement += columnName;
+ statement += " = ?";
+
+ if (pkNames.end() != pkColumnNames && pkNamesProperties.end() != pkPropertyNames) {
+ statement += " and ";
+ }
+
+ parameters.insert(createParameter(tableWrapper, type.getProperty(propertyName), idx++));
+
+ }
+
+ if (tableWrapper.getCollisionColumn() == NULL) {
+
+ for (it = changedFields.begin() ; it != changesFields.end() ; it++;) {
+ statement += " and ";
+ Property& changedProperty = *it;
+
+ Column& column = tableWrapper.getColumnByPropertyName(changedProperty.getName());
+ statement += (column == NULL) ? changedProperty.getName() : column.getColumnName();
+
+ DASObject value;
+ Setting& setting = summary.getOldValue(changedObject, changedProperty);
+
+ // Setting is null if this is a relationship change
+ if (setting == NULL) {
+ value = changedObject.get(changedProperty);
+ } else {
+ value = setting.getValue();
+ }
+
+ if (value == NULL) {
+ statement += " is null";
+ } else {
+ ParameterImpl& param = createCollisionParameter(tableWrapper, changedProperty, idx++);
+ statement += " = ?";
+ param.setValue(value);
+ parameters.insert(param);
+
+ }
+
+
+ }
+
+ } else {
+ statement += " and ";
+ statement += tableWrapper.getCollisionColumn().getColumnName();
+ statement += " = ?";
+ parameters.insert(createParameter(tableWrapper,
+ type.getProperty(tableWrapper.getCollisionColumnPropertyName()), idx++));
+
+ }
+
+ UpdateCommandImpl* updateCommand = new OptimisticWriteCommandImpl(statement.c_chr());
+
+ list<ParameterImpl*>::iterator params;
+ for (params = parameters.begin() ; params != parameters.end() ; params++) {
+ updateCommand.addParameter(*params);
+ }
+
+ /*if (this.logger.isDebugEnabled()) {
+ this.logger.debug(statement.toString());
+ }*/
+
+ return updateCommand;
+
+}
+
+void UpdateGenerator::appendFieldSet(string statement, bool appendComma, string columnName) {
+ if (appendComma) {
+ statement += ", ";
+ }
+
+ statement += columnName;
+ statement += " = ?";
+
+}
+
+map<Property&, Property*> UpdateGenerator::getChangedFields(MappingWrapper& config, ChangeSummary& summary, DataObject& obj, TableWrapper& tw) {
+ map<Property&, Property*> changes;
+ list<ChangeSummary::Setting*>& oldValuesList = summary.getOldValues(obj);
+ list<ChangeSummary::Setting*>::iterator i;
+
+ for (i = oldValuesList.begin() ; i != oldValuesList.end() ; i++) {
+
+ if (i->getProperty().getType().isDataType()) {
+
+ Property& p = i->getProperty();
+ map<Property&, Property*>::iterator changesIterator = changes.find(p);
+
+ if (changesIterator != changes.end()) {
+ //throw new RuntimeException("Foreign key properties should not be set when the corresponding relationship has changed");
+ }
+
+ changes.insert(make_pair(p, p));
+
+ } else {
+ Property& ref = i->getProperty();
+
+ if (!ref.isMany()) {
+
+ RelationshipWrapper r(config.getRelationshipByReference(ref));
+ list<string>& fkList = r.getForeignKeys();
+ list<string>::iterator fkIterator;
+
+ for (fkIterator = fkList.begin() ; fkIterator != fkList.end() ; fkIterator++) {
+ string keyProperty = config.getColumnPropertyName(tw.getTableName(), *fkIterator);
+ Property& keyProp = obj.getType().getProperty(keyProperty);
+
+ if ( keyProp == NULL ) {
+ //throw new RuntimeException("Invalid foreign key column: " + *fkIterator);
+ }
+
+ map<Property&, Property*>::iterator changesIterator = changes.find(keyProp);
+
+ if (changesIterator != changes.end()) {
+ //throw new RuntimeException("Foreign key properties should not be set when the corresponding relationship has changed");
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+ return changes;
+
+}
+
+ParameterImpl& UpdateGenerator::fillParameter(ParameterImpl& param, TableWrapper& table, Property& propert, int idx) {
+ param.setName(propert.getName());
+ param.setType(propert.getType());
+ param.setConverter(getConverter(table.getConverter(propert.getName())));
+
+ if (idx != -1) {
+ param.setIndex(idx);
+ }
+
+ return param;
+
+}
+
+ParameterImpl& UpdateGenerator::createCollisionParameter(TableWrapper& tableWrapper, Property& propert, int i) {
+ return fillParameter(param, tableWrapper, *(new CollisionParameter()), i);
+}
+
+ParameterImpl& UpdateGenerator::createManagedParameter(TableWrapper& table, Property& propert, int idx) {
+ return fillParameter(*(new ManagedParameterImpl()), table, propert, idx);
+}
+
+ParameterImpl& UpdateGenerator::createParameter(TableWrapper& table, Property propert, int idx) {
+ return fillParameter(*(new ParameterImpl()), table, propert, idx);
+}
Added: incubator/tuscany/cpp/das/runtime/core/src/UpdateGenerator.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/UpdateGenerator.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/UpdateGenerator.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/UpdateGenerator.h Fri Jan 12 15:33:46 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.
+ */
+#ifndef UPDATE_GENERATOR_H
+#define UPDATE_GENERATOR_H
+
+class UpdateGenerator : public BaseGenerator {
+
+ private:
+ UpdateGenerator(void);
+ void appendFieldSet(string statement, bool appendComma, string columnName);
+ map<Property*, Property*>* getChangedFields(MappingWrapper* config, ChangeSummary* summary, DataObject* obj, TableWrapper* tw);
+ ParameterImpl* fillParameter(ParameterImpl* param, TableWrapper* table, Property* propert, int idx);
+ ParameterImpl* createCollisionParameter(TableWrapper* tableWrapper, Property* propert, int i);
+ ParameterImpl* createManagedParameter(TableWrapper* table, Property* propert, int idx);
+ ParameterImpl* createParameter(TableWrapper* table, Property* propert, int idx);
+
+
+ public:
+ static UpdateGenerator INSTANCE;
+
+ ~UpdateGenerator(void);
+ UpdateCommandImpl* getUpdateCommand(MappingWrapper* mapping, DataObject* changedObject, Table* table);
+
+};
+
+#endif //UPDATE_GENERATOR_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/UpdateList.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/UpdateList.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/UpdateList.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/UpdateList.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,34 @@
+/*
+ * 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 "UpdateList.h"
+
+UpdateList::UpdateList(void) {
+ super();
+}
+
+UpdateList::~UpdateList(void) {
+}
+
+void UpdateList::add(ChangeOperation* c) {
+ updates.insert(c);
+}
+
+list<ChangeOperation*>* UpdateList::getSortedList(void) {
+ return &updates;
+}
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/UpdateList.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/UpdateList.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/UpdateList.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/UpdateList.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#ifndef UPDATE_LIST_H
+#define UPDATE_LIST_H
+
+#include <list>
+
+#include "ChangeOperation.h"
+
+using namespace std;
+
+class UpdateList {
+
+ private:
+ list<ChangeOperation*> updates;
+
+ public:
+ UpdateList(void);
+ ~UpdateList(void);
+ void add(ChangeOperation* c);
+ list<ChangeOperation*>* getSortedList(void);
+
+};
+
+#endif //UPDATE_LIST_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/UpdateOperation.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/UpdateOperation.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/UpdateOperation.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/UpdateOperation.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include "UpdateOperation.h"
+
+UpdateOperation::UpdateOperation(UpdateCommandImpl* command, DataObject* changedObject, string id) {
+ super(command, changedObject);
+ propagatedID = id;
+
+}
+
+UpdateOperation::~UpdateOperation(void) {
+}
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/UpdateOperation.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/UpdateOperation.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/UpdateOperation.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/UpdateOperation.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#ifndef UPDATE_OPERATION_H
+#define UPDATE_OPERATION_H
+
+#include "ChangeOperation.h"
+#include "UpdateCommandImpl.h"
+
+#include "commonj/sdo/DataFactory.h"
+
+using namespace commonj::sdo;
+
+class UpdateOperation : public ChangeOperation {
+
+ public:
+ UpdateOperation(UpdateCommandImpl* command, DataObject* changedObject, string id);
+ ~UpdateOperation(void);
+
+};
+
+#endif //UPDATE_OPERATION_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/WriteCommandImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/WriteCommandImpl.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/WriteCommandImpl.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/WriteCommandImpl.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,110 @@
+/*
+ * 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 "WriteCommandImpl.h"
+
+WriteCommandImpl::WriteCommandImpl(string sqlString) {
+ super(sqlString);
+}
+
+WriteCommandImpl::~WriteCommandImpl(void) {
+}
+
+void WriteCommandImpl::execute(void) {
+ int success = 0;
+
+ //try {
+ statement->executeUpdate(parameters);
+ success = 1;
+
+ //} catch (SQLException e) {
+ // throw new RuntimeException(e);
+ //} finally {
+ if (success) {
+ statement->getConnection()->cleanUp();
+ } else {
+ statement->getConnection()->errorCleanUp();
+ }
+
+ }
+
+}
+
+DataObject* WriteCommandImpl::executeQuery(void) {
+// throw new UnsupportedOperationException();
+}
+
+Config* WriteCommandImpl::getMappingModel(void) {
+ return configWrapper.getConfig();
+}
+
+//string WriteCommandImpl::toString(void) {}
+
+int WriteCommandImpl::getGeneratedKey(void) {
+ //throw new RuntimeException("No generated key is available");
+}
+
+void WriteCommandImpl::addParameters(string parameters) {
+ int i, j, sp, tb, nl, cr, ff, next, pos = 0, idx = 1;
+ int size = strlen(parameters);
+ string strParams = (string) parameters;
+
+ do {
+ next = min(strParams.find(' ', pos), strParams.find('\t', pos));
+ next = min(next, strParams.find('\n', pos));
+ next = min(next, strParams.find('\r', pos));
+ next = min(next, strParams.find('\f', pos));
+
+ if (next == pos) {
+ pos++;
+ } else {
+
+ string param;
+
+ if (next == string::npos) {
+ param = strParams.substr(pos, size);
+ } else {
+ param = strParams.substr(pos, (next - 1) - pos);
+ }
+
+ ParameterImpl p;
+ p.setName((string) param);
+ p.setIndex(idx);
+ addParameter(&p);
+
+ idx++;
+
+ pos = next + 1;
+
+ }
+
+
+
+ } while (next != string::npos && pos < size);
+
+}
+
+int WriteCommandImpl::min(int value1, int value2) {
+
+ if (value2 > value1) {
+ return value2;
+ }
+
+ return value1;
+
+}
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/WriteCommandImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/WriteCommandImpl.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/WriteCommandImpl.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/WriteCommandImpl.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#ifndef WRITE_COMMAND_IMPL_H
+#define WRITE_COMMAND_IMPL_H
+
+#include <string>
+
+#include "CommandImpl.h"
+#include "Config.h"
+#include "ParameterImpl.h"
+
+#include "commonj/sdo/DataFactory.h"
+
+using namespace commonj::sdo;
+
+class WriteCommandImpl : public CommandImpl {
+
+ private:
+ int minValue(int value1, int value2);
+
+ public:
+ WriteCommandImpl(string sqlString);
+ ~WriteCommandImpl(void);
+ void execute(void);
+ DataObject* executeQuery(void);
+ Config* getMappingModel(void);
+ //string toString(void);
+ int getGeneratedKey(void);
+ void addParameters(string parameters);
+
+};
+
+#endif //WRITE_COMMAND_IMPL_H
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org