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 [3/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/CreateOperation.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/CreateOperation.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/CreateOperation.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/CreateOperation.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 "CreateOperation.h"
+
+CreateOperation::CreateOperation(InsertCommandImpl* command, DataObject* changedObject, string id) {
+ super(command, changedObject);
+ propagatedID = id;
+
+}
+
+CreateOperation::~CreateOperation() {
+}
Added: incubator/tuscany/cpp/das/runtime/core/src/CreateOperation.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/CreateOperation.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/CreateOperation.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/CreateOperation.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,36 @@
+/*
+ * 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 CREATE_OPERATION_H
+#define CREATE_OPERATION_H
+
+#include "InsertCommandImpl.h"
+
+#include "commonj/sdo/DataObject.h"
+
+using namespace commonj::sdo;
+
+class CreateOperation : public ChangeOperation {
+
+ public:
+ CreateOperation(InsertCommandImpl* command, DataObject* changedObject, string id);
+ virtual ~CreateOperation(void);
+
+};
+
+#endif //CREATE_OPERATION_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DAS.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DAS.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DAS.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DAS.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 D_A_S_H
+#define D_A_S_H
+
+#include "DASFactory.h"
+#include "DASFactoryImpl.h"
+#include "Command.h"
+
+#include "commonj/sdo/DataObject.h"
+
+using namespace commonj::sdo;
+
+virtual class DAS {
+
+ public:
+ DASFactory FACTORY = new DASFactoryImpl();
+
+ void applyChanges(DataObject* root);
+ Command* getCommand(char* name);
+ void releaseResources(void);
+ Command* createCommand(string sql);
+
+};
+
+#endif //D_A_S_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DASFactory.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DASFactory.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DASFactory.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DASFactory.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 D_A_S_FACTORY_H
+#define D_A_S_FACTORY_H
+
+#include <sql.h>
+
+#include "Config.h"
+
+virtual class DASFactory {
+
+ public:
+ DAS* createDAS(string configStream);
+ DAS* createDAS(string configStream, HDBC* connection);
+ DAS* createDAS(Config* config);
+ DAS* createDAS(Config* config, HDBC* connection);
+ DAS* createDAS(HDBC* connection);
+
+};
+
+#endif //D_A_S_FACTORY_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DASFactoryImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DASFactoryImpl.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DASFactoryImpl.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DASFactoryImpl.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,39 @@
+/*
+ * 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 "DASFactoryImpl.h"
+
+DAS* DASFactoryImpl::createDAS(InputStream* configStream) {
+ return DASImpl(configStream);
+}
+
+DAS* DASFactoryImpl::createDAS(Config* config) {
+ return DASImpl(config);
+}
+
+DAS* DASFactoryImpl::createDAS(InputStream* configStream, HDBC* connection) {
+ return DASImpl(configStream, connection);
+}
+
+DAS* DASFactoryImpl::createDAS(Config* config, Connection* connection) {
+ return DASImpl(config, connection);
+}
+
+DAS* DASFactoryImpl::createDAS(HDBC* connection) {
+ return DASImpl(connection);
+}
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DASFactoryImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DASFactoryImpl.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DASFactoryImpl.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DASFactoryImpl.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,40 @@
+/*
+ * 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 D_A_S_FACTORY_IMPL_H
+#define D_A_S_FACTORY_IMPL_H
+
+#include <sql.h>
+
+#include "DAS.h"
+#include "DASImpl.h"
+#include "Config.h"
+#include "Connection.h"
+
+class DASFactoryImpl : public DASFactory {
+
+ public:
+ DAS* createDAS(InputStream* configStream);
+ DAS* createDAS(Config* config);
+ DAS* createDAS(InputStream* configStream, HDBC* connection);
+ DAS* createDAS(Config* config, Connection* connection);
+ DAS* createDAS(HDBC* connection);
+
+};
+
+#endif //D_A_S_FACTORY_IMPL_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DASImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DASImpl.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DASImpl.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DASImpl.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,280 @@
+/*
+ * 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 "DASImpl.h"
+
+DASImpl::DASImpl(InputStream* stream) {
+ this(ConfigUtil.loadConfig(stream));
+}
+
+DASImpl::DASImpl(Config* inConfig) {
+ Config* cfg = inConfig;
+
+ if (cfg == NULL) {
+ cfg = ConfigFactory.INSTANCE.createConfig();
+ }
+
+ configWrapper = MappingWrapper(cfg);
+
+ list<Command*>* commandList = configWrapper.getConfig().getCommand();
+ list<Command*>::iterator i;
+
+ for (i = commandList->begin() ; i != commandList->end() ; i++) {
+ Command* commandConfig = *i;
+ string kind = commandConfig->getKind();
+ toLower(kind);
+
+ if (strcmp("select", kind)) == 0) {
+ commands.insert(make_pair(commandConfig->getName(), ReadCommandImpl(commandConfig->getSQL(),
+ configWrapper, commandConfig->getResultDescriptor())));
+
+ } else if (strcmp("update", kind)) == 0) {
+ commands.insert(commandConfig->getName(), UpdateCommandImpl(commandConfig->getSQL()));
+
+ } else if (strcmp("insert", kind)) == 0) {
+ string* stringList = {{0}};
+ commands.insert(commandConfig->getName(), InsertCommandImpl(commandConfig->getSQL(), stringList));
+
+ } else if (strcmp("delete", kind)) == 0) {
+ commands.insert(commandConfig->getName(), DeleteCommandImpl(commandConfig->getSQL()));
+
+ } else if (strcmp("procedure", kind)) == 0) {
+ commands.insert(commandConfig->getName(), SPCommandImpl(commandConfig->getSQL(),
+ configWrapper, commandConfig->getParameter()));
+
+ } else {
+ //throw new RuntimeException("Invalid kind of command: " + kind);
+ }
+
+ }
+
+}
+
+DASImpl::DASImpl(Config* inConfig, HDBC* inConnection) {
+ this(inConfig);
+ setConnection(inConnection);
+
+}
+
+DASImpl::DASImpl(InputStream* configStream, HDBC* inConnection) {
+ this(ConfigUtil.loadConfig(configStream), inConnection);
+}
+
+DASImpl::DASImpl(HDBC* inConnection) {
+ this(ConfigFactory.INSTANCE.createConfig());
+ setConnection(inConnection);
+
+}
+
+DASImpl::~DASImpl() {
+}
+
+ApplyChangesCommandImpl* DASImpl::getApplyChangesCommand(void) {
+ return ApplyChangesCommandImpl(configWrapper, connection);
+}
+
+Command* DASImpl::getCommand(string name) {
+
+ map<string, CommandImpl*>::iterator i = commands.find(name);
+ if (i == commands.end()) {
+ //throw new RuntimeException("CommandGroup has no command named: " + name);
+ }
+
+ CommandImpl* cmd = (CommandImpl*) *i;
+ cmd->setConnection(getConnection(), configWrapper->getConfig());
+
+ return cmd;
+
+}
+
+void DASImpl::setConnection(HDBC* aConnection) {
+ connection = aConnection;
+}
+
+HDBC* DASImpl::getConnection(void) {
+
+ if (connection == NULL) {
+ initializeConnection();
+ }
+
+ return connection;
+
+}
+
+void DASImpl::initializeConnection(void) {
+ Config* config = configWrapper->getConfig();
+
+ if (config == NULL || config->getConnectionInfo() == NULL
+ || config->getConnectionInfo()->getDataSource() == NULL) {
+ //throw new RuntimeException("No connection has been provided and no data source has been specified");
+ }
+
+ Connection* connection = NULL;
+
+ InitialContext* ctx;
+
+ //try {
+ ctx = InitialContext();
+ //} catch (NamingException e) {
+ // throw new RuntimeException(e);
+ //}
+
+// try {
+ DataSource* ds = (DataSource*) ctx->lookup(configWrapper->getConfig()->getConnectionInfo()->getDataSource());
+ // try {
+ connection = ds->getConnection();
+
+ if (connection == NULL) {
+ // throw new RuntimeException("Could not obtain a Connection from DataSource");
+ }
+
+ SQLSetConnectAttr(connection, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF, SQL_NTS);
+ setConnection(connection);
+
+ //} catch (SQLException e) {
+ // throw new RuntimeException(e);
+ //}
+
+ //} catch (NamingException e) {
+ // throw new RuntimeException(e);
+ //}
+
+
+}
+
+void DASImpl::releaseResources(void) {
+
+ if (managingConnections()) {
+ closeConnection();
+ }
+
+}
+
+Command* DASImpl::createCommand(string sql) {
+ return baseCreateCommand(sql, configWrapper);
+}
+
+Command* DASImpl::createCommand(string sql, Config* config) {
+ return baseCreateCommand(sql, MappingWrapper(config));
+}
+
+Command* DASImpl::baseCreateCommand(string inSql, MappingWrapper* config) {
+ CommandImpl* returnCmd = NULL;
+ trim(inSql); // Remove leading white space
+ char firstChar = toupper(sql[0]);
+
+ switch (firstChar) {
+ case 'S':
+ returnCmd = ReadCommandImpl(sql, config, NULL);
+ break;
+
+ case 'I':
+ string* stringList[0];
+ returnCmd = InsertCommandImpl(sql, stringList);
+ break;
+
+ case 'U':
+ returnCmd = UpdateCommandImpl(sql);
+ break;
+
+ case 'D':
+ returnCmd = DeleteCommandImpl(sql);
+ break;
+
+ case '{':
+ returnCmd = SPCommandImpl(sql, config, Collections.EMPTY_LIST);
+ break;
+
+ default:
+ //throw new RuntimeException("SQL => " + sql + " is not valid");
+
+ }
+
+ returnCmd->setConnection(getConnection(), config-:getConfig());
+ return returnCmd;
+
+}
+
+void DASImpl::applyChanges(DataObject* root) {
+ getApplyChangesCommand()->execute(root);
+}
+
+int DASImpl::managingConnections(void) {
+
+ if (configWrapper->getConfig()->getConnectionInfo()->getDataSource() == NULL) {
+ return 0;
+ }
+
+ return 1;
+
+}
+void DASImpl::closeConnection(void) {
+
+ if (connection != null) {
+
+ //try {
+ SQLDisconnect(connection);
+ connection = NULL;
+ //} catch (SQLException e) {
+ // throw new RuntimeException(e);
+ //}
+
+ }
+
+}
+
+void DASImpl::toLower(string string) {
+ int i;
+ int stringSize = strlen(string);
+
+ for (i = 0 ; i < stringSize ; i++) {
+ string[i] = tolower(string[i]);
+ }
+
+}
+
+void DASImpl::trim(string string) {
+ int stringSize = strlen(string);
+ int stringBegin = 0;
+ int stringEnd = strlen(string) - 1;
+ char actual = string[0];
+
+ while (actual != ' ') {
+ stringBegin++;
+ actual = string[stringBegin];
+
+ }
+
+ char actual = string[stringEnd];
+ while (actual != ' ') {
+ stringEnd--;
+ actual = string[stringBegin];
+
+ }
+
+ int i;
+ int j = 0;
+ for (i = stringBegin ; i <= stringEnd ; i++) {
+ string[j] = string[i];
+ j++;
+
+ }
+
+ string[j] = 0;
+
+}
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DASImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DASImpl.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DASImpl.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DASImpl.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,80 @@
+/*
+ * 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 D_A_S_IMPL_H
+#define D_A_S_IMPL_H
+
+#include <sql.h>
+#include <map>
+#include <string>
+#include <cctype>
+#include <list>
+
+#include "MappingWrapper.h"
+#include "DAS.h"
+#include "CommandImpl.h"
+#include "Config.h"
+#include "ApplyChangesCommandImpl.h"
+#include "ConfigUtil.h"
+#include "ConfigFactory.h"
+#include "ReadCommandImpl.h"
+#include "UpdateCommandImpl.h"
+#include "InsertCommandImpl.h"
+#include "DeleteCommandImpl.h"
+#include "SPCommandImpl.h"
+#include "Connection.h"
+#include "DataSource.h"
+
+#include "commonj/sdo/DataFactory.h"
+
+using namespace commonj::sdo;
+using namespace std;
+
+class DASImpl : public DAS {
+
+ private:
+ MappingWrapper* configWrapper;
+ HDBC* connection;
+ map<string, CommandImpl*> commands;
+
+ int managingConnections(void);
+ void closeConnection(void);
+ void toLower(string string);
+ void trim(string string);
+
+ public:
+ DASImpl(InputStream* stream);
+ DASImpl(Config* inConfig);
+ DASImpl(Config* inConfig, HDBC* inConnection);
+ DASImpl(InputStream* configStream, HDBC* inConnection);
+ DASImpl(HDBC* inConnection);
+ virtual ~DASImpl(void);
+ ApplyChangesCommandImpl* getApplyChangesCommand(void);
+ Command* getCommand(string name);
+ HDBC* getConnection(void);
+ void setConnection(HDBC* aConnection);
+ void initializeConnection(void);
+ void releaseResources(void);
+ Command* createCommand(string sql);
+ Command* createCommand(string sql, Config* config);
+ Command* baseCreateCommand(string inSql, MappingWrapper* config);
+ void applyChanges(DataObject* root);
+
+};
+
+#endif //D_A_S_IMPL_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DASObject.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DASObject.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DASObject.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DASObject.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 D_A_S_OBJECT_H
+#define D_A_S_OBJECT_H
+
+class DASObject {
+};
+
+#endif //D_A_S_OBJECT_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DataObjectMaker.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DataObjectMaker.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DataObjectMaker.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DataObjectMaker.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,102 @@
+/*
+ * 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 "DataObjectMaker.h"
+
+DataObjectMaker::DataObjectMaker(DataObject& root) {
+ rootObject = root;
+}
+
+DataObjectMaker::~DataObjectMaker(void) {
+}
+
+DataObject& DataObjectMaker::createAndAddDataObject(TableData& tableData, ResultMetadata& resultMetadata) {
+ /*if (this.logger.isDebugEnabled()) {
+ this.logger.debug("Looking for Type for " + tableData.getTableName());
+ }*/
+
+ Type& tableClass = findTableTypeByPropertyName(tableData.getTableName());
+
+ if (tableClass == NULL) {
+ //throw new RuntimeException("An SDO Type with name " + tableData.getTableName() + " was not found");
+ }
+
+ DataObject& obj = DataFactory.INSTANCE.create(tableClass);
+
+ // Now, check to see if the root data object has a containment reference
+ // to this EClass. If so, add it to the graph. If not, it will be taken
+ // care
+ // of when we process relationships
+
+ list<Property*>& propertiesList = rootObject.getType().getProperties();
+ list<Property*>::iterator i;
+
+ for (i = propertiesList.begin() ; i != propertiesList.end() ; i++) {
+
+ if (i->isContainment() && i->getType() == tableClass) {
+
+ if (i->isMany()) {
+ rootObject.getList(*i).insert(obj);
+ } else {
+ rootObject.set(*i, obj);
+ }
+
+ }
+
+ }
+
+ list<string>& columnNames = resultMetadata.getPropertyNames(tableData.getTableName());
+ list<string>::iterator j;
+
+ for (j = columnNames.begin() ; j != columnNames.end() ; j++) {
+ Property& p = findProperty(obj.getType(), *j);
+
+ if (j == NULL) {
+ //throw new RuntimeException("Type " + obj.getType().getName()
+ // + " does not contain a property named " + propertyName);
+ }
+
+ DASObject value = tableData.getColumnData(propertyName);
+
+ obj.set(*j, value);
+
+ }
+
+ return obj;
+
+}
+
+Type& DataObjectMaker::findTableTypeByPropertyName(string tableName) {
+}
+
+Property& findProperty(Type& type, string columnName) {
+ list<Property*>& propertiesList = type.getProperties();
+ list<Property*>::iterator i;
+
+ for (i = propertiesList.begin() ; i != propertiesList.end() ; i++) {
+
+ if (strcmp(columnName, i->getName()) == 0) {
+ return *i;
+ }
+
+ }
+
+ return NULL;
+
+}
+
Added: incubator/tuscany/cpp/das/runtime/core/src/DataObjectMaker.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DataObjectMaker.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DataObjectMaker.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DataObjectMaker.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 DATA_OBJECT_MAKER_H
+#define DATA_OBJECT_MAKER_H
+
+class DataObjectMaker {
+
+ private:
+ DataObject* rootObject;
+
+ Type* findTableTypeByPropertyName(string tableName);
+ Property* findProperty(Type* type, string columnName);
+
+ public:
+ DataObjectMaker(DataObject* root);
+ virtual ~DataObjectMaker(void);
+ DataObject* createAndAddDataObject(TableData* tableData, ResultMetadata* resultMetadata);
+
+};
+
+#endif //DATA_OBJECT_MAKER_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DatabaseObject.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DatabaseObject.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DatabaseObject.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DatabaseObject.cpp 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.
+ */
+#include "DatabaseObject.h"
+
+DatabaseObject::DatabaseObject(Config* model, DataObject* changedObject) {
+ mappingWrapper = MappingWrapper(model);
+ dataObject = changedObject;
+ initialize();
+
+}
+
+DatabaseObject::~DatabaseObject() {
+}
+
+void DatabaseObject::initialize(void) {
+
+ if (mappingWrapper->getConfig() != NULL) {
+
+ list<Relationship*>* listRelationship = mappingWrapper.getConfig().getRelationship();
+ list<Relationship*>::iterator i;
+
+ for (i = listRelationship->begin() ; i != listRelationship->end() ; i++) {
+ Relationship* r = *i;
+
+ /*if (this.logger.isDebugEnabled()) {
+ this.logger.debug("Initializing relationship: " + r.getName());
+ }*/
+
+ if (r->getForeignKeyTable() == getTypeName()) {
+
+ list<KeyPair*>* pairs = r.getKeyPair();
+ list<KeyPair*>::iterator j;
+
+ for (j = pairs->begin() ; j != pairs->end() ; j++) {
+ keyMappings.insert(make_pair(*j->getForeignKeyColumn(), r));
+
+ }
+
+ }
+
+ }
+
+ }
+
+}
+
+DASObject* DatabaseObject::get(string parameter) {
+
+ if (isPartOfPrimaryKey(parameter)) {
+ return dataObject->get(parameter);
+ }
+
+ Relationship* r = *(keyMappings.find(parameter));
+
+ if (r == NULL) {
+ return dataObject->get(parameter);
+ }
+
+ Property* parentRef = getParentReference(r->getPrimaryKeyTable());
+ DataObject* parent = dataObject->getDataObject(parentRef);
+
+ if (parent == NULL) {
+ return NULL;
+ }
+
+ string parentKey = getParentKey(r, parameter);
+ return parent->get(parentKey);
+
+}
+
+Property* DatabaseObject::getParentReference(string parentName) {
+
+ if (parentReference == NULL) {
+
+ list<Property*>* properties = dataObject.getType().getProperties();
+ list<Property*>::iterator i;
+ for (i = properties->begin() ; i != properties->end() ; i++) {
+
+ if ((!*i->getType()->isDataType()) && (ref->getType()->getName() == parentName)) {
+ parentReference = *i;
+ }
+
+ }
+
+ }
+
+ return parentReference;
+
+}
+
+string DatabaseObject::getTableName(void) {
+
+ if (mappingWrapper->getConfig() != NULL) {
+ return mappingWrapper->getTableByTypeName(getTypeName())->getTableName();
+ }
+
+ return NULL;
+
+}
+
+string DatabaseObject::getTypeName(void) {
+ return dataObject->getType()->getName();
+}
+
+void DatabaseObject::setPropagatedID(string propagatedID, int id) {
+ dataObject->setInt(propagatedID, id);
+}
+
+string DatabaseObject::getParentKey(Relationship* r, string parameter) {
+ list<KeyPair*>* keyPairs = r->getKeyPair();
+ list<KeyPair*>::iterator i;
+
+ for (i = keyPairs->begin() ; i != keyPairs->end() ; i++) {
+
+ if (*i->getForeignKeyColumn() == parameter) {
+ return pair->getPrimaryKeyColumn();
+ }
+
+ }
+
+ return NULL;
+
+}
+
+int DatabaseObject::isPartOfPrimaryKey(string parameter) {
+
+ if (mappingWrapper->getConfig() == NULL) {
+ return 0;
+ }
+
+ Table* t = mappingWrapper->getTable(getTableName());
+ if (t == NULL) {
+ return 0;
+ }
+
+ Column* c = mappingWrapper->getColumnByPropertyName(t, parameter);
+ if (c == NULL) {
+ return 0;
+ }
+
+ return c->isPrimaryKey();
+
+}
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DatabaseObject.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DatabaseObject.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DatabaseObject.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DatabaseObject.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,62 @@
+/*
+ * 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 DATABASE_OBJECT_H
+#define DATABASE_OBJECT_H
+
+#include <map>
+#include <list>
+
+#include "MappingWrapper.h"
+#include "Relationship.h"
+#include "Config.h"
+#include "DASObject.h"
+#include "KeyPair.h"
+#include "Table.h"
+#include "Column.h"
+
+#include "commonj/sdo/Property.h"
+#include "commonj/sdo/DataFactory.h"
+
+using namespace commonj::sdo;
+using namespace std;
+
+class DatabaseObject {
+
+ private:
+ MappingWrapper* mappingWrapper;
+ DataObject* dataObject;
+ Property* parentReference;
+ map<string, Relationship*> keyMappings;
+
+ string getParentKey(Relationship* r, string parameter);
+ int isPartOfPrimaryKey(string parameter);
+ void initialize(void);
+
+ public:
+ DatabaseObject(Config* model, DataObject* changedObject);
+ virtual ~DatabaseObject(void);
+ DASObject* get(string parameter);
+ Property* getParentReference(string parentName);
+ string getTableName(void);
+ string getTypeName(void);
+ void setPropagatedID(string propagatedID, int id);
+
+};
+
+#endif //DATABASE_OBJECT_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DefaultConverter.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DefaultConverter.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DefaultConverter.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DefaultConverter.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,45 @@
+/*
+ * 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 "DefaultConverter.h"
+
+DefaultConverter::DefaultConverter(void) {
+ //super();
+}
+
+DefaultConverter::~DefaultConverter(void) {
+}
+
+DASObject& DefaultConverter::getColumnValue(DASObject& data) {
+ return data;
+}
+
+DASObject& DefaultConverter::getPropertyValue(DASObject& data) {
+
+ //if (data instanceof Blob) {
+ Blob b = (Blob) data;
+ // try {
+ return b.getBytes(1, (int) b.length());
+ //} catch (SQLException e) {
+ //throw new RuntimeException(e);
+ //}
+ }
+
+ return data;
+
+}
Added: incubator/tuscany/cpp/das/runtime/core/src/DefaultConverter.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DefaultConverter.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DefaultConverter.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DefaultConverter.h 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.
+ */
+#ifndef DEFAULT_CONVERTER_H
+#define DEFAULT_CONVERTER_H
+
+class DefaultConverter : public Converter {
+
+ public:
+ DefaultConverter(void);
+ virtual ~DefaultConverter(void);
+ DASObject* getColumnValue(DASObject* data);
+ DASObject* getPropertyValue(DASObject* data);
+
+};
+
+#endif //DEFAULT_CONVERTER_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/Delete.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/Delete.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/Delete.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/Delete.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 DELETE_H
+#define DELETE_H
+
+virtual class Delete {
+ /**
+ * 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.Delete#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.Delete#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);
+
+}; // Delete
+
+
+#endif //DELETE_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DeleteCommandImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DeleteCommandImpl.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DeleteCommandImpl.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DeleteCommandImpl.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 "DeleteCommandImpl.h"
+
+DeleteCommandImpl::DeleteCommandImpl(string sqlString) {
+ super(sqlString);
+}
+
+DeleteCommandImpl::DeleteCommandImpl(Delete* delete) {
+ super(delete.getSql());
+ addParameters(delete->getParameters());
+
+}
+
+DeleteCommandImpl::~DeleteCommandImpl() {
+}
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DeleteCommandImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DeleteCommandImpl.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DeleteCommandImpl.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DeleteCommandImpl.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 DELETE_COMMAND_IMPL_H
+#define DELETE_COMMAND_IMPL_H
+
+#include "WriteCommandImpl.h"
+#include "Delete.h"
+
+class DeleteCommandImpl : public WriteCommandImpl {
+
+ public:
+ DeleteCommandImpl(string sqlString);
+ DeleteCommandImpl(Delete* delet);
+ virtual ~DeleteCommandImpl(void);
+
+};
+
+#endif //DELETE_COMMAND_IMPL_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DeleteGenerator.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DeleteGenerator.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DeleteGenerator.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DeleteGenerator.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,82 @@
+/*
+ * 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 "DeleteGenerator.h"
+
+DeleteGenerator::DeleteGenerator(void) {}
+
+string DeleteGenerator::getDeleteStatement(Table* t) const {
+ TableWrapper* table = new TableWrapper(t);
+
+ StringBuffer* statement = new StringBuffer();
+ statement->append("delete from ");
+ statement->append(t->getTableName());
+ statement->append(" where ");
+
+ list<string>* pkNames = table->getPrimaryKeyNames();
+ list<string>::iterator pkNamesIterator = pkNames->begin();
+ list<string>* pkProperties = table->getPrimaryKeyProperties();
+ list<string>::iterator pkPropertiesIterator = pkProperties->begin();
+
+ while (pkNames->end() != pkNamesIterator && pkProperties->end() != pkPropertiesIterator) {
+ statement->append(pkNamesIterator);
+ statement->append(" = ?");
+ pkNamesIterator++;
+
+ if (pkNames->end() != pkNamesIterator && pkProperties->end() != pkPropertiesIterator) {
+ statement->append(" and ");
+ }
+
+ }
+
+ /*if (this.logger.isDebugEnabled()) {
+ this.logger.debug(statement.toString());
+ }*/
+
+ return statement->toString();
+
+}
+
+DeleteGenerator::~DeleteGenerator(void) {
+}
+
+DeleteCommandImpl DeleteGenerator::getDeleteCommand(Table t) const {
+ TableWrapper* tw = new TableWrapper(t);
+ DeleteCommandImpl* deleteCommand = new DeleteCommandImpl(getDeleteStatement(t));
+
+ list<string>* pkProperties = tw->getPrimaryKeyProperties();
+ list<string>::iterator i = pkProperties->begin();
+ int idx = 1
+
+ while (i != pkProperties->end()) {
+
+ ParameterImpl* p = new ParameterImpl();
+ p->setName(i);
+ p->setType(SDODataTypes.OBJECT);
+ p->setConverter(getConverter(tw->getConverter(i)));
+ p->setIndex(idx);
+ deleteCommand->addParameter(p);
+
+ idx++;
+ i++;
+
+ }
+
+ return deleteCommand;
+
+}
Added: incubator/tuscany/cpp/das/runtime/core/src/DeleteGenerator.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DeleteGenerator.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DeleteGenerator.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DeleteGenerator.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,38 @@
+/*
+ * 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 DELETE_GENERATOR_H
+#define DELETE_GENERATOR_H
+
+#include "BaseGenerator.h"
+
+class DeleteGenerator : public BaseGenerator {
+
+ private:
+ DeleteGenerator(void);
+ string getDeleteStatement(Table* t) const;
+
+ public:
+ static DeleteGenerator INSTANCE;
+
+ virtual ~DeleteGenerator(void);
+ DeleteCommandImpl* getDeleteCommand(Table* t) const;
+
+};
+
+#endif //DELETE_GENERATOR_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DeleteList.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DeleteList.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DeleteList.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DeleteList.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,76 @@
+/*
+ * 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 "DeleteList.h"
+
+DeleteList::DeleteList(void) {
+ super();
+}
+
+DeleteList::~DeleteList(void) {
+}
+
+void DeleteList::add(ChangeOperation* op) {
+
+ if ((order->size() == 0) || (op->getTableName() == NULL)) {
+ deleteOperations.insert(op);
+
+ } else {
+ string name = op->getTableName();
+ list<ChangeOperation*>* ops = *(opsByTableName.find(name));
+
+ if (ops == opsByTableName.end()) {
+ ops = list<ChangeOperation*>;
+ }
+
+ ops->add(op);
+ opsByTableName.insert(make_pair(name, ops));
+
+ }
+
+}
+
+list<ChangeOperation*>* DeleteList::getSortedList(void) {
+
+ if ((order->size() > 0) && (opsByTableName/*.keySet()*/.size() > 0)) {
+ list<string>::iterator i;
+
+ for (i = order->begin() ; i != order->end() ; i++) {
+ map<string, ChangeOperation*>::iterator keyPair = opsByTableName.find(*i);
+
+ if (listChangeOperationIterator != opsByTableName.end()) {
+ list<ChangeOperation*> list = keyPair->second;
+ list<ChangeOperation*>::iterator j;
+
+ for (j = list->begin() ; j != list->end() ; j++) {
+ deleteOperations.insert(*j);
+ }
+
+ }
+
+ }
+
+ }
+
+ return deleteOperations;
+
+}
+
+void DeleteList::setOrder(list<string>* deleteOrder) {
+ order = deleteOrder;
+}
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DeleteList.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DeleteList.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DeleteList.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DeleteList.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,45 @@
+/*
+ * 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 DELETE_LIST_H
+#define DELETE_LIST_H
+
+#include <map>
+#include <list>
+
+#include "ChangeOperation.h"
+
+using namespace std;
+
+class DeleteList {
+
+ private:
+ map<string, list<ChangeOperation*>*> opsByTableName;
+ list<string>* order;
+ list<ChangeOperation*> deleteOperations;
+
+ public:
+ DeleteList(void);
+ ~DeleteList(void);
+ void add(ChangeOperation* op);
+ list<ChangeOperation*>* getSortedList(void);
+ void setOrder(list<string>* deleteOrder);
+
+};
+
+#endif //DELETE_LIST_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DeleteOperation.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DeleteOperation.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DeleteOperation.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DeleteOperation.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 "DeleteOperation.h"
+
+DeleteOperation::DeleteOperation(DeleteCommandImpl* command, DataObject* changedObject) {
+ super(command);
+ dObject = DatabaseObject(command->getMappingModel(), DataObjectUtil->getRestoredCopy(changedObject));
+
+}
+
+DeleteOperation::~DeleteOperation() {
+}
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/DeleteOperation.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/DeleteOperation.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/DeleteOperation.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/DeleteOperation.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,38 @@
+/*
+ * 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 DELETE_OPERATION_H
+#define DELETE_OPERATION_H
+
+#include "ChangeOperation.h"
+#include "DeleteCommandImpl.h"
+#include "DatabaseObject.h"
+
+#include "commonj/sdo/DataFactory.h"
+
+using namespace commonj::sdo;
+
+class DeleteOperation : public ChangeOperation {
+
+ public:
+ DeleteOperation(DeleteCommandImpl* command, DataObject* changedObject);
+ virtual ~DeleteOperation();
+
+};
+
+#endif //DELETE_OPERATION_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/FactoryRegistry.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/FactoryRegistry.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/FactoryRegistry.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/FactoryRegistry.cpp 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.
+ */
+#include "FactoryRegistry.h"
+
+FactoryRegistry::FactoryRegistry(MappingWrapper* aMapping, ConnectionImpl* aConnection) {
+ mapping = mapping;
+ connection = connection;
+
+}
+
+FactoryRegistry::~FactoryRegistry() {
+}
+
+ChangeFactory* FactoryRegistry::getFactory(const Type& type) {
+ ChangeFactory* factory = ((map<Type*, ChangeFactory*>::iterator) registry.get(type))->second;
+
+ if (factory == NULL) {
+
+ /*if (this.logger.isDebugEnabled()) {
+ this.logger.debug("Creating new ChangeFactory for type " + type.getName());
+ }*/
+
+ factory = ChangeFactory(mapping, connection);
+ registry.insert(make_key(type, factory));
+
+ }
+
+ return factory;
+
+}
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/FactoryRegistry.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/FactoryRegistry.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/FactoryRegistry.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/FactoryRegistry.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,47 @@
+/*
+ * 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 FACTORY_REGISTRY_H
+#define FACTORY_REGISTRY_H
+
+#include <map>
+
+#include "ChangeFactory.h"
+#include "MappingWrapper.h"
+#include "ConnectionImpl.h"
+
+#include "commonj/sdo/Type.h"
+
+using namespace commonj::sdo;
+using namespace std;
+
+class FactoryRegistry {
+
+ private:
+ map<Type, ChangeFactory> registry;
+ MappingWrapper* mapping;
+ ConnectionImpl* connection;
+
+ public:
+ FactoryRegistry(MappingWrapper* aMapping, ConnectionImpl* aConnection);
+ virtual ~FactoryRegistry(void);
+ ChangeFactory* getFactory(const Type& type);
+
+};
+
+#endif //FACTORY_REGISTRY_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/GraphBuilderMetadata.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/GraphBuilderMetadata.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/GraphBuilderMetadata.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/GraphBuilderMetadata.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,241 @@
+/*
+ * 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 "GraphBuilderMetadata.h"
+
+GraphBuilderMetadata(list<ResultSet*>& results, Config& model, ResultSetShape& shape) {// throws SQLException {
+ configWrapper = new MappingWrapper(model);
+
+ if (model != NULL) {
+ typeURI = model.getDataObjectModel();
+ }
+
+ list<ResultSet*>::iterator i;
+
+ for (i = results.begin() ; i != results.end() ; i++) {
+ ResultMetadata* resultMetadata = new ResultMetadata(rs, configWrapper, shape);
+ resultSets.insert(*resultMetadata);
+
+ }
+
+}
+
+~GraphBuilderMetadata(void) {
+}
+
+void initializeVariables(void) {
+ typeURI = NULL;
+ rootType = NULL;
+ typeHelper = NULL;
+
+}
+
+list<ResultSet*>& getResultMetadata(void) {
+ return resultSets;
+}
+
+list<Relationship*>& getRelationships(void) {
+ return configWrapper->getConfig().getRelationship();
+}
+
+Type& getRootType(void) {
+ if (rootType == NULL) {
+
+ if (typeURI == NULL) {
+ createDynamicTypes();
+ } else {
+ createDynamicRoot();
+ }
+
+ }
+
+ return rootType;
+
+}
+
+MappingWrapper& getConfigWrapper(void) {
+ return *configWrapper;
+}
+
+list<Type*>& getDefinedTypes(void) {
+ if (typeURI == NULL) {
+ return SDOUtil.getTypes(typeHelper, getDefaultURI());
+ }
+
+ list<Type*>& types = SDOUtil.getTypes(typeHelper, typeURI);
+ types.insert(rootType);
+
+ return types;
+
+}
+
+void createDynamicTypes(void) {
+ DataObjectUtil.initRuntime();
+
+ Type& root = SDOUtil.createType(typeHelper, getDefaultURI(), "DataGraphRoot", false);
+
+ list<ResultSet*>& resultMetadaList = getResultMetadata();
+ list<ResultSet*>::iterator iter;
+ for (iter = resultMetadaList.begin() ; iter != resultMetadaList.end() ; iter++) {
+ ResultMetadata& resultMetadata = *iter;
+
+ // Create a Type for each Table represented in the ResultSet
+ list<string>& allTablePropertyNames = resultMetadata.getAllTablePropertyNames();
+ list<string>::iterator names;
+
+ for (names = allTablePropertyNames.begin() ; names != allTablePropertyNames.end() ; names++) {
+ string tableName = *names;
+
+ if (root.getProperty(tableName) == NULL) {
+ Type& tableType = SDOUtil.createType(typeHelper, getDefaultURI(), tableName, false);
+ Property& propert = SDOUtil.createProperty(root, tableName, tableType);
+ SDOUtil.setMany(propert, true);
+ SDOUtil.setContainment(propert, true);
+
+ }
+
+ }
+
+ // TODO tablePropertyMap is temporary until Tuscany-203 is fixed
+ map<string, list<string>*> tablePropertyMap = new HashMap();
+ int i;
+
+ for (i = 1; i <= resultMetadata.getResultSetSize(); i++) {
+
+ Property& ref = root.getProperty(resultMetadata.getTablePropertyName(i));
+
+ if (ref == NULL) {
+ //throw new RuntimeException("Could not find table " + resultMetadata.getTablePropertyName(i)
+ //+ " in the SDO model");
+ }
+
+ // TODO Temporary code to check to see if a property has already been added.
+ // Replace when Tuscany-203 is fixed
+ map<string, list<string>*>::iterator mapIter = maptablePropertyMap.find(ref.getName());
+ list<string>& addedProperties;
+
+
+ if (mapIter == maptablePropertyMap.end()) {
+ addedProperties = *(new list<string>);
+ tablePropertyMap.put(ref.getName(), addedProperties);
+
+ } else {
+ addedProperties = mapIter->second;
+ }
+
+ string columnName = resultMetadata.getColumnPropertyName(i);
+ list<string>::iterator i;
+ bool found = false;
+
+ for (i = addedProperties.begin() ; i != addedProperties.end() ; i++) {
+
+ if (strcmp(columnName, *i) == 0) {
+ found = true;
+ break;
+
+ }
+
+ }
+
+ // TODO temporary check until Tuscany-203 is fixed
+ if (!found) {
+ addedProperties.insert(columnName);
+ Type& atype = resultMetadata.getDataType(i);
+
+ SDOUtil.createProperty(ref.getType(), columnName, atype);
+
+ }
+
+ }
+
+ }
+
+ MappingWrapper& wrapper = getConfigWrapper();
+ list<Relationship*>& relationshipList = getRelationships();
+ list<Relationship*>::iterator j;
+
+ for (j = relationshipList.begin() ; j != relationshipList.end() ; j++) {
+
+ string parentName = wrapper.getTableTypeName(j->getPrimaryKeyTable());
+ string childName = wrapper.getTableTypeName(j->getForeignKeyTable());
+
+ if (parentName == NULL) {
+ //throw new RuntimeException("The parent table (" + r.getPrimaryKeyTable()
+ //+ ") in relationship " + r.getName()
+ //+ " was not found in the mapping information.");
+
+ } else if (childName == NULL) {
+ //throw new RuntimeException("The child table (" + r.getForeignKeyTable()
+ //+ ") in relationship " + r.getName()
+ //+ " was not found in the mapping information.");
+
+ }
+
+ Property& parentProperty = root.getProperty(parentName);
+ Property& childProperty = root.getProperty(childName);
+
+ if (parentProperty == NULL) {
+ //throw new RuntimeException("The parent table (" + parentName + ") in relationship "
+ // + r.getName() + " was not found.");
+
+ } else if (childProperty == NULL) {
+ //throw new RuntimeException("The child table (" + childName + ") in relationship "
+ // + r.getName() + " was not found.");
+
+ }
+
+ Type& parent = parentProperty.getType();
+ Type& child = childProperty.getType();
+
+ Property& parentProp = SDOUtil.createProperty(parent, i->getName(), child);
+ Property& childProp = SDOUtil.createProperty(child, i->getName() + "_opposite", parent);
+ SDOUtil.setOpposite(parentProp, childProp);
+ SDOUtil.setOpposite(childProp, parentProp);
+ SDOUtil.setMany(parentProp, i->isMany());
+
+ }
+
+ rootType = root;
+
+}
+
+string getDefaultURI() {
+ return "http:///org.apache.tuscany.das.rdb/das";
+}
+
+void createDynamicRoot(void) {
+ Type root = SDOUtil.createType(typeHelper, getDefaultURI() + "/DataGraphRoot", "DataGraphRoot", false);
+
+ list<Type*>& types = SDOUtil.getTypes(typeHelper, typeURI);
+
+ if (types == NULL) {
+ //throw new RuntimeException("SDO Types have not been registered for URI " + typeURI);
+ }
+
+ list<Type*>::iterator i;
+
+ for (i = types.begin() ; i != types.end() ; i++) {
+ Property& propert = SDOUtil.createProperty(root, i->getName(), *i);
+ SDOUtil.setContainment(propert, true);
+ SDOUtil.setMany(propert, true);
+
+ }
+
+ rootType = root;
+
+}
Added: incubator/tuscany/cpp/das/runtime/core/src/GraphBuilderMetadata.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/GraphBuilderMetadata.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/GraphBuilderMetadata.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/GraphBuilderMetadata.h Fri Jan 12 15:33:46 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.
+ */
+#ifndef GRAPH_BUILDER_METADATA_H
+#define GRAPH_BUILDER_METADATA_H
+
+class GraphBuilderMetadata {
+
+ private:
+ MappingWrapper* configWrapper;
+ list<ResultSet*> resultSets;
+ string typeURI;
+ Type* rootType;
+ TypeHelper* typeHelper;
+
+ void createDynamicTypes(void);
+ string getDefaultURI();
+ void createDynamicRoot(void);
+
+ protected:
+ void initializeVariables(void);
+
+ public:
+ GraphBuilderMetadata(list<ResultSet*>* results, Config* model, ResultSetShape* shape);// throws SQLException {
+ ~GraphBuilderMetadata(void);
+ list<ResultSet*>* getResultMetadata(void);
+ list<Relationship*>* getRelationships(void);
+ Type* getRootType(void);
+ MappingWrapper* getConfigWrapper(void);
+ list<Type*>* getDefinedTypes(void);
+
+};
+
+
+
+
+#endif //GRAPH_BUILDER_METADATA_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/InsertCommandImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/InsertCommandImpl.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/InsertCommandImpl.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/InsertCommandImpl.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,57 @@
+/*
+ * 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 "InsertCommandImpl.h"
+
+InsertCommandImpl::InsertCommandImpl(string sqlString, string* generatedKeys) {
+ super(sqlString);
+ keys = generatedKeys;
+
+}
+
+InsertCommandImpl::InsertCommandImpl(Create* create) {
+ super(create.getSql());
+ addParameters(create.getParameters());
+ keys = char[0]*;
+
+}
+
+InsertCommandImpl::~InsertCommandImpl(void) {
+}
+
+void InsertCommandImpl::execute(void) {
+ int success = 0;
+
+ //try {
+ statement->executeUpdate(parameters, keys);
+ success = 1;
+ //} catch (SQLException e) {
+ // throw new RuntimeException(e);
+ //} finally {
+ if (success) {
+ statement->getConnection()->cleanUp();
+ } else {
+ statement->getConnection()->errorCleanUp();
+ }
+ //}
+
+}
+
+int InsertCommandImpl::getGeneratedKey(void) {
+ return statement.getGeneratedKey();
+}
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/InsertCommandImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/InsertCommandImpl.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/InsertCommandImpl.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/InsertCommandImpl.h Fri Jan 12 15:33:46 2007
@@ -0,0 +1,40 @@
+/*
+ * 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 INSERT_COMMAND_IMPL_H
+#define INSERT_COMMAND_IMPL_H
+
+#include "WriteCommandImpl.h"
+#include "Create.h"
+
+class InsertCommandImpl : public WriteCommandImpl {
+
+ private:
+ string* keys;
+ int keysCount;
+
+ public:
+ InsertCommandImpl(string sqlString, string* generatedKeys, int keysCount);
+ InsertCommandImpl(Create* create);
+ ~InsertCommandImpl(void);
+ void execute(void);
+ int getGeneratedKey(void);
+
+};
+
+#endif //INSERT_COMMAND_IMPL_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/InsertGenerator.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/InsertGenerator.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/InsertGenerator.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/InsertGenerator.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include "InsertGenerator.h"
+
+InsertGenerator::InsertGenerator(void) {}
+
+InsertGenerator::~InsertGenerator(void) {
+}
+
+InsertCommandImpl& InsertGenerator::getInsertCommand(MappingWrapper& config, DataObject& changedObject, Table& t) const {
+ list<Property*> parameters;
+ TableWrapper table(t);
+ string statement = "insert into ";
+ statement += t.getTableName();
+
+ map<Property*> changedProperties = getAttributeProperties(changedObject, config, table);
+ list<Property*>& propertyList;
+ list<Property*>::iterator i;
+
+ if ( changedProperties.size() == 0 ) {
+ propertyList = changedObject.getType().getProperties();
+ } else {
+ propertyList = changedProperties;
+ }
+
+
+ list<string> attributes;
+ list<string> generatedKeys;
+
+ for (i = propertyList.begin() ; i != propertyList.end() ; i++) {
+
+ if ( i->getType().isDataType()) {
+
+ if (table.isGeneratedColumnProperty(i->getName())) {
+ generatedKeys.insert(i->getName());
+
+ } else {
+ attributes.insert(i->getName());
+ parameters.insert(changedObject.getType().getProperty(i->getName()));
+
+ }
+
+ }
+
+ }
+
+ statement += "(";
+ list<string>::iterator j;
+
+ for (j = attributes.begin() ; j != attributes.end() ;) {
+ statement += ("");
+ Column& c = config.getColumnByPropertyName(t, j);
+ statement += ((c == NULL) ? name : c.getColumnName());
+
+ j++;
+
+ if (j != attributes.end()) {
+ statement += ", ";
+ } else {
+ statement += ")";
+ }
+
+ }
+
+ statement += " values (";
+ int idx;
+ for (idx = 1; idx <= attributes.size(); idx++) {
+ statement += '?';
+
+ if (idx < attributes.size()) {
+ statement += ", ";
+ } else {
+ statement += ")";
+ }
+
+ }
+
+ char[generatedKeys.size()]* generatedKeysArray;
+ int c = 0;
+ for (c = 0, j = generatedKeys.begin() ; j != generatedKeys.end() ; j++, c++) {
+ generatedKeysArrays[c] = *j;
+ }
+
+ InsertCommandImpl* cmd = new InsertCommandImpl(statement.c_chr(), generatedKeysArray);
+ list<Property*>::iterator k = parameters.begin();
+
+ for (int idx = 1; parameters.end() != k; idx++, k++) {
+ ParameterImpl* p = new ParameterImpl();
+ p->setName(k->getName());
+ p->setType(k->getType());
+ p->setConverter(getConverter(table.getConverter(k->getName())));
+ p->setIndex(idx);
+ cmd.addParameter(p);
+
+ }
+
+ /*if (this.logger.isDebugEnabled()) {
+ this.logger.debug(statement.toString());
+ }*/
+
+ return cmd;
+
+}
+
+map<Property*>& InsertGenerator::getAttributeProperties(DataObject obj, MappingWrapper config, TableWrapper tw) {
+ map<Property&, Property*> fields;
+ list<Property*>& propertyList = obj.getType().getProperties();
+ list<Property*>::iterator i;
+
+ for (i = propertyList.begin() ; i != propertyList.end() ; i++) {
+
+ if (i->getType().isDataType()) {
+
+ if (obj.isSet(*i)) {
+
+ fields.insert(*i);
+ map<Property&, Property*>::iterator findProperty = fields.find(*i);
+
+ if (findProperty != fields.end()) {
+ //throw new RuntimeException("Foreign key properties should not be set when the corrsponding relationship has changed");
+ }
+
+ }
+
+ } else {
+
+ if (obj.isSet(p)) {
+ Relationship& relationship = config.getRelationshipByReference(*i);
+
+ if ((i->getOpposite() != NULL && i->getOpposite().isMany())
+ || (hasState(tw, relationship, obj))) {
+
+ RelationshipWrapper r(relationship);
+ list<string>& fkList = r.getForeignKeys();
+ list<string>::iterator j;
+
+ for (j = fkList.begin() ; j != fkList.end() ; j++) {
+ string keyProperty = config.getColumnPropertyName(tw.getTableName(), *j);
+ Property& keyProp = obj.getType().getProperty(keyProperty);
+
+ if ( keyProp == NULL )
+ //throw new RuntimeException("Invalid foreign key column: " + key);
+ else {
+
+ fields.insert(keyProp);
+ map<Property&, Property*>::iterator findProperty = fields.find(keyProp);
+
+ if (findProperty != fields.end()) {
+ //throw new RuntimeException("Foreign key properties should not be set when the corresponding relationship has changed");
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+ }
+ }
+
+ return fields;
+
+}
+
+bool InsertGenerator::hasState(TableWrapper& tw, Relationship& rel, DataObject& changedObject) {
+ if (!rel.isMany()) {
+
+ RelationshipWrapper rw(rel);
+
+ if ((strcmp(rel.getForeignKeyTable(), tw.getTableName()) == 0)
+ && (Collections.disjoint(tw.getPrimaryKeyProperties(), rw.getForeignKeys()))) {
+
+ return true;
+
+ }
+
+ }
+
+ return false;
+
+}
Added: incubator/tuscany/cpp/das/runtime/core/src/InsertGenerator.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/InsertGenerator.h?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/InsertGenerator.h (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/InsertGenerator.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 INSERT_GENERATOR_H
+#define INSERT_GENERATOR_H
+
+#include <map>
+
+#include "TableWrapper.h"
+#include "MappingWrapper.h"
+#include "Relationship.h"
+
+#include "commonj/sdo/Property.h"
+#include "commonj/sdo/DataObject.h"
+
+using namespace commonj::sdo;
+using namespace std;
+
+class InsertGenerator : public BaseGenerator {
+
+ private:
+ InsertGenerator(void);
+ map<Property*, Property*>* getAttributeProperties(DataObject* obj, MappingWrapper* config, TableWrapper* tw);
+ bool hasState(TableWrapper* tw, Relationship* rel, DataObject* changedObject);
+
+ public:
+ static InsertGenerator INSTANCE;
+
+ ~InsertGenerator(void);
+ InsertCommandImpl* getInsertCommand(MappingWrapper* config, DataObject* changedObject, Table* t);
+
+};
+
+
+#endif //INSERT_GENERATOR_H
\ No newline at end of file
Added: incubator/tuscany/cpp/das/runtime/core/src/InsertList.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/das/runtime/core/src/InsertList.cpp?view=auto&rev=495788
==============================================================================
--- incubator/tuscany/cpp/das/runtime/core/src/InsertList.cpp (added)
+++ incubator/tuscany/cpp/das/runtime/core/src/InsertList.cpp Fri Jan 12 15:33:46 2007
@@ -0,0 +1,88 @@
+/*
+ * 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 "InsertList.h"
+
+InsertList::InsertList(void) {
+ super();
+}
+
+InsertList::~InsertList(void) {
+}
+
+void InsertList::add(ChangeOperation* op) {
+
+ /*if (this.logger.isDebugEnabled()) {
+ this.logger.debug("Adding insert operation ");
+ }*/
+
+ if ((order->size() == 0) || (op->getTableName() == NULL)) {
+ insertOperations.insert(op);
+
+ } else {
+ string name = op->getTableName();
+ list<ChangeOperation*>* ops = *(opsByTableName.find(name));
+
+ if (ops == opsByTableName.end()) {
+ ops = list<ChangeOperation*>;
+ }
+
+ ops->add(op);
+ opsByTableName.insert(make_pair(name, ops));
+
+ }
+
+}
+
+list<ChangeOperation*>* InsertList::getSortedList(void) {
+
+ /*if (this.logger.isDebugEnabled()) {
+ this.logger.debug("Getting sorted insert list");
+ }*/
+
+ if ((order->size() > 0) && (opsByTableName/*.keySet()*/.size() > 0)) {
+ list<string>::iterator i;
+
+ for (i = order->begin() ; i != order->end() ; i++) {
+ map<string, ChangeOperation*>::iterator keyPair = opsByTableName.find(*i);
+
+ if (listChangeOperationIterator != opsByTableName.end()) {
+ list<ChangeOperation*> list = keyPair->second;
+ list<ChangeOperation*>::iterator j;
+
+ for (j = list->begin() ; j != list->end() ; j++) {
+ insertOperations.insert(*j);
+ }
+
+ }
+
+ }
+
+ }
+
+ /*if (this.logger.isDebugEnabled()) {
+ this.logger.debug("Returning " + insertOperations.size() + " insert operations");
+ }*/
+
+ return insertOperations;
+
+}
+
+void DeleteList::setOrder(list<string>* insertOrder) {
+ order = insertOrder;
+}
\ 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