Upload upstream chromium 71.0.3578.0
[platform/framework/web/chromium-efl.git] / sql / transaction.cc
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "sql/transaction.h"
6
7 #include "base/logging.h"
8 #include "sql/database.h"
9
10 namespace sql {
11
12 Transaction::Transaction(Database* database)
13     : database_(database), is_open_(false) {}
14
15 Transaction::~Transaction() {
16   if (is_open_)
17     database_->RollbackTransaction();
18 }
19
20 bool Transaction::Begin() {
21   DCHECK(!is_open_) << "Beginning a transaction twice!";
22   is_open_ = database_->BeginTransaction();
23   return is_open_;
24 }
25
26 void Transaction::Rollback() {
27   DCHECK(is_open_) << "Attempting to roll back a nonexistent transaction. "
28                    << "Did you remember to call Begin() and check its return?";
29   is_open_ = false;
30   database_->RollbackTransaction();
31 }
32
33 bool Transaction::Commit() {
34   DCHECK(is_open_) << "Attempting to commit a nonexistent transaction. "
35                    << "Did you remember to call Begin() and check its return?";
36   is_open_ = false;
37   return database_->CommitTransaction();
38 }
39
40 }  // namespace sql