From c5846d0e19e3b5fd9d818d714fea2df3f3ef90eb Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 16 Nov 2009 06:46:29 +0000 Subject: Cleaning up SVN structure, moving das trunk to das-cpp/trunk. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@880626 13f79535-47bb-0310-9956-ffa450edef68 --- das-cpp/trunk/samples/CompanySample/Readme.html | 148 +++++++++++++++++ .../CompanySample/VSExpress/CompanySample.sln | 19 +++ .../CompanySample/VSExpress/CompanySample.suo | Bin 0 -> 61952 bytes .../VSExpress/CompanySample/CompanySample.vcproj | 180 +++++++++++++++++++++ das-cpp/trunk/samples/CompanySample/build.xml | 134 +++++++++++++++ .../samples/CompanySample/rsc/sampleConfig.xml | 35 ++++ das-cpp/trunk/samples/CompanySample/src/main.cpp | 175 ++++++++++++++++++++ das-cpp/trunk/samples/build.xml | 68 ++++++++ 8 files changed, 759 insertions(+) create mode 100644 das-cpp/trunk/samples/CompanySample/Readme.html create mode 100644 das-cpp/trunk/samples/CompanySample/VSExpress/CompanySample.sln create mode 100644 das-cpp/trunk/samples/CompanySample/VSExpress/CompanySample.suo create mode 100644 das-cpp/trunk/samples/CompanySample/VSExpress/CompanySample/CompanySample.vcproj create mode 100644 das-cpp/trunk/samples/CompanySample/build.xml create mode 100644 das-cpp/trunk/samples/CompanySample/rsc/sampleConfig.xml create mode 100644 das-cpp/trunk/samples/CompanySample/src/main.cpp create mode 100644 das-cpp/trunk/samples/build.xml (limited to 'das-cpp/trunk/samples') diff --git a/das-cpp/trunk/samples/CompanySample/Readme.html b/das-cpp/trunk/samples/CompanySample/Readme.html new file mode 100644 index 0000000000..335b6b1543 --- /dev/null +++ b/das-cpp/trunk/samples/CompanySample/Readme.html @@ -0,0 +1,148 @@ + + + + + Tuscany RDB DAS Sample + + + + + + + + + + + + + + + + + + +

Tuscany RDB DAS Sample (CompanySample) 

+

This sample shows how to load data from a RDB + source, using RDB DAS, into a SDO graph, then retrieve data + from it, modify the graph and update the data source based on the modified graph.

+

Setup

+ +

Compiling the Sample

+

Compile the sample source using Visual Studio Express +solution under <tuscany_das_cpp>/samples/CompanySample/VSExpress/.

+

Running the Sample

+

To run the sample execute the file +<tuscany_das_cpp>/samples/CompanySample/VSExpress/debug/CompanySample.exe

+

Requirements:

+ +

Sample Architecture

+

The sample files are located under +<tuscany_das_cpp>/samples/CompanySample/.

+

Contents:

+ + + + + \ No newline at end of file diff --git a/das-cpp/trunk/samples/CompanySample/VSExpress/CompanySample.sln b/das-cpp/trunk/samples/CompanySample/VSExpress/CompanySample.sln new file mode 100644 index 0000000000..7cf5a5a2f4 --- /dev/null +++ b/das-cpp/trunk/samples/CompanySample/VSExpress/CompanySample.sln @@ -0,0 +1,19 @@ +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual C++ Express 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CompanySample", "CompanySample\CompanySample.vcproj", "{AAA4B06B-A3FA-485D-A450-4965B6EF2F58}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AAA4B06B-A3FA-485D-A450-4965B6EF2F58}.Debug|Win32.ActiveCfg = Debug|Win32 + {AAA4B06B-A3FA-485D-A450-4965B6EF2F58}.Debug|Win32.Build.0 = Debug|Win32 + {AAA4B06B-A3FA-485D-A450-4965B6EF2F58}.Release|Win32.ActiveCfg = Release|Win32 + {AAA4B06B-A3FA-485D-A450-4965B6EF2F58}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/das-cpp/trunk/samples/CompanySample/VSExpress/CompanySample.suo b/das-cpp/trunk/samples/CompanySample/VSExpress/CompanySample.suo new file mode 100644 index 0000000000..f2bb5e33c5 Binary files /dev/null and b/das-cpp/trunk/samples/CompanySample/VSExpress/CompanySample.suo differ diff --git a/das-cpp/trunk/samples/CompanySample/VSExpress/CompanySample/CompanySample.vcproj b/das-cpp/trunk/samples/CompanySample/VSExpress/CompanySample/CompanySample.vcproj new file mode 100644 index 0000000000..6675c344f6 --- /dev/null +++ b/das-cpp/trunk/samples/CompanySample/VSExpress/CompanySample/CompanySample.vcproj @@ -0,0 +1,180 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/das-cpp/trunk/samples/CompanySample/build.xml b/das-cpp/trunk/samples/CompanySample/build.xml new file mode 100644 index 0000000000..83a7e86dcb --- /dev/null +++ b/das-cpp/trunk/samples/CompanySample/build.xml @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/das-cpp/trunk/samples/CompanySample/rsc/sampleConfig.xml b/das-cpp/trunk/samples/CompanySample/rsc/sampleConfig.xml new file mode 100644 index 0000000000..e87be4781d --- /dev/null +++ b/das-cpp/trunk/samples/CompanySample/rsc/sampleConfig.xml @@ -0,0 +1,35 @@ + + + + + + + + + + +
+ + + + + + +
\ No newline at end of file diff --git a/das-cpp/trunk/samples/CompanySample/src/main.cpp b/das-cpp/trunk/samples/CompanySample/src/main.cpp new file mode 100644 index 0000000000..b0e567486e --- /dev/null +++ b/das-cpp/trunk/samples/CompanySample/src/main.cpp @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include +#include +#include + +// including DAS headers +#include +#include +#include +#include + +// including SDO header +#include + +using namespace apache::das::rdb; +using namespace apache::das; +using namespace commonj::sdo; +using namespace std; + +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), 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')", + "insert into company values (2, 'acme')", + "insert into company values (3, 'google')", + "insert into company values (4, 'ibm')", + "insert into company values (5, 'yahoo')", + "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 { + //Connect to a database using a DSN + std::string dsn = "DASCompanySample"; + 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); + + } + + // Create and populate the database tables + + 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;} + + } + + // Commit the changes + stmt->executeQuery("commit"); + + return conn; + +} + +void main() { + ConfigImpl config("../rsc/sampleConfig.xml"); + + // Get a connection + Connection* connection = getConnection(); + + // Create a DAS instance providing a connection using a factory + DASImpl* das = (DASImpl*) DASImpl::getFACTORY().createDAS(config, *connection); + + // Get a SQL command from the config + CommandPtr command = das->getCommand("get all tables"); + + // Execute the sql command and generate a SDO graph with the returned data + DataObjectPtr root = command->executeQuery(); + + // Get all companies + DataObjectList& companyList = root->getList("COMPANY"); + + // Print each company id and name + for (int i = 0 ; i < companyList.size() ; i++) { + // Get the company id + long id = companyList[i]->getInt("ID"); + + // Get the name string length and allocate enough space for it + unsigned int stringLength = companyList[i]->getLength("NAME"); + wchar_t* buffer = new wchar_t[stringLength]; + + // Get the company name + companyList[i]->getString("NAME", buffer, stringLength); + wstring name = wstring(buffer, stringLength); + + // Print the company data + wcout << "Company: " << i << endl; + wcout << " id = " << id << endl; + wcout << " name = " << name << endl << endl; + + // Free the allocated memory + delete [] buffer; + + } + + // Get a company named "apache" + DataObjectPtr company = root->getDataObject("COMPANY[NAME='apache']"); + + // Remove the first department of this company and get it + commonj::sdo::DataObjectPtr department = company->getList("DEPARTMENT").remove(0);; + + // Change the company name to "amd" + wstring companyName = L"amd"; + company->setString("NAME", companyName.c_str(), companyName.size()); + + // The department is added to the company named "ibm" + root->getDataObject("COMPANY[NAME='ibm']")->getList("DEPARTMENT").append(department); + + // The graph changes are persited on the database + das->applyChanges(root); + + // Free the allocated connection and DAS instance + delete das; + delete connection; + + system("PAUSE"); + +} diff --git a/das-cpp/trunk/samples/build.xml b/das-cpp/trunk/samples/build.xml new file mode 100644 index 0000000000..9d1d761ec3 --- /dev/null +++ b/das-cpp/trunk/samples/build.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3