1 /* 2 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef IDBIndexBackendImpl_h 27 #define IDBIndexBackendImpl_h 28 29 #if ENABLE(INDEXED_DATABASE) 30 31 #include "IDBCursorBackendInterface.h" 32 #include "IDBIndexBackendInterface.h" 33 34 namespace WebCore { 35 36 class IDBBackingStore; 37 class IDBKey; 38 class IDBObjectStoreBackendImpl; 39 class ScriptExecutionContext; 40 41 class IDBIndexBackendImpl : public IDBIndexBackendInterface { 42 public: create(IDBBackingStore * backingStore,int64_t databaseId,const IDBObjectStoreBackendImpl * objectStoreBackend,int64_t id,const String & name,const String & storeName,const String & keyPath,bool unique)43 static PassRefPtr<IDBIndexBackendImpl> create(IDBBackingStore* backingStore, int64_t databaseId, const IDBObjectStoreBackendImpl* objectStoreBackend, int64_t id, const String& name, const String& storeName, const String& keyPath, bool unique) 44 { 45 return adoptRef(new IDBIndexBackendImpl(backingStore, databaseId, objectStoreBackend, id, name, storeName, keyPath, unique)); 46 } create(IDBBackingStore * backingStore,int64_t databaseId,const IDBObjectStoreBackendImpl * objectStoreBackend,const String & name,const String & storeName,const String & keyPath,bool unique)47 static PassRefPtr<IDBIndexBackendImpl> create(IDBBackingStore* backingStore, int64_t databaseId, const IDBObjectStoreBackendImpl* objectStoreBackend, const String& name, const String& storeName, const String& keyPath, bool unique) 48 { 49 return adoptRef(new IDBIndexBackendImpl(backingStore, databaseId, objectStoreBackend, name, storeName, keyPath, unique)); 50 } 51 virtual ~IDBIndexBackendImpl(); 52 id()53 int64_t id() const 54 { 55 ASSERT(m_id != InvalidId); 56 return m_id; 57 } setId(int64_t id)58 void setId(int64_t id) { m_id = id; } hasValidId()59 bool hasValidId() const { return m_id != InvalidId; }; 60 61 bool addingKeyAllowed(IDBKey*); 62 63 // Implements IDBIndexBackendInterface. name()64 virtual String name() { return m_name; } storeName()65 virtual String storeName() { return m_storeName; } keyPath()66 virtual String keyPath() { return m_keyPath; } unique()67 virtual bool unique() { return m_unique; } 68 69 virtual void openCursor(PassRefPtr<IDBKeyRange>, unsigned short direction, PassRefPtr<IDBCallbacks>, IDBTransactionBackendInterface*, ExceptionCode&); 70 virtual void openKeyCursor(PassRefPtr<IDBKeyRange>, unsigned short direction, PassRefPtr<IDBCallbacks>, IDBTransactionBackendInterface*, ExceptionCode&); 71 virtual void get(PassRefPtr<IDBKey>, PassRefPtr<IDBCallbacks>, IDBTransactionBackendInterface*, ExceptionCode&); 72 virtual void getKey(PassRefPtr<IDBKey>, PassRefPtr<IDBCallbacks>, IDBTransactionBackendInterface*, ExceptionCode&); 73 74 private: 75 IDBIndexBackendImpl(IDBBackingStore*, int64_t databaseId, const IDBObjectStoreBackendImpl*, int64_t id, const String& name, const String& storeName, const String& keyPath, bool unique); 76 IDBIndexBackendImpl(IDBBackingStore*, int64_t databaseId, const IDBObjectStoreBackendImpl*, const String& name, const String& storeName, const String& keyPath, bool unique); 77 78 static void openCursorInternal(ScriptExecutionContext*, PassRefPtr<IDBIndexBackendImpl>, PassRefPtr<IDBKeyRange>, unsigned short direction, IDBCursorBackendInterface::CursorType, PassRefPtr<IDBCallbacks>, PassRefPtr<IDBTransactionBackendInterface>); 79 static void getInternal(ScriptExecutionContext*, PassRefPtr<IDBIndexBackendImpl>, PassRefPtr<IDBKey>, bool getObject, PassRefPtr<IDBCallbacks>); 80 81 static const int64_t InvalidId = 0; 82 83 RefPtr<IDBBackingStore> m_backingStore; 84 85 int64_t m_databaseId; 86 const IDBObjectStoreBackendImpl* m_objectStoreBackend; 87 int64_t m_id; 88 String m_name; 89 String m_storeName; 90 String m_keyPath; 91 bool m_unique; 92 }; 93 94 } // namespace WebCore 95 96 #endif 97 98 #endif // IDBIndexBackendImpl_h 99