StoredMap (Oracle Corporation - Berkeley DB Java API)
Keywords: com.sleepycat.collections.StoredMap class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Berkeley DB version 4.5.20
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.sleepycat.collections
Class StoredMap

    java.lang.Object
      com.sleepycat.collections.StoredContainer
          com.sleepycat.collections.StoredMap

All Implemented Interfaces:
  Cloneable, Map

Direct Known Subclasses:
  StoredSortedMap

    public class StoredMap

extends StoredContainer
implements Map

A Map view of a `Database`.

In addition to the standard Map methods, this class provides the following methods for stored maps only. Note that the use of these methods is not compatible with the standard Java collections interface.

- `duplicates(java.lang.Object)`
- `duplicatesMap(java.lang.Object, com.sleepycat.bind.EntryBinding)`
- `append(java.lang.Object)`

Nested Class Summary

Nested classes/interfaces inherited from interface java.util.Map
`Map.Entry`

Constructor Summary
`StoredMap(Database database, EntryBinding keyBinding, EntityBinding valueEntityBinding, boolean writeAllowed)` Creates a map entity view of a `Database`.
`StoredMap(Database database, EntryBinding keyBinding, EntityBinding valueEntityBinding, PrimaryKeyAssigner keyAssigner)` Creates a map entity view of a `Database` with a `PrimaryKeyAssigner`.
`StoredMap(Database database, EntryBinding keyBinding, EntryBinding valueBinding, boolean writeAllowed)` Creates a map view of a `Database`.
`StoredMap(Database database, EntryBinding keyBinding, EntryBinding valueBinding, PrimaryKeyAssigner keyAssigner)` Creates a map view of a `Database` with a `PrimaryKeyAssigner`.

Method Summary
`Object` | `append(Object value)` Appends a given value returning the newly assigned key.
`boolean` | `containsKey(Object key)` Returns true if this map contains the specified key.
`boolean` | `containsValue(Object value)` Returns true if this map contains the specified value.
`Collection` | `duplicates(Object key)` Returns a new collection containing the values mapped to the given key in this map.
`Map` | `duplicatesMap(Object secondaryKey, EntryBinding primaryKeyBinding)` Returns a new map from primary key to value for the subset of records having a given secondary key (duplicates).
`Set` | `entrySet()` Returns a set view of the mappings contained in this map.
`boolean` | `equals(Object other)` Compares the specified object with this map for equality.
`Object` | `get(Object key)` Returns the value to which this map maps the specified key.
`int` | `hashCode()`
`Set` | `keySet()` Returns a set view of the keys contained in this map.
`Object` | `put(Object key, Object value)` Associates the specified value with the specified key in this map (optional operation).
`void` | `putAll(Map map)` Copies all of the mappings from the specified map to this map (optional operation).
`Object` | `remove(Object key)` Removes the mapping for this key from this map if present (optional operation).
`int` | `size()` Returns the number of records in the collection or map.
`String` | `toString()` Converts the map to a string representation for debugging.
`Collection` | `values()` Returns a collection view of the values contained in this map.

Methods inherited from class com.sleepycat.collections.StoredContainer
`areDuplicatesAllowed, areDuplicatesOrdered, areKeysRenumbered, clear, getCursorConfig, isDirtyRead, isDirtyReadAllowed, isEmpty, isOrdered, isSecondary, isTransactional, isWriteAllowed`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Methods inherited from interface java.util.Map
`clear, isEmpty`

Constructor Detail

### StoredMap

    public StoredMap(Database database,
                     EntryBinding keyBinding,
                     EntryBinding valueBinding,
                     boolean writeAllowed)

  Creates a map view of a `Database`.

  Parameters:
    `database` - is the Database underlying the new collection.
    `keyBinding` - is the binding used to translate between key buffers and key objects.
    `valueBinding` - is the binding used to translate between value buffers and value objects.
    `writeAllowed` - is true to create a read-write collection or false to create a read-only collection.
  Throws:
    `IllegalArgumentException` - if formats are not consistently defined or a parameter is invalid.
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.

### StoredMap

    public StoredMap(Database database,
                     EntryBinding keyBinding,
                     EntryBinding valueBinding,
                     PrimaryKeyAssigner keyAssigner)

  Creates a map view of a `Database` with a `PrimaryKeyAssigner`. Writing is allowed for the created map.

  Parameters:
    `database` - is the Database underlying the new collection.
    `keyBinding` - is the binding used to translate between key buffers and key objects.
    `valueBinding` - is the binding used to translate between value buffers and value objects.
    `keyAssigner` - is used by the `append(java.lang.Object)` method to assign primary keys.
  Throws:
    `IllegalArgumentException` - if formats are not consistently defined or a parameter is invalid.
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.

### StoredMap

    public StoredMap(Database database,
                     EntryBinding keyBinding,
                     EntityBinding valueEntityBinding,
                     boolean writeAllowed)

  Creates a map entity view of a `Database`.

  Parameters:
    `database` - is the Database underlying the new collection.
    `keyBinding` - is the binding used to translate between key buffers and key objects.
    `valueEntityBinding` - is the binding used to translate between key/value buffers and entity value objects.
    `writeAllowed` - is true to create a read-write collection or false to create a read-only collection.
  Throws:
    `IllegalArgumentException` - if formats are not consistently defined or a parameter is invalid.
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.

### StoredMap

    public StoredMap(Database database,
                     EntryBinding keyBinding,
                     EntityBinding valueEntityBinding,
                     PrimaryKeyAssigner keyAssigner)

  Creates a map entity view of a `Database` with a `PrimaryKeyAssigner`. Writing is allowed for the created map.

  Parameters:
    `database` - is the Database underlying the new collection.
    `keyBinding` - is the binding used to translate between key buffers and key objects.
    `valueEntityBinding` - is the binding used to translate between key/value buffers and entity value objects.
    `keyAssigner` - is used by the `append(java.lang.Object)` method to assign primary keys.
  Throws:
    `IllegalArgumentException` - if formats are not consistently defined or a parameter is invalid.
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.

Method Detail

### get

    public Object get(Object key)

  Returns the value to which this map maps the specified key. If duplicates are allowed, this method returns the first duplicate, in the order in which duplicates are configured, that maps to the specified key. This method conforms to the `Map.get(java.lang.Object)` interface.

  Specified by:
    `get` in interface `Map`
  Throws:
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.

### put

    public Object put(Object key,
                      Object value)

  Associates the specified value with the specified key in this map (optional operation). If duplicates are allowed and the specified key is already mapped to a value, this method appends the new duplicate after the existing duplicates. This method conforms to the `Map.put(java.lang.Object, java.lang.Object)` interface.

  The key parameter may be null if an entity binding is used and the key will be derived from the value (entity) parameter. If an entity binding is used and the key parameter is non-null, then the key parameter must be equal to the key derived from the value parameter.

  Specified by:
    `put` in interface `Map`
  Returns:
    the previous value associated with specified key, or null if there was no mapping for the key or if duplicates are allowed.
  Throws:
    `UnsupportedOperationException` - if the collection is indexed, or if the collection is read-only.
    `IllegalArgumentException` - if an entity value binding is used and the primary key of the value given is different than the existing stored primary key.
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.

### append

    public Object append(Object value)

  Appends a given value returning the newly assigned key. If a `PrimaryKeyAssigner` is associated with Store for this map, it will be used to assigned the returned key. Otherwise the Store must be a QUEUE or RECNO database and the next available record number is assigned as the key. This method does not exist in the standard `Map` interface.

  Note that for the JE product, QUEUE and RECNO databases are not supported, and therefore a PrimaryKeyAssigner must be associated with the map in order to call this method.

  Parameters:
    `value` - the value to be appended.
  Returns:
    the assigned key.
  Throws:
    `UnsupportedOperationException` - if the collection is indexed, or if the collection is read-only, or if the Store has no `PrimaryKeyAssigner` and is not a QUEUE or RECNO database.
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.

### remove

    public Object remove(Object key)

  Removes the mapping for this key from this map if present (optional operation). If duplicates are allowed, this method removes all duplicates for the given key. This method conforms to the `Map.remove(java.lang.Object)` interface.

  Specified by:
    `remove` in interface `Map`
  Throws:
    `UnsupportedOperationException` - if the collection is read-only.
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.

### containsKey

    public boolean containsKey(Object key)

  Returns true if this map contains the specified key. This method conforms to the `Map.containsKey(java.lang.Object)` interface.

  Specified by:
    `containsKey` in interface `Map`
  Throws:
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.

### containsValue

    public boolean containsValue(Object value)

  Returns true if this map contains the specified value. When an entity binding is used, this method returns whether the map contains the primary key and value mapping of the entity. This method conforms to the `Map.containsValue(java.lang.Object)` interface.

  Specified by:
    `containsValue` in interface `Map`
  Throws:
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.

### putAll

    public void putAll(Map map)

  Copies all of the mappings from the specified map to this map (optional operation). When duplicates are allowed, the mappings in the specified map are effectively appended to the existing mappings in this map, that is no previously existing mappings in this map are replaced. This method conforms to the `Map.putAll(java.util.Map)` interface.

  Specified by:
    `putAll` in interface `Map`
  Throws:
    `UnsupportedOperationException` - if the collection is read-only, or if the collection is indexed.
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.

### keySet

    public Set keySet()

  Returns a set view of the keys contained in this map. A `SortedSet` is returned if the map is ordered. The returned collection will be read-only if the map is read-only. This method conforms to the `Map.keySet()` interface.

  Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.

  Specified by:
    `keySet` in interface `Map`
  Returns:
    a `StoredKeySet` or a `StoredSortedKeySet` for this map.
  Throws:
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.
  See Also:
    `StoredContainer.isOrdered()`, `StoredContainer.isWriteAllowed()`

### entrySet

    public Set entrySet()

  Returns a set view of the mappings contained in this map. A `SortedSet` is returned if the map is ordered. The returned collection will be read-only if the map is read-only. This method conforms to the `Map.entrySet()` interface.

  Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.

  Specified by:
    `entrySet` in interface `Map`
  Returns:
    a `StoredEntrySet` or a `StoredSortedEntrySet` for this map.
  Throws:
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.
  See Also:
    `StoredContainer.isOrdered()`, `StoredContainer.isWriteAllowed()`

### values

    public Collection values()

  Returns a collection view of the values contained in this map. A `SortedSet` is returned if the map is ordered and the value/entity binding can be used to derive the map's key from its value/entity object. The returned collection will be read-only if the map is read-only. This method conforms to the `Map.values()` interface.

  Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.

  Specified by:
    `values` in interface `Map`
  Returns:
    a `StoredValueSet` or a `StoredSortedValueSet` for this map.
  Throws:
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.
  See Also:
    `StoredContainer.isOrdered()`, `StoredContainer.isWriteAllowed()`

### duplicates

    public Collection duplicates(Object key)

  Returns a new collection containing the values mapped to the given key in this map. This collection's iterator() method is particularly useful for iterating over the duplicates for a given key, since this is not supported by the standard Map interface. This method does not exist in the standard `Map` interface.

  If no mapping for the given key is present, an empty collection is returned. If duplicates are not allowed, at most a single value will be in the collection returned. If duplicates are allowed, the returned collection's add() method may be used to add values for the given key.

  Parameters:
    `key` - is the key for which values are to be returned.
  Throws:
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.

### duplicatesMap

    public Map duplicatesMap(Object secondaryKey,
                             EntryBinding primaryKeyBinding)

  Returns a new map from primary key to value for the subset of records having a given secondary key (duplicates). This method does not exist in the standard `Map` interface.

  If no mapping for the given key is present, an empty collection is returned. If duplicates are not allowed, at most a single value will be in the collection returned. If duplicates are allowed, the returned collection's add() method may be used to add values for the given key.

  Parameters:
    `secondaryKey` - is the secondary key for which duplicates values will be represented by the returned map.
    `primaryKeyBinding` - is the binding used for keys in the returned map.
  Throws:
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.

### equals

    public boolean equals(Object other)

  Compares the specified object with this map for equality. A value comparison is performed by this method and the stored values are compared rather than calling the equals() method of each element. This method conforms to the `Map.equals(java.lang.Object)` interface.

  Specified by:
    `equals` in interface `Map`
  Overrides:
    `equals` in class `Object`
  Throws:
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.

### hashCode

    public int hashCode()

  Specified by:
    `hashCode` in interface `Map`
  Overrides:
    `hashCode` in class `Object`

### size

    public int size()

  Description copied from class: `StoredContainer`
  Returns the number of records in the collection or map. This method conforms to the `Collection.size()` and `Map.size()` interfaces.

  Note that if other threads are adding or removing records while this method is executing, the size returned may be incorrect. This method does not lock the database.

  Also note that, for a large database, this method may be expensive. All non-duplicate records in the database are enumerated by this method, bringing them into memory if they are not already cached.

  Specified by:
    `size` in interface `Map`
  Specified by:
    `size` in class `StoredContainer`

### toString

    public String toString()

  Converts the map to a string representation for debugging. WARNING: All mappings will be converted to strings and returned and therefore the returned string may be very large.

  Overrides:
    `toString` in class `Object`
  Returns:
    the string representation.
  Throws:
    `RuntimeExceptionWrapper` - if a `DatabaseException` is thrown.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Berkeley DB version 4.5.20
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright(c) 1996-2006 Oracle Corporation - All rights reserved.