/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** * Class used to cache statements (mozIStorageStatement or * mozIStorageAsyncStatement).
*/ template <typename StatementType> class StatementCache { public: /** * Constructor for the cache. * * @note a connection can have more than one cache. * * @param aConnection * A reference to the nsCOMPtr for the connection this cache is to be * used for. This nsCOMPtr must at least live as long as this class, * otherwise crashes will happen.
*/ explicit StatementCache(nsCOMPtr<mozIStorageConnection>& aConnection)
: mConnection(aConnection) {}
/** * Obtains a cached statement. If this statement is not yet created, it will * be created and stored for later use. * * @param aQuery * The SQL string (either a const char [] or nsACString) to get a * cached query for. * @return the cached statement, or null upon error.
*/ inline already_AddRefed<StatementType> GetCachedStatement( const nsACString& aQuery) {
nsCOMPtr<StatementType> stmt; if (!mCachedStatements.Get(aQuery, getter_AddRefs(stmt))) {
stmt = CreateStatement(aQuery);
NS_ENSURE_TRUE(stmt, nullptr);
/** * Finalizes all cached statements so the database can be safely closed. The * behavior of this cache is unspecified after this method is called.
*/ inlinevoid FinalizeStatements() { for (constauto& data : mCachedStatements.Values()) {
(void)data->Finalize();
}
// Clear the cache at this time too!
(void)mCachedStatements.Clear();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.