Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 Google Inc.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
   * use this file except in compliance with the License. You may obtain a copy of
   * the License at
   * 
   * http://www.apache.org/licenses/LICENSE-2.0
   * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  * License for the specific language governing permissions and limitations under
  * the License.
  */
 package elemental.html;
 
 import  elemental.html.*;
 
 import java.util.Date;

The IDBObjectStore interface of the IndexedDB API represents an object store in a database. Records within an object store are sorted according to their keys. This sorting enable fast insertion, look-up, and  ordered retrieval. 
 
 public interface IDBObjectStore {
 
   boolean isAutoIncrement();


  
A list of the names of indexes on objects in this object store.
 
The key path of this object store. If this attribute is null, the application must provide a key for each modification operation.
 
   Object getKeyPath();


  
The name of this object store.
 
   String getName();
 

Returns an IDBRequest object, and, in a separate thread, creates a structured clone of the value, and stores the cloned value in the object store. If the record is successfully stored, then a success event is fired on the returned request object, using the IDBTransactionEvent interface, with the result set to the key for the stored record, and transaction set to the transaction in which this object store is opened. If a record already exists in the object store with the key parameter as its key, then an error event is fired on the returned request object, with code set to CONSTRAINT_ERR.

Parameters
value
The value to be stored.
key
The key to use to identify the record. If unspecified, it results to null.
Returns
IDBRequest
A request object on which subsequent events related to this operation are fired.
Exceptions

This method can raise an IDBDatabaseException with the following codes:

DATA_ERR
If the object store uses in-line keys or has a key generator, and a key parameter was provided.
If the object store uses out-of-line keys and has no key generator, and no key parameter was provided.
If the object store uses in-line keys but no key generator, and the object store's key path does not yield a valid key.
If the key parameter was provided but does not contain a valid key.
If there are indexed on this object store, and using their key path on the value parameter yields a value that is not a valid key.
READ_ONLY_ERR
If the mode of the associated transaction is READ_ONLY.
TRANSACTION_INACTIVE_ERR
If the associated transaction is not active.

This method can raise a DOMException with the following code:

DATA_CLONE_ERR
If the data being stored could not be cloned by the internal structured cloning algorithm.
 
   IDBRequest add(Object value);


  

Returns an IDBRequest object, and, in a separate thread, creates a structured clone of the value, and stores the cloned value in the object store. If the record is successfully stored, then a success event is fired on the returned request object, using the IDBTransactionEvent interface, with the result set to the key for the stored record, and transaction set to the transaction in which this object store is opened. If a record already exists in the object store with the key parameter as its key, then an error event is fired on the returned request object, with code set to CONSTRAINT_ERR.

Parameters
value
The value to be stored.
key
The key to use to identify the record. If unspecified, it results to null.
Returns
IDBRequest
A request object on which subsequent events related to this operation are fired.
Exceptions

This method can raise an IDBDatabaseException with the following codes:

DATA_ERR
If the object store uses in-line keys or has a key generator, and a key parameter was provided.
If the object store uses out-of-line keys and has no key generator, and no key parameter was provided.
If the object store uses in-line keys but no key generator, and the object store's key path does not yield a valid key.
If the key parameter was provided but does not contain a valid key.
If there are indexed on this object store, and using their key path on the value parameter yields a value that is not a valid key.
READ_ONLY_ERR
If the mode of the associated transaction is READ_ONLY.
TRANSACTION_INACTIVE_ERR
If the associated transaction is not active.

This method can raise a DOMException with the following code:

DATA_CLONE_ERR
If the data being stored could not be cloned by the internal structured cloning algorithm.
 
  IDBRequest add(Object valueObject key);


  

If the mode of the transaction that this object store belongs to is READ_ONLY, this method raises an IDBDatabaseException with its code set to READ_ONLY_ERR. Otherwise, this method creates and immediately returns an IDBRequest object, and clears this object store in a separate thread. Clearing an object store consists of removing all records from the object store and removing all records in indexes that reference the object store.

Returns
IDBRequest
A request object on which subsequent events related to this operation are fired.
Exceptions

This method can raise an IDBDatabaseException with the following codes:

READ_ONLY_ERR
If the mode of the transaction that this object store belongs to is READ_ONLY.
TRANSACTION_INACTIVE_ERR
If the transaction that this object store belongs to is not active.
  IDBRequest clear();


  

Immediately returns an IDBRequest object and asynchronously count the amount of objects in the object store that match the parameter, a key or a key range. If the parameter is not valid returns an exception.

Parameters
key
The key or key range that identifies the records to be counted.
Returns
IDBRequest
A request object on which subsequent events related to this operation are fired.
Exceptions

This method can raise an IDBDatabaseException with the following codes:

DATA_ERR
If the object store uses in-line keys or has a key generator, and a key parameter was provided.
If the object store uses out-of-line keys and has no key generator, and no key parameter was provided.
If the object store uses in-line keys but no key generator, and the object store's key path does not yield a valid key.
If the key parameter was provided but does not contain a valid key.
If there are indexed on this object store, and using their key path on the value parameter yields a value that is not a valid key.
NOT_ALLOWED_ERR
The request was made on a source object that has been deleted or removed.
  IDBRequest count();


  

Immediately returns an IDBRequest object and asynchronously count the amount of objects in the object store that match the parameter, a key or a key range. If the parameter is not valid returns an exception.

Parameters
key
The key or key range that identifies the records to be counted.
Returns
IDBRequest
A request object on which subsequent events related to this operation are fired.
Exceptions

This method can raise an IDBDatabaseException with the following codes:

DATA_ERR
If the object store uses in-line keys or has a key generator, and a key parameter was provided.
If the object store uses out-of-line keys and has no key generator, and no key parameter was provided.
If the object store uses in-line keys but no key generator, and the object store's key path does not yield a valid key.
If the key parameter was provided but does not contain a valid key.
If there are indexed on this object store, and using their key path on the value parameter yields a value that is not a valid key.
NOT_ALLOWED_ERR
The request was made on a source object that has been deleted or removed.
  IDBRequest count(IDBKeyRange range);


  

Immediately returns an IDBRequest object and asynchronously count the amount of objects in the object store that match the parameter, a key or a key range. If the parameter is not valid returns an exception.

Parameters
key
The key or key range that identifies the records to be counted.
Returns
IDBRequest
A request object on which subsequent events related to this operation are fired.
Exceptions

This method can raise an IDBDatabaseException with the following codes:

DATA_ERR
If the object store uses in-line keys or has a key generator, and a key parameter was provided.
If the object store uses out-of-line keys and has no key generator, and no key parameter was provided.
If the object store uses in-line keys but no key generator, and the object store's key path does not yield a valid key.
If the key parameter was provided but does not contain a valid key.
If there are indexed on this object store, and using their key path on the value parameter yields a value that is not a valid key.
NOT_ALLOWED_ERR
The request was made on a source object that has been deleted or removed.
  IDBRequest count(Object key);


  

Creates and returns a new index in the connected database. Note that this method must be called only from a VERSION_CHANGE transaction callback.

IDBIndex createIndex (
  in DOMString name, 
  in DOMString keyPath, 
  in Object optionalParameters
) raises (IDBDatabaseException);

Parameters
name
The name of the index to create.
keyPath
The key path for the index to use.
optionalParameters
Warning: The latest draft of the specification changed this to IDBIndexParameters, which is not yet recognized by any browser

Options object whose attributes are optional parameters to the method. It includes the following properties:

AttributeDescription
uniqueIf true, the index will not allow duplicate values for a single key.
multientryIf true, the index will add an entry in the index for each array element when the keypath resolves to an Array. If false, it will add one single entry containing the Array.

Unknown parameters are ignored.

Returns
IDBIndex
The newly created index.
Exceptions

This method can raise an IDBDatabaseException with the following codes:

CONSTRAINT_ERR
If an index with the same name (based on case-sensitive comparison) already exists in the connected database.
NOT_ALLOWED_ERR
If this method was not called from a VERSION_CHANGE transaction callback.
  IDBIndex createIndex(String nameString keyPath);


  

Creates and returns a new index in the connected database. Note that this method must be called only from a VERSION_CHANGE transaction callback.

IDBIndex createIndex (
  in DOMString name, 
  in DOMString keyPath, 
  in Object optionalParameters
) raises (IDBDatabaseException);

Parameters
name
The name of the index to create.
keyPath
The key path for the index to use.
optionalParameters
Warning: The latest draft of the specification changed this to IDBIndexParameters, which is not yet recognized by any browser

Options object whose attributes are optional parameters to the method. It includes the following properties:

AttributeDescription
uniqueIf true, the index will not allow duplicate values for a single key.
multientryIf true, the index will add an entry in the index for each array element when the keypath resolves to an Array. If false, it will add one single entry containing the Array.

Unknown parameters are ignored.

Returns
IDBIndex
The newly created index.
Exceptions

This method can raise an IDBDatabaseException with the following codes:

CONSTRAINT_ERR
If an index with the same name (based on case-sensitive comparison) already exists in the connected database.
NOT_ALLOWED_ERR
If this method was not called from a VERSION_CHANGE transaction callback.
  IDBIndex createIndex(String nameString keyPathMappable options);


  

Immediately returns an IDBRequest object, and removes the record specified by the given key from this object store, and any indexes that reference it, in a separate thread. If no record exists in this object store corresponding to the key, an error event is fired on the returned request object, with its code set to NOT_FOUND_ERR and an appropriate message. If the record is successfully removed, then a success event is fired on the returned request object, using the IDBTransactionEvent interface, with the result set to undefined, and transaction set to the transaction in which this object store is opened.

IDBRequest delete (
in any key
) raises (IDBDatabaseException); 
Parameters
key
The key to use to identify the record.
Returns
IDBRequest
A request object on which subsequent events related to this operation are fired.
Exceptions

This method can raise an IDBDatabaseException with the following codes:

  IDBRequest _delete(IDBKeyRange keyRange);


  

Immediately returns an IDBRequest object, and removes the record specified by the given key from this object store, and any indexes that reference it, in a separate thread. If no record exists in this object store corresponding to the key, an error event is fired on the returned request object, with its code set to NOT_FOUND_ERR and an appropriate message. If the record is successfully removed, then a success event is fired on the returned request object, using the IDBTransactionEvent interface, with the result set to undefined, and transaction set to the transaction in which this object store is opened.

IDBRequest delete (
in any key
) raises (IDBDatabaseException); 
Parameters
key
The key to use to identify the record.
Returns
IDBRequest
A request object on which subsequent events related to this operation are fired.
Exceptions

This method can raise an IDBDatabaseException with the following codes:

  IDBRequest _delete(Object key);


  

Destroys the index with the specified name in the connected database. Note that this method must be called only from a VERSION_CHANGE transaction callback.

void removeIndex(
in DOMString indexName
) raises (IDBDatabaseException); 
Parameters

 

NOT_ALLOWED_ERR
If the object store is not in the scope of any existing transaction, or if the associated transaction's mode is READ_ONLY or SNAPSHOT_READ.
TRANSACTION_INACTIVE_ERR
If the associated transaction is not active.
indexName
The name of the existing index to remove.
Exceptions

This method can raise an IDBDatabaseException with the following codes:

NOT_ALLOWED_ERR
If this method was not called from a VERSION_CHANGE transaction callback.
NOT_FOUND_ERR
If no index exists with the specified name (based on case-sensitive comparison) in the connected database.
  void deleteIndex(String name);

Opens the named index in this object store.

Parameters
name
The name of the index to open.
Returns
IDBIndex
An object for accessing the index.
Exceptions

This method can raise an IDBDatabaseException with the following code:

NOT_FOUND_ERR
If no index exists with the specified name (based on case-sensitive comparison) in the connected database.
  IDBIndex index(String name);


  

Immediately returns an IDBRequest object, and creates a cursor over the records in this object store, in a separate thread. If there is even a single record that matches the key range, then a success event is fired on the returned object, with its result set to the IDBCursor object for the new cursor. If no records match the key range, then a success event is fired on the returned object, with its result set to null.

IDBRequest openCursor (
  in optional IDBKeyRange range, 
  in optional unsigned short direction
) raises (IDBDatabaseException);
Parameters
range
The key range to use as the cursor's range. If this parameter is unspecified or null, then the range includes all the records in the object store.
direction
The cursor's direction.
Returns
IDBRequest
A request object on which subsequent events related to this operation are fired.
Exceptions

This method can raise an IDBDatabaseException with the following code:

NOT_ALLOWED_ERR
If this object store is not in the scope of any existing transaction on the connected database.

Immediately returns an IDBRequest object, and creates a cursor over the records in this object store, in a separate thread. If there is even a single record that matches the key range, then a success event is fired on the returned object, with its result set to the IDBCursor object for the new cursor. If no records match the key range, then a success event is fired on the returned object, with its result set to null.

IDBRequest openCursor (
  in optional IDBKeyRange range, 
  in optional unsigned short direction
) raises (IDBDatabaseException);
Parameters
range
The key range to use as the cursor's range. If this parameter is unspecified or null, then the range includes all the records in the object store.
direction
The cursor's direction.
Returns
IDBRequest
A request object on which subsequent events related to this operation are fired.
Exceptions

This method can raise an IDBDatabaseException with the following code:

NOT_ALLOWED_ERR
If this object store is not in the scope of any existing transaction on the connected database.
  IDBRequest openCursor(IDBKeyRange rangeString direction);


  

Immediately returns an IDBRequest object, and creates a cursor over the records in this object store, in a separate thread. If there is even a single record that matches the key range, then a success event is fired on the returned object, with its result set to the IDBCursor object for the new cursor. If no records match the key range, then a success event is fired on the returned object, with its result set to null.

IDBRequest openCursor (
  in optional IDBKeyRange range, 
  in optional unsigned short direction
) raises (IDBDatabaseException);
Parameters
range
The key range to use as the cursor's range. If this parameter is unspecified or null, then the range includes all the records in the object store.
direction
The cursor's direction.
Returns
IDBRequest
A request object on which subsequent events related to this operation are fired.
Exceptions

This method can raise an IDBDatabaseException with the following code:

NOT_ALLOWED_ERR
If this object store is not in the scope of any existing transaction on the connected database.

Immediately returns an IDBRequest object, and creates a cursor over the records in this object store, in a separate thread. If there is even a single record that matches the key range, then a success event is fired on the returned object, with its result set to the IDBCursor object for the new cursor. If no records match the key range, then a success event is fired on the returned object, with its result set to null.

IDBRequest openCursor (
  in optional IDBKeyRange range, 
  in optional unsigned short direction
) raises (IDBDatabaseException);
Parameters
range
The key range to use as the cursor's range. If this parameter is unspecified or null, then the range includes all the records in the object store.
direction
The cursor's direction.
Returns
IDBRequest
A request object on which subsequent events related to this operation are fired.
Exceptions

This method can raise an IDBDatabaseException with the following code:

NOT_ALLOWED_ERR
If this object store is not in the scope of any existing transaction on the connected database.
  IDBRequest openCursor(Object keyString direction);


  

Immediately returns an IDBRequest object, and creates a cursor over the records in this object store, in a separate thread. If there is even a single record that matches the key range, then a success event is fired on the returned object, with its result set to the IDBCursor object for the new cursor. If no records match the key range, then a success event is fired on the returned object, with its result set to null.

IDBRequest openCursor (
  in optional IDBKeyRange range, 
  in optional unsigned short direction
) raises (IDBDatabaseException);
Parameters
range
The key range to use as the cursor's range. If this parameter is unspecified or null, then the range includes all the records in the object store.
direction
The cursor's direction.
Returns
IDBRequest
A request object on which subsequent events related to this operation are fired.
Exceptions

This method can raise an IDBDatabaseException with the following code:

NOT_ALLOWED_ERR
If this object store is not in the scope of any existing transaction on the connected database.
  IDBRequest openCursor(IDBKeyRange rangeint direction);


  

Immediately returns an IDBRequest object, and creates a cursor over the records in this object store, in a separate thread. If there is even a single record that matches the key range, then a success event is fired on the returned object, with its result set to the IDBCursor object for the new cursor. If no records match the key range, then a success event is fired on the returned object, with its result set to null.

IDBRequest openCursor (
  in optional IDBKeyRange range, 
  in optional unsigned short direction
) raises (IDBDatabaseException);
Parameters
range
The key range to use as the cursor's range. If this parameter is unspecified or null, then the range includes all the records in the object store.
direction
The cursor's direction.
Returns
IDBRequest
A request object on which subsequent events related to this operation are fired.
Exceptions

This method can raise an IDBDatabaseException with the following code:

NOT_ALLOWED_ERR
If this object store is not in the scope of any existing transaction on the connected database.
  IDBRequest openCursor(Object keyint direction);


  

Returns an IDBRequest object, and, in a separate thread, creates a structured clone of the value, and stores the cloned value in the object store. If the record is successfully stored, then a success event is fired on the returned request object, using the IDBTransactionEvent interface, with the result set to the key for the stored record, and transaction set to the transaction in which this object store is opened.

Parameters
value
The value to be stored.
key
The key to use to identify the record. If unspecified, it results to null.
Returns
IDBRequest
A request object on which subsequent events related to this operation are fired.
Exceptions

This method can raise an IDBDatabaseException with the following codes:

    • If this object store uses out-of-line keys and does not use a key generator, but the key parameter was not passed
    • If the object store uses in-line keys, but the value object does not have a property identified by the object store's key path.
  • NOT_ALLOWED_ERR
    If the object store is not in the scope of any existing transaction, or if the associated transaction's mode is READ_ONLY or SNAPSHOT_READ.
    SERIAL_ERR
    If the data being stored could not be serialized by the internal structured cloning algorithm.

    This method can raise a DOMException with the following code:

    DATA_CLONE_ERR
    If the data being stored could not be cloned by the internal structured cloning algorithm.
      IDBRequest put(Object value);


      

    Returns an IDBRequest object, and, in a separate thread, creates a structured clone of the value, and stores the cloned value in the object store. If the record is successfully stored, then a success event is fired on the returned request object, using the IDBTransactionEvent interface, with the result set to the key for the stored record, and transaction set to the transaction in which this object store is opened.

    Parameters
    value
    The value to be stored.
    key
    The key to use to identify the record. If unspecified, it results to null.
    Returns
    IDBRequest
    A request object on which subsequent events related to this operation are fired.
    Exceptions

    This method can raise an IDBDatabaseException with the following codes:

    • If this object store uses out-of-line keys and does not use a key generator, but the key parameter was not passed
    • If the object store uses in-line keys, but the value object does not have a property identified by the object store's key path.
  • NOT_ALLOWED_ERR
    If the object store is not in the scope of any existing transaction, or if the associated transaction's mode is READ_ONLY or SNAPSHOT_READ.
    SERIAL_ERR
    If the data being stored could not be serialized by the internal structured cloning algorithm.

    This method can raise a DOMException with the following code:

    DATA_CLONE_ERR
    If the data being stored could not be cloned by the internal structured cloning algorithm.
      IDBRequest put(Object valueObject key);
    New to GrepCode? Check out our FAQ X