org.apache.lucene.gdata.storage.lucenestorage
Class StorageQuery

java.lang.Object
  extended by org.apache.lucene.gdata.storage.lucenestorage.StorageQuery

public class StorageQuery
extends Object

StorageQuery wraps a Lucene IndexSearcher and a StorageBuffer to perform all request on the lucene storage. The wrapped components are thread - safe.

An instance of this class will serve all client requests. To obtain the current instance of the StorageQuery the method StorageCoreController.getStorageQuery() has to be invoked. This method will release the current StorageQuery.

Author:
Simon Willnauer
See Also:
IndexSearcher, StorageCoreController, StorageBuffer

Constructor Summary
protected StorageQuery(StorageBuffer buffer, Searcher searcher)
          Creates a new StorageQuery
 
Method Summary
protected  boolean checkEntryVersion(String id, String feedId, int version)
           
 void close()
          Closes all resources used in the StorageQuery.
 List<com.google.gdata.data.BaseEntry> entryQuery(List<String> entryIds, String feedId, ProvidedService config)
          Fetches the requested entries from the storage.
 String getAccountNameForFeedId(String feedId)
          Looks up the account reference for the given feed id
protected  long getEntryLastModified(String entryId, String feedId)
           
protected  long getFeedLastModified(String feedId)
           
 com.google.gdata.data.BaseFeed getLatestFeedQuery(String feedId, int resultCount, int startIndex, ProvidedService config)
          This method fetches the latest feed entries from the storage.
 String getService(String feedID)
          Looks up the feed type for the given feed ID
 GDataAccount getUser(String username)
          Queries the storage for an user instance
protected  boolean isEntryStored(String entryId, String feedId)
           
 boolean isFeedStored(String feedId)
          Checks whether a feed for the given feedID is stored
 com.google.gdata.data.BaseEntry singleEntryQuery(String entryId, String feedId, ProvidedService config)
          This method retrieves a single entry from the storage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StorageQuery

protected StorageQuery(StorageBuffer buffer,
                       Searcher searcher)
Creates a new StorageQuery

Parameters:
buffer - - the buffer instance to get the buffered inserts, updates from.
searcher - - the searcher instance to use to query the storage index.
Method Detail

getLatestFeedQuery

public com.google.gdata.data.BaseFeed getLatestFeedQuery(String feedId,
                                                         int resultCount,
                                                         int startIndex,
                                                         ProvidedService config)
                                                  throws IOException,
                                                         com.google.gdata.util.ParseException
This method fetches the latest feed entries from the storage. Feed usually requested via a search query or as a simple query to the REST interface.

The REST interface requests all the entries from a Storage. The Storage retrieves the entries corresponding to the parameters specified. This method first requests the latest entries or updated entries from the StorageBuffer. If the buffer already contains enough entries for the the specified result count the entries will be returned. If not, the underlying lucene index will be searcher for all documents of the specified feed sorted by storing timestamp desc.

The entries will be searched in a feed context specified by the given feed ID

Parameters:
feedId - - the requested feed, this id will be used to retrieve the entries.
resultCount - - how many entries are requested
startIndex - - the offset of the entry to start from.
config - - the FeedInstanceConfiguration containing extension profile used to create the entry instances
Returns:
- an ordered list of BaseEntry objects, or an empty list if no entries could be found
Throws:
IOException - - if the index could not be queries or the entries could not be build
com.google.gdata.util.ParseException - - if an entry could not be parsed while building it from the Lucene Document.

singleEntryQuery

public com.google.gdata.data.BaseEntry singleEntryQuery(String entryId,
                                                        String feedId,
                                                        ProvidedService config)
                                                 throws IOException,
                                                        com.google.gdata.util.ParseException
This method retrieves a single entry from the storage. If the StorageBuffer does not contain the requested entry the underlying storage index will be searched.

The Entry will be searched in a feed context specified by the given feed ID

Parameters:
entryId - - the entry to fetch
feedId - - the feed id e.g. feed context
config - - the FeedInstanceConfiguration containing extension profile used to create the entry instances
Returns:
- the requested BaseEntry or null if the entry can not be found
Throws:
IOException - - if the index could not be queries or the entries could not be build
com.google.gdata.util.ParseException - - if an entry could not be parsed while building it from the Lucene Document.

entryQuery

public List<com.google.gdata.data.BaseEntry> entryQuery(List<String> entryIds,
                                                        String feedId,
                                                        ProvidedService config)
                                                 throws IOException,
                                                        com.google.gdata.util.ParseException
Fetches the requested entries from the storage. The given list contains entry id's to be looked up in the storage. First the StorageBuffer will be queried for the entry id's. If not all of the entries remain in the buffer the underlying lucene index will be searched. The entries are not guaranteed to be in the same order as they are in the given id list. Entry ID's not found in the index or the buffer will be omitted.

The entries will be searched in a feed context specified by the given feed ID

Parameters:
entryIds - - the entry id's to fetch.
feedId - - the feed id e.g. feed context.
config - - the FeedInstanceConfiguration containing extension profile used to create the entry instances
Returns:
- the list of entries corresponding to the given entry id list.
Throws:
IOException - - if the index could not be queries or the entries could not be build
com.google.gdata.util.ParseException - - if an entry could not be parsed while building it from the Lucene Document.

getUser

public GDataAccount getUser(String username)
                     throws IOException
Queries the storage for an user instance

Parameters:
username - - the username (primary key)
Returns:
- the user instance if found or null if not exists
Throws:
IOException - - if the storage can not be accessed.

close

public void close()
           throws IOException
Closes all resources used in the StorageQuery. The instance can not be reused after invoking this method.

Throws:
IOException - - if the resources can not be closed

isFeedStored

public boolean isFeedStored(String feedId)
                     throws IOException
Checks whether a feed for the given feedID is stored

Parameters:
feedId - - the feed ID
Returns:
true if and only if a feed is stored for the provided feed ID, false if no feed for the given id is stored
Throws:
IOException

getService

public String getService(String feedID)
                  throws IOException
Looks up the feed type for the given feed ID

Parameters:
feedID - - the feed ID
Returns:
- the feed type
Throws:
IOException - - if the storage can not be accessed

getAccountNameForFeedId

public String getAccountNameForFeedId(String feedId)
                               throws IOException
Looks up the account reference for the given feed id

Parameters:
feedId - - id of the feed
Returns:
- the name of the account associated with the feed for the given feed id, or null if the feed is not stored
Throws:
IOException - - if the storage can not be accessed

getEntryLastModified

protected long getEntryLastModified(String entryId,
                                    String feedId)
                             throws IOException,
                                    StorageException
Throws:
IOException
StorageException

getFeedLastModified

protected long getFeedLastModified(String feedId)
                            throws IOException
Throws:
IOException

isEntryStored

protected boolean isEntryStored(String entryId,
                                String feedId)
                         throws IOException
Throws:
IOException

checkEntryVersion

protected boolean checkEntryVersion(String id,
                                    String feedId,
                                    int version)
                             throws IOException
Throws:
IOException


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.