1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// **********************************************************************
//
// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
#include <Ice/Ice.h>
#include <Freeze/Freeze.h>
#include <Contacts.h>
using namespace std;
using namespace Demo;
using namespace Freeze;
class Create : public Ice::Application
{
public:
virtual int run(int, char*[]);
};
int main(int argc, char* argv[])
{
Create app;
return app.main(argc, argv);
}
int
Create::run(int, char*[])
{
const string names[] = { "don", "ed", "frank", "gary", "arnold", "bob", "carlos" };
const string phoneNumbers[] = { "(777)777-7777", "(666)666-6666", "(555)555-5555 x123",
"(444)444-4444", "(333)333-3333 x1234", "(222)222-2222", "(111)111-1111" };
const size_t size = 7;
ConnectionPtr connection = createConnection(communicator(), "db");
Contacts contacts(connection, "contacts");
//
// Create a bunch of contacts within one transaction, and commit it
//
TransactionHolder txh(connection);
for(size_t i = 0; i < size; ++i)
{
ContactData data;
data.phoneNumber = phoneNumbers[i];
contacts.put(Contacts::value_type(names[i], data));
}
txh.commit();
cout << size << " contacts were successfully created or updated" << endl;
return 0;
}
|