Bug 481045. <svg:use> shouldn't paint its kids. r+sr=roc
[mozilla-central.git] / storage / src / mozStorageConnection.h
blobcc5ed6cdf27ab87d83d91be60848229ac1edc905
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Oracle Corporation code.
17 * The Initial Developer of the Original Code is
18 * Oracle Corporation
19 * Portions created by the Initial Developer are Copyright (C) 2004
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
24 * Lev Serebryakov <lev@serebryakov.spb.ru>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef _MOZSTORAGECONNECTION_H_
41 #define _MOZSTORAGECONNECTION_H_
43 #include "nsCOMPtr.h"
44 #include "nsAutoLock.h"
46 #include "nsString.h"
47 #include "nsInterfaceHashtable.h"
48 #include "mozIStorageProgressHandler.h"
49 #include "mozIStorageConnection.h"
51 #include "nsIMutableArray.h"
53 #include <sqlite3.h>
55 class nsIFile;
56 class nsIEventTarget;
57 class nsIThread;
58 class mozIStorageService;
60 class mozStorageConnection : public mozIStorageConnection
62 public:
64 mozStorageConnection(mozIStorageService* aService);
66 NS_IMETHOD Initialize(nsIFile *aDatabaseFile);
68 // interfaces
69 NS_DECL_ISUPPORTS
70 NS_DECL_MOZISTORAGECONNECTION
72 // fetch the native handle
73 sqlite3 *GetNativeConnection() { return mDBConn; }
75 /**
76 * Lazily creates and returns a background execution thread. In the future,
77 * the thread may be re-claimed if left idle, so you should call this
78 * method just before you dispatch and not save the reference.
80 * @returns an event target suitable for asynchronous statement execution.
82 already_AddRefed<nsIEventTarget> getAsyncExecutionTarget();
84 private:
85 ~mozStorageConnection();
87 protected:
88 struct FindFuncEnumArgs {
89 nsISupports *mTarget;
90 PRBool mFound;
93 /**
94 * Describes a certain primitive type in the database.
96 * Possible Values Are:
97 * INDEX - To check for the existence of an index
98 * TABLE - To check for the existence of a table
100 enum DatabaseElementType {
101 INDEX,
102 TABLE
106 * Determines if the specified primitive exists.
108 * @param aElementType
109 * The type of element to check the existence of
110 * @param aElementName
111 * The name of the element to check for
112 * @returns true if element exists, false otherwise
114 nsresult DatabaseElementExists(enum DatabaseElementType aElementType,
115 const nsACString& aElementName,
116 PRBool *_exists);
118 void HandleSqliteError(const char *aSqlStatement);
119 static PLDHashOperator s_FindFuncEnum(const nsACString &aKey,
120 nsISupports* aData, void* userArg);
121 PRBool FindFunctionByInstance(nsISupports *aInstance);
123 static int s_ProgressHelper(void *arg);
124 // Generic progress handler
125 // Dispatch call to registered progress handler,
126 // if there is one. Do nothing in other cases.
127 int ProgressHandler();
129 sqlite3 *mDBConn;
130 nsCOMPtr<nsIFile> mDatabaseFile;
133 * Protects access to mAsyncExecutionThread.
135 PRLock *mAsyncExecutionMutex;
138 * Lazily created thread for asynchronous statement execution. Consumers
139 * should use getAsyncExecutionTarget rather than directly accessing this
140 * field.
142 nsCOMPtr<nsIThread> mAsyncExecutionThread;
144 * Set to true by Close() prior to actually shutting down the thread. This
145 * lets getAsyncExecutionTarget() know not to hand out any more thread
146 * references (or to create the thread in the first place). This variable
147 * should be accessed while holding the mAsyncExecutionMutex.
149 PRBool mAsyncExecutionThreadShuttingDown;
151 PRLock *mTransactionMutex;
152 PRBool mTransactionInProgress;
154 PRLock *mFunctionsMutex;
155 nsInterfaceHashtable<nsCStringHashKey, nsISupports> mFunctions;
157 PRLock *mProgressHandlerMutex;
158 nsCOMPtr<mozIStorageProgressHandler> mProgressHandler;
160 // This isn't accessed but is used to make sure that the connections do
161 // not outlive the service. The service, for example, owns certain locks
162 // in mozStorageAsyncIO file that the connections depend on.
163 nsCOMPtr<mozIStorageService> mStorageService;
166 #endif /* _MOZSTORAGECONNECTION_H_ */