0
|
1 |
/*
|
|
2 |
* Copyright (C) 2007 Apple Inc. All rights reserved.
|
|
3 |
*
|
|
4 |
* Redistribution and use in source and binary forms, with or without
|
|
5 |
* modification, are permitted provided that the following conditions
|
|
6 |
* are met:
|
|
7 |
*
|
|
8 |
* 1. Redistributions of source code must retain the above copyright
|
|
9 |
* notice, this list of conditions and the following disclaimer.
|
|
10 |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
11 |
* notice, this list of conditions and the following disclaimer in the
|
|
12 |
* documentation and/or other materials provided with the distribution.
|
|
13 |
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
|
|
14 |
* its contributors may be used to endorse or promote products derived
|
|
15 |
* from this software without specific prior written permission.
|
|
16 |
*
|
|
17 |
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
|
|
18 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20 |
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
|
|
21 |
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
22 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
23 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
24 |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
26 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27 |
*/
|
|
28 |
#ifndef SQLTransaction_h
|
|
29 |
#define SQLTransaction_h
|
|
30 |
|
|
31 |
#if ENABLE(DATABASE)
|
|
32 |
|
|
33 |
#include <wtf/Threading.h>
|
|
34 |
|
|
35 |
#include "SQLiteTransaction.h"
|
|
36 |
#include "SQLStatement.h"
|
|
37 |
#include "SQLTransactionCallback.h"
|
|
38 |
#include "SQLTransactionErrorCallback.h"
|
|
39 |
#include <wtf/Deque.h>
|
|
40 |
#include <wtf/Forward.h>
|
|
41 |
#include <wtf/OwnPtr.h>
|
|
42 |
#include <wtf/RefPtr.h>
|
|
43 |
#include <wtf/Vector.h>
|
|
44 |
|
|
45 |
namespace WebCore {
|
|
46 |
|
|
47 |
typedef int ExceptionCode;
|
|
48 |
|
|
49 |
class Database;
|
|
50 |
class SQLError;
|
|
51 |
class SQLStatementCallback;
|
|
52 |
class SQLStatementErrorCallback;
|
|
53 |
class SQLTransaction;
|
|
54 |
class SQLValue;
|
|
55 |
class String;
|
|
56 |
class VoidCallback;
|
|
57 |
|
|
58 |
class SQLTransactionWrapper : public ThreadSafeShared<SQLTransactionWrapper> {
|
|
59 |
public:
|
|
60 |
virtual ~SQLTransactionWrapper() { }
|
|
61 |
virtual bool performPreflight(SQLTransaction*) = 0;
|
|
62 |
virtual bool performPostflight(SQLTransaction*) = 0;
|
|
63 |
|
|
64 |
virtual SQLError* sqlError() const = 0;
|
|
65 |
};
|
|
66 |
|
|
67 |
class SQLTransaction : public ThreadSafeShared<SQLTransaction> {
|
|
68 |
public:
|
|
69 |
static PassRefPtr<SQLTransaction> create(Database*, PassRefPtr<SQLTransactionCallback>, PassRefPtr<SQLTransactionErrorCallback>,
|
|
70 |
PassRefPtr<VoidCallback>, PassRefPtr<SQLTransactionWrapper>, bool readOnly = false);
|
|
71 |
|
|
72 |
~SQLTransaction();
|
|
73 |
|
|
74 |
void executeSQL(const String& sqlStatement, const Vector<SQLValue>& arguments,
|
|
75 |
PassRefPtr<SQLStatementCallback> callback, PassRefPtr<SQLStatementErrorCallback> callbackError, ExceptionCode& e);
|
|
76 |
|
|
77 |
void lockAcquired();
|
|
78 |
bool performNextStep();
|
|
79 |
void performPendingCallback();
|
|
80 |
|
|
81 |
Database* database() { return m_database.get(); }
|
|
82 |
bool isReadOnly() { return m_readOnly; }
|
|
83 |
|
|
84 |
private:
|
|
85 |
SQLTransaction(Database*, PassRefPtr<SQLTransactionCallback>, PassRefPtr<SQLTransactionErrorCallback>,
|
|
86 |
PassRefPtr<VoidCallback>, PassRefPtr<SQLTransactionWrapper>, bool readOnly);
|
|
87 |
|
|
88 |
typedef void (SQLTransaction::*TransactionStepMethod)();
|
|
89 |
TransactionStepMethod m_nextStep;
|
|
90 |
|
|
91 |
void enqueueStatement(PassRefPtr<SQLStatement>);
|
|
92 |
|
|
93 |
void checkAndHandleClosedDatabase();
|
|
94 |
|
|
95 |
void acquireLock();
|
|
96 |
void openTransactionAndPreflight();
|
|
97 |
void deliverTransactionCallback();
|
|
98 |
void scheduleToRunStatements();
|
|
99 |
void runStatements();
|
|
100 |
void getNextStatement();
|
|
101 |
bool runCurrentStatement();
|
|
102 |
void handleCurrentStatementError();
|
|
103 |
void deliverStatementCallback();
|
|
104 |
void deliverQuotaIncreaseCallback();
|
|
105 |
void postflightAndCommit();
|
|
106 |
void deliverSuccessCallback();
|
|
107 |
void cleanupAfterSuccessCallback();
|
|
108 |
void handleTransactionError(bool inCallback);
|
|
109 |
void deliverTransactionErrorCallback();
|
|
110 |
void cleanupAfterTransactionErrorCallback();
|
|
111 |
|
|
112 |
#ifndef NDEBUG
|
|
113 |
static const char* debugStepName(TransactionStepMethod);
|
|
114 |
#endif
|
|
115 |
|
|
116 |
RefPtr<SQLStatement> m_currentStatement;
|
|
117 |
|
|
118 |
bool m_executeSqlAllowed;
|
|
119 |
|
|
120 |
RefPtr<Database> m_database;
|
|
121 |
RefPtr<SQLTransactionWrapper> m_wrapper;
|
|
122 |
RefPtr<SQLTransactionCallback> m_callback;
|
|
123 |
RefPtr<VoidCallback> m_successCallback;
|
|
124 |
RefPtr<SQLTransactionErrorCallback> m_errorCallback;
|
|
125 |
RefPtr<SQLError> m_transactionError;
|
|
126 |
bool m_shouldRetryCurrentStatement;
|
|
127 |
bool m_modifiedDatabase;
|
|
128 |
bool m_lockAcquired;
|
|
129 |
bool m_readOnly;
|
|
130 |
|
|
131 |
Mutex m_statementMutex;
|
|
132 |
Deque<RefPtr<SQLStatement> > m_statementQueue;
|
|
133 |
|
|
134 |
OwnPtr<SQLiteTransaction> m_sqliteTransaction;
|
|
135 |
};
|
|
136 |
|
|
137 |
} // namespace WebCore
|
|
138 |
|
|
139 |
#endif
|
|
140 |
|
|
141 |
#endif // SQLTransaction_h
|