KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > snapper > business > BusinessUtil


1 package org.enhydra.snapper.business;
2
3 import com.lutris.appserver.server.sql.DBConnection;
4 import com.lutris.appserver.server.sql.DatabaseManager;
5
6 import com.lutris.appserver.server.sql.DatabaseManagerException;
7 import com.lutris.dods.builder.generator.query.QueryBuilder;
8 import com.lutris.dods.builder.generator.query.RDBColumn;
9 import com.lutris.dods.builder.generator.query.RDBTable;
10
11 import java.sql.ResultSet JavaDoc;
12 import java.sql.SQLException JavaDoc;
13 import java.sql.Timestamp JavaDoc;
14
15 import java.util.Date JavaDoc;
16 import java.util.HashMap JavaDoc;
17 import java.util.Map JavaDoc;
18 import java.util.TreeSet JavaDoc;
19 import java.util.Vector JavaDoc;
20
21 import org.enhydra.dods.DODS;
22 import org.enhydra.snapper.SnapperManager;
23
24
25
26
27 public class BusinessUtil {
28     
29     Vector JavaDoc filtered;
30     private Vector JavaDoc included;
31     public String JavaDoc title = "";
32     private DatabaseManager dbm;
33     
34     
35     public BusinessUtil() {}
36     public BusinessUtil(DatabaseManager dbm){
37         this.dbm = dbm;
38     }
39     
40     
41     /**
42      * @param db
43      * @param tb
44      * @param co
45      * @throws SQLException
46      * @throws DatabaseManagerException
47      */

48     public Vector JavaDoc getFilteredFiles(String JavaDoc db, String JavaDoc tb, String JavaDoc co) throws SQLException JavaDoc, DatabaseManagerException {
49         filtered = new Vector JavaDoc();
50         DBConnection dbconn = null;
51         ResultSet JavaDoc rs =null;
52         QueryBuilder qb = null;
53         try{
54          dbconn = dbm.findLogicalDatabase(db).allocateConnection();
55          qb = new QueryBuilder(tb, co);
56         if (!(SnapperManager.getInstance().getFetchSize() < 1))
57             qb.setCurrentFetchSize(SnapperManager.getInstance().getFetchSize());
58          rs = qb.executeQuery(dbconn);
59         while (rs.next()) {
60             String JavaDoc str = rs.getString(1);
61             str = str.replaceAll("\\\\","/");
62             //str = str.toLowerCase();
63
filtered.add(str);
64         }
65         
66         rs.close();
67         rs = null;
68         if (qb.getStatement() != null)
69             qb.getStatement().close();
70         qb.close();
71         dbconn.release();
72         rs = null;
73         qb = null;
74         dbconn = null;
75         } catch (Exception JavaDoc ex) {
76             SnapperManager.getInstance().getLoggingManager().error("Could not get filtered files");
77         
78         }
79         finally{
80             if (rs != null){
81                 rs.close();
82                 rs = null;
83             }
84             
85             if (qb != null) {
86                 if (qb.getStatement() != null)
87                     qb.getStatement().close();
88                 qb.close();
89                 qb = null;
90                 
91             }
92             if (dbconn != null){
93                 dbconn.release();
94                 dbconn = null;
95             }
96         }
97         return filtered;
98     }
99     
100     public TreeSet JavaDoc getIncludedFiles(String JavaDoc db, String JavaDoc tb, String JavaDoc co) throws SQLException JavaDoc, DatabaseManagerException {
101         TreeSet JavaDoc included = new TreeSet JavaDoc();
102         QueryBuilder qb = null;
103         DBConnection dbconn = null;
104         ResultSet JavaDoc rs = null;
105         try{
106         dbconn = dbm.findLogicalDatabase(db).allocateConnection();
107         qb = new QueryBuilder(tb, co);
108         if (!(SnapperManager.getInstance().getFetchSize() < 1))
109             qb.setCurrentFetchSize(SnapperManager.getInstance().getFetchSize());
110         rs = qb.executeQuery(dbconn);
111         while (rs.next()) {
112             String JavaDoc str = rs.getString(1);
113
114             included.add(str);
115         }
116         
117         rs.close();
118         rs = null;
119         if (qb.getStatement() != null)
120             qb.getStatement().close();
121         qb.close();
122         dbconn.release();
123         
124         qb = null;
125         dbconn = null;
126         } catch (Exception JavaDoc ex) {
127             SnapperManager.getInstance().getLoggingManager().error("Could not get included files");
128         }
129         finally{
130             if (rs != null){
131                 rs.close();
132                 rs = null;
133             }
134             
135             if (qb != null) {
136                 if (qb.getStatement() != null)
137                     qb.getStatement().close();
138                 qb.close();
139                 qb = null;
140                 
141             }
142             if (dbconn != null){
143                 dbconn.release();
144                 dbconn = null;
145             }
146         }
147         return included;
148     }
149     
150     public Map JavaDoc getData(String JavaDoc db, String JavaDoc tb, String JavaDoc filepath, String JavaDoc mod, long indexMod) throws SQLException JavaDoc, DatabaseManagerException {
151         Map JavaDoc data = new HashMap JavaDoc();
152         DBConnection dbconn = null;
153         ResultSet JavaDoc rs = null;
154         QueryBuilder qb = null;
155         try{
156         dbconn = dbm.findLogicalDatabase(db).allocateConnection();
157         qb = new QueryBuilder(tb);
158         if (!(SnapperManager.getInstance().getFetchSize() < 1))
159             qb.setCurrentFetchSize(SnapperManager.getInstance().getFetchSize());
160         
161         RDBTable t = new RDBTable(tb);
162         qb = new QueryBuilder(tb);
163         qb.addWhere(new RDBColumn(t, mod), new Timestamp JavaDoc(indexMod), QueryBuilder.GREATER_THAN);
164         
165         rs = qb.executeQuery(dbconn);
166         while (rs.next()) {
167             String JavaDoc path = rs.getString(filepath);
168             Date JavaDoc modified = rs.getDate(mod);
169             path = path.replaceAll("\\\\","/");
170             //path = path.toLowerCase();
171
data.put(path, modified);
172         }
173         rs.close();
174         rs = null;
175         if (qb.getStatement() != null)
176             qb.getStatement().close();
177         qb.close();
178         dbconn.release();
179         rs = null;
180         qb = null;
181         dbconn = null;
182         } catch (Exception JavaDoc ex) {
183             SnapperManager.getInstance().getLoggingManager().error("Could not get included files");
184         }
185         
186         finally{
187             if (rs != null){
188                 rs.close();
189                 rs = null;
190             }
191
192             
193             if (qb != null) {
194                 if (qb.getStatement() != null)
195                     qb.getStatement().close();
196                 qb.close();
197                 qb = null;
198                 
199             }
200             if (dbconn != null){
201                 dbconn.release();
202                 dbconn = null;
203             }
204         }
205         return data;
206     }
207     
208     public String JavaDoc getMetadata(String JavaDoc path, String JavaDoc db, String JavaDoc tb, String JavaDoc cp, String JavaDoc ck, String JavaDoc cv) throws SQLException JavaDoc, DatabaseManagerException {
209         StringBuffer JavaDoc properties = new StringBuffer JavaDoc();
210         DBConnection dbconn = null;
211         ResultSet JavaDoc rs = null;
212         QueryBuilder qb = null;
213         try{
214         dbconn = dbm.findLogicalDatabase(db).allocateConnection();
215         RDBTable t = new RDBTable(tb);
216         qb = new QueryBuilder(tb);
217         qb.addWhere(new RDBColumn(t, cp), path);
218         
219         if (!(SnapperManager.getInstance().getFetchSize() < 1))
220             qb.setCurrentFetchSize(SnapperManager.getInstance().getFetchSize());
221         
222          rs = qb.executeQuery(dbconn);
223         
224             
225         while (rs.next()) {
226             properties.append(rs.getString(ck) + " = " + rs.getString(cv) + " , ");
227             if (rs.getString(ck).trim().equals(SnapperManager.getInstance().getDocumentLogicalName()))
228                 title = rs.getString(cv).trim();
229         }
230         
231         rs.close();
232         rs = null;
233         if (qb.getStatement() != null)
234             qb.getStatement().close();
235         qb.close();
236         dbconn.release();
237         rs = null;
238         qb = null;
239         dbconn = null;
240         
241         } catch (Exception JavaDoc ex) {
242             SnapperManager.getInstance().getLoggingManager().debug("Could not get metadata properties");
243         
244         }
245         finally{
246             if (rs != null){
247                 rs.close();
248                 rs = null;
249             }
250            
251             
252             if (qb != null) {
253                 if (qb.getStatement() != null)
254                     qb.getStatement().close();
255                 qb.close();
256                 qb = null;
257                 
258             }
259             if (dbconn != null){
260                 dbconn.release();
261                 dbconn = null;
262             }
263         }
264         
265         return properties.toString();
266     }
267     
268     
269     public void gc (){
270         if (filtered != null){
271         filtered.removeAllElements();
272         filtered=null;
273         }
274         if (included != null){
275         included.removeAllElements();
276         included=null;
277         }
278     }
279         
280 }
281
Popular Tags