Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / indexeddb / IDBObjectStore.h
1 /*
2  * Copyright (C) 2010 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 IDBObjectStore_h
27 #define IDBObjectStore_h
28
29 #include "bindings/core/v8/ScriptWrappable.h"
30 #include "bindings/core/v8/SerializedScriptValue.h"
31 #include "modules/indexeddb/IDBCursor.h"
32 #include "modules/indexeddb/IDBIndex.h"
33 #include "modules/indexeddb/IDBIndexParameters.h"
34 #include "modules/indexeddb/IDBKey.h"
35 #include "modules/indexeddb/IDBKeyRange.h"
36 #include "modules/indexeddb/IDBMetadata.h"
37 #include "modules/indexeddb/IDBRequest.h"
38 #include "modules/indexeddb/IDBTransaction.h"
39 #include "public/platform/WebIDBCursor.h"
40 #include "public/platform/WebIDBDatabase.h"
41 #include "public/platform/WebIDBTypes.h"
42 #include "wtf/PassRefPtr.h"
43 #include "wtf/RefPtr.h"
44 #include "wtf/text/WTFString.h"
45
46 namespace blink {
47
48 class DOMStringList;
49 class IDBAny;
50 class ExceptionState;
51
52 class IDBObjectStore : public GarbageCollectedFinalized<IDBObjectStore>, public ScriptWrappable {
53     DEFINE_WRAPPERTYPEINFO();
54 public:
55     static IDBObjectStore* create(const IDBObjectStoreMetadata& metadata, IDBTransaction* transaction)
56     {
57         return new IDBObjectStore(metadata, transaction);
58     }
59     ~IDBObjectStore() { }
60     void trace(Visitor*);
61
62     // Implement the IDBObjectStore IDL
63     int64_t id() const { return m_metadata.id; }
64     const String& name() const { return m_metadata.name; }
65     ScriptValue keyPath(ScriptState*) const;
66     PassRefPtrWillBeRawPtr<DOMStringList> indexNames() const;
67     IDBTransaction* transaction() const { return m_transaction.get(); }
68     bool autoIncrement() const { return m_metadata.autoIncrement; }
69
70     IDBRequest* openCursor(ScriptState*, const ScriptValue& range, const String& direction, ExceptionState&);
71     IDBRequest* openKeyCursor(ScriptState*, const ScriptValue& range, const String& direction, ExceptionState&);
72     IDBRequest* get(ScriptState*, const ScriptValue& key, ExceptionState&);
73     IDBRequest* add(ScriptState*, const ScriptValue&, const ScriptValue& key, ExceptionState&);
74     IDBRequest* put(ScriptState*, const ScriptValue&, const ScriptValue& key, ExceptionState&);
75     IDBRequest* deleteFunction(ScriptState*, const ScriptValue& key, ExceptionState&);
76     IDBRequest* clear(ScriptState*, ExceptionState&);
77
78     IDBIndex* createIndex(ScriptState* scriptState, const String& name, const String& keyPath, const IDBIndexParameters& options, ExceptionState& exceptionState)
79     {
80         return createIndex(scriptState, name, IDBKeyPath(keyPath), options, exceptionState);
81     }
82     IDBIndex* createIndex(ScriptState* scriptState, const String& name, const Vector<String>& keyPath, const IDBIndexParameters& options, ExceptionState& exceptionState)
83     {
84         return createIndex(scriptState, name, IDBKeyPath(keyPath), options, exceptionState);
85     }
86     IDBIndex* index(const String& name, ExceptionState&);
87     void deleteIndex(const String& name, ExceptionState&);
88
89     IDBRequest* count(ScriptState*, const ScriptValue& range, ExceptionState&);
90
91     // Used by IDBCursor::update():
92     IDBRequest* put(ScriptState*, WebIDBPutMode, IDBAny* source, const ScriptValue&, IDBKey*, ExceptionState&);
93
94     // Used internally and by InspectorIndexedDBAgent:
95     IDBRequest* openCursor(ScriptState*, IDBKeyRange*, WebIDBCursorDirection, WebIDBTaskType = WebIDBTaskTypeNormal);
96
97     void markDeleted() { m_deleted = true; }
98     bool isDeleted() const { return m_deleted; }
99     void transactionFinished();
100
101     const IDBObjectStoreMetadata& metadata() const { return m_metadata; }
102     void setMetadata(const IDBObjectStoreMetadata& metadata) { m_metadata = metadata; }
103
104     typedef HeapVector<Member<IDBKey> > IndexKeys;
105
106     WebIDBDatabase* backendDB() const;
107
108 private:
109     IDBObjectStore(const IDBObjectStoreMetadata&, IDBTransaction*);
110
111     IDBIndex* createIndex(ScriptState*, const String& name, const IDBKeyPath&, const IDBIndexParameters&, ExceptionState&);
112     IDBRequest* put(ScriptState*, WebIDBPutMode, IDBAny* source, const ScriptValue&, const ScriptValue& key, ExceptionState&);
113
114     int64_t findIndexId(const String& name) const;
115     bool containsIndex(const String& name) const
116     {
117         return findIndexId(name) != IDBIndexMetadata::InvalidId;
118     }
119
120     IDBObjectStoreMetadata m_metadata;
121     Member<IDBTransaction> m_transaction;
122     bool m_deleted;
123
124     typedef HeapHashMap<String, Member<IDBIndex> > IDBIndexMap;
125     IDBIndexMap m_indexMap;
126 };
127
128 } // namespace blink
129
130 #endif // IDBObjectStore_h