View Javadoc

1   /*
2    * ModeShape (http://www.modeshape.org)
3    * See the COPYRIGHT.txt file distributed with this work for information
4    * regarding copyright ownership.  Some portions may be licensed
5    * to Red Hat, Inc. under one or more contributor license agreements.
6    * See the AUTHORS.txt file in the distribution for a full listing of 
7    * individual contributors.
8    *
9    * Unless otherwise indicated, all code in ModeShape is licensed
10   * to you under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation; either version 2.1 of
12   * the License, or (at your option) any later version.
13   * 
14   * ModeShape is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this software; if not, write to the Free
21   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23   */
24  package org.modeshape.graph.request;
25  
26  import java.util.List;
27  import org.modeshape.graph.query.QueryResults.Columns;
28  import org.modeshape.graph.query.QueryResults.Statistics;
29  
30  /**
31   * A {@link Request} to search or query a graph.
32   */
33  public abstract class SearchRequest extends Request {
34  
35      private static final long serialVersionUID = 1L;
36  
37      private Columns columns;
38      private List<Object[]> tuples;
39      private Statistics statistics;
40  
41      /**
42       * {@inheritDoc}
43       * 
44       * @see org.modeshape.graph.request.Request#isReadOnly()
45       */
46      @Override
47      public final boolean isReadOnly() {
48          return true;
49      }
50  
51      /**
52       * Set the results for this request.
53       * 
54       * @param resultColumns the definition of the result columns
55       * @param tuples the result values
56       * @param statistics the statistics, or null if there are none
57       */
58      protected void doSetResults( Columns resultColumns,
59                                   List<Object[]> tuples,
60                                   Statistics statistics ) {
61          this.columns = resultColumns;
62          this.tuples = tuples;
63          this.statistics = statistics;
64      }
65  
66      /**
67       * Get the specification of the columns for the results.
68       * 
69       * @return the column specifications; never null
70       */
71      protected Columns columns() {
72          return columns;
73      }
74  
75      /**
76       * Get the results of this query.
77       * 
78       * @return the results of the query, or null if this request has not been processed
79       */
80      public List<Object[]> getTuples() {
81          return tuples;
82      }
83  
84      /**
85       * Get the statistics that describe the time metrics for this query.
86       * 
87       * @return the statistics; may be null if there are no statistics
88       */
89      public Statistics getStatistics() {
90          return statistics;
91      }
92  
93      /**
94       * {@inheritDoc}
95       * 
96       * @see org.modeshape.graph.request.Request#cancel()
97       */
98      @Override
99      public void cancel() {
100         super.cancel();
101         this.tuples = null;
102         this.statistics = null;
103     }
104 
105 }