Skip to content

Commit 265ea6e

Browse files
author
Koen Deforche
committed
A batch of fixes:
- #1993 WebSockets 'Compressed bit must be 0 if no negotiated deflate-frame extension' message - #1988 WPushButton user-provided style class is lost when a setLink() occurs after initial render - #1987 WPushButton user-provided style class is lost when a setLink() occurs after initial render - #1984 QueryModel addColumn - #1981 WPaintedWidget setInline(true) does not display as linline in IE9 and IE10 - #1977 Inconsistent wt_config.xml.in comment/setting UA-Compatible - #1964 WBorderLayout Documentation - Enum Namespace is Wrong
1 parent acad52e commit 265ea6e

Some content is hidden

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

41 files changed

+328
-262
lines changed

examples/blog/BlogRSSFeed.C

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@
1818

1919
namespace dbo = Wt::Dbo;
2020

21-
BlogRSSFeed::BlogRSSFeed(const std::string& sqliteDb,
21+
BlogRSSFeed::BlogRSSFeed(dbo::SqlConnectionPool& connectionPool,
2222
const std::string& title,
2323
const std::string& url,
2424
const std::string& description)
25-
: session_(new BlogSession(sqliteDb)),
25+
: connectionPool_(connectionPool),
2626
title_(title),
2727
url_(url),
2828
description_(description)
2929
{ }
3030

3131
BlogRSSFeed::~BlogRSSFeed()
32-
{
33-
delete session_;
34-
}
32+
{ }
3533

3634
void BlogRSSFeed::handleRequest(const Wt::Http::Request &request,
3735
Wt::Http::Response &response)
3836
{
37+
BlogSession session(connectionPool_);
38+
3939
response.setMimeType("application/rss+xml");
4040

4141
std::string url = url_;
@@ -59,9 +59,9 @@ void BlogRSSFeed::handleRequest(const Wt::Http::Request &request,
5959
" <description>" << Wt::Utils::htmlEncode(description_)
6060
<< "</description>\n";
6161

62-
dbo::Transaction t(*session_);
62+
dbo::Transaction t(session);
6363

64-
Posts posts = session_->find<Post>
64+
Posts posts = session.find<Post>
6565
("where state = ? "
6666
"order by date desc "
6767
"limit 10").bind(Post::Published);

examples/blog/BlogRSSFeed.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class BlogSession;
1414
class BlogRSSFeed : public Wt::WResource
1515
{
1616
public:
17-
BlogRSSFeed(const std::string& sqliteDb,
17+
BlogRSSFeed(Wt::Dbo::SqlConnectionPool& connectionPool,
1818
const std::string& title,
1919
const std::string& url,
2020
const std::string& description);
@@ -25,8 +25,7 @@ class BlogRSSFeed : public Wt::WResource
2525
Wt::Http::Response &response);
2626

2727
private:
28-
BlogSession *session_;
29-
28+
Wt::Dbo::SqlConnectionPool& connectionPool_;
3029
std::string title_, url_, description_;
3130
};
3231

examples/blog/blog.C

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <Wt/WApplication>
77
#include <Wt/WContainerWidget>
88
#include <Wt/WServer>
9+
#include <Wt/Dbo/SqlConnectionPool>
910

1011
#include "model/BlogSession.h"
1112
#include "model/Token.h"
@@ -24,18 +25,18 @@ static const char *BlogUrl = "/blog";
2425
class BlogApplication : public WApplication
2526
{
2627
public:
27-
BlogApplication(const WEnvironment& env)
28+
BlogApplication(const WEnvironment& env, Wt::Dbo::SqlConnectionPool& blogDb)
2829
: WApplication(env)
2930
{
30-
root()->addWidget(new BlogView("/",
31-
WApplication::appRoot() + "blog.db", FeedUrl));
31+
root()->addWidget(new BlogView("/", blogDb, FeedUrl));
3232
useStyleSheet("css/blogexample.css");
3333
}
3434
};
3535

36-
WApplication *createApplication(const WEnvironment& env)
36+
WApplication *createApplication(const WEnvironment& env,
37+
Wt::Dbo::SqlConnectionPool *blogDb)
3738
{
38-
return new BlogApplication(env);
39+
return new BlogApplication(env, *blogDb);
3940
}
4041

4142
int main(int argc, char **argv)
@@ -47,13 +48,16 @@ int main(int argc, char **argv)
4748

4849
BlogSession::configureAuth();
4950

50-
BlogRSSFeed rssFeed(server.appRoot() + "blog.db", "Wt blog example",
51-
"", "It's just an example.");
51+
Wt::Dbo::SqlConnectionPool *blogDb
52+
= BlogSession::createConnectionPool(server.appRoot() + "blog.db");
53+
54+
BlogRSSFeed rssFeed(*blogDb, "Wt blog example", "", "It's just an example.");
5255

5356
server.addResource(&rssFeed, FeedUrl);
5457
//When the blog application is deployed in ISAPI on the path "/blog"
5558
//the resources (css+images) are not fetched correctly
56-
server.addEntryPoint(Application, createApplication, BlogUrl);
59+
server.addEntryPoint(Application,
60+
boost::bind(&createApplication, _1, blogDb), BlogUrl);
5761

5862
std::cerr << "\n\n -- Warning: Example is deployed at '"
5963
<< BlogUrl << "'\n\n";
@@ -62,6 +66,8 @@ int main(int argc, char **argv)
6266
WServer::waitForShutdown();
6367
server.stop();
6468
}
69+
70+
delete blogDb;
6571
} catch (WServer::Exception& e) {
6672
std::cerr << e.what() << std::endl;
6773
} catch (std::exception &e) {

examples/blog/model/BlogSession.C

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
#include "User.h"
1313
#include "../asciidoc/asciidoc.h"
1414

15-
#include "Wt/Auth/AuthService"
16-
#include "Wt/Auth/HashFunction"
17-
#include "Wt/Auth/Identity"
18-
#include "Wt/Auth/PasswordService"
19-
#include "Wt/Auth/PasswordStrengthValidator"
20-
#include "Wt/Auth/PasswordVerifier"
21-
#include "Wt/Auth/GoogleService"
15+
#include <Wt/Auth/AuthService>
16+
#include <Wt/Auth/HashFunction>
17+
#include <Wt/Auth/Identity>
18+
#include <Wt/Auth/PasswordService>
19+
#include <Wt/Auth/PasswordStrengthValidator>
20+
#include <Wt/Auth/PasswordVerifier>
21+
#include <Wt/Auth/GoogleService>
22+
23+
#include <Wt/Dbo/FixedSqlConnectionPool>
2224

2325
#ifndef WIN32
2426
#include <unistd.h>
@@ -96,15 +98,22 @@ void BlogSession::configureAuth()
9698
blogOAuth.push_back(new Auth::GoogleService(blogAuth));
9799
}
98100

99-
BlogSession::BlogSession(const std::string& sqliteDb)
100-
: connection_(sqliteDb),
101-
users_(*this)
101+
dbo::SqlConnectionPool *BlogSession::createConnectionPool(const std::string& sqliteDb)
102102
{
103-
connection_.setProperty("show-queries", "true");
104-
connection_.setDateTimeStorage(Wt::Dbo::SqlDateTime,
103+
dbo::backend::Sqlite3 *connection = new dbo::backend::Sqlite3(sqliteDb);
104+
105+
connection->setProperty("show-queries", "true");
106+
connection->setDateTimeStorage(Wt::Dbo::SqlDateTime,
105107
Wt::Dbo::backend::Sqlite3::PseudoISO8601AsText);
106108

107-
setConnection(connection_);
109+
return new dbo::FixedSqlConnectionPool(connection, 10);
110+
}
111+
112+
BlogSession::BlogSession(dbo::SqlConnectionPool& connectionPool)
113+
: connectionPool_(connectionPool),
114+
users_(*this)
115+
{
116+
setConnectionPool(connectionPool_);
108117

109118
mapClass<Comment>("comment");
110119
mapClass<Post>("post");

examples/blog/model/BlogSession.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class BlogSession : public dbo::Session
3333
public:
3434
static void configureAuth();
3535

36-
BlogSession(const std::string& sqliteDb);
36+
BlogSession(dbo::SqlConnectionPool& connectionPool);
3737

3838
dbo::ptr<User> user() const;
3939

@@ -46,8 +46,10 @@ class BlogSession : public dbo::Session
4646
Wt::Auth::PasswordService *passwordAuth() const;
4747
const std::vector<const Wt::Auth::OAuthService *>& oAuth() const;
4848

49+
static dbo::SqlConnectionPool *createConnectionPool(const std::string& sqlite3);
50+
4951
private:
50-
dbo::backend::Sqlite3 connection_;
52+
dbo::SqlConnectionPool& connectionPool_;
5153
BlogUserDatabase users_;
5254
Wt::Auth::Login login_;
5355

examples/blog/view/BlogView.C

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ namespace dbo = Wt::Dbo;
4242
class BlogImpl : public WContainerWidget
4343
{
4444
public:
45-
BlogImpl(const std::string& basePath, const std::string& sqliteDb,
45+
BlogImpl(const std::string& basePath, dbo::SqlConnectionPool& connectionPool,
4646
const std::string& rssFeedUrl, BlogView *blogView)
4747
: basePath_(basePath),
4848
rssFeedUrl_(rssFeedUrl),
49-
session_(sqliteDb),
49+
session_(connectionPool),
5050
blogView_(blogView),
5151
panel_(0),
5252
authorPanel_(0),
@@ -456,12 +456,12 @@ private:
456456
}
457457
};
458458

459-
BlogView::BlogView(const std::string& basePath, const std::string& sqliteDb,
459+
BlogView::BlogView(const std::string& basePath, dbo::SqlConnectionPool& db,
460460
const std::string& rssFeedUrl, WContainerWidget *parent)
461461
: WCompositeWidget(parent),
462462
userChanged_(this)
463463
{
464-
impl_ = new BlogImpl(basePath, sqliteDb, rssFeedUrl, this);
464+
impl_ = new BlogImpl(basePath, db, rssFeedUrl, this);
465465
setImplementation(impl_);
466466
}
467467

examples/blog/view/BlogView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class BlogImpl;
1818
class BlogView : public Wt::WCompositeWidget
1919
{
2020
public:
21-
BlogView(const std::string& basePath, const std::string& sqliteDb,
21+
BlogView(const std::string& basePath, Wt::Dbo::SqlConnectionPool& db,
2222
const std::string& rssFeedUrl, Wt::WContainerWidget *parent = 0);
2323

2424
void setInternalBasePath(const std::string& basePath);

examples/wt-homepage/Home.C

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ Home::~Home()
3535
{
3636
}
3737

38-
Home::Home(const WEnvironment& env, const std::string& title,
39-
const std::string& resourceBundle, const std::string& cssPath)
38+
Home::Home(const WEnvironment& env,
39+
Wt::Dbo::SqlConnectionPool& blogDb,
40+
const std::string& title, const std::string& resourceBundle,
41+
const std::string& cssPath)
4042
: WApplication(env),
4143
releases_(0),
44+
blogDb_(blogDb),
4245
homePage_(0),
4346
sourceViewer_(0)
4447
{
@@ -257,7 +260,7 @@ WWidget *Home::blog()
257260
const Lang& l = languages[language_];
258261
std::string langPath = l.path_;
259262
BlogView *blog = new BlogView(langPath + "blog/",
260-
appRoot() + "blog.db", "/wt/blog/feed/");
263+
blogDb_, "/wt/blog/feed/");
261264
blog->setObjectName("blog");
262265

263266
if (!blog->user().empty())

examples/wt-homepage/Home.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ DeferredWidget<Function> *deferCreate(Function f)
6767
class Home : public WApplication
6868
{
6969
public:
70-
Home(const WEnvironment& env,
70+
Home(const WEnvironment& env, Wt::Dbo::SqlConnectionPool& blogDb,
7171
const std::string& title,
7272
const std::string& resourceBundle, const std::string& cssPath);
7373

@@ -95,6 +95,7 @@ class Home : public WApplication
9595
void readReleases(WTable *releaseTable);
9696

9797
private:
98+
Wt::Dbo::SqlConnectionPool& blogDb_;
9899
WWidget *homePage_;
99100
WWidget *sourceViewer_;
100101

examples/wt-homepage/JWtHome.C

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424

2525
#include "ExampleSourceViewer.h"
2626

27-
JWtHome::JWtHome(const WEnvironment& env)
28-
: Home(env,
29-
"JWt, Java Web Toolkit",
30-
"jwt-home", "css/jwt")
27+
JWtHome::JWtHome(const WEnvironment& env, Wt::Dbo::SqlConnectionPool& blogDb)
28+
: Home(env, blogDb,
29+
"JWt, Java Web Toolkit",
30+
"jwt-home", "css/jwt")
3131
{
3232
addLanguage(Lang("en", "/", "en", "English"));
3333

@@ -154,7 +154,8 @@ WWidget *JWtHome::wrapView(WWidget *(JWtHome::*createWidget)())
154154
return makeStaticModel(boost::bind(createWidget, this));
155155
}
156156

157-
WApplication *createJWtHomeApplication(const WEnvironment& env)
157+
WApplication *createJWtHomeApplication(const WEnvironment& env,
158+
Wt::Dbo::SqlConnectionPool *blogDb)
158159
{
159-
return new JWtHome(env);
160+
return new JWtHome(env, *blogDb);
160161
}

0 commit comments

Comments
 (0)