#ifndef SQLTransaction_h
#define SQLTransaction_h
#if ENABLE(DATABASE)
#include "ExceptionCode.h"
#include "SQLStatement.h"
#include <wtf/Deque.h>
#include <wtf/Forward.h>
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/Vector.h>
namespace WebCore {
class Database;
class SQLError;
class SQLiteTransaction;
class SQLStatementCallback;
class SQLStatementErrorCallback;
class SQLTransaction;
class SQLTransactionCallback;
class SQLTransactionErrorCallback;
class SQLValue;
class VoidCallback;
class SQLTransactionWrapper : public ThreadSafeRefCounted<SQLTransactionWrapper> {
public:
virtual ~SQLTransactionWrapper() { }
virtual bool performPreflight(SQLTransaction*) = 0;
virtual bool performPostflight(SQLTransaction*) = 0;
virtual SQLError* sqlError() const = 0;
};
class SQLTransaction : public ThreadSafeRefCounted<SQLTransaction> {
public:
static PassRefPtr<SQLTransaction> create(Database*, PassRefPtr<SQLTransactionCallback>, PassRefPtr<SQLTransactionErrorCallback>,
PassRefPtr<VoidCallback>, PassRefPtr<SQLTransactionWrapper>, bool readOnly = false);
~SQLTransaction();
void executeSQL(const String& sqlStatement, const Vector<SQLValue>& arguments,
PassRefPtr<SQLStatementCallback>, PassRefPtr<SQLStatementErrorCallback>, ExceptionCode&);
void lockAcquired();
bool performNextStep();
void performPendingCallback();
Database* database() { return m_database.get(); }
bool isReadOnly() { return m_readOnly; }
void notifyDatabaseThreadIsShuttingDown();
private:
SQLTransaction(Database*, PassRefPtr<SQLTransactionCallback>, PassRefPtr<SQLTransactionErrorCallback>,
PassRefPtr<VoidCallback>, PassRefPtr<SQLTransactionWrapper>, bool readOnly);
typedef void (SQLTransaction::*TransactionStepMethod)();
TransactionStepMethod m_nextStep;
void enqueueStatement(PassRefPtr<SQLStatement>);
void checkAndHandleClosedOrInterruptedDatabase();
void acquireLock();
void openTransactionAndPreflight();
void deliverTransactionCallback();
void scheduleToRunStatements();
void runStatements();
void getNextStatement();
bool runCurrentStatement();
void handleCurrentStatementError();
void deliverStatementCallback();
void deliverQuotaIncreaseCallback();
void postflightAndCommit();
void deliverSuccessCallback();
void cleanupAfterSuccessCallback();
void handleTransactionError(bool inCallback);
void deliverTransactionErrorCallback();
void cleanupAfterTransactionErrorCallback();
#ifndef NDEBUG
static const char* debugStepName(TransactionStepMethod);
#endif
RefPtr<SQLStatement> m_currentStatement;
bool m_executeSqlAllowed;
RefPtr<Database> m_database;
RefPtr<SQLTransactionWrapper> m_wrapper;
SQLCallbackWrapper<SQLTransactionCallback> m_callbackWrapper;
SQLCallbackWrapper<VoidCallback> m_successCallbackWrapper;
SQLCallbackWrapper<SQLTransactionErrorCallback> m_errorCallbackWrapper;
RefPtr<SQLError> m_transactionError;
bool m_shouldRetryCurrentStatement;
bool m_modifiedDatabase;
bool m_lockAcquired;
bool m_readOnly;
Mutex m_statementMutex;
Deque<RefPtr<SQLStatement> > m_statementQueue;
OwnPtr<SQLiteTransaction> m_sqliteTransaction;
};
}
#endif
#endif // SQLTransaction_h