org.openanzo.common.rdb.layout
Class NodeLayoutCacheProxy<T extends org.openrdf.model.Value>

java.lang.Object
  extended by org.openanzo.common.rdb.layout.NodeLayoutCacheProxy<T>
Type Parameters:
T - Type of Value being stored
All Implemented Interfaces:
ILayoutCache<T>, INodeLayout<T>

public class NodeLayoutCacheProxy<T extends org.openrdf.model.Value>
extends java.lang.Object
implements INodeLayout<T>, ILayoutCache<T>

Wraps and caches the data accessed by a INodeLayout object. *

Author:
Joe Betz, Stephen Evanchik

Constructor Summary
NodeLayoutCacheProxy(INodeLayout<T> base, java.util.Map<java.lang.Long,T> byIdCache, java.util.Map<T,java.lang.Long> byNodeCache)
          Create NodeLayoutCacheProxy for the given base layout.
 
Method Summary
 T cache(java.lang.Long id, java.lang.String value, java.lang.Long modifierId)
          Create object from provided ID and value and cache result
 void clearCache()
          Clear all cached objects and IDs
 void clearUncommittedCache()
          Clear any uncommitted cache entries
 void commitUncommittedCache()
          Commit any uncommitted cache entries
 T convert(java.lang.String value, java.lang.Long modifierId)
          Convert raw value from database into Node of appropriate type
 java.lang.Long fetchId(T n)
          Fetches a node's ID from the database
 T fetchValue(java.lang.Long id)
          Fetches a nodes value from the database based on its long identifier and NodeType.
 T getIfCached(java.lang.Long id)
          Get the Object for this ID, if already cached
 java.lang.Long getIfCached(T value)
          Get the ID for this Object, if already cached
 NodeType getType()
           
 boolean isCached(java.lang.Long id)
          Return true if an Object with this ID is already cached
 boolean isCached(T n)
          Return true if a ID for this Object is already cached
 java.util.Map<java.lang.Long,T> resolveStoredIds(java.util.Set<java.lang.Long> ids)
          This method will determine which IDs in a list of given Ids are already stored in the database.
 java.util.Map<T,java.lang.Long> resolveStoredNodes(java.util.Set<T> nodes, boolean storeUnresolvedNodes)
          This method will determine which nodes in a list of given nodes are already stored in the database.
 java.lang.Long store(T n)
          Stores a node in the database
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeLayoutCacheProxy

public NodeLayoutCacheProxy(INodeLayout<T> base,
                            java.util.Map<java.lang.Long,T> byIdCache,
                            java.util.Map<T,java.lang.Long> byNodeCache)
Create NodeLayoutCacheProxy for the given base layout.

Parameters:
base - Base layout to add caching layer onto
byIdCache - ID cache for this layout
byNodeCache - Node cache for this layout
Method Detail

clearCache

public void clearCache()
Description copied from interface: ILayoutCache
Clear all cached objects and IDs

Specified by:
clearCache in interface ILayoutCache<T extends org.openrdf.model.Value>

cache

public T cache(java.lang.Long id,
               java.lang.String value,
               java.lang.Long modifierId)
Description copied from interface: ILayoutCache
Create object from provided ID and value and cache result

Specified by:
cache in interface ILayoutCache<T extends org.openrdf.model.Value>
Parameters:
id - ID of node
value - String value of node
modifierId - modifierId for literals
Returns:
converted object for provided data

store

public java.lang.Long store(T n)
Description copied from interface: INodeLayout
Stores a node in the database

Specified by:
store in interface INodeLayout<T extends org.openrdf.model.Value>
Parameters:
n - The node to be stored
Returns:
The ID of the node stored

commitUncommittedCache

public void commitUncommittedCache()
Description copied from interface: ILayoutCache
Commit any uncommitted cache entries

Specified by:
commitUncommittedCache in interface ILayoutCache<T extends org.openrdf.model.Value>

clearUncommittedCache

public void clearUncommittedCache()
Description copied from interface: ILayoutCache
Clear any uncommitted cache entries

Specified by:
clearUncommittedCache in interface ILayoutCache<T extends org.openrdf.model.Value>

isCached

public boolean isCached(T n)
Description copied from interface: ILayoutCache
Return true if a ID for this Object is already cached

Specified by:
isCached in interface ILayoutCache<T extends org.openrdf.model.Value>
Parameters:
n - object to check
Returns:
true if a ID for this Object is already cached

isCached

public boolean isCached(java.lang.Long id)
Description copied from interface: ILayoutCache
Return true if an Object with this ID is already cached

Specified by:
isCached in interface ILayoutCache<T extends org.openrdf.model.Value>
Parameters:
id - id to check
Returns:
true if an Object with this ID is already cached

getIfCached

public java.lang.Long getIfCached(T value)
Description copied from interface: ILayoutCache
Get the ID for this Object, if already cached

Specified by:
getIfCached in interface ILayoutCache<T extends org.openrdf.model.Value>
Parameters:
value - object to find cached ID
Returns:
the ID for this Object, if already cached

getIfCached

public T getIfCached(java.lang.Long id)
Description copied from interface: ILayoutCache
Get the Object for this ID, if already cached

Specified by:
getIfCached in interface ILayoutCache<T extends org.openrdf.model.Value>
Parameters:
id - id of Object to retrieve
Returns:
the Object for this ID, if already cached

fetchId

public java.lang.Long fetchId(T n)
Description copied from interface: INodeLayout
Fetches a node's ID from the database

Specified by:
fetchId in interface INodeLayout<T extends org.openrdf.model.Value>
Parameters:
n - The node who's ID is to be found
Returns:
The ID of the node or null if not found

fetchValue

public T fetchValue(java.lang.Long id)
Description copied from interface: INodeLayout
Fetches a nodes value from the database based on its long identifier and NodeType.

Specified by:
fetchValue in interface INodeLayout<T extends org.openrdf.model.Value>
Parameters:
id - The ID of the node to be found
Returns:
The node

resolveStoredNodes

public java.util.Map<T,java.lang.Long> resolveStoredNodes(java.util.Set<T> nodes,
                                                          boolean storeUnresolvedNodes)
Description copied from interface: INodeLayout
This method will determine which nodes in a list of given nodes are already stored in the database. If storeUnresolvedNodes is true, then any node that is unresolved will be stored.

Specified by:
resolveStoredNodes in interface INodeLayout<T extends org.openrdf.model.Value>
Parameters:
nodes - The nodes which need to be resolved to whether they are already stored or need to be stored.
storeUnresolvedNodes - Store nodes that are not already stored
Returns:
A Map of the nodes already stored in the database.

resolveStoredIds

public java.util.Map<java.lang.Long,T> resolveStoredIds(java.util.Set<java.lang.Long> ids)
Description copied from interface: INodeLayout
This method will determine which IDs in a list of given Ids are already stored in the database.

Specified by:
resolveStoredIds in interface INodeLayout<T extends org.openrdf.model.Value>
Parameters:
ids - The ids which need to be resolved to whether they are already stored.
Returns:
A Map of the ids already stored in the database.

getType

public NodeType getType()
Specified by:
getType in interface INodeLayout<T extends org.openrdf.model.Value>
Returns:
type of Nodes this layout handles

convert

public T convert(java.lang.String value,
                 java.lang.Long modifierId)
Description copied from interface: INodeLayout
Convert raw value from database into Node of appropriate type

Specified by:
convert in interface INodeLayout<T extends org.openrdf.model.Value>
Parameters:
value - raw value of node from database
modifierId - for literal values
Returns:
converted Node of appropriate type


Copyright © 2007 Cambridge Semantics Inc.. All Rights Reserved.