18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/* 28e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Copyright (C) 2007 Apple Inc. All rights reserved. 38e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 48e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Redistribution and use in source and binary forms, with or without 58e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * modification, are permitted provided that the following conditions 68e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * are met: 78e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 88e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 1. Redistributions of source code must retain the above copyright 98e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * notice, this list of conditions and the following disclaimer. 108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright 118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * notice, this list of conditions and the following disclaimer in the 128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * documentation and/or other materials provided with the distribution. 138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * its contributors may be used to endorse or promote products derived 158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * from this software without specific prior written permission. 168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project */ 288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#ifndef SQLTransaction_h 298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#define SQLTransaction_h 308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 318ccf722629b08f2a06b2cadbdc3d0c9dc885e25dBen Murdoch#if ENABLE(DATABASE) 328ccf722629b08f2a06b2cadbdc3d0c9dc885e25dBen Murdoch 33967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch#include "ExceptionCode.h" 348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "SQLStatement.h" 358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include <wtf/Deque.h> 368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include <wtf/Forward.h> 372bde8e466a4451c7319e3a072d118917957d6554Steve Block#include <wtf/ThreadSafeRefCounted.h> 388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include <wtf/Vector.h> 398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore { 418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass Database; 438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass SQLError; 44545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdochclass SQLiteTransaction; 458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass SQLStatementCallback; 468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass SQLStatementErrorCallback; 478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass SQLTransaction; 48545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdochclass SQLTransactionCallback; 49545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdochclass SQLTransactionErrorCallback; 508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass SQLValue; 518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass VoidCallback; 528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 532bde8e466a4451c7319e3a072d118917957d6554Steve Blockclass SQLTransactionWrapper : public ThreadSafeRefCounted<SQLTransactionWrapper> { 548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectpublic: 558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project virtual ~SQLTransactionWrapper() { } 568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project virtual bool performPreflight(SQLTransaction*) = 0; 578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project virtual bool performPostflight(SQLTransaction*) = 0; 58231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 598e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project virtual SQLError* sqlError() const = 0; 608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}; 618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 622bde8e466a4451c7319e3a072d118917957d6554Steve Blockclass SQLTransaction : public ThreadSafeRefCounted<SQLTransaction> { 638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectpublic: 64231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block static PassRefPtr<SQLTransaction> create(Database*, PassRefPtr<SQLTransactionCallback>, PassRefPtr<SQLTransactionErrorCallback>, 65231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block PassRefPtr<VoidCallback>, PassRefPtr<SQLTransactionWrapper>, bool readOnly = false); 668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project ~SQLTransaction(); 68231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 69231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block void executeSQL(const String& sqlStatement, const Vector<SQLValue>& arguments, 70545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch PassRefPtr<SQLStatementCallback>, PassRefPtr<SQLStatementErrorCallback>, ExceptionCode&); 71231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 72231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block void lockAcquired(); 738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool performNextStep(); 748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void performPendingCallback(); 75231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project Database* database() { return m_database.get(); } 77231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block bool isReadOnly() { return m_readOnly; } 785e2bc6953fe6923165b8a5d7679939693a1d58d6Steve Block void notifyDatabaseThreadIsShuttingDown(); 798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprivate: 81231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block SQLTransaction(Database*, PassRefPtr<SQLTransactionCallback>, PassRefPtr<SQLTransactionErrorCallback>, 82231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block PassRefPtr<VoidCallback>, PassRefPtr<SQLTransactionWrapper>, bool readOnly); 838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project typedef void (SQLTransaction::*TransactionStepMethod)(); 858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project TransactionStepMethod m_nextStep; 86231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void enqueueStatement(PassRefPtr<SQLStatement>); 88231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 89db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block void checkAndHandleClosedOrInterruptedDatabase(); 90231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 91231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block void acquireLock(); 928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void openTransactionAndPreflight(); 938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void deliverTransactionCallback(); 948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void scheduleToRunStatements(); 958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void runStatements(); 968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void getNextStatement(); 978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool runCurrentStatement(); 988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void handleCurrentStatementError(); 998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void deliverStatementCallback(); 1008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void deliverQuotaIncreaseCallback(); 1018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void postflightAndCommit(); 1028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void deliverSuccessCallback(); 1038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void cleanupAfterSuccessCallback(); 1048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void handleTransactionError(bool inCallback); 1058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void deliverTransactionErrorCallback(); 1068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void cleanupAfterTransactionErrorCallback(); 1078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#ifndef NDEBUG 1098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project static const char* debugStepName(TransactionStepMethod); 1108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif 1118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project RefPtr<SQLStatement> m_currentStatement; 113231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 1148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool m_executeSqlAllowed; 115231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 1168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project RefPtr<Database> m_database; 1178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project RefPtr<SQLTransactionWrapper> m_wrapper; 1182bde8e466a4451c7319e3a072d118917957d6554Steve Block SQLCallbackWrapper<SQLTransactionCallback> m_callbackWrapper; 1192bde8e466a4451c7319e3a072d118917957d6554Steve Block SQLCallbackWrapper<VoidCallback> m_successCallbackWrapper; 1202bde8e466a4451c7319e3a072d118917957d6554Steve Block SQLCallbackWrapper<SQLTransactionErrorCallback> m_errorCallbackWrapper; 1218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project RefPtr<SQLError> m_transactionError; 1228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool m_shouldRetryCurrentStatement; 1238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool m_modifiedDatabase; 124231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block bool m_lockAcquired; 125231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block bool m_readOnly; 126231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 1278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project Mutex m_statementMutex; 1288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project Deque<RefPtr<SQLStatement> > m_statementQueue; 1298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project OwnPtr<SQLiteTransaction> m_sqliteTransaction; 1318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}; 132231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block 1338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} // namespace WebCore 1348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1358ccf722629b08f2a06b2cadbdc3d0c9dc885e25dBen Murdoch#endif 1368ccf722629b08f2a06b2cadbdc3d0c9dc885e25dBen Murdoch 1378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif // SQLTransaction_h 138