Skip to content

Commit 0699e16

Browse files
author
Koen Deforche
committed
documentation updates, fix blog example bad_lexical_cast error, code cleanups
1 parent 7c6324b commit 0699e16

File tree

144 files changed

+64
-433
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+64
-433
lines changed

doc/tutorial/dbo.doc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,6 @@ happen within a transaction.
234234
user->karma = 13;
235235

236236
dbo::ptr<User> userPtr = session.add(user);
237-
238-
transaction.commit();
239237
}
240238
----
241239

@@ -259,6 +257,11 @@ database. Flushing happens automatically when committing the
259257
transaction, or whenever needed to maintain consistency between the
260258
transient objects and the database copy (e.g. before doing a query).
261259

260+
The transaction commits automatically if the transaction object goes
261+
out of scope. If however an exception is thrown, which unwinds the
262+
stack and causes the transaction to go out of scope, then the
263+
transaction will roll back instead.
264+
262265
This generates the following SQL:
263266

264267
[source,sql]
@@ -1086,8 +1089,6 @@ void run()
10861089
userInfo->info = "great guy";
10871090

10881091
session.add(userInfo);
1089-
1090-
transaction.commit();
10911092
}
10921093

10931094
{
@@ -1096,8 +1097,6 @@ void run()
10961097
dbo::ptr<UserInfo> info = session.find<UserInfo>();
10971098

10981099
std::cerr << info->user->name << " is a " << info->info << std::endl;
1099-
1100-
transaction.commit();
11011100
}
11021101
}
11031102

@@ -1182,7 +1181,11 @@ wider transaction if that is available. A transaction will in fact
11821181
defer opening a real transaction in the database until needed, and
11831182
thus there is no penalty for instantiating a transaction to make sure
11841183
a unit of work is atomic, even if you are not yet sure that there will
1185-
be actual work done.
1184+
be actual work done. Note that there is no need (sinds Wt 3.2.1) to
1185+
explicitly commit a transaction: a transaction will automatically
1186+
commited when it goes out of scope, unless the transaction goes out of
1187+
scope (and thus its destructor is called) while an exception is being
1188+
thrown.
11861189

11871190
Transactions may fail and dealing with failing transactions is an
11881191
integral aspect of their usage. When the library detects a concurrent

examples/blog/view/BlogView.C

Lines changed: 37 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -369,73 +369,54 @@ private:
369369
boost::split(parts, path, boost::is_any_of("/"));
370370

371371
WDate lower, upper;
372-
int year = boost::lexical_cast<int>(parts[0]);
372+
try {
373+
int year = boost::lexical_cast<int>(parts[0]);
373374

374-
if (parts.size() > 1) {
375-
int month = boost::lexical_cast<int>(parts[1]);
375+
if (parts.size() > 1) {
376+
int month = boost::lexical_cast<int>(parts[1]);
376377

377-
if (parts.size() > 2) {
378-
int day = boost::lexical_cast<int>(parts[2]);
378+
if (parts.size() > 2) {
379+
int day = boost::lexical_cast<int>(parts[2]);
379380

380-
lower.setDate(year, month, day);
381-
upper = lower.addDays(1);
381+
lower.setDate(year, month, day);
382+
upper = lower.addDays(1);
383+
} else {
384+
lower.setDate(year, month, 1);
385+
upper = lower.addMonths(1);
386+
}
382387
} else {
383-
lower.setDate(year, month, 1);
384-
upper = lower.addMonths(1);
388+
lower.setDate(year, 1, 1);
389+
upper = lower.addYears(1);
385390
}
386-
} else {
387-
lower.setDate(year, 1, 1);
388-
upper = lower.addYears(1);
389-
}
390-
391-
Posts posts = session_.find<Post>
392-
("where date >= ? "
393-
"and date < ? "
394-
"and (state = ? or author_id = ?)")
395-
.bind(WDateTime(lower))
396-
.bind(WDateTime(upper))
397-
.bind(Post::Published)
398-
.bind(session_.user().id());
399-
400-
if (parts.size() > 3) {
401-
std::string title = parts[3];
402-
403-
for (Posts::const_iterator i = posts.begin(); i != posts.end(); ++i)
404-
if ((*i)->titleToUrl() == title) {
405-
showPost(*i, PostView::Detail, parent);
406-
return;
407-
}
408391

392+
Posts posts = session_.find<Post>
393+
("where date >= ? "
394+
"and date < ? "
395+
"and (state = ? or author_id = ?)")
396+
.bind(WDateTime(lower))
397+
.bind(WDateTime(upper))
398+
.bind(Post::Published)
399+
.bind(session_.user().id());
400+
401+
if (parts.size() > 3) {
402+
std::string title = parts[3];
403+
404+
for (Posts::const_iterator i = posts.begin(); i != posts.end(); ++i)
405+
if ((*i)->titleToUrl() == title) {
406+
showPost(*i, PostView::Detail, parent);
407+
return;
408+
}
409+
410+
showError(tr("blog-no-post"));
411+
} else {
412+
showPosts(posts, parent);
413+
}
414+
} catch (std::exception& e) {
409415
showError(tr("blog-no-post"));
410-
} else {
411-
showPosts(posts, parent);
412416
}
413417
}
414418

415419
void showPosts(dbo::ptr<User> user) {
416-
/*
417-
<<<<<<< HEAD:examples/blog/view/BlogView.C
418-
if (user == session_.user() && user->role == User::Admin) {
419-
WTemplate *authorPanel = new WTemplate(tr("blog-author-panel"), items_);
420-
421-
WPushButton *newPost = new WPushButton(tr("new-post"));
422-
newPost->clicked().connect(this, &BlogImpl::newPost);
423-
424-
WContainerWidget *unpublishedPosts = new WContainerWidget();
425-
showPosts(user->allPosts(Post::Unpublished), unpublishedPosts);
426-
427-
authorPanel->bindString("user", user->name);
428-
authorPanel->bindInt("unpublished-count",
429-
user->allPosts(Post::Unpublished).size());
430-
authorPanel->bindInt("published-count",
431-
user->allPosts(Post::Published).size());
432-
authorPanel->bindWidget("new-post", newPost);
433-
authorPanel->bindWidget("unpublished-posts", unpublishedPosts);
434-
}
435-
436-
=======
437-
>>>>>>> bvh_blog:examples/blog/view/BlogView.C
438-
*/
439420
showPosts(user->latestPosts(), items_);
440421
}
441422

examples/feature/dbo/tutorial1.C

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ void run()
7676
user->karma = 13;
7777

7878
dbo::ptr<User> userPtr = session.add(user);
79-
80-
transaction.commit();
8179
}
8280

8381
/*****
@@ -93,8 +91,6 @@ void run()
9391

9492
dbo::ptr<User> joe2 = session.query< dbo::ptr<User> >
9593
("select u from user u").where("name = ?").bind("Joe");
96-
97-
transaction.commit();
9894
}
9995

10096
{
@@ -109,8 +105,6 @@ void run()
109105
for (Users::const_iterator i = users.begin(); i != users.end(); ++i)
110106
std::cerr << " user " << (*i)->name
111107
<< " with karma of " << (*i)->karma << std::endl;
112-
113-
transaction.commit();
114108
}
115109

116110
/*****
@@ -124,16 +118,13 @@ void run()
124118

125119
joe.modify()->karma++;
126120
joe.modify()->password = "public";
127-
128-
transaction.commit();
129121
}
130122

131123
{
132124
dbo::Transaction transaction(session);
133125
dbo::ptr<User> joe = session.find<User>().where("name = ?").bind("Joe");
134126
if (joe)
135127
joe.remove();
136-
transaction.commit();
137128
}
138129

139130
{
@@ -142,8 +133,6 @@ void run()
142133
dbo::ptr<User> silly = session.add(new User());
143134
silly.modify()->name = "Silly";
144135
silly.remove();
145-
146-
transaction.commit();
147136
}
148137

149138
}

examples/feature/dbo/tutorial2.C

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ void run()
105105
user->karma = 13;
106106

107107
dbo::ptr<User> userPtr = session.add(user);
108-
109-
transaction.commit();
110108
}
111109

112110
dbo::ptr<Post> post;
@@ -120,8 +118,6 @@ void run()
120118

121119
// will print 'Joe has 1 post(s).'
122120
std::cerr << "Joe has " << joe->posts.size() << " post(s)." << std::endl;
123-
124-
transaction.commit();
125121
}
126122

127123
{
@@ -134,8 +130,6 @@ void run()
134130

135131
// will print '1 post(s) tagged with Cooking.'
136132
std::cerr << cooking->posts.size() << " post(s) tagged with Cooking." << std::endl;
137-
138-
transaction.commit();
139133
}
140134

141135
}

examples/feature/dbo/tutorial5.C

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ void run()
127127
user->karma = 13;
128128

129129
dbo::ptr<User> userPtr = session.add(user);
130-
131-
transaction.commit();
132130
}
133131

134132
dbo::ptr<Post> post;
@@ -142,8 +140,6 @@ void run()
142140

143141
// will print 'Joe has 1 post(s).'
144142
std::cerr << "Joe has " << joe->posts.size() << " post(s)." << std::endl;
145-
146-
transaction.commit();
147143
}
148144

149145
{
@@ -156,8 +152,6 @@ void run()
156152

157153
// will print '1 post(s) tagged with Cooking.'
158154
std::cerr << cooking->posts.size() << " post(s) tagged with Cooking." << std::endl;
159-
160-
transaction.commit();
161155
}
162156
}
163157

examples/feature/dbo/tutorial7.C

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ void run()
9999
userInfo->info = "great guy";
100100

101101
session.add(userInfo);
102-
103-
transaction.commit();
104102
}
105103

106104
{
@@ -109,8 +107,6 @@ void run()
109107
dbo::ptr<UserInfo> info = session.find<UserInfo>();
110108

111109
std::cerr << info->user->name << " is a " << info->info << std::endl;
112-
113-
transaction.commit();
114110
}
115111
}
116112

examples/feature/dbo/tutorial8.C

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ void run()
170170
std::cerr << " " << ms.id.organisation->name
171171
<< " (karma: " << ms.karma << ")" << std::endl;
172172
}
173-
174-
transaction.commit();
175173
}
176174
}
177175

src/Wt/Auth/AbstractPasswordService

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public:
5353
* a numeric scale (from 0 to 5) in addition to the normal validator
5454
* functionality of validating a password.
5555
*
56-
* The actual computation is done by validateStrength(), which returns
56+
* The actual computation is done by evaluateStrength(), which returns
5757
* an opaque number that is interpreted with isValid(), message() and
5858
* strength() methods.
5959
*

src/Wt/Auth/AuthModel.C

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@
1212

1313
#include "Wt/WApplication"
1414
#include "Wt/WEnvironment"
15-
#include "Wt/WLineEdit"
15+
#include "Wt/WInteractWidget"
1616
#include "Wt/WLogger"
17-
#include "Wt/WText"
1817

1918
#ifndef WT_DEBUG_JS
2019
#include "js/AuthModel.min.js"
2120
#endif
2221

23-
#include "web/Utils.h"
24-
2522
namespace Wt {
2623

27-
LOGGER("Auth::AuthModel");
24+
LOGGER("Auth::AuthModel");
2825

2926
namespace Auth {
3027

src/Wt/Auth/AuthService.C

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include "Wt/WApplication"
1515
#include "Wt/WRandom"
1616

17-
#include "web/Utils.h"
18-
1917
namespace Wt {
2018
namespace Auth {
2119

0 commit comments

Comments
 (0)