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 ; 12 import java.sql.SQLException ; 13 import java.sql.Timestamp ; 14 15 import java.util.Date ; 16 import java.util.HashMap ; 17 import java.util.Map ; 18 import java.util.TreeSet ; 19 import java.util.Vector ; 20 21 import org.enhydra.dods.DODS; 22 import org.enhydra.snapper.SnapperManager; 23 24 25 26 27 public class BusinessUtil { 28 29 Vector filtered; 30 private Vector included; 31 public String title = ""; 32 private DatabaseManager dbm; 33 34 35 public BusinessUtil() {} 36 public BusinessUtil(DatabaseManager dbm){ 37 this.dbm = dbm; 38 } 39 40 41 48 public Vector getFilteredFiles(String db, String tb, String co) throws SQLException , DatabaseManagerException { 49 filtered = new Vector (); 50 DBConnection dbconn = null; 51 ResultSet 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 str = rs.getString(1); 61 str = str.replaceAll("\\\\","/"); 62 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 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 getIncludedFiles(String db, String tb, String co) throws SQLException , DatabaseManagerException { 101 TreeSet included = new TreeSet (); 102 QueryBuilder qb = null; 103 DBConnection dbconn = null; 104 ResultSet 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 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 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 getData(String db, String tb, String filepath, String mod, long indexMod) throws SQLException , DatabaseManagerException { 151 Map data = new HashMap (); 152 DBConnection dbconn = null; 153 ResultSet 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 (indexMod), QueryBuilder.GREATER_THAN); 164 165 rs = qb.executeQuery(dbconn); 166 while (rs.next()) { 167 String path = rs.getString(filepath); 168 Date modified = rs.getDate(mod); 169 path = path.replaceAll("\\\\","/"); 170 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 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 getMetadata(String path, String db, String tb, String cp, String ck, String cv) throws SQLException , DatabaseManagerException { 209 StringBuffer properties = new StringBuffer (); 210 DBConnection dbconn = null; 211 ResultSet 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 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 |