org.datanucleus.store.mapped.scostore
Class AbstractMapStore

java.lang.Object
  extended by org.datanucleus.store.mapped.scostore.BaseContainerStore
      extended by org.datanucleus.store.mapped.scostore.AbstractMapStore
All Implemented Interfaces:
MapStoreQueryable, MapStore, Store
Direct Known Subclasses:
FKMapStore, JoinMapStore

public abstract class AbstractMapStore
extends BaseContainerStore
implements MapStore, MapStoreQueryable

Abstract representation of the backing store for a Map.


Field Summary
protected  boolean iterateUsingDiscriminator
          Flag to set whether the iterator statement will use a discriminator or not.
protected  JavaTypeMapping keyMapping
          Mapping to the key from the mapTable.
protected  boolean keysAreEmbedded
          Whether the keys are embedded.
protected  boolean keysAreSerialised
          Whether the keys are serialised.
protected  java.lang.String keyType
          Type of the key.
protected  AbstractClassMetaData kmd
          Metadata for the keys (if persistable).
protected  DatastoreContainerObject mapTable
          Table storing the map relation.
protected  AbstractMapStoreSpecialization specialization
           
protected  JavaTypeMapping valueMapping
          Mapping to the value from the mapTable.
protected  boolean valuesAreEmbedded
          Whether the values are embedded.
protected  boolean valuesAreSerialised
          Whether the values are serialised.
protected  DatastoreClass valueTable
          Table storing the values.
protected  java.lang.String valueType
          Type of the value.
protected  AbstractClassMetaData vmd
          Metadata for the values (if persistable).
 
Fields inherited from class org.datanucleus.store.mapped.scostore.BaseContainerStore
allowsNull, dba, LOCALISER, ownerMapping, ownerMemberMetaData, relationType, storeMgr
 
Constructor Summary
AbstractMapStore(StoreManager storeMgr, AbstractMapStoreSpecialization specialization)
          Constructor.
 
Method Summary
 boolean containsKey(StateManager sm, java.lang.Object key)
          Method to check if a key exists in the Map.
 boolean containsValue(StateManager sm, java.lang.Object value)
          Method to check if a value exists in the Map.
 java.lang.Object get(StateManager sm, java.lang.Object key)
          Method to return the value for a key.
 QueryExpression getExistsSubquery(QueryExpression qs, JavaTypeMapping mapping, LogicSetExpression ownerTe, DatastoreIdentifier mapTableAlias)
          Method used where a Query uses map.isEmpty().
 JavaTypeMapping getKeyMapping()
           
 java.lang.String getKeyType()
          Accessor for the key type for storing in this Map.
 AbstractClassMetaData getKmd()
           
 DatastoreContainerObject getMapTable()
           
 QueryExpression getSizeSubquery(QueryExpression qs, JavaTypeMapping mapping, LogicSetExpression ownerTe, DatastoreIdentifier mapTableAlias)
          Query utility to generate a subquery for the size() of the map.
protected abstract  java.lang.Object getValue(StateManager sm, java.lang.Object key)
          Method to retrieve a value from the Map given the key.
 JavaTypeMapping getValueMapping()
           
 java.lang.String getValueType()
          Accessor for the value type for storing in this Map.
 AbstractClassMetaData getVmd()
           
 boolean isValuesAreEmbedded()
           
 boolean isValuesAreSerialised()
           
 ScalarExpression[] joinKeysToGet(QueryExpression stmt, QueryExpression parentStmt, JavaTypeMapping ownerMapping, LogicSetExpression te, DatastoreIdentifier mapTableAlias, java.lang.Class filteredKeyType, DatastoreIdentifier keyTableAlias, DatastoreIdentifier valueTableAlias)
          Used as part of the Querying of Maps where a get(Key) is used.
 boolean keysAreEmbedded()
          Accessor for whether the keys are embedded or not.
 boolean keysAreSerialised()
          Accessor for whether the keys are serialised or not.
 void putAll(StateManager sm, java.util.Map m)
          Method to put all elements from a Map into our Map.
 boolean updateEmbeddedKey(StateManager sm, java.lang.Object key, int fieldNumber, java.lang.Object newValue)
          Method to update a field of an embedded key.
 boolean updateEmbeddedValue(StateManager sm, java.lang.Object value, int fieldNumber, java.lang.Object newValue)
          Method to update a field of an embedded key.
protected  boolean validateKeyForReading(StateManager sm, java.lang.Object key)
          Utility to validate a key is ok for reading.
protected  void validateKeyForWriting(StateManager sm, java.lang.Object key)
          Utility to validate a key is ok for writing (present in the datastore).
protected  void validateKeyType(ClassLoaderResolver clr, java.lang.Object key)
          Utility to validate the type of a key for storing in the Map.
protected  boolean validateValueForReading(StateManager sm, java.lang.Object value)
          Utility to validate a value is ok for reading.
protected  void validateValueForWriting(StateManager sm, java.lang.Object value)
          Utility to validate a value is ok for writing (present in the datastore).
protected  void validateValueType(ClassLoaderResolver clr, java.lang.Object value)
          Utility to validate the type of a value for storing in the Map.
 boolean valuesAreEmbedded()
          Accessor for whether the values are embedded or not.
 boolean valuesAreSerialised()
          Accessor for whether the values are serialised or not.
 
Methods inherited from class org.datanucleus.store.mapped.scostore.BaseContainerStore
allowsBatching, getDatastoreAdapter, getOwnerMapping, getOwnerMemberMetaData, getRelationType, getStateManagerForEmbeddedPCObject, getStoreManager, isEmbeddedMapping, setOwner
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.datanucleus.store.scostore.MapStore
clear, entrySetStore, keySetStore, put, remove, valueSetStore
 
Methods inherited from interface org.datanucleus.store.scostore.Store
getStoreManager
 
Methods inherited from interface org.datanucleus.store.mapped.expression.MapStoreQueryable
joinKeysTo, joinKeysValuesTo, joinValuesTo
 

Field Detail

iterateUsingDiscriminator

protected boolean iterateUsingDiscriminator
Flag to set whether the iterator statement will use a discriminator or not.


mapTable

protected DatastoreContainerObject mapTable
Table storing the map relation. May be join table, or key table, or value table.


valueTable

protected DatastoreClass valueTable
Table storing the values.


kmd

protected AbstractClassMetaData kmd
Metadata for the keys (if persistable).


vmd

protected AbstractClassMetaData vmd
Metadata for the values (if persistable).


keyMapping

protected JavaTypeMapping keyMapping
Mapping to the key from the mapTable.


valueMapping

protected JavaTypeMapping valueMapping
Mapping to the value from the mapTable.


keyType

protected java.lang.String keyType
Type of the key.


valueType

protected java.lang.String valueType
Type of the value.


keysAreEmbedded

protected boolean keysAreEmbedded
Whether the keys are embedded.


keysAreSerialised

protected boolean keysAreSerialised
Whether the keys are serialised.


valuesAreEmbedded

protected boolean valuesAreEmbedded
Whether the values are embedded.


valuesAreSerialised

protected boolean valuesAreSerialised
Whether the values are serialised.


specialization

protected final AbstractMapStoreSpecialization specialization
Constructor Detail

AbstractMapStore

public AbstractMapStore(StoreManager storeMgr,
                        AbstractMapStoreSpecialization specialization)
Constructor.

Parameters:
storeMgr - Manager for the store
specialization - Specialisation for this datastore
Method Detail

keysAreEmbedded

public boolean keysAreEmbedded()
Accessor for whether the keys are embedded or not. If they are PC instances then returns false;

Specified by:
keysAreEmbedded in interface MapStore
Returns:
Whether the keys are embedded

keysAreSerialised

public boolean keysAreSerialised()
Accessor for whether the keys are serialised or not. If they are PC instances then returns false;

Specified by:
keysAreSerialised in interface MapStore
Returns:
Whether the keys are serialised

valuesAreEmbedded

public boolean valuesAreEmbedded()
Accessor for whether the values are embedded or not. If they are PC instances then returns false;

Specified by:
valuesAreEmbedded in interface MapStore
Returns:
Whether the values are embedded

valuesAreSerialised

public boolean valuesAreSerialised()
Accessor for whether the values are serialised or not. If they are PC instances then returns false;

Specified by:
valuesAreSerialised in interface MapStore
Returns:
Whether the values are serialised

getKeyType

public java.lang.String getKeyType()
Accessor for the key type for storing in this Map.

Specified by:
getKeyType in interface MapStore
Returns:
The type of the key

getValueType

public java.lang.String getValueType()
Accessor for the value type for storing in this Map. Types inherited from this (base) type can also be stored as values.

Specified by:
getValueType in interface MapStore
Returns:
The type of the value (base class).

containsKey

public boolean containsKey(StateManager sm,
                           java.lang.Object key)
Method to check if a key exists in the Map.

Specified by:
containsKey in interface MapStore
Parameters:
sm - State Manager for the map
key - The key to check for.
Returns:
Whether the key exists in the Map.

containsValue

public boolean containsValue(StateManager sm,
                             java.lang.Object value)
Method to check if a value exists in the Map.

Specified by:
containsValue in interface MapStore
Parameters:
sm - State Manager for the map
value - The value to check for.
Returns:
Whether the value exists in the Map.

get

public java.lang.Object get(StateManager sm,
                            java.lang.Object key)
Method to return the value for a key.

Specified by:
get in interface MapStore
Parameters:
sm - State Manager for the Map.
key - The key of the object to retrieve.
Returns:
The value for this key.

putAll

public void putAll(StateManager sm,
                   java.util.Map m)
Method to put all elements from a Map into our Map.

Specified by:
putAll in interface MapStore
Parameters:
sm - State Manager for the Map
m - The Map to add

validateKeyType

protected void validateKeyType(ClassLoaderResolver clr,
                               java.lang.Object key)
Utility to validate the type of a key for storing in the Map.

Parameters:
clr - The ClassLoaderResolver
key - The key to check.

validateValueType

protected void validateValueType(ClassLoaderResolver clr,
                                 java.lang.Object value)
Utility to validate the type of a value for storing in the Map.

Parameters:
clr - The ClassLoaderResolver
value - The value to check.

validateKeyForReading

protected boolean validateKeyForReading(StateManager sm,
                                        java.lang.Object key)
Utility to validate a key is ok for reading.

Parameters:
sm - State Manager for the map.
key - The key to check.
Returns:
Whether it is validated.

validateValueForReading

protected boolean validateValueForReading(StateManager sm,
                                          java.lang.Object value)
Utility to validate a value is ok for reading.

Parameters:
sm - State Manager for the map.
value - The value to check.
Returns:
Whether it is validated.

validateKeyForWriting

protected void validateKeyForWriting(StateManager sm,
                                     java.lang.Object key)
Utility to validate a key is ok for writing (present in the datastore).

Parameters:
sm - State Manager for the map.
key - The key to check.

validateValueForWriting

protected void validateValueForWriting(StateManager sm,
                                       java.lang.Object value)
Utility to validate a value is ok for writing (present in the datastore).

Parameters:
sm - State Manager for the map.
value - The value to check.

getValue

protected abstract java.lang.Object getValue(StateManager sm,
                                             java.lang.Object key)
                                      throws java.util.NoSuchElementException
Method to retrieve a value from the Map given the key.

Parameters:
sm - State Manager for the map.
key - The key to retrieve the value for.
Returns:
The value for this key
Throws:
java.util.NoSuchElementException - if the value for the key was not found

updateEmbeddedKey

public boolean updateEmbeddedKey(StateManager sm,
                                 java.lang.Object key,
                                 int fieldNumber,
                                 java.lang.Object newValue)
Method to update a field of an embedded key.

Specified by:
updateEmbeddedKey in interface MapStore
Parameters:
sm - State Manager of the owner
key - The key to update
fieldNumber - The number of the field to update
newValue - The new value
Returns:
Whether the element was modified

updateEmbeddedValue

public boolean updateEmbeddedValue(StateManager sm,
                                   java.lang.Object value,
                                   int fieldNumber,
                                   java.lang.Object newValue)
Method to update a field of an embedded key.

Specified by:
updateEmbeddedValue in interface MapStore
Parameters:
sm - State Manager of the owner
value - The value to update
fieldNumber - The number of the field to update
newValue - The new value
Returns:
Whether the element was modified

getValueMapping

public JavaTypeMapping getValueMapping()

getKeyMapping

public JavaTypeMapping getKeyMapping()

isValuesAreEmbedded

public boolean isValuesAreEmbedded()

isValuesAreSerialised

public boolean isValuesAreSerialised()

getMapTable

public DatastoreContainerObject getMapTable()

getKmd

public AbstractClassMetaData getKmd()

getVmd

public AbstractClassMetaData getVmd()

getExistsSubquery

public QueryExpression getExistsSubquery(QueryExpression qs,
                                         JavaTypeMapping mapping,
                                         LogicSetExpression ownerTe,
                                         DatastoreIdentifier mapTableAlias)
Method used where a Query uses map.isEmpty().

Specified by:
getExistsSubquery in interface MapStoreQueryable
Parameters:
qs - The QueryStatement
mapping - The mapping of the java type
ownerTe - The owner table expression
mapTableAlias - The alias for the "Map" table.
Returns:
A subquery

getSizeSubquery

public QueryExpression getSizeSubquery(QueryExpression qs,
                                       JavaTypeMapping mapping,
                                       LogicSetExpression ownerTe,
                                       DatastoreIdentifier mapTableAlias)
Query utility to generate a subquery for the size() of the map.

Specified by:
getSizeSubquery in interface MapStoreQueryable
Parameters:
qs - The query statement
mapping - mapping of the field
ownerTe - Expression for the table
mapTableAlias - alias for the map table
Returns:
The query statement

joinKeysToGet

public ScalarExpression[] joinKeysToGet(QueryExpression stmt,
                                        QueryExpression parentStmt,
                                        JavaTypeMapping ownerMapping,
                                        LogicSetExpression te,
                                        DatastoreIdentifier mapTableAlias,
                                        java.lang.Class filteredKeyType,
                                        DatastoreIdentifier keyTableAlias,
                                        DatastoreIdentifier valueTableAlias)
Used as part of the Querying of Maps where a get(Key) is used.

Specified by:
joinKeysToGet in interface MapStoreQueryable
Parameters:
stmt - The Query Statement to apply the join
parentStmt - the parent Query Statement. If there is no parent, parentStmt must be equal to stmt
ownerMapping - Mapping for the owner.
te - Table Expression for the owner
mapTableAlias - The SQL alias to assign to the expression or to the main table.
filteredKeyType - The Class Type for the filtered key
keyTableAlias - The SQL alias to assign to the expression or to the key table.
valueTableAlias - The SQL alias to assign to the expression or to the value table.
Returns:
an array with 2 elements of QueryColumnList. The first element contains the columns from the key mapping and the second element the columns from the value mapping


Copyright © 2010. All Rights Reserved.