1 | /* |
2 | * Copyright (C) 2015 Apple 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 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "IDBCursorInfo.h" |
28 | |
29 | #if ENABLE(INDEXED_DATABASE) |
30 | |
31 | #include "IDBDatabase.h" |
32 | #include "IDBTransaction.h" |
33 | #include "IndexedDB.h" |
34 | #include <wtf/text/StringConcatenateNumbers.h> |
35 | |
36 | namespace WebCore { |
37 | |
38 | IDBCursorInfo IDBCursorInfo::objectStoreCursor(IDBTransaction& transaction, uint64_t objectStoreIdentifier, const IDBKeyRangeData& range, IndexedDB::CursorDirection direction, IndexedDB::CursorType type) |
39 | { |
40 | return { transaction, objectStoreIdentifier, range, direction, type }; |
41 | } |
42 | |
43 | IDBCursorInfo IDBCursorInfo::indexCursor(IDBTransaction& transaction, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const IDBKeyRangeData& range, IndexedDB::CursorDirection direction, IndexedDB::CursorType type) |
44 | { |
45 | return { transaction, objectStoreIdentifier, indexIdentifier, range, direction, type }; |
46 | } |
47 | |
48 | IDBCursorInfo::IDBCursorInfo() |
49 | { |
50 | } |
51 | |
52 | IDBCursorInfo::IDBCursorInfo(IDBTransaction& transaction, uint64_t objectStoreIdentifier, const IDBKeyRangeData& range, IndexedDB::CursorDirection direction, IndexedDB::CursorType type) |
53 | : m_cursorIdentifier(transaction.database().connectionProxy()) |
54 | , m_transactionIdentifier(transaction.info().identifier()) |
55 | , m_objectStoreIdentifier(objectStoreIdentifier) |
56 | , m_sourceIdentifier(objectStoreIdentifier) |
57 | , m_range(range) |
58 | , m_source(IndexedDB::CursorSource::ObjectStore) |
59 | , m_direction(direction) |
60 | , m_type(type) |
61 | { |
62 | } |
63 | |
64 | IDBCursorInfo::IDBCursorInfo(IDBTransaction& transaction, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const IDBKeyRangeData& range, IndexedDB::CursorDirection direction, IndexedDB::CursorType type) |
65 | : m_cursorIdentifier(transaction.database().connectionProxy()) |
66 | , m_transactionIdentifier(transaction.info().identifier()) |
67 | , m_objectStoreIdentifier(objectStoreIdentifier) |
68 | , m_sourceIdentifier(indexIdentifier) |
69 | , m_range(range) |
70 | , m_source(IndexedDB::CursorSource::Index) |
71 | , m_direction(direction) |
72 | , m_type(type) |
73 | { |
74 | } |
75 | |
76 | IDBCursorInfo::IDBCursorInfo(const IDBResourceIdentifier& cursorIdentifier, const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreIdentifier, uint64_t sourceIdentifier, const IDBKeyRangeData& range, IndexedDB::CursorSource source, IndexedDB::CursorDirection direction, IndexedDB::CursorType type) |
77 | : m_cursorIdentifier(cursorIdentifier) |
78 | , m_transactionIdentifier(transactionIdentifier) |
79 | , m_objectStoreIdentifier(objectStoreIdentifier) |
80 | , m_sourceIdentifier(sourceIdentifier) |
81 | , m_range(range) |
82 | , m_source(source) |
83 | , m_direction(direction) |
84 | , m_type(type) |
85 | { |
86 | } |
87 | |
88 | bool IDBCursorInfo::isDirectionForward() const |
89 | { |
90 | return m_direction == IndexedDB::CursorDirection::Next || m_direction == IndexedDB::CursorDirection::Nextunique; |
91 | } |
92 | |
93 | CursorDuplicity IDBCursorInfo::duplicity() const |
94 | { |
95 | return m_direction == IndexedDB::CursorDirection::Nextunique || m_direction == IndexedDB::CursorDirection::Prevunique ? CursorDuplicity::NoDuplicates : CursorDuplicity::Duplicates; |
96 | } |
97 | |
98 | IDBCursorInfo IDBCursorInfo::isolatedCopy() const |
99 | { |
100 | return { m_cursorIdentifier.isolatedCopy(), m_transactionIdentifier.isolatedCopy(), m_objectStoreIdentifier, m_sourceIdentifier, m_range.isolatedCopy(), m_source, m_direction, m_type }; |
101 | } |
102 | |
103 | #if !LOG_DISABLED |
104 | |
105 | String IDBCursorInfo::loggingString() const |
106 | { |
107 | if (m_source == IndexedDB::CursorSource::Index) |
108 | return makeString("<Crsr: " , m_cursorIdentifier.loggingString(), " Idx " , m_sourceIdentifier, ", OS " , m_objectStoreIdentifier, ", tx " , m_transactionIdentifier.loggingString(), '>'); |
109 | |
110 | return makeString("<Crsr: " , m_cursorIdentifier.loggingString(), " OS " , m_objectStoreIdentifier, ", tx " , m_transactionIdentifier.loggingString(), '>'); |
111 | } |
112 | |
113 | #endif |
114 | |
115 | } // namespace WebCore |
116 | |
117 | #endif // ENABLE(INDEXED_DATABASE) |
118 | |