org.mmbase.core.util
Class StorageConnector

java.lang.Object
  extended byorg.mmbase.core.util.StorageConnector

public class StorageConnector
extends Object

A StorageConnector object is associated with a specific builder. It provides methods for loading nodes from the cloud (using the search query classes), either indivbidual nodes or nodelists.

Since:
MMBase-1.8
Version:
$Id: StorageConnector.java,v 1.9 2006/07/08 12:44:46 nklasens Exp $
Author:
Pierre van Rooden

Field Summary
protected  MMObjectBuilder builder
           
protected  int maxNodesFromQuery
          Maximum number of nodes to return on a query (-1 means no limit, and is also the default)
 
Constructor Summary
StorageConnector(MMObjectBuilder builder)
           
 
Method Summary
 void addIndex(Index index)
           
 void addIndices(List indexList)
           
 void addToIndex(String key, Field field)
           
 int count(SearchQuery query)
          Counts number of nodes matching a specified constraint.
 boolean created()
          Check whether the table is accessible.
 Index createIndex(String key)
           
 MMObjectBuilder getBuilderForNode(int number)
           
protected  Map getCache(SearchQuery query)
          Returns the Cache which should be used for the result of a certain query.
 Index getIndex(String key)
           
 Map getIndices()
           
 MMObjectNode getNode(int number, boolean useCache)
          Retrieves a node based on it's number (a unique key).
 List getNodes()
          Returns all the nodes from the associated builder.
 List getNodes(Collection virtuals)
          Convert virtual nodes to real nodes based on their otype Normally a multirelations-search will return virtual nodes.
 List getNodes(SearchQuery query)
          Returns nodes matching a specified constraint.
 List getNodes(SearchQuery query, boolean useCache)
          Returns nodes matching a specified constraint.
 int getNodeType(int number)
          Retrieves an object's type.
 NodeSearchQuery getSearchQuery(String where)
          Creates search query that retrieves nodes matching a specified constraint.
 boolean isInIndex(String key, Field field)
           
 void removeFromIndex(String key, Field field)
           
 int size()
          Determine the number of objects in this table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxNodesFromQuery

protected int maxNodesFromQuery
Maximum number of nodes to return on a query (-1 means no limit, and is also the default)


builder

protected final MMObjectBuilder builder
Warning: No Java Documentation Available.
Constructor Detail

StorageConnector

public StorageConnector(MMObjectBuilder builder)
Warning: No Java Documentation Available.
Method Detail

size

public int size()
Determine the number of objects in this table.

Returns:
The number of entries in the table.

created

public boolean created()
Check whether the table is accessible. In general, this means the table does not exist. Please note that this routine may also return false if the table is inaccessible due to insufficient rights.

Returns:
true if the table is accessible, false otherwise.

getIndices

public Map getIndices()

addIndex

public void addIndex(Index index)

addIndices

public void addIndices(List indexList)

getIndex

public Index getIndex(String key)

createIndex

public Index createIndex(String key)

addToIndex

public void addToIndex(String key,
                       Field field)

removeFromIndex

public void removeFromIndex(String key,
                            Field field)

isInIndex

public boolean isInIndex(String key,
                         Field field)

getNode

public MMObjectNode getNode(int number,
                            boolean useCache)
                     throws StorageException
Retrieves a node based on it's number (a unique key).

Parameters:
number - The number of the node to search for
useCache - If false, a fresh copy is returned.
Returns:
null if the node does not exist, the key is invalid,or a MMObjectNode containing the contents of the requested node.
Throws:
StorageException
To Do:
when something goes wrong, the method currently catches the exception and returns null. It should actually throw a NotFoundException instead.

getBuilderForNode

public MMObjectBuilder getBuilderForNode(int number)

getNodeType

public int getNodeType(int number)
                throws StorageException
Retrieves an object's type. If necessary, the type is added to the cache.

Parameters:
number - The number of the node to search for
Returns:
an int value which is the object type (otype) of the node.
Throws:
StorageException
To Do:
when something goes wrong, the method currently catches the exception and returns -1. It should actually throw a NotFoundException instead.

getNodes

public List getNodes(Collection virtuals)
              throws SearchQueryException
Convert virtual nodes to real nodes based on their otype Normally a multirelations-search will return virtual nodes. These nodes will only contain values which where specified in the field-vector. This method will make real nodes of those virtual nodes.

Parameters:
virtuals - containing virtual nodes
Returns:
List containing real nodes, directly from this Builders
Throws:
SearchQueryException

count

public int count(SearchQuery query)
          throws SearchQueryException
Counts number of nodes matching a specified constraint. The constraint is specified by a query that selects nodes of a specified type, which must be the nodetype corresponding to this builder.

Parameters:
query - The query.
Returns:
The number of nodes.
Throws:
IllegalArgumentException - when an invalid argument is supplied.
SearchQueryException - when failing to retrieve the data.

getCache

protected Map getCache(SearchQuery query)
Returns the Cache which should be used for the result of a certain query. The current implementation only makes the distinction between queries for the 'related nodes caches' and for the 'node list caches'. Multilevel queries are not done here, so are at the moment not anticipated. It returns a Map rather then a Cache. The idea behind this is that if in the future a query-result can be in more than one cache, a kind of 'chained map' can be returned, to reflect that.

To Do:
Perhaps other usefull parameters like query-duration and query-result could be added (in that case searching a result should certainly returns such a chained map, because then of course you don't have those).

getNodes

public List getNodes(SearchQuery query)
              throws SearchQueryException
Returns nodes matching a specified constraint. The constraint is specified by a query that selects nodes of a specified type, which must be the nodetype corresponding to this builder.

Parameters:
query - The query.
Returns:
The nodes.
Throws:
IllegalArgumentException - When the nodetype specified by the query is not the nodetype corresponding to this builder.
SearchQueryException

getNodes

public List getNodes(SearchQuery query,
                     boolean useCache)
              throws SearchQueryException
Returns nodes matching a specified constraint. The constraint is specified by a query that selects nodes of a specified type, which must be the nodetype corresponding to this builder.

Parameters:
query - The query.
useCache - if true, the querycache is used
Returns:
The nodes.
Throws:
IllegalArgumentException - When the nodetype specified by the query is not the nodetype corresponding to this builder.
SearchQueryException

getNodes

public List getNodes()
              throws SearchQueryException
Returns all the nodes from the associated builder.

Returns:
The nodes.
Throws:
SearchQueryException

getSearchQuery

public NodeSearchQuery getSearchQuery(String where)
Creates search query that retrieves nodes matching a specified constraint.

Parameters:
where - The constraint, can be a SQL where-clause, a MMNODE expression, an altavista-formatted expression, empty or null.
Returns:
The query.
Since:
MMBase-1.7


MMBase build 1.8.1.20060716