001    package com.sptci.prevayler.query;
002    
003    import com.sptci.prevayler.PrevalentSystem;
004    import org.prevayler.Query;
005    
006    import java.util.Date;
007    
008    /**
009     * A base class for all simple queries against the prevalent system.
010     *
011     * <p>&copy; Copyright 2008 <a href='http://sptci.com/' target='_top'>Sans Pareil
012     *   Technologies, Inc.</a></p>
013     * @author Rakesh Vidyadharan 2008-05-27
014     * @version $Id: AbstractQuery.java 22 2008-11-24 19:04:25Z sptrakesh $
015     */
016    public abstract class AbstractQuery<T,S extends PrevalentSystem>
017        implements Query
018    {
019      /**
020       * Implementation of the interface method.  Properly type-casts the
021       * object parameter to a {@link PrevalentSystem} and hands over to
022       * {@link #query( PrevalentSystem, Date )}.
023       *
024       * @param prevalentSystem The prevalent system against which the query
025       *   is to be performed.
026       * @param executionTime The timestamp for the query.
027       * @return The result of executing the query.
028       * @throws Exception If errors are encountered while executing the query.
029       */
030      @SuppressWarnings( {"unchecked"} )
031      public Object query( final Object prevalentSystem,
032          final Date executionTime ) throws Exception
033      {
034        return query( (S) prevalentSystem, executionTime  );
035      }
036    
037      /**
038       * Execute the query on the prevalent system and return the results.
039       *
040       * @param system The prevalent system that is to be acted upon.
041       * @param timestamp The timestamp for the query.
042       * @return The results of the query.
043       * @throws Exception If errors are encountered while executing the query.
044       */
045      protected abstract T query( final S system,
046          final Date timestamp  ) throws Exception;
047    }