Bug 488379 - Update mozStorageConnection.* to follow style guidelines

Consistent spacing, consistent naming, and namespaces - OH MY!
r=asuth
This commit is contained in:
Shawn Wilsher 2009-04-17 17:19:31 -04:00
parent dabd65d0e1
commit c000eb400c
7 changed files with 954 additions and 996 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
@ -57,110 +58,113 @@ class nsIEventTarget;
class nsIThread;
class mozIStorageService;
class mozStorageConnection : public mozIStorageConnection
namespace mozilla {
namespace storage {
class Connection : public mozIStorageConnection
{
public:
NS_DECL_ISUPPORTS
NS_DECL_MOZISTORAGECONNECTION
mozStorageConnection(mozIStorageService* aService);
Connection(mozIStorageService* aService);
NS_IMETHOD Initialize(nsIFile *aDatabaseFile);
/**
* Creates the connection to the database.
*
* @param aDatabaseFile
* The nsIFile of the location of the database to open, or create if it
* does not exist. Passing in nsnull here creates an in-memory
* database.
*/
nsresult initialize(nsIFile *aDatabaseFile);
// interfaces
NS_DECL_ISUPPORTS
NS_DECL_MOZISTORAGECONNECTION
// fetch the native handle
sqlite3 *GetNativeConnection() { return mDBConn; }
// fetch the native handle
sqlite3 *GetNativeConnection() { return mDBConn; }
/**
* Lazily creates and returns a background execution thread. In the future,
* the thread may be re-claimed if left idle, so you should call this
* method just before you dispatch and not save the reference.
*
* @returns an event target suitable for asynchronous statement execution.
*/
already_AddRefed<nsIEventTarget> getAsyncExecutionTarget();
/**
* Lazily creates and returns a background execution thread. In the future,
* the thread may be re-claimed if left idle, so you should call this
* method just before you dispatch and not save the reference.
*
* @returns an event target suitable for asynchronous statement execution.
*/
already_AddRefed<nsIEventTarget> getAsyncExecutionTarget();
private:
~mozStorageConnection();
~Connection();
protected:
struct FindFuncEnumArgs {
nsISupports *mTarget;
PRBool mFound;
};
/**
* Describes a certain primitive type in the database.
*
* Possible Values Are:
* INDEX - To check for the existence of an index
* TABLE - To check for the existence of a table
*/
enum DatabaseElementType {
INDEX,
TABLE
};
/**
* Describes a certain primitive type in the database.
*
* Possible Values Are:
* INDEX - To check for the existence of an index
* TABLE - To check for the existence of a table
*/
enum DatabaseElementType {
INDEX,
TABLE
};
/**
* Determines if the specified primitive exists.
*
* @param aElementType
* The type of element to check the existence of
* @param aElementName
* The name of the element to check for
* @returns true if element exists, false otherwise
*/
nsresult databaseElementExists(enum DatabaseElementType aElementType,
const nsACString& aElementName,
PRBool *_exists);
/**
* Determines if the specified primitive exists.
*
* @param aElementType
* The type of element to check the existence of
* @param aElementName
* The name of the element to check for
* @returns true if element exists, false otherwise
*/
nsresult DatabaseElementExists(enum DatabaseElementType aElementType,
const nsACString& aElementName,
PRBool *_exists);
bool findFunctionByInstance(nsISupports *aInstance);
void HandleSqliteError(const char *aSqlStatement);
static PLDHashOperator s_FindFuncEnum(const nsACString &aKey,
nsISupports* aData, void* userArg);
PRBool FindFunctionByInstance(nsISupports *aInstance);
static int sProgressHelper(void *aArg);
// Generic progress handler
// Dispatch call to registered progress handler,
// if there is one. Do nothing in other cases.
int progressHandler();
static int s_ProgressHelper(void *arg);
// Generic progress handler
// Dispatch call to registered progress handler,
// if there is one. Do nothing in other cases.
int ProgressHandler();
sqlite3 *mDBConn;
nsCOMPtr<nsIFile> mDatabaseFile;
sqlite3 *mDBConn;
nsCOMPtr<nsIFile> mDatabaseFile;
/**
* Protects access to mAsyncExecutionThread.
*/
PRLock *mAsyncExecutionMutex;
/**
* Protects access to mAsyncExecutionThread.
*/
PRLock *mAsyncExecutionMutex;
/**
* Lazily created thread for asynchronous statement execution. Consumers
* should use getAsyncExecutionTarget rather than directly accessing this
* field.
*/
nsCOMPtr<nsIThread> mAsyncExecutionThread;
/**
* Set to true by Close() prior to actually shutting down the thread. This
* lets getAsyncExecutionTarget() know not to hand out any more thread
* references (or to create the thread in the first place). This variable
* should be accessed while holding the mAsyncExecutionMutex.
*/
PRBool mAsyncExecutionThreadShuttingDown;
/**
* Lazily created thread for asynchronous statement execution. Consumers
* should use getAsyncExecutionTarget rather than directly accessing this
* field.
*/
nsCOMPtr<nsIThread> mAsyncExecutionThread;
/**
* Set to true by Close() prior to actually shutting down the thread. This
* lets getAsyncExecutionTarget() know not to hand out any more thread
* references (or to create the thread in the first place). This variable
* should be accessed while holding the mAsyncExecutionMutex.
*/
PRBool mAsyncExecutionThreadShuttingDown;
PRLock *mTransactionMutex;
PRBool mTransactionInProgress;
PRLock *mTransactionMutex;
PRBool mTransactionInProgress;
PRLock *mFunctionsMutex;
nsInterfaceHashtable<nsCStringHashKey, nsISupports> mFunctions;
PRLock *mFunctionsMutex;
nsInterfaceHashtable<nsCStringHashKey, nsISupports> mFunctions;
PRLock *mProgressHandlerMutex;
nsCOMPtr<mozIStorageProgressHandler> mProgressHandler;
PRLock *mProgressHandlerMutex;
nsCOMPtr<mozIStorageProgressHandler> mProgressHandler;
// This isn't accessed but is used to make sure that the connections do
// not outlive the service. The service, for example, owns certain locks
// in mozStorageAsyncIO file that the connections depend on.
nsCOMPtr<mozIStorageService> mStorageService;
// This isn't accessed but is used to make sure that the connections do
// not outlive the service. The service, for example, owns certain locks
// in mozStorageAsyncIO file that the connections depend on.
nsCOMPtr<mozIStorageService> mStorageService;
};
} // namespace storage
} // namespace mozilla
#endif /* _MOZSTORAGECONNECTION_H_ */

View File

@ -55,6 +55,8 @@
#include "mozStoragePrivateHelpers.h"
#include "mozStorageEvents.h"
using namespace mozilla::storage;
/**
* The following constants help batch rows into result sets.
* MAX_MILLISECONDS_BETWEEN_RESULTS was chosen because any user-based task that
@ -625,7 +627,7 @@ NS_IMPL_THREADSAFE_ISUPPORTS2(
nsresult
NS_executeAsync(nsTArray<sqlite3_stmt *> &aStatements,
mozStorageConnection *aConnection,
Connection *aConnection,
mozIStorageStatementCallback *aCallback,
mozIStoragePendingStatement **_stmt)
{

View File

@ -43,10 +43,15 @@
#include "nscore.h"
#include "nsTArray.h"
struct sqlite3_stmt;
class mozStorageConnection;
class mozIStorageStatementCallback;
class mozIStoragePendingStatement;
namespace mozilla {
namespace storage {
class Connection;
} // namespace storage
} // namespace mozilla
/**
* Executes a statement in the background, and passes results back to the
* caller.
@ -62,7 +67,7 @@ class mozIStoragePendingStatement;
*/
nsresult NS_executeAsync(
nsTArray<sqlite3_stmt *> &aStatements,
mozStorageConnection *aConnection,
mozilla::storage::Connection *aConnection,
mozIStorageStatementCallback *aCallback,
mozIStoragePendingStatement **_stmt
);

View File

@ -210,10 +210,10 @@ Service::OpenSpecialDatabase(const char *aStorageKey,
return NS_ERROR_INVALID_ARG;
}
mozStorageConnection *msc = new mozStorageConnection(this);
Connection *msc = new Connection(this);
NS_ENSURE_TRUE(msc, NS_ERROR_OUT_OF_MEMORY);
rv = msc->Initialize(storageFile);
rv = msc->initialize(storageFile);
NS_ENSURE_SUCCESS(rv, rv);
NS_ADDREF(*_connection = msc);
@ -224,12 +224,12 @@ NS_IMETHODIMP
Service::OpenDatabase(nsIFile *aDatabaseFile,
mozIStorageConnection **_connection)
{
nsRefPtr<mozStorageConnection> msc = new mozStorageConnection(this);
nsRefPtr<Connection> msc = new Connection(this);
NS_ENSURE_TRUE(msc, NS_ERROR_OUT_OF_MEMORY);
{
nsAutoLock lock(mLock);
nsresult rv = msc->Initialize(aDatabaseFile);
nsresult rv = msc->initialize(aDatabaseFile);
NS_ENSURE_SUCCESS(rv, rv);
}
@ -241,7 +241,7 @@ NS_IMETHODIMP
Service::OpenUnsharedDatabase(nsIFile *aDatabaseFile,
mozIStorageConnection **_connection)
{
nsRefPtr<mozStorageConnection> msc = new mozStorageConnection(this);
nsRefPtr<Connection> msc = new Connection(this);
NS_ENSURE_TRUE(msc, NS_ERROR_OUT_OF_MEMORY);
// Initialize the connection, temporarily turning off shared caches so the
@ -257,7 +257,7 @@ Service::OpenUnsharedDatabase(nsIFile *aDatabaseFile,
if (rc != SQLITE_OK)
return ConvertResultCode(rc);
rv = msc->Initialize(aDatabaseFile);
rv = msc->initialize(aDatabaseFile);
rc = ::sqlite3_enable_shared_cache(1);
if (rc != SQLITE_OK)

View File

@ -193,7 +193,7 @@ mozStorageStatement::mozStorageStatement()
}
nsresult
mozStorageStatement::Initialize(mozStorageConnection *aDBConnection,
mozStorageStatement::Initialize(Connection *aDBConnection,
const nsACString & aSQLStatement)
{
NS_ASSERTION(aDBConnection, "No database connection given!");

View File

@ -48,14 +48,14 @@
#include <sqlite3.h>
class mozStorageConnection;
class nsIXPConnectJSObjectHolder;
namespace mozilla {
namespace storage {
class StatementJSHelper;
}
}
class Connection;
} // storage
} // mozilla
class mozStorageStatement : public mozIStorageStatement
{
@ -76,7 +76,7 @@ public:
* @param aSQLStatement
* The SQL statement to prepare that this object will represent.
*/
nsresult Initialize(mozStorageConnection *aDBConnection,
nsresult Initialize(mozilla::storage::Connection *aDBConnection,
const nsACString &aSQLStatement);
@ -89,7 +89,7 @@ private:
~mozStorageStatement();
protected:
nsRefPtr<mozStorageConnection> mDBConnection;
nsRefPtr<mozilla::storage::Connection> mDBConnection;
sqlite3_stmt *mDBStatement;
PRUint32 mParamCount;
PRUint32 mResultColumnCount;