de.mguennewig.pobjects
Class PObjMap<T extends Record>

java.lang.Object
  extended by de.mguennewig.pobjects.AbstractPObjJoin<T>
      extended by de.mguennewig.pobjects.PObjMap<T>

public class PObjMap<T extends Record>
extends AbstractPObjJoin<T>

Wrapper object for map valued joins between two tables.

Please note that the methods of this class resemble that of the standard collection class Map, but that the semantics usually differ to some degree. In particular, every method call is an operation on the RDBMS, and the backing store's semantics do not follow those of Java. For example, given statement level read consistency on the RDBMS, a size() followed by a findAll().length may produce different results.

Even thought the methods of this map are synchronized is there still the chance for concurrent modifications made by other database users.

Author:
Michael Günnewig

Constructor Summary
PObjMap(PObject parent, java.lang.Class<? extends Record> elementClass)
          Creates a new map.
 
Method Summary
 boolean containsKey(java.lang.Object... key)
          Return true if the given key exists in this map.
 T get(java.lang.Object... key)
          Return the map element matching the given key, or null if no such row exists.
 T put(java.lang.Object... keyValues)
          Add the given arguments as an element to the map.
 T putIfAbsent(java.lang.Object... keyValues)
          If the specified key is not already associated with a value, associate it with the given value.
 boolean remove(java.lang.Object... key)
          Remove the given arguments as an element from the map.
 boolean remove(T obj)
          Remove the give record obj as an element from the map.
 
Methods inherited from class de.mguennewig.pobjects.AbstractPObjJoin
clear, findAll, getContainer, getElementClass, getElementDecl, getParent, isEmpty, size
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PObjMap

public PObjMap(PObject parent,
               java.lang.Class<? extends Record> elementClass)
Creates a new map.

Method Detail

get

public T get(java.lang.Object... key)
Return the map element matching the given key, or null if no such row exists.

Throws:
java.lang.IllegalArgumentException - if key.length != pk.length-1.

containsKey

public boolean containsKey(java.lang.Object... key)
Return true if the given key exists in this map.

Throws:
java.lang.IllegalArgumentException - if key.length != pk.length-1.

put

public T put(java.lang.Object... keyValues)
                     throws PObjConstraintException,
                            PObjSQLException
Add the given arguments as an element to the map. It is an error if the element already exists. The data is stored immediately in the RDBMS. In this, the put() method resembles store() on a newly created PObject.

Parameters:
keyValues - the list of keys followed by the list of values
Returns:
The old value associated to the key or null if the key didn't exist before.
Throws:
PObjConstraintException
PObjSQLException

putIfAbsent

public final T putIfAbsent(java.lang.Object... keyValues)
                                   throws PObjConstraintException,
                                          PObjSQLException
If the specified key is not already associated with a value, associate it with the given value.

Parameters:
keyValues - the list of keys followed by the list of values
Returns:
The old value associated to the key or null if the key didn't exist before.
Throws:
PObjConstraintException
PObjSQLException
See Also:
get(Object[]), put(Object[])

remove

public boolean remove(T obj)
               throws PObjConstraintException,
                      PObjSQLException
Remove the give record obj as an element from the map. If the element exists prior to the call, then the result is true. The data is stored immediately in the RDBMS. In this, the remove() method resembles store() on a delete PObject.

Throws:
PObjConstraintException
PObjSQLException

remove

public boolean remove(java.lang.Object... key)
               throws PObjConstraintException,
                      PObjSQLException
Remove the given arguments as an element from the map. If the element exists prior to the call, then the result is true. The data is stored immediately in the RDBMS. In this, the put() method resembles store() on a deleted PObject.

Throws:
PObjConstraintException
PObjSQLException