View Javadoc

1   package com.explosion.expfmodules.rdbmsconn.dbom;
2   
3   import java.util.ArrayList;
4   import java.util.HashMap;
5   import java.util.List;
6   import java.util.Map;
7   
8   import org.apache.log4j.LogManager;
9   import org.apache.log4j.Logger;
10  
11  /*
12   * =============================================================================
13   * 
14   * Copyright 2004 Stephen Cowx
15   * 
16   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
17   * use this file except in compliance with the License. You may obtain a copy of
18   * the License at
19   * 
20   * http://www.apache.org/licenses/LICENSE-2.0
21   * 
22   * Unless required by applicable law or agreed to in writing, software
23   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
25   * License for the specific language governing permissions and limitations under
26   * the License.
27   * 
28   * =============================================================================
29   */
30  
31  /***
32   * @author Stephen Cowx Date created:@10-Feb-2003
33   */
34  public class DBEntityBuffer
35  {
36      private static Logger log = LogManager.getLogger(DBEntityBuffer.class);
37      private String fetchSQL;
38      private List sortedColumnsList;
39      private Map sortedColumnsMap;
40  
41      public static final int ASCENDING = 1;
42      public static final int DESCENDING = -1;
43      public static final int NOTSORTED = 0;
44      private boolean useCustomQuery = false;
45      
46      private Map columnWidths = new HashMap(); 
47  
48      /***
49       * Constructor for DBEntityBuffer.
50       */
51      public DBEntityBuffer()
52      {
53          sortedColumnsList = new ArrayList();
54          sortedColumnsMap = new HashMap();
55      }
56  
57      /***
58       * Returns the fetchFilter.
59       * 
60       * @return String
61       */
62      public String getFetchSQL()
63      {
64          return fetchSQL;
65      }
66  
67      /***
68       * Sets the fetchSQL.
69       * 
70       * @param fetchSQL The fetchSQL to set
71       */
72      public void setFetchSQL(String fetchSQL)
73      {
74          this.fetchSQL = fetchSQL;
75      }
76  
77      /***
78       * This method works in sequence. The column proivided is matched against
79       * columns already in the sortOrder and the following logic is executed 1)
80       * If the column is not currently in the sort then it is added at the end.
81       * 2) If the column is currently in the sort and is sorted ascending then it
82       * is reversed to be sorted descending. 3) If the column is currently in the
83       * sort and is sorted descending then it is removed from the sort.
84       * 
85       * @param columnName
86       */
87      public void setSortingStatus(String columnName, int status)
88      {
89          if (status == ASCENDING || status == DESCENDING)
90          {
91              sortedColumnsMap.put(columnName, new Integer(status));
92              if (!sortedColumnsList.contains(columnName))
93                  sortedColumnsList.add(columnName);
94          } 
95          else
96          {
97              removeFromSort(columnName);
98          }
99      }
100     
101     /***
102      * Removes the named column from the sort
103      * 
104      * @param columnName
105      */
106     public void removeFromSort(String columnName)
107     {
108         log.debug("before: "+sortedColumnsList.size());
109         sortedColumnsMap.remove(columnName);
110         sortedColumnsList.remove(columnName);
111         log.debug("after:"+sortedColumnsList.size());
112     }
113 
114     /***
115      * Returns the Sorting status of this column
116      * 
117      * @param columnName
118      * @return
119      */
120     public int getSortDirection(String columnName)
121     {
122         Integer value = (Integer) sortedColumnsMap.get(columnName);
123         if (value != null)
124             return value.intValue();
125         else
126             return NOTSORTED;
127     }
128 
129     /***
130      * Returns the Sorting index of this column
131      * 
132      * @param columnName
133      * @return
134      */
135     public int getSortIndex(String columnName)
136     {
137         return sortedColumnsList.indexOf(columnName);    }
138 
139     /***
140      * @return Returns the sortedColumnsList.
141      */
142     public List getSortedColumnsList()
143     {
144         return sortedColumnsList;
145     }
146     
147     /***
148      * Remembers the width of this column
149      * @param columnName
150      * @param newWidth
151      */
152     public void setColumnWidth(String columnName, int newWidth)
153     {
154        columnWidths.put(columnName, new Integer(newWidth));
155     }
156 
157     /***
158      * This methdo returns the width of the named column
159      * @param columnName
160      * @return
161      */
162     public int getColumnWidth(String columnName)
163     {
164         Integer width = (Integer) columnWidths.get(columnName);
165         if (width != null)
166             return width.intValue();
167         else
168             return -1;
169     }
170 
171     /***
172      * Sets the value of the parameter which indicates whether or not the customised query is in use.
173      * @param truth
174      */
175     public void setUseCustomQuery(boolean truth)
176     {
177         this.useCustomQuery = truth;
178     }
179     
180     /***
181      * @return returns the value of the parameter which indicates whether or not the customised query is in use.
182      */
183     public boolean isUseCustomQyuery()
184     {
185         return useCustomQuery;
186     }
187 }