001    package com.sptci.prevayler.query;
002    
003    import com.sptci.prevayler.PrevalentManager;
004    import com.sptci.prevayler.PrevalentSystem;
005    
006    import java.util.Date;
007    
008    /**
009     * The query for retrieving the total number of objects of the specified
010     * type in the prevalent system.
011     *
012     * @see PrevalentManager#count(Class)
013     * <p>&copy; Copyright 2008 <a href='http://sptci.com/' target='_top'>Sans Pareil
014     *   Technologies, Inc.</a></p>
015     * @author Rakesh Vidyadharan 2008-05-27
016     * @version $Id: Count.java 18 2008-07-20 03:35:47Z sptrakesh $
017     */
018    public class Count<S extends PrevalentSystem> extends AbstractQuery<Integer,S>
019    {
020      /** The type of object whose total count is required. */
021      private final Class cls;
022    
023      /**
024       * Create a new instance of the query for the specified prevalent object
025       * type.
026       *
027       * @param cls The {@link #cls} value to use.
028       */
029       public Count( final Class cls )
030       {
031         this.cls = cls;
032       }
033    
034      /**
035       * Execute the query on the prevalent system and return the
036       * total number of objects of {@link #cls} in the system.
037       *
038       * @param system The prevalent system that is to be acted upon.
039       * @param timestamp The timestamp for the query.
040       * @return The count of prevalent objects of {@link #cls} in the system.
041       */
042      @Override
043      protected Integer query( final S system, final Date timestamp )
044      {
045        return system.count( cls );
046      }
047    }