OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } | 53 } |
54 | 54 |
55 IDBIndex::~IDBIndex() | 55 IDBIndex::~IDBIndex() |
56 { | 56 { |
57 } | 57 } |
58 | 58 |
59 PassRefPtr<IDBRequest> IDBIndex::openCursor(ScriptExecutionContext* context, Pas
sRefPtr<IDBKeyRange> keyRange, const String& directionString, ExceptionState& es
) | 59 PassRefPtr<IDBRequest> IDBIndex::openCursor(ScriptExecutionContext* context, Pas
sRefPtr<IDBKeyRange> keyRange, const String& directionString, ExceptionState& es
) |
60 { | 60 { |
61 IDB_TRACE("IDBIndex::openCursor"); | 61 IDB_TRACE("IDBIndex::openCursor"); |
62 if (isDeleted()) { | 62 if (isDeleted()) { |
63 es.throwDOMException(InvalidStateError); | 63 es.throwDOMException(InvalidStateError, IDBDatabase::indexDeletedErrorMe
ssage); |
| 64 return 0; |
| 65 } |
| 66 if (m_transaction->isFinished()) { |
| 67 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF
inishedErrorMessage); |
64 return 0; | 68 return 0; |
65 } | 69 } |
66 if (!m_transaction->isActive()) { | 70 if (!m_transaction->isActive()) { |
67 es.throwDOMException(TransactionInactiveError); | 71 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI
nactiveErrorMessage); |
68 return 0; | 72 return 0; |
69 } | 73 } |
70 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio
nString, es); | 74 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio
nString, es); |
71 if (es.hadException()) | 75 if (es.hadException()) |
72 return 0; | 76 return 0; |
73 | 77 |
74 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 78 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
75 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); | 79 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); |
76 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, false, IDBDatabaseBackendInterface::NormalTask, reques
t); | 80 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, false, IDBDatabaseBackendInterface::NormalTask, reques
t); |
77 return request; | 81 return request; |
78 } | 82 } |
79 | 83 |
80 PassRefPtr<IDBRequest> IDBIndex::openCursor(ScriptExecutionContext* context, con
st ScriptValue& key, const String& direction, ExceptionState& es) | 84 PassRefPtr<IDBRequest> IDBIndex::openCursor(ScriptExecutionContext* context, con
st ScriptValue& key, const String& direction, ExceptionState& es) |
81 { | 85 { |
82 IDB_TRACE("IDBIndex::openCursor"); | 86 IDB_TRACE("IDBIndex::openCursor"); |
83 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); | 87 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); |
84 if (es.hadException()) | 88 if (es.hadException()) |
85 return 0; | 89 return 0; |
86 return openCursor(context, keyRange.release(), direction, es); | 90 return openCursor(context, keyRange.release(), direction, es); |
87 } | 91 } |
88 | 92 |
89 PassRefPtr<IDBRequest> IDBIndex::count(ScriptExecutionContext* context, PassRefP
tr<IDBKeyRange> keyRange, ExceptionState& es) | 93 PassRefPtr<IDBRequest> IDBIndex::count(ScriptExecutionContext* context, PassRefP
tr<IDBKeyRange> keyRange, ExceptionState& es) |
90 { | 94 { |
91 IDB_TRACE("IDBIndex::count"); | 95 IDB_TRACE("IDBIndex::count"); |
92 if (isDeleted()) { | 96 if (isDeleted()) { |
93 es.throwDOMException(InvalidStateError); | 97 es.throwDOMException(InvalidStateError, IDBDatabase::indexDeletedErrorMe
ssage); |
| 98 return 0; |
| 99 } |
| 100 if (m_transaction->isFinished()) { |
| 101 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF
inishedErrorMessage); |
94 return 0; | 102 return 0; |
95 } | 103 } |
96 if (!m_transaction->isActive()) { | 104 if (!m_transaction->isActive()) { |
97 es.throwDOMException(TransactionInactiveError); | 105 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI
nactiveErrorMessage); |
98 return 0; | 106 return 0; |
99 } | 107 } |
100 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 108 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
101 backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange, request); | 109 backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange, request); |
102 return request; | 110 return request; |
103 } | 111 } |
104 | 112 |
105 PassRefPtr<IDBRequest> IDBIndex::count(ScriptExecutionContext* context, const Sc
riptValue& key, ExceptionState& es) | 113 PassRefPtr<IDBRequest> IDBIndex::count(ScriptExecutionContext* context, const Sc
riptValue& key, ExceptionState& es) |
106 { | 114 { |
107 IDB_TRACE("IDBIndex::count"); | 115 IDB_TRACE("IDBIndex::count"); |
108 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); | 116 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); |
109 if (es.hadException()) | 117 if (es.hadException()) |
110 return 0; | 118 return 0; |
111 return count(context, keyRange.release(), es); | 119 return count(context, keyRange.release(), es); |
112 } | 120 } |
113 | 121 |
114 PassRefPtr<IDBRequest> IDBIndex::openKeyCursor(ScriptExecutionContext* context,
PassRefPtr<IDBKeyRange> keyRange, const String& directionString, ExceptionState&
es) | 122 PassRefPtr<IDBRequest> IDBIndex::openKeyCursor(ScriptExecutionContext* context,
PassRefPtr<IDBKeyRange> keyRange, const String& directionString, ExceptionState&
es) |
115 { | 123 { |
116 IDB_TRACE("IDBIndex::openKeyCursor"); | 124 IDB_TRACE("IDBIndex::openKeyCursor"); |
117 if (isDeleted()) { | 125 if (isDeleted()) { |
118 es.throwDOMException(InvalidStateError); | 126 es.throwDOMException(InvalidStateError, IDBDatabase::indexDeletedErrorMe
ssage); |
| 127 return 0; |
| 128 } |
| 129 if (m_transaction->isFinished()) { |
| 130 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF
inishedErrorMessage); |
119 return 0; | 131 return 0; |
120 } | 132 } |
121 if (!m_transaction->isActive()) { | 133 if (!m_transaction->isActive()) { |
122 es.throwDOMException(TransactionInactiveError); | 134 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI
nactiveErrorMessage); |
123 return 0; | 135 return 0; |
124 } | 136 } |
125 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio
nString, es); | 137 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio
nString, es); |
126 if (es.hadException()) | 138 if (es.hadException()) |
127 return 0; | 139 return 0; |
128 | 140 |
129 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 141 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
130 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); | 142 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); |
131 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, true, IDBDatabaseBackendInterface::NormalTask, request
); | 143 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, true, IDBDatabaseBackendInterface::NormalTask, request
); |
132 return request; | 144 return request; |
(...skipping 14 matching lines...) Expand all Loading... |
147 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); | 159 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); |
148 if (es.hadException()) | 160 if (es.hadException()) |
149 return 0; | 161 return 0; |
150 return get(context, keyRange.release(), es); | 162 return get(context, keyRange.release(), es); |
151 } | 163 } |
152 | 164 |
153 PassRefPtr<IDBRequest> IDBIndex::get(ScriptExecutionContext* context, PassRefPtr
<IDBKeyRange> keyRange, ExceptionState& es) | 165 PassRefPtr<IDBRequest> IDBIndex::get(ScriptExecutionContext* context, PassRefPtr
<IDBKeyRange> keyRange, ExceptionState& es) |
154 { | 166 { |
155 IDB_TRACE("IDBIndex::get"); | 167 IDB_TRACE("IDBIndex::get"); |
156 if (isDeleted()) { | 168 if (isDeleted()) { |
157 es.throwDOMException(InvalidStateError); | 169 es.throwDOMException(InvalidStateError, IDBDatabase::indexDeletedErrorMe
ssage); |
| 170 return 0; |
| 171 } |
| 172 if (m_transaction->isFinished()) { |
| 173 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF
inishedErrorMessage); |
158 return 0; | 174 return 0; |
159 } | 175 } |
160 if (!m_transaction->isActive()) { | 176 if (!m_transaction->isActive()) { |
161 es.throwDOMException(TransactionInactiveError); | 177 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI
nactiveErrorMessage); |
162 return 0; | 178 return 0; |
163 } | 179 } |
164 if (!keyRange) { | 180 if (!keyRange) { |
165 es.throwDOMException(DataError); | 181 es.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage
); |
166 return 0; | 182 return 0; |
167 } | 183 } |
168 | 184 |
169 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 185 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
170 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange, false, request); | 186 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange, false, request); |
171 return request; | 187 return request; |
172 } | 188 } |
173 | 189 |
174 PassRefPtr<IDBRequest> IDBIndex::getKey(ScriptExecutionContext* context, const S
criptValue& key, ExceptionState& es) | 190 PassRefPtr<IDBRequest> IDBIndex::getKey(ScriptExecutionContext* context, const S
criptValue& key, ExceptionState& es) |
175 { | 191 { |
176 IDB_TRACE("IDBIndex::getKey"); | 192 IDB_TRACE("IDBIndex::getKey"); |
177 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); | 193 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); |
178 if (es.hadException()) | 194 if (es.hadException()) |
179 return 0; | 195 return 0; |
180 | 196 |
181 return getKey(context, keyRange.release(), es); | 197 return getKey(context, keyRange.release(), es); |
182 } | 198 } |
183 | 199 |
184 PassRefPtr<IDBRequest> IDBIndex::getKey(ScriptExecutionContext* context, PassRef
Ptr<IDBKeyRange> keyRange, ExceptionState& es) | 200 PassRefPtr<IDBRequest> IDBIndex::getKey(ScriptExecutionContext* context, PassRef
Ptr<IDBKeyRange> keyRange, ExceptionState& es) |
185 { | 201 { |
186 IDB_TRACE("IDBIndex::getKey"); | 202 IDB_TRACE("IDBIndex::getKey"); |
187 if (isDeleted()) { | 203 if (isDeleted()) { |
188 es.throwDOMException(InvalidStateError); | 204 es.throwDOMException(InvalidStateError, IDBDatabase::indexDeletedErrorMe
ssage); |
| 205 return 0; |
| 206 } |
| 207 if (m_transaction->isFinished()) { |
| 208 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF
inishedErrorMessage); |
189 return 0; | 209 return 0; |
190 } | 210 } |
191 if (!m_transaction->isActive()) { | 211 if (!m_transaction->isActive()) { |
192 es.throwDOMException(TransactionInactiveError); | 212 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI
nactiveErrorMessage); |
193 return 0; | 213 return 0; |
194 } | 214 } |
195 if (!keyRange) { | 215 if (!keyRange) { |
196 es.throwDOMException(DataError); | 216 es.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage
); |
197 return 0; | 217 return 0; |
198 } | 218 } |
199 | 219 |
200 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 220 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
201 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange, true, request); | 221 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange, true, request); |
202 return request; | 222 return request; |
203 } | 223 } |
204 | 224 |
205 IDBDatabaseBackendInterface* IDBIndex::backendDB() const | 225 IDBDatabaseBackendInterface* IDBIndex::backendDB() const |
206 { | 226 { |
207 return m_transaction->backendDB(); | 227 return m_transaction->backendDB(); |
208 } | 228 } |
209 | 229 |
210 bool IDBIndex::isDeleted() const | 230 bool IDBIndex::isDeleted() const |
211 { | 231 { |
212 return m_deleted || m_objectStore->isDeleted(); | 232 return m_deleted || m_objectStore->isDeleted(); |
213 } | 233 } |
214 | 234 |
215 } // namespace WebCore | 235 } // namespace WebCore |
OLD | NEW |