001    package com.sptci.prevayler.query;
002    
003    import com.sptci.prevayler.PrevalentException;
004    import com.sptci.prevayler.PrevalentObject;
005    import com.sptci.prevayler.PrevalentSystem;
006    
007    import java.util.Collection;
008    import java.util.Date;
009    
010    /**
011     * A query used to fetch prevalent objects that are indexed by the specified
012     * field.
013     *
014     * <p>&copy; Copyright 2008 <a href='http://sptci.com/' target='_top'>Sans
015     * Pareil Technologies, Inc.</a></p>
016     *
017     * @author Rakesh Vidyadharan 2008-07-13
018     * @version $Id: FetchByIndex.java 22 2008-11-24 19:04:25Z sptrakesh $
019     */
020    public class FetchByIndex<P extends Collection<PrevalentObject>, S extends PrevalentSystem>
021      extends AbstractQuery<P,S>
022    {
023      /** The type of the prevalent object that is to be queried. */
024      private final Class type;
025    
026      /** The name of the indexed field in the prevalent objects to query. */
027      private final String field;
028    
029      /** The value of the indexed field to use to query the system. */
030      private final Object value;
031    
032      /**
033       * Create a new instance of the query with the specified values.
034       *
035       * @param type The {@link #type} to use for the query.
036       * @param field The {@link #field} to use for the query.
037       * @param value The {@link #value} to use for the query.
038       */
039      public FetchByIndex( final Class type, final String field, final Object value )
040      {
041        this.type = type;
042        this.field = field;
043        this.value = value;
044      }
045    
046      /**
047       * Execute the query on the prevalent system and return the collection of
048       *
049       * @param system The prevalent system that is to be acted upon.
050       * @param timestamp The timestamp for the query.
051       * @return The collection of prevalent objects matching the specified
052       *   indexed field.
053       * @throws PrevalentException If errors are encountered while querying
054       *   the system.
055       */
056      @Override
057      @SuppressWarnings( {"unchecked"} )
058      protected P query( final S system, final Date timestamp )
059          throws PrevalentException
060      {
061        return (P) system.fetch( type, field, value );
062      }
063    }