View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.model.sql;
12  
13  import java.io.Serializable;
14  import java.util.LinkedList;
15  import java.util.List;
16  import java.util.Map;
17  
18  /**
19   * A class to store data source test tool related data in a session attribute.
20   */
21  public class DataSourceTestInfo implements Serializable {
22  
23    /** The Constant serialVersionUID. */
24    private static final long serialVersionUID = 1L;
25  
26    /** The Constant DS_TEST_SESS_ATTR. */
27    public static final String DS_TEST_SESS_ATTR = "dataSourceTestData";
28  
29    /** The results. */
30    private List<Map<String, String>> results;
31  
32    /** The query history. */
33    private final LinkedList<String> queryHistory;
34  
35    /** The max rows. */
36    private int maxRows;
37  
38    /** The rows per page. */
39    private int rowsPerPage;
40  
41    /** The history size. */
42    private int historySize;
43  
44    /**
45     * DataSourceTestInfo Constructor.
46     */
47    public DataSourceTestInfo() {
48      queryHistory = new LinkedList<>();
49    }
50  
51    /**
52     * Adds the query to history.
53     *
54     * @param sql the sql
55     */
56    public void addQueryToHistory(String sql) {
57      queryHistory.remove(sql);
58      queryHistory.addFirst(sql);
59  
60      while (historySize >= 0 && queryHistory.size() > historySize) {
61        queryHistory.removeLast();
62      }
63    }
64  
65    /**
66     * Gets the results.
67     *
68     * @return the results
69     */
70    public List<Map<String, String>> getResults() {
71      return results;
72    }
73  
74    /**
75     * Sets the results.
76     *
77     * @param results the results
78     */
79    public void setResults(List<Map<String, String>> results) {
80      this.results = results;
81    }
82  
83    /**
84     * Gets the query history.
85     *
86     * @return the query history
87     */
88    public List<String> getQueryHistory() {
89      return queryHistory;
90    }
91  
92    /**
93     * Gets the max rows.
94     *
95     * @return the max rows
96     */
97    public int getMaxRows() {
98      return maxRows;
99    }
100 
101   /**
102    * Sets the max rows.
103    *
104    * @param maxRows the new max rows
105    */
106   public void setMaxRows(int maxRows) {
107     this.maxRows = maxRows;
108   }
109 
110   /**
111    * Gets the rows per page.
112    *
113    * @return the rows per page
114    */
115   public int getRowsPerPage() {
116     return rowsPerPage;
117   }
118 
119   /**
120    * Sets the rows per page.
121    *
122    * @param rowsPerPage the new rows per page
123    */
124   public void setRowsPerPage(int rowsPerPage) {
125     this.rowsPerPage = rowsPerPage;
126   }
127 
128   /**
129    * Gets the history size.
130    *
131    * @return the history size
132    */
133   public int getHistorySize() {
134     return historySize;
135   }
136 
137   /**
138    * Sets the history size.
139    *
140    * @param historySize the new history size
141    */
142   public void setHistorySize(int historySize) {
143     this.historySize = historySize;
144   }
145 
146 }