15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2010 Google Inc. All rights reserved.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met:
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1.  Redistributions of source code must retain the above copyright
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     notice, this list of conditions and the following disclaimer.
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2.  Redistributions in binary form must reproduce the above copyright
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     notice, this list of conditions and the following disclaimer in the
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     documentation and/or other materials provided with the distribution.
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef IDBObjectStore_h
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define IDBObjectStore_h
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "bindings/v8/Dictionary.h"
3053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "bindings/v8/ScriptWrappable.h"
3153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "bindings/v8/SerializedScriptValue.h"
3253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/indexeddb/IDBCursor.h"
3353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/indexeddb/IDBIndex.h"
3453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/indexeddb/IDBKey.h"
3553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/indexeddb/IDBKeyRange.h"
3653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/indexeddb/IDBMetadata.h"
3753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/indexeddb/IDBRequest.h"
3853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/indexeddb/IDBTransaction.h"
3953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "wtf/PassRefPtr.h"
4053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "wtf/RefCounted.h"
4153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "wtf/RefPtr.h"
4253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "wtf/text/WTFString.h"
435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace WebCore {
455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class DOMStringList;
475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class IDBAny;
48e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochclass ExceptionState;
495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class IDBObjectStore : public ScriptWrappable, public RefCounted<IDBObjectStore> {
515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public:
52926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    static PassRefPtr<IDBObjectStore> create(const IDBObjectStoreMetadata& metadata, IDBTransaction* transaction)
535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
54926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        return adoptRef(new IDBObjectStore(metadata, transaction));
555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    ~IDBObjectStore() { }
575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    // Implement the IDBObjectStore IDL
59926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    int64_t id() const { return m_metadata.id; }
605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    const String name() const { return m_metadata.name; }
615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    PassRefPtr<IDBAny> keyPathAny() const { return IDBAny::create(m_metadata.keyPath); }
625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    const IDBKeyPath keyPath() const { return m_metadata.keyPath; }
635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    PassRefPtr<DOMStringList> indexNames() const;
645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    PassRefPtr<IDBTransaction> transaction() const { return m_transaction; }
655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool autoIncrement() const { return m_metadata.autoIncrement; }
665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
67e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBRequest> openCursor(ScriptExecutionContext* context, PassRefPtr<IDBKeyRange> range, const String& direction, ExceptionState& es) { return openCursor(context, range, direction, IDBDatabaseBackendInterface::NormalTask, es); }
68e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBRequest> openCursor(ScriptExecutionContext*, const ScriptValue& key, const String& direction, ExceptionState&);
69e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBRequest> get(ScriptExecutionContext*, const ScriptValue& key, ExceptionState&);
70e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBRequest> get(ScriptExecutionContext*, PassRefPtr<IDBKeyRange>, ExceptionState&);
71e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBRequest> add(ScriptState*, ScriptValue&, const ScriptValue& key, ExceptionState&);
72e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBRequest> put(ScriptState*, ScriptValue&, const ScriptValue& key, ExceptionState&);
73e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBRequest> deleteFunction(ScriptExecutionContext*, PassRefPtr<IDBKeyRange>, ExceptionState&);
74e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBRequest> deleteFunction(ScriptExecutionContext*, const ScriptValue& key, ExceptionState&);
75e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBRequest> clear(ScriptExecutionContext*, ExceptionState&);
765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
77e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBIndex> createIndex(ScriptExecutionContext* context, const String& name, const String& keyPath, const Dictionary& options, ExceptionState& es) { return createIndex(context, name, IDBKeyPath(keyPath), options, es); }
78e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBIndex> createIndex(ScriptExecutionContext* context, const String& name, const Vector<String>& keyPath, const Dictionary& options, ExceptionState& es) { return createIndex(context, name, IDBKeyPath(keyPath), options, es); }
79e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBIndex> index(const String& name, ExceptionState&);
80e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    void deleteIndex(const String& name, ExceptionState&);
815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
82e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBRequest> count(ScriptExecutionContext*, PassRefPtr<IDBKeyRange>, ExceptionState&);
83e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBRequest> count(ScriptExecutionContext*, const ScriptValue& key, ExceptionState&);
845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
8553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    // Used by IDBCursor::update():
86e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBRequest> put(IDBDatabaseBackendInterface::PutMode, PassRefPtr<IDBAny> source, ScriptState*, ScriptValue&, PassRefPtr<IDBKey>, ExceptionState&);
8753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void markDeleted() { m_deleted = true; }
8953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)    bool isDeleted() const { return m_deleted; }
905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void transactionFinished();
915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    IDBObjectStoreMetadata metadata() const { return m_metadata; }
935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    void setMetadata(const IDBObjectStoreMetadata& metadata) { m_metadata = metadata; }
945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    typedef Vector<RefPtr<IDBKey> > IndexKeys;
965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    typedef HashMap<String, IndexKeys> IndexKeyMap;
975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
98926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    IDBDatabaseBackendInterface* backendDB() const;
99926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
1005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)private:
101926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    IDBObjectStore(const IDBObjectStoreMetadata&, IDBTransaction*);
1025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
103e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBRequest> openCursor(ScriptExecutionContext*, PassRefPtr<IDBKeyRange>, const String& direction, IDBDatabaseBackendInterface::TaskType, ExceptionState&);
104e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBIndex> createIndex(ScriptExecutionContext*, const String& name, const IDBKeyPath&, const Dictionary&, ExceptionState&);
105e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBIndex> createIndex(ScriptExecutionContext*, const String& name, const IDBKeyPath&, bool unique, bool multiEntry, ExceptionState&);
106e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch    PassRefPtr<IDBRequest> put(IDBDatabaseBackendInterface::PutMode, PassRefPtr<IDBAny> source, ScriptState*, ScriptValue&, const ScriptValue& key, ExceptionState&);
10753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
1085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    int64_t findIndexId(const String& name) const;
1095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool containsIndex(const String& name) const
1105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    {
1115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return findIndexId(name) != IDBIndexMetadata::InvalidId;
1125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
1135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    IDBObjectStoreMetadata m_metadata;
1155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    RefPtr<IDBTransaction> m_transaction;
1165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    bool m_deleted;
1175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    typedef HashMap<String, RefPtr<IDBIndex> > IDBIndexMap;
1195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    IDBIndexMap m_indexMap;
1205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
1215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} // namespace WebCore
1235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // IDBObjectStore_h
125