summaryrefslogtreecommitdiffstats
path: root/das-cpp/trunk/runtime/test/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'das-cpp/trunk/runtime/test/src/main.cpp')
-rw-r--r--das-cpp/trunk/runtime/test/src/main.cpp843
1 files changed, 843 insertions, 0 deletions
diff --git a/das-cpp/trunk/runtime/test/src/main.cpp b/das-cpp/trunk/runtime/test/src/main.cpp
new file mode 100644
index 0000000000..b8f6239680
--- /dev/null
+++ b/das-cpp/trunk/runtime/test/src/main.cpp
@@ -0,0 +1,843 @@
+/*
+ * 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 <iostream>
+#include <apache/das/rdb/Connection.h>
+#include <apache/das/DAS.h>
+#include <apache/das/rdb/DASImpl.h>
+#include <apache/das/CommandPtr.h>
+#include <apache/das/rdb/ResultSet.h>
+#include <apache/das/rdb/Statement.h>
+#include <apache/das/DASNullPointerException.h>
+#include <apache/das/rdb/DASOptimisticConcurrencyControlException.h>
+#include <apache/das/rdb/das_constants.h>
+#include <apache/das/rdb/Column.h>
+#include <apache/das/rdb/Table.h>
+#include <apache/das/DataGraphPrinter.h>
+#include <commonj/sdo/DataObject.h>
+#include <commonj/sdo/SDORuntimeException.h>
+#include <commonj/sdo/DataFactory.h>
+
+#define TEST_RESOURCE_PATH "../rsc/"
+
+using namespace std;
+using namespace apache::das;
+using namespace apache::das::rdb;
+
+std::string clearDBStatements[] = { "delete from EMPLOYEE",
+ "delete from DEPARTMENT",
+ "delete from COMPANY",
+ "drop table EMPLOYEE",
+ "drop table DEPARTMENT",
+ "drop table COMPANY"
+ };
+
+std::string resetDBStatements[] = { "create table COMPANY ( ID int not null, NAME varchar(20), OCC int, primary key(ID) )",
+ "create table DEPARTMENT ( ID int not null, NAME varchar(20) not null, COMPANY_ID int, foreign key (COMPANY_ID) references company (ID), primary key(ID, NAME) )",
+ "create table EMPLOYEE ( ID int not null, NAME varchar(20), DEPARTMENT_ID int, DEPARTMENT_NAME varchar(20), primary key(ID) )",
+ "insert into COMPANY values (1, 'apache', 0)",
+ "insert into COMPANY values (2, 'acme', 0)",
+ "insert into COMPANY values (3, 'google', 0)",
+ "insert into COMPANY values (4, 'ibm', 0)",
+ "insert into COMPANY values (5, 'yahoo', 0)",
+ "insert into DEPARTMENT values (1, 'department1', 1)",
+ "insert into DEPARTMENT values (2, 'department1', 1)",
+ "insert into DEPARTMENT values (3, 'department2', 2)",
+ "insert into DEPARTMENT values (5, 'department3', 3)",
+ "insert into DEPARTMENT values (4, 'department5', 2)",
+ "insert into DEPARTMENT values (6, 'department6', 3)",
+ "insert into EMPLOYEE values (1, 'adriano', 1, 'department1')",
+ "insert into EMPLOYEE values (2, 'paul', 1, 'department1')",
+ "insert into EMPLOYEE values (3, 'richard', 1, 'department1')",
+ "insert into EMPLOYEE values (4, 'ema', 2, 'department2')",
+ "insert into EMPLOYEE values (5, 'james', 2, 'department2')"
+ };
+
+Connection* getConnection() {
+ Connection* conn;
+
+ try {
+ std::string dsn = "DAStestcases";
+ std::string user = "postgres";
+ std::string password = "tuscany";
+
+ conn = new Connection(dsn, user, password);
+
+ } catch (SQLException& ex) {
+ cout << "couldn't connect to the data source: " << ex.what() << endl;
+ system("PAUSE");
+ exit(1);
+
+ }
+
+ StatementPtr stmt = conn->createStatement();
+
+ for (unsigned int i = 0 ; i < 6 ; i++) {
+
+ try {
+ stmt->executeQuery(clearDBStatements[i]);
+ } catch (SQLException& ex) {cout << ex.what() << endl;}
+
+ }
+
+ for (unsigned int i = 0 ; i < 19 ; i++) {
+
+ try {
+ stmt->executeQuery(resetDBStatements[i]);
+ } catch (SQLException& ex) {cout << ex.what() << endl;}
+
+ }
+
+ stmt->executeQuery("commit");
+
+ return conn;
+
+}
+
+
+void testPointers() {
+ cout << "-------------testPointers--------------" << endl;
+ Connection* conn = getConnection();
+ DASImpl* das = (DASImpl*) DASImpl::getFACTORY().createDAS(*conn);
+ Command* comm = new ReadCommandImpl(*das, "select * from COMPANY");
+ CommandPtr comm1 = *comm;
+ CommandPtr comm2 = comm1;
+ CommandPtr comm3 = das->createCommand("select * from COMPANY;");
+ StatementPtr stmtPtr1 = conn->createStatement();
+ Statement* stmt = stmtPtr1;
+ StatementPtr stmtPtr2 = stmtPtr1;
+ StatementPtr stmtPtr3 = conn->createStatement();
+ StatementPtr* stmtPtr4 = new StatementPtr(stmt);
+
+ cout << "Command pointer working correctly = ";
+ try {
+ comm1->executeQuery();
+ cout << "OK" << endl;
+ } catch (DASNullPointerException& exp) {
+ cout << "DASNullPointerException" << endl;
+ }
+
+ comm1 = 0;
+ comm2 = 0;
+ cout << "Command object deleted when there is no more reference = ";
+ try {
+ comm1->executeQuery();
+ cout << "not deleted" << endl;
+ } catch (DASNullPointerException& exp) {
+ cout << "OK" << endl;
+ }
+
+ delete das;
+ cout << "Command pointer set as null when object is deleted = ";
+ if (comm3 != 0) {
+ cout << "not null" << endl;
+ } else {
+ cout << "OK" << endl;
+ }
+
+ ResultSetPtr resultSetPtr = stmtPtr1->executeQuery("select * from COMPANY;");
+
+ cout << "ResultSet pointer working correctly = ";
+ try {
+ resultSetPtr->getStatement();
+ cout << "OK" << endl;
+ } catch (DASNullPointerException& exp) {
+ cout << "DASNullPointerException" << endl;
+ }
+
+ stmtPtr1->executeQuery("select * from EMPLOYEE;");
+ cout << "ResultSet object deleted when there is another query on its statement = ";
+ try {
+ resultSetPtr->getStatement();
+ cout << "not deleted" << endl;
+ } catch (DASNullPointerException& exp) {
+ cout << "OK" << endl;
+ }
+
+ cout << "Statement pointer working correctly = ";
+ try {
+ stmtPtr1->getODBCStatement();
+ cout << "OK" << endl;
+ } catch (DASNullPointerException& exp) {
+ cout << "DASNullPointerException" << endl;
+ }
+
+ stmtPtr1 = 0;
+ stmtPtr2 = 0;
+ delete stmtPtr4;
+ cout << "Statement object deleted when there is no more reference = ";
+ try {
+ stmtPtr1->getODBCStatement();
+ cout << "not deleted" << endl;
+ } catch (DASNullPointerException& exp) {
+ cout << "OK" << endl;
+ }
+
+ stmtPtr1 = conn->createStatement();
+ resultSetPtr = stmtPtr1 ->executeQuery("select * from COMPANY;");
+ ResultSetPtr resultSetPtr2 = resultSetPtr;
+ delete conn;
+ stmtPtr1 = 0;
+ resultSetPtr = 0;
+ resultSetPtr2 = 0;
+
+ cout << "Statement pointer set as null when object is deleted = ";
+ if (stmtPtr3 != 0) {
+ cout << "not null" << endl;
+ } else {
+ cout << "OK" << endl;
+ }
+
+ cout << "---------------------------------" << endl << endl;
+
+}
+
+void testIncompleteCompositeRelationship() {
+ cout << "-------------testIncompleteCompositeRelationship--------------" << endl;
+
+ Connection* conn = getConnection();
+
+ {
+ ConfigImpl config((std::string) TEST_RESOURCE_PATH + "testIncompleteCompositeRelationship1.xml");
+
+ DASImpl* das = (DASImpl*) DASImpl::getFACTORY().createDAS(config, *conn);
+
+ CommandPtr command = das->getCommand("get incomplete relationship");
+
+ commonj::sdo::DataObjectPtr root = command->executeQuery();
+
+ cout << "relationship ignored when the ResultSet does not contain all KeyPairs = ";
+ try {
+ root->getDataFactory()->getType(config.getURI(), "DEPARTMENT").getProperty("EMPLOYEE");
+ cout << "not ignored" << endl;
+
+ } catch (commonj::sdo::SDOPropertyNotFoundException& ex) {
+ cout << "OK" << endl;
+ }
+
+ delete das;
+
+ }
+
+ {
+ ConfigImpl config((std::string) TEST_RESOURCE_PATH + "testIncompleteCompositeRelationship2.xml");
+
+ DASImpl* das = (DASImpl*) DASImpl::getFACTORY().createDAS(config, *conn);
+
+ CommandPtr command = das->getCommand("get incomplete relationship");
+
+ commonj::sdo::DataObjectPtr root = command->executeQuery();
+
+ cout << "relationship ignored when a defined relationship pk is not a table pk = ";
+ try {
+ root->getDataFactory()->getType(config.getURI(), "DEPARTMENT").getProperty("EMPLOYEE");
+ cout << "not ignored" << endl;
+
+ } catch (commonj::sdo::SDOPropertyNotFoundException& ex) {
+ cout << "OK" << endl;
+ }
+
+ delete das;
+
+ }
+
+ delete conn;
+
+ cout << "---------------------------------" << endl << endl;
+
+}
+
+void testCompositeRelationship() {
+ cout << "-------------testCompositeRelationship--------------" << endl;
+
+ Connection* conn = getConnection();
+ ConfigImpl config((std::string) TEST_RESOURCE_PATH + "testCompositeRelationship.xml");
+
+ DASImpl* das = (DASImpl*) DASImpl::getFACTORY().createDAS(config, *conn);
+
+ CommandPtr command = das->getCommand("get composite relationship");
+
+ commonj::sdo::DataObjectPtr root = command->executeQuery();
+
+ cout << "relationship created = ";
+ try {
+ root->getDataFactory()->getType(config.getURI(), "DEPARTMENT").getProperty("EMPLOYEE");
+ cout << "OK" << endl;
+
+ cout << "references set = ";
+ if (root->getDataObject("DEPARTMENT[1]")->getList("EMPLOYEE").size() != 0) {
+ cout << "OK" << endl;
+ } else {
+ cout << "not set" << endl;
+ }
+
+ } catch (commonj::sdo::SDOPropertyNotFoundException& ex) {
+ cout << "not created" << endl;
+
+ }
+
+ delete conn;
+ delete das;
+
+ cout << "---------------------------------" << endl << endl;
+
+}
+
+void testCOCRelationship() {
+ cout << "-------------testCOCRelationship--------------" << endl;
+
+ Connection* conn = getConnection();
+ DASImpl* das = (DASImpl*) DASImpl::getFACTORY().createDAS(*conn);
+
+ CommandPtr command = das->createCommand("SELECT * FROM DEPARTMENT, COMPANY;");
+
+ commonj::sdo::DataObjectPtr root = command->executeQuery();
+
+
+ cout << "relationship created = ";
+ try {
+ root->getDataFactory()->getType(das->getConfig().getURI(), "COMPANY").getProperty("DEPARTMENT");
+ cout << "OK" << endl;
+
+ } catch (commonj::sdo::SDOPropertyNotFoundException& ex) {
+ cout << "not created" << endl;
+ }
+
+ delete conn;
+ delete das;
+
+ cout << "---------------------------------" << endl << endl;
+
+}
+
+void testKeyPairColumnTypeNotEqual() {
+ cout << "-------------testKeyPairColumnTypeNotEqual--------------" << endl;
+
+ Connection* conn = getConnection();
+ ConfigImpl config((std::string) TEST_RESOURCE_PATH + "testKeyPairColumnTypeNotEqual.xml");
+ DASImpl* das = (DASImpl*) DASImpl::getFACTORY().createDAS(config, *conn);
+ CommandPtr command = das->getCommand("get all employees and departments");
+ commonj::sdo::DataObjectPtr root = command->executeQuery();
+
+ cout << "relationship ignored when keypair types are not equal = ";
+ try {
+ root->getDataFactory()->getType(config.getURI(), "DEPARTMENT").getProperty("EMPLOYEE");
+ cout << "not ignored" << endl;
+
+ } catch (commonj::sdo::SDOPropertyNotFoundException& ex) {
+ cout << "OK" << endl;
+ }
+
+ delete conn;
+ delete das;
+
+ cout << "---------------------------------" << endl << endl;
+
+}
+
+void testUniqueObjectByID() {
+ cout << "-------------testUniqueObjectByID--------------" << endl;
+
+ Connection* conn = getConnection();
+ DASImpl* das = (DASImpl*) DASImpl::getFACTORY().createDAS(*conn);
+ CommandPtr command = das->createCommand("SELECT * FROM COMPANY, DEPARTMENT where COMPANY.ID = 1;");
+ commonj::sdo::DataObjectPtr root = command->executeQuery();
+
+ cout << "table duplicated row ignored = ";
+ if (root->getList("COMPANY").size() == 1) {
+ cout << "OK" << endl;
+ } else {
+ cout << "not ignored" << endl;
+ }
+
+ delete conn;
+ delete das;
+
+ cout << "---------------------------------" << endl << endl;
+
+}
+
+void testDeleteOperation() {
+ cout << "-------------testDeleteOperation--------------" << endl;
+
+ Connection* conn = getConnection();
+
+ ConfigImpl config((std::string) TEST_RESOURCE_PATH + "testDeleteOperation.xml");
+ DASImpl* das = (DASImpl*) DASImpl::getFACTORY().createDAS(config, *conn);
+ CommandPtr command = das->getCommand("get all tables");
+ commonj::sdo::DataObjectPtr root = command->executeQuery();
+
+ root->getDataObject("COMPANY[1]")->getDataObject("DEPARTMENT[1]")->detach();
+ commonj::sdo::DataObjectPtr company = root->getDataObject("COMPANY[1]");
+ company->detach();
+ long removedCompanyID = company->getInt("ID");
+
+ cout << "COMPANY with id " << removedCompanyID << " deleted on database: ";
+
+ das->applyChanges(root);
+
+ root = command->executeQuery();
+
+ commonj::sdo::DataObjectList& companies = root->getList("COMPANY");
+ bool failed = true;
+ for (unsigned int i = 0 ; i < companies.size() ; i++) {
+ failed = false;
+
+ if (companies[i]->getInt("ID") == removedCompanyID) {
+ cout << "Failed" << endl;
+ failed = true;
+ break;
+
+ }
+
+ }
+
+ if (!failed) {
+ cout << "OK" << endl;
+ }
+
+ delete conn;
+ delete das;
+
+ cout << "---------------------------------" << endl << endl;
+
+}
+
+void testCreateOperation() {
+ cout << "-------------testCreateOperation--------------" << endl;
+
+ Connection* conn = getConnection();
+ ConfigImpl config((std::string) TEST_RESOURCE_PATH + "testCreateOperation.xml");
+ DASImpl* das = (DASImpl*) DASImpl::getFACTORY().createDAS(config, *conn);
+ CommandPtr command = das->getCommand("get all tables");
+ commonj::sdo::DataObjectPtr root = command->executeQuery();
+
+ commonj::sdo::DataObjectPtr company = root->createDataObject("COMPANY");
+ StringWrapper("hp").defineOnDataObject(company, "NAME");
+ company->setInt("ID", 40);
+
+ commonj::sdo::DataObjectPtr department = root->createDataObject("DEPARTMENT");
+ StringWrapper("DEPARTMENT40").defineOnDataObject(department, "NAME");
+ department->setInt("ID", 39);
+
+ company = root->getDataObject("COMPANY[1]");
+ long departmentCompanyID = company->getInt("ID");
+ company->getList("DEPARTMENT").append(department);
+
+ commonj::sdo::DataObjectPtr employee = root->createDataObject("EMPLOYEE");
+ StringWrapper("juan").defineOnDataObject(employee, "NAME");
+ employee->setInt("ID", 38);
+ department->getList("EMPLOYEE").append(employee);
+
+ das->applyChanges(root);
+
+ root = command->executeQuery();
+
+ commonj::sdo::DataObjectList& departments = root->getList("DEPARTMENT");
+ bool failed = true;
+ for (unsigned int i = 0 ; i < departments.size() ; i++) {
+
+ if (departments[i]->getInt("ID") == 39 && StringWrapper(departments[i], "NAME").getString() == "DEPARTMENT40"
+ && departments[i]->getDataObject("EMPLOYEE[1]")->getInt("ID") == 38
+ && StringWrapper(departments[i]->getDataObject("EMPLOYEE[1]"), "NAME").getString() == "juan") {
+
+ failed = false;
+ break;
+
+ }
+
+ }
+
+ if (!failed) {
+ failed = true;
+ commonj::sdo::DataObjectList& companies = root->getList("COMPANY");
+ for (unsigned int i = 0 ; i < companies.size() ; i++) {
+
+ if (companies[i]->getInt("ID") == departmentCompanyID) {
+ commonj::sdo::DataObjectList& companyDepartments = root->getList("DEPARTMENT");
+
+ for (unsigned int i = 0 ; i < companyDepartments.size() ; i++) {
+
+ if (companyDepartments[i]->getInt("ID") == 39) {
+ failed = false;
+ break;
+
+ }
+
+ }
+
+ break;
+
+ }
+
+ }
+
+ }
+
+ if (failed) {
+ cout << "Failed" << endl;
+ } else {
+ cout << "OK" << endl;
+ }
+
+ delete conn;
+ delete das;
+
+ cout << "---------------------------------" << endl << endl;
+
+}
+
+//
+
+void testMofidyOperation() {
+ cout << "-------------testMofidyOperation--------------" << endl;
+
+ Connection* conn = getConnection();
+ ConfigImpl config((std::string) TEST_RESOURCE_PATH + "testModifyOperation.xml");
+ DASImpl* das = (DASImpl*) DASImpl::getFACTORY().createDAS(config, *conn);
+ CommandPtr command = das->getCommand("get all tables");
+ commonj::sdo::DataObjectPtr root = command->executeQuery();
+
+ commonj::sdo::DataObjectPtr company1 = root->getDataObject("COMPANY[1]");
+ commonj::sdo::DataObjectPtr company2 = root->getDataObject("COMPANY[2]");
+
+ StringWrapper("intel").defineOnDataObject(company1, "NAME");
+
+ commonj::sdo::DataObjectPtr department = root->createDataObject("DEPARTMENT");
+ StringWrapper("department40").defineOnDataObject(department, "NAME");
+ department->setInt("ID", 39);
+ company1->getList("DEPARTMENT").append(department);
+
+ department = company1->getList("DEPARTMENT").remove(0);//company->getDataObject("DEPARTMENT[1]");
+ company2->getList("DEPARTMENT").append(department);
+
+ commonj::sdo::DataObjectPtr employee = root->createDataObject("EMPLOYEE");
+ StringWrapper("albert").defineOnDataObject(employee, "NAME");
+ employee->setInt("ID", 37);
+ department->getList("EMPLOYEE").append(employee);
+
+ das->applyChanges(root);
+
+ commonj::sdo::DataObjectPtr dob;
+ bool failed = false;
+ try {
+ dob = root->getDataObject("COMPANY[NAME='intel']");
+ } catch (commonj::sdo::SDOPathNotFoundException& ex) {
+ cout << ex.getMessageText() << endl;
+ failed = true;
+
+ }
+
+ try {
+ dob = root->getDataObject("COMPANY[NAME='intel']/DEPARTMENT[NAME='department40'and ID=39]");
+ } catch (commonj::sdo::SDOPathNotFoundException& ex) {
+ cout << ex.getMessageText() << endl;
+ failed = true;
+
+ }
+
+ try {
+ dob = root->getDataObject("COMPANY[ID=2]/DEPARTMENT[ID=1]");
+ } catch (commonj::sdo::SDOPathNotFoundException& ex) {
+ cout << ex.getMessageText() << endl;
+ failed = true;
+
+ }
+
+ try {
+ dob = root->getDataObject("COMPANY[ID=2]/DEPARTMENT[ID=1]/EMPLOYEE[ID=37 and NAME='albert']");
+ } catch (commonj::sdo::SDOPathNotFoundException& ex) {
+ cout << ex.getMessageText() << endl;
+ failed = true;
+
+ }
+
+ if (failed) {
+ cout << "Failed" << endl;
+ } else {
+ cout << "OK" << endl;
+ }
+
+ delete conn;
+ delete das;
+
+ cout << "---------------------------------" << endl << endl;
+
+}
+
+void testOCC() {
+ cout << "-------------testOCC--------------" << endl;
+
+ Connection* conn = getConnection();
+ {
+ ConfigImpl config((std::string) TEST_RESOURCE_PATH + "testOCC1.xml");
+ DASImpl* das = (DASImpl*) DASImpl::getFACTORY().createDAS(config, *conn);
+ CommandPtr command = das->getCommand("get all companies");
+ commonj::sdo::DataObjectPtr root1 = command->executeQuery();
+ commonj::sdo::DataObjectPtr root2 = command->executeQuery();
+
+ commonj::sdo::DataObjectPtr company = root1->getDataObject("COMPANY[ID=1]");
+ StringWrapper("microsoft").defineOnDataObject(company, "NAME");
+ long oldOCCValue = company->getInt("OCC");
+
+ das->applyChanges(root1);
+
+ root1 = command->executeQuery();
+
+ cout << "OCC field incremented after changes applied: ";
+ if (root1->getDataObject("COMPANY[ID=1]")->getInt("OCC") > oldOCCValue) {
+ cout << "OK";
+ } else {
+ cout << "Failed";
+ }
+
+ cout << endl;
+
+ company = root2->getDataObject("COMPANY[ID=1]");
+ StringWrapper("dell").defineOnDataObject(company, "NAME");
+
+ cout << "DASOptimisticConcurrencyControlException thrown in attempt to modify a row with different occ field value: ";
+ try {
+ das->applyChanges(root2);
+ cout << "Failed";
+
+ } catch (DASOptimisticConcurrencyControlException&) {
+ cout << "OK";
+ }
+
+ cout << endl;
+ delete das;
+
+
+ }
+
+ {
+ ConfigImpl config((std::string) TEST_RESOURCE_PATH + "testOCC2.xml");
+ DASImpl* das = (DASImpl*) DASImpl::getFACTORY().createDAS(config, *conn);
+ CommandPtr command = das->getCommand("get all companies");
+ commonj::sdo::DataObjectPtr root = command->executeQuery();
+
+ commonj::sdo::DataObjectPtr company = root->getDataObject("COMPANY[ID=1]");
+ StringWrapper("dell").defineOnDataObject(company, "NAME");
+ long oldOCCValue = company->getInt("OCC");
+
+ das->applyChanges(root);
+
+ root = command->executeQuery();
+
+ cout << "OCC field not incremented when it's not managed by DAS: ";
+ if (root->getDataObject("COMPANY[ID=1]")->getInt("OCC") == oldOCCValue) {
+ cout << "OK";
+ } else {
+ cout << "Failed";
+ }
+
+ cout << endl;
+ delete das;
+
+ }
+
+ delete conn;
+
+ cout << "---------------------------------" << endl << endl;
+
+}
+
+void testManyRelationship() {
+ cout << "-------------testManyRelationship--------------" << endl;
+
+ Connection* conn = getConnection();
+ {
+ ConfigImpl config((std::string) TEST_RESOURCE_PATH + "testManyRelationship1.xml");
+ DASImpl* das = (DASImpl*) DASImpl::getFACTORY().createDAS(config, *conn);
+ CommandPtr command = das->getCommand("get company 1 and its departments");
+ commonj::sdo::DataObjectPtr root = command->executeQuery();
+
+ cout << "reference created as many on data graph = ";
+ if (root->getDataFactory()->getType(config.getURI(), "COMPANY").getProperty("DEPARTMENT").isMany()) {
+ cout << "OK" << endl;
+
+ cout << "all data objects added on reference list = ";
+ if (root->getDataObject("COMPANY[1]")->getList("DEPARTMENT").size() > 1) {
+ cout << "OK" << endl;
+ } else {
+ cout << "not added all data objects" << endl;
+ }
+
+ } else {
+ cout << "not created as many" << endl;
+ }
+
+ delete das;
+
+ }
+
+ {
+ ConfigImpl config((std::string) TEST_RESOURCE_PATH + "testManyRelationship2.xml");
+ DASImpl* das = (DASImpl*) DASImpl::getFACTORY().createDAS(config, *conn);
+ CommandPtr command = das->getCommand("get company 1 and its departments");
+ commonj::sdo::DataObjectPtr root = command->executeQuery();
+
+ cout << "reference created as not many on data graph = ";
+ if (!root->getDataFactory()->getType(config.getURI(), "COMPANY").getProperty("DEPARTMENT").isMany()) {
+ cout << "OK" << endl;
+
+ cout << "only one data object added on reference = ";
+ if (root->getDataObject("COMPANY[1]")->isNull("DEPARTMENT")) {
+ cout << "reference data object not set" << endl;
+ } else {
+ cout << "OK" << endl;
+ }
+
+ } else {
+ cout << "not created as many" << endl;
+ }
+
+ delete das;
+
+ }
+
+ delete conn;
+
+ cout << "---------------------------------" << endl << endl;
+
+}
+
+void testDataTypes() {
+ Connection* conn;
+
+ try {
+ std::string dsn = "PostgresTestcases2";
+ std::string user = "postgres";
+ std::string password = "tuscany";
+
+ conn = new Connection(dsn, user, password);
+
+ } catch (SQLException& ex) {
+ cout << "couldn't connect to the data source: " << ex.what() << endl;
+ system("PAUSE");
+ exit(1);
+
+ }
+
+ StatementPtr stmt = conn->createStatement();
+ ResultSetPtr rs = stmt->executeQuery("select * from DATA;");
+ const ResultSetMetaData& rsm = rs->getResultSetMetaData();
+ rs->next();
+ for (int i = 0 ; i < rsm.getColumnCount() ; i++) {
+ SQLSMALLINT type = rsm.getSQLType(i);
+ cout << rsm.getColumnName(i) << ": ";
+
+ switch (type) {
+ case SQL_INTEGER : cout << "SQL_INTEGER" << endl; break;
+ case SQL_DECIMAL : cout << "SQL_DECIMAL" << endl; break;
+ case SQL_CHAR : cout << "SQL_CHAR" << endl; break;
+ case SQL_NUMERIC : cout << "SQL_NUMERIC" << endl; break;
+ case SQL_SMALLINT : cout << "SQL_SMALLINT" << endl; break;
+ case SQL_FLOAT : cout << "SQL_FLOAT" << endl; break;
+ case SQL_REAL : cout << "SQL_REAL" << endl; break;
+ case SQL_DOUBLE : cout << "SQL_DOUBLE" << endl; break;
+ case SQL_DATETIME : cout << "SQL_DATETIME" << endl; break;
+ case SQL_VARCHAR : cout << "SQL_VARCHAR" << endl; break;
+ case SQL_TYPE_DATE : cout << "SQL_TYPE_DATE" << endl; break;
+ case SQL_TYPE_TIME : cout << "SQL_TYPE_TIME" << endl; break;
+ case SQL_TYPE_TIMESTAMP : cout << "SQL_TYPE_TIMESTAMP" << endl; break;
+ case SQL_UNKNOWN_TYPE : cout << "SQL_UNKNOWN_TYPE" << endl; break;
+ default : cout << "more than unknown = " << type << endl;
+
+ }
+
+ Table table("DATA");
+ const apache::das::rdb::Column& column = table.addColumn(rsm.getColumnName(i), type);
+
+ cout << "SQL value = " << ColumnData(column, rs).toSQL() << endl;
+
+ }
+
+ delete conn;
+
+}
+
+int main() {
+
+ //testDataTypes();
+
+ //try {
+ testMofidyOperation();
+ /*} catch (...) {
+ cout << "FAILED (unexpected unknown exception)" << endl;
+ }*/
+
+ try {
+ testDeleteOperation();
+ } catch (...) {
+ cout << "FAILED (unexpected unknown exception)" << endl;
+ }
+
+ try {
+ testCreateOperation();
+ } catch (...) {
+ cout << "FAILED (unexpected unknown exception)" << endl;
+ }
+
+ try {
+ testPointers();
+ } catch (...) {
+ cout << "FAILED (unexpected unknown exception)" << endl;
+ }
+
+ try {
+ testUniqueObjectByID();
+ } catch (...) {
+ cout << "FAILED (unexpected unknown exception)" << endl;
+ }
+
+ try {
+ testIncompleteCompositeRelationship();
+ } catch (...) {
+ cout << "FAILED (unexpected unknown exception)" << endl;
+ }
+
+ try {
+ testCompositeRelationship();
+ } catch (...) {
+ cout << "FAILED (unexpected unknown exception)" << endl;
+ }
+
+ try {
+ testCOCRelationship();
+ } catch (...) {
+ cout << "FAILED (unexpected unknown exception)" << endl;
+ }
+
+ try {
+ testManyRelationship();
+ } catch (...) {
+ cout << "FAILED (unexpected unknown exception)" << endl;
+ }
+
+ try {
+ testOCC();
+ } catch (...) {
+ cout << "FAILED (unexpected unknown exception)" << endl;
+ }
+
+ system("PAUSE");
+
+}