michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozStorageBindingParams_h michael@0: #define mozStorageBindingParams_h michael@0: michael@0: #include "nsCOMArray.h" michael@0: #include "nsIVariant.h" michael@0: #include "nsInterfaceHashtable.h" michael@0: michael@0: #include "mozStorageBindingParamsArray.h" michael@0: #include "mozStorageStatement.h" michael@0: #include "mozStorageAsyncStatement.h" michael@0: michael@0: #include "mozIStorageBindingParams.h" michael@0: #include "IStorageBindingParamsInternal.h" michael@0: michael@0: namespace mozilla { michael@0: namespace storage { michael@0: michael@0: class BindingParams : public mozIStorageBindingParams michael@0: , public IStorageBindingParamsInternal michael@0: { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_MOZISTORAGEBINDINGPARAMS michael@0: NS_DECL_ISTORAGEBINDINGPARAMSINTERNAL michael@0: michael@0: /** michael@0: * Locks the parameters and prevents further modification to it (such as michael@0: * binding more elements to it). michael@0: */ michael@0: void lock(); michael@0: michael@0: /** michael@0: * Unlocks the parameters and allows modification to it again. michael@0: * michael@0: * @param aOwningStatement michael@0: * The statement that owns us. We cleared this when we were locked, michael@0: * and our invariant requires us to have this, so you need to tell us michael@0: * again. michael@0: */ michael@0: void unlock(Statement *aOwningStatement); michael@0: michael@0: /** michael@0: * @returns the pointer to the owning BindingParamsArray. Used by a michael@0: * BindingParamsArray to verify that we belong to it when added. michael@0: */ michael@0: const mozIStorageBindingParamsArray *getOwner() const; michael@0: michael@0: BindingParams(mozIStorageBindingParamsArray *aOwningArray, michael@0: Statement *aOwningStatement); michael@0: virtual ~BindingParams() {} michael@0: michael@0: protected: michael@0: BindingParams(mozIStorageBindingParamsArray *aOwningArray); michael@0: nsCOMArray mParameters; michael@0: bool mLocked; michael@0: michael@0: private: michael@0: michael@0: /** michael@0: * Track the BindingParamsArray that created us until we are added to it. michael@0: * (Once we are added we are locked and no one needs to look up our owner.) michael@0: * Ref-counted since there is no invariant that guarantees it stays alive michael@0: * otherwise. This keeps mOwningStatement alive for us too since the array michael@0: * also holds a reference. michael@0: */ michael@0: nsCOMPtr mOwningArray; michael@0: /** michael@0: * Used in the synchronous binding case to map parameter names to indices. michael@0: * Not reference-counted because this is only non-null as long as mOwningArray michael@0: * is non-null and mOwningArray also holds a statement reference. michael@0: */ michael@0: Statement *mOwningStatement; michael@0: uint32_t mParamCount; michael@0: }; michael@0: michael@0: /** michael@0: * Adds late resolution of named parameters so they don't get resolved until we michael@0: * try and bind the parameters on the async thread. We also stop checking michael@0: * parameter indices for being too big since we just just don't know how many michael@0: * there are. michael@0: * michael@0: * We support *either* binding by name or binding by index. Trying to do both michael@0: * results in only binding by name at sqlite3_stmt bind time. michael@0: */ michael@0: class AsyncBindingParams : public BindingParams michael@0: { michael@0: public: michael@0: NS_IMETHOD BindByName(const nsACString & aName, michael@0: nsIVariant *aValue); michael@0: NS_IMETHOD BindByIndex(uint32_t aIndex, nsIVariant *aValue); michael@0: michael@0: virtual already_AddRefed bind(sqlite3_stmt * aStatement); michael@0: michael@0: AsyncBindingParams(mozIStorageBindingParamsArray *aOwningArray); michael@0: virtual ~AsyncBindingParams() {} michael@0: michael@0: private: michael@0: nsInterfaceHashtable mNamedParameters; michael@0: michael@0: struct NamedParameterIterationClosureThunk michael@0: { michael@0: AsyncBindingParams *self; michael@0: sqlite3_stmt *statement; michael@0: nsCOMPtr err; michael@0: }; michael@0: michael@0: static PLDHashOperator iterateOverNamedParameters(const nsACString &aName, michael@0: nsIVariant *aValue, michael@0: void *voidClosureThunk); michael@0: }; michael@0: michael@0: } // namespace storage michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozStorageBindingParams_h