LCOV - code coverage report
Current view: directory - dom/indexedDB - IDBKeyRange.h (source / functions) Found Hit Coverage
Test: app.info Lines: 52 52 100.0 %
Date: 2012-06-02 Functions: 15 15 100.0 %

       1                 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* vim: set ts=2 et sw=2 tw=80: */
       3                 : /* ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is Indexed Database.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * The Mozilla Foundation.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 2010
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *   Ben Turner <bent.mozilla@gmail.com>
      25                 :  *
      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.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #ifndef mozilla_dom_indexeddb_idbkeyrange_h__
      41                 : #define mozilla_dom_indexeddb_idbkeyrange_h__
      42                 : 
      43                 : #include "mozilla/dom/indexedDB/IndexedDatabase.h"
      44                 : #include "mozilla/dom/indexedDB/Key.h"
      45                 : 
      46                 : #include "nsIIDBKeyRange.h"
      47                 : 
      48                 : #include "nsCycleCollectionParticipant.h"
      49                 : 
      50                 : class mozIStorageStatement;
      51                 : 
      52                 : BEGIN_INDEXEDDB_NAMESPACE
      53                 : 
      54                 : class IDBKeyRange : public nsIIDBKeyRange
      55                 : {
      56                 : public:
      57               2 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
      58                 :   NS_DECL_NSIIDBKEYRANGE
      59            4194 :   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBKeyRange)
      60                 : 
      61                 :   static JSBool DefineConstructors(JSContext* aCx,
      62                 :                                    JSObject* aObject);
      63                 : 
      64                 :   static
      65                 :   nsresult FromJSVal(JSContext* aCx,
      66                 :                      const jsval& aVal,
      67                 :                      IDBKeyRange** aKeyRange);
      68                 : 
      69             374 :   IDBKeyRange(bool aLowerOpen, bool aUpperOpen, bool aIsOnly)
      70                 :   : mCachedLowerVal(JSVAL_VOID), mCachedUpperVal(JSVAL_VOID),
      71                 :     mLowerOpen(aLowerOpen), mUpperOpen(aUpperOpen), mIsOnly(aIsOnly),
      72             374 :     mHaveCachedLowerVal(false), mHaveCachedUpperVal(false), mRooted(false)
      73             374 :   { }
      74                 : 
      75             470 :   const Key& Lower() const
      76                 :   {
      77             470 :     return mLower;
      78                 :   }
      79                 : 
      80             590 :   Key& Lower()
      81                 :   {
      82             590 :     return mLower;
      83                 :   }
      84                 : 
      85             218 :   const Key& Upper() const
      86                 :   {
      87             218 :     return mIsOnly ? mLower : mUpper;
      88                 :   }
      89                 : 
      90             434 :   Key& Upper()
      91                 :   {
      92             434 :     return mIsOnly ? mLower : mUpper;
      93                 :   }
      94                 : 
      95             102 :   bool IsLowerOpen() const
      96                 :   {
      97             102 :     return mLowerOpen;
      98                 :   }
      99                 : 
     100             150 :   bool IsUpperOpen() const
     101                 :   {
     102             150 :     return mUpperOpen;
     103                 :   }
     104                 : 
     105             654 :   bool IsOnly() const
     106                 :   {
     107             654 :     return mIsOnly;
     108                 :   }
     109                 : 
     110             327 :   void GetBindingClause(const nsACString& aKeyColumnName,
     111                 :                         nsACString& _retval) const
     112                 :   {
     113             654 :     NS_NAMED_LITERAL_CSTRING(andStr, " AND ");
     114             654 :     NS_NAMED_LITERAL_CSTRING(spacecolon, " :");
     115             654 :     NS_NAMED_LITERAL_CSTRING(lowerKey, "lower_key");
     116                 : 
     117             327 :     if (IsOnly()) {
     118                 :       // Both keys are set and they're equal.
     119             492 :       _retval = andStr + aKeyColumnName + NS_LITERAL_CSTRING(" =") + spacecolon +
     120             246 :                 lowerKey;
     121                 :     }
     122                 :     else {
     123             162 :       nsCAutoString clause;
     124                 : 
     125              81 :       if (!Lower().IsUnset()) {
     126                 :         // Lower key is set.
     127              62 :         clause.Append(andStr + aKeyColumnName);
     128              62 :         clause.AppendLiteral(" >");
     129              62 :         if (!IsLowerOpen()) {
     130              40 :           clause.AppendLiteral("=");
     131                 :         }
     132              62 :         clause.Append(spacecolon + lowerKey);
     133                 :       }
     134                 : 
     135              81 :       if (!Upper().IsUnset()) {
     136                 :         // Upper key is set.
     137              56 :         clause.Append(andStr + aKeyColumnName);
     138              56 :         clause.AppendLiteral(" <");
     139              56 :         if (!IsUpperOpen()) {
     140              40 :           clause.AppendLiteral("=");
     141                 :         }
     142              56 :         clause.Append(spacecolon + NS_LITERAL_CSTRING("upper_key"));
     143                 :       }
     144                 : 
     145              81 :       _retval = clause;
     146                 :     }
     147             327 :   }
     148                 : 
     149             327 :   nsresult BindToStatement(mozIStorageStatement* aStatement) const
     150                 :   {
     151             654 :     NS_NAMED_LITERAL_CSTRING(lowerKey, "lower_key");
     152                 : 
     153             327 :     if (IsOnly()) {
     154             246 :       return Lower().BindToStatement(aStatement, lowerKey);
     155                 :     }
     156                 : 
     157                 :     nsresult rv;
     158                 : 
     159              81 :     if (!Lower().IsUnset()) {
     160              62 :       rv = Lower().BindToStatement(aStatement, lowerKey);
     161              62 :       NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
     162                 :     }
     163                 : 
     164              81 :     if (!Upper().IsUnset()) {
     165              56 :       rv = Upper().BindToStatement(aStatement, NS_LITERAL_CSTRING("upper_key"));
     166              56 :       NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
     167                 :     }
     168                 : 
     169              81 :     return NS_OK;
     170                 :   }
     171                 : 
     172                 : protected:
     173                 :   ~IDBKeyRange();
     174                 : 
     175                 :   Key mLower;
     176                 :   Key mUpper;
     177                 :   jsval mCachedLowerVal;
     178                 :   jsval mCachedUpperVal;
     179                 :   bool mLowerOpen;
     180                 :   bool mUpperOpen;
     181                 :   bool mIsOnly;
     182                 :   bool mHaveCachedLowerVal;
     183                 :   bool mHaveCachedUpperVal;
     184                 :   bool mRooted;
     185                 : };
     186                 : 
     187                 : END_INDEXEDDB_NAMESPACE
     188                 : 
     189                 : #endif // mozilla_dom_indexeddb_idbkeyrange_h__

Generated by: LCOV version 1.7