org.datanucleus.store.mapped.scostore
Class FKMapStore

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

public abstract class FKMapStore
extends AbstractMapStore

Representation of a FK backing for a Map. This class is used where you have a 1-N and the tables are not joined via a link table, instead using a FK. There are 2 possible uses here

In both cases the value class will have a field that represents the key, and so the user must specify a 'key mapped-by="..."' attribute to denote which field is the key, or a 'value mapped-by="..."' to denote which field is the value.


Field Summary
protected  ClassLoaderResolver clr
           
protected  int keyFieldNumber
          Field number of key in value class (when Key=Non-PC, Value=PC).
 
Fields inherited from class org.datanucleus.store.mapped.scostore.AbstractMapStore
iterateUsingDiscriminator, keyMapping, keysAreEmbedded, keysAreSerialised, keyType, kmd, mapTable, specialization, valueMapping, valuesAreEmbedded, valuesAreSerialised, valueTable, valueType, vmd
 
Fields inherited from class org.datanucleus.store.mapped.scostore.BaseContainerStore
allowsNull, dba, LOCALISER, ownerMapping, ownerMemberMetaData, relationType, storeMgr
 
Constructor Summary
FKMapStore(AbstractMemberMetaData fmd, MappedStoreManager storeMgr, ClassLoaderResolver clr, AbstractMapStoreSpecialization specialization)
          Constructor for an Inverse Map.
 
Method Summary
 void clear(StateManager sm)
          Method to clear the map of all values.
 void clearKeyOfValue(StateManager sm, java.lang.Object key, java.lang.Object oldValue)
          Utility to clear the key of a value from the Map.
 SetStore entrySetStore()
          Accessor for the map entries in the Map.
protected abstract  void initialise()
           
 ScalarExpression joinKeysTo(QueryExpression stmt, QueryExpression parentStmt, JavaTypeMapping ownerMapping, LogicSetExpression te, DatastoreIdentifier mapTableAlias, java.lang.Class filteredKeyType, ScalarExpression kExpr, DatastoreIdentifier keyTableAlias)
          Utility to create a join for keys to be used in a containsKey() query.
 ScalarExpression[] joinKeysValuesTo(QueryExpression stmt, QueryExpression parentStmt, JavaTypeMapping ownerMapping, LogicSetExpression ownerTe, DatastoreIdentifier mapRangeVar, java.lang.Class filteredKeyType, java.lang.Class filteredValueType, ScalarExpression keyExpr, ScalarExpression valExpr, DatastoreIdentifier keyRangeVar, DatastoreIdentifier valueRangeVar)
          Utility to create a join for keys and values to be used in ai containsEntry() query.
 ScalarExpression joinValuesTo(QueryExpression stmt, QueryExpression parentStmt, JavaTypeMapping ownerMapping, LogicSetExpression ownerTe, DatastoreIdentifier mapRangeVar, java.lang.Class filteredValueType, ScalarExpression valExpr, DatastoreIdentifier valueRangeVar)
          Used as part of the Querying of Maps where a containsValue() is used.
 SetStore keySetStore()
          Accessor for the keys in the Map.
protected abstract  MapEntrySetStore newMapEntrySetStore()
           
protected abstract  MapKeySetStore newMapKeySetStore()
           
protected abstract  MapValueSetStore newMapValueSetStore()
           
 java.lang.Object put(StateManager sm, java.lang.Object newKey, java.lang.Object newValue)
          Method to put an item in the Map.
 java.lang.Object remove(StateManager sm, java.lang.Object key)
          Method to remove an item from the map.
protected abstract  boolean updateKeyFkInternal(StateManager sm, java.lang.Object key, java.lang.Object owner)
           
protected abstract  boolean updateValueFkInternal(StateManager sm, java.lang.Object value, java.lang.Object owner)
           
protected  void validateValueType(ClassLoaderResolver clr, java.lang.Object value)
          Utility to validate the type of a value for storing in the Map.
 SetStore valueSetStore()
          Accessor for the values in the Map.
 
Methods inherited from class org.datanucleus.store.mapped.scostore.AbstractMapStore
containsKey, containsValue, get, getExistsSubquery, getKeyMapping, getKeyType, getKmd, getMapTable, getSizeSubquery, getValue, getValueMapping, getValueType, getVmd, isValuesAreEmbedded, isValuesAreSerialised, joinKeysToGet, keysAreEmbedded, keysAreSerialised, putAll, updateEmbeddedKey, updateEmbeddedValue, validateKeyForReading, validateKeyForWriting, validateKeyType, validateValueForReading, validateValueForWriting, valuesAreEmbedded, valuesAreSerialised
 
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.Store
getStoreManager
 

Field Detail

clr

protected final ClassLoaderResolver clr

keyFieldNumber

protected int keyFieldNumber
Field number of key in value class (when Key=Non-PC, Value=PC).

Constructor Detail

FKMapStore

public FKMapStore(AbstractMemberMetaData fmd,
                  MappedStoreManager storeMgr,
                  ClassLoaderResolver clr,
                  AbstractMapStoreSpecialization specialization)
Constructor for an Inverse Map.

Parameters:
fmd - Field Meta-Data for the Map field.
storeMgr - The Store Manager we are using.
clr - The ClassLoaderResolver
specialization - The datastore-specific specialization
Method Detail

initialise

protected abstract void initialise()

updateKeyFkInternal

protected abstract boolean updateKeyFkInternal(StateManager sm,
                                               java.lang.Object key,
                                               java.lang.Object owner)

updateValueFkInternal

protected abstract boolean updateValueFkInternal(StateManager sm,
                                                 java.lang.Object value,
                                                 java.lang.Object owner)

newMapKeySetStore

protected abstract MapKeySetStore newMapKeySetStore()

newMapValueSetStore

protected abstract MapValueSetStore newMapValueSetStore()

newMapEntrySetStore

protected abstract MapEntrySetStore newMapEntrySetStore()

validateValueType

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

Overrides:
validateValueType in class AbstractMapStore
Parameters:
value - The value to check.
clr - The ClassLoaderResolver

put

public java.lang.Object put(StateManager sm,
                            java.lang.Object newKey,
                            java.lang.Object newValue)
Method to put an item in the Map.

Parameters:
sm - State Manager for the map.
newKey - The key to store the value against
newValue - The value to store.
Returns:
The value stored.

remove

public java.lang.Object remove(StateManager sm,
                               java.lang.Object key)
Method to remove an item from the map.

Parameters:
sm - State Manager for the map.
key - Key of the item to remove.
Returns:
The value that was removed.

clear

public void clear(StateManager sm)
Method to clear the map of all values.

Parameters:
sm - State Manager for the map.

clearKeyOfValue

public void clearKeyOfValue(StateManager sm,
                            java.lang.Object key,
                            java.lang.Object oldValue)
Utility to clear the key of a value from the Map. If the key is non nullable, delete the value.

Parameters:
sm - State Manager for the map.
key - Key of the object
oldValue - Value to remove

keySetStore

public SetStore keySetStore()
Accessor for the keys in the Map.

Returns:
The keys

valueSetStore

public SetStore valueSetStore()
Accessor for the values in the Map.

Returns:
The values.

entrySetStore

public SetStore entrySetStore()
Accessor for the map entries in the Map.

Returns:
The map entries.

joinKeysTo

public ScalarExpression joinKeysTo(QueryExpression stmt,
                                   QueryExpression parentStmt,
                                   JavaTypeMapping ownerMapping,
                                   LogicSetExpression te,
                                   DatastoreIdentifier mapTableAlias,
                                   java.lang.Class filteredKeyType,
                                   ScalarExpression kExpr,
                                   DatastoreIdentifier keyTableAlias)
Utility to create a join for keys to be used in a containsKey() query.

Parameters:
stmt - The Query Statement
parentStmt - the parent Query Statement. If there is no parent, parentStmt must be equals to stmt
ownerMapping - Mapping for the owner
te - Table Expression for the owner
mapTableAlias - Alias for the "Map" table.
filteredKeyType - The Class Type for the filtered key
keyTableAlias - The SQL alias to assign to the expression or to the key table.
kExpr - the expression to the key field
Returns:
QueryColumnList with the columns from the key mapping

joinValuesTo

public ScalarExpression joinValuesTo(QueryExpression stmt,
                                     QueryExpression parentStmt,
                                     JavaTypeMapping ownerMapping,
                                     LogicSetExpression ownerTe,
                                     DatastoreIdentifier mapRangeVar,
                                     java.lang.Class filteredValueType,
                                     ScalarExpression valExpr,
                                     DatastoreIdentifier valueRangeVar)
Used as part of the Querying of Maps where a containsValue() is used.

Parameters:
stmt - The Query Statement
parentStmt - the parent Query Statement. If there is no parent, parentStmt must be equals to stmt
ownerMapping - Mapping for the owner
ownerTe - Table Expression for the owner
mapRangeVar - The range variable for the "Map" table.
filteredValueType - The Class Type for the filtered value
valExpr - Table Expression for the value
valueRangeVar - The SQL alias, or "range variable", to assign to the expression or to the value table.
Returns:
QueryColumnList with the columns from the value mapping

joinKeysValuesTo

public ScalarExpression[] joinKeysValuesTo(QueryExpression stmt,
                                           QueryExpression parentStmt,
                                           JavaTypeMapping ownerMapping,
                                           LogicSetExpression ownerTe,
                                           DatastoreIdentifier mapRangeVar,
                                           java.lang.Class filteredKeyType,
                                           java.lang.Class filteredValueType,
                                           ScalarExpression keyExpr,
                                           ScalarExpression valExpr,
                                           DatastoreIdentifier keyRangeVar,
                                           DatastoreIdentifier valueRangeVar)
Utility to create a join for keys and values to be used in ai containsEntry() query.

Parameters:
stmt - The Query Statement to apply the join
parentStmt - the parent Query Statement. If there is no parent, parentStmt must be equals to stmt
ownerMapping - Mapping for the owner
ownerTe - Table Expression for the owner
mapRangeVar - The SQL alias, or "range variable", to assign to the expression or to the main table.
filteredKeyType - The Class Type for the filtered key
filteredValueType - The Class Type for the filtered value
keyExpr - the expression to the key field
valExpr - Table Expression for the value
keyRangeVar - The SQL alias, or "range variable", to assign to the expression or to the key table.
valueRangeVar - The SQL alias, or "range variable", 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.