Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

DBJobManager.java

Go to the documentation of this file.
00001 package cedar.jetweb.db;
00002 
00003 import cedar.jetweb.*;
00004 
00005 //import cedar.jetweb.model.Model;
00006 //import cedar.jetweb.model.RunSeries;
00007 //import cedar.jetweb.model.ResultSearchPattern;
00008 import cedar.jetweb.batch.SubmitScriptHandler;
00009 import cedar.jetweb.job.*;
00010 import cedar.jetweb.util.JetWebFile;
00011 import cedar.jetweb.util.Match;
00012 
00013 import java.io.File;
00014 
00015 import java.sql.*;
00016 
00017 import java.text.DecimalFormat;
00018 
00019 import java.util.Date;
00020 import java.util.Enumeration;
00021 import java.util.Vector;
00022 
00023 
00031 public abstract class DBJobManager {
00035     public static final String SUCCESS = "Operation Completed Successfully";
00036 
00037     //private static DBObjectManager objManager = new DBObjectManager();
00038 
00045     public static synchronized void addLogfile(LogFile log)
00046         throws JetWebException {
00047         String ins = "";
00048 
00049         try {
00050             Statement stmt = DBConfig.getConnection().createStatement();
00051 
00052         //add the CutCollection for this logfile to the DB
00053 
00054         log.getGenerator().getCutCollection().store();
00055 
00056             // add a row to the logfile table.
00057             if (log.getId() > 0) {
00058                 ins = "UPDATE logfile SET file='" + log.getFile() + 
00059             "',runseries_id=" + log.getRunSeries().getId() + 
00060             ",status=" + log.getStatus() + 
00061             ",lumi=" + log.getLumi() + 
00062             ", cross_section=" +log.getCrossSection() +
00063             ",cut_collection_id=" + 
00064             log.getGenerator().getCutCollection().getId()+
00065             " WHERE log_id=" + log.getId();
00066             } else {
00067 
00068         String select = "SELECT MAX(log_id) FROM logfile";
00069         ResultSet rs = stmt.executeQuery(select);
00070 
00071         int newId = 1;
00072 
00073         while(rs.next()){
00074             newId = rs.getInt(1);
00075             ++newId;
00076         }
00077         
00078         log.setId(newId);
00079 
00080                 ins = "INSERT INTO logfile " + 
00081             "(log_id, " + 
00082             "file, " + 
00083             "runseries_id, " + 
00084             "status, " + 
00085             "lumi, " + 
00086             "cross_section," +
00087             "cut_collection_id)" 
00088             + "values(" + 
00089             log.getId() + ", '" +
00090                     log.getFile() + "'," + 
00091             log.getRunSeries().getId() + "," +
00092                     log.getStatus() + "," + 
00093             log.getLumi() + "," + 
00094             log.getCrossSection() + "," +
00095             log.getGenerator().getCutCollection().getId() +
00096             ")";
00097             }
00098 
00099             int rowsChanged = stmt.executeUpdate(ins);
00100             stmt.close();
00101         } catch (SQLException E) {
00102             System.out.println("SQLException: " + E.getMessage());
00103             System.out.println("SQLState:     " + E.getSQLState());
00104             System.out.println("VendorError:  " + E.getErrorCode());
00105             log.setStatus(LogFile.ERROR);
00106             throw new JetWebDBException(E, ins, "LogfileId:" + log.getId());
00107         }
00108     }
00109 
00118     public static synchronized void selectFromDBbyName(LogFile log)
00119         throws JetWebException {
00120 
00121     String query = "SELECT * from logfile where file like '%" +
00122         log.getFile() + "%'";
00123 
00124         try {
00125             // First see if the file is in there.
00126             Statement stmt = DBConfig.getConnection().createStatement();
00127             ResultSet rs = stmt.executeQuery(query);
00128 
00129             if (rs.next()) {
00130         System.out.println
00131             ("DBJobManager: found logfile in DB matching file " +
00132              log.getFile());
00133                 // Read from DB to get runseries id from logfile table.
00134                 fillLog(rs, log);
00135             }else{
00136         System.out.println
00137             ("DBJobManager: no file in DB found matching " + 
00138              log.getFile());
00139         }
00140 
00141             // Finish up & return.
00142             rs.close();
00143             stmt.close();
00144         } catch (SQLException E) {
00145             System.out.println("DBFitManager.fillRunSeriesId");
00146             System.out.println("SQLException: " + E.getMessage());
00147             System.out.println("SQLState:     " + E.getSQLState());
00148             System.out.println("VendorError:  " + E.getErrorCode());
00149             throw new JetWebDBException(E, query, "LogfileId:" + log.getId());
00150         }
00151     }
00152 
00160     public static synchronized boolean selectFromDB(CutCollection cuts)
00161     throws JetWebException{
00162 
00163     try{
00164         if(cuts.getIdDontRetrieve()>0){
00165         if(fillById(cuts)) return true;
00166         }
00167         
00168         if(cuts.getCuts().size()!=0){
00169         if(fillByCuts(cuts)) return true;
00170         
00171         // if we get here then there are some cuts in the collection
00172         // but they do not match any collection in the DB
00173         
00174         return false;
00175         }
00176     }catch(SQLException err){
00177         throw new JetWebException(err);
00178     }
00179     return false;
00180     }
00181 
00182     public static synchronized boolean addToDB(CutCollection cuts)
00183     throws JetWebException{
00184 
00185     boolean hasId = (cuts.getId()>0);
00186     boolean hasCuts = (cuts.getCuts().size()!=0);
00187 
00188     try{
00189         //If the collection has an id that is already present in the DB
00190         // then fill the collection object from the DB and return false
00191         if(hasId){
00192 
00193         if(fillById(cuts)) return false;
00194         
00195         }
00196 
00197         if(hasCuts){
00198         // if the same collection of cuts already exists in the 
00199         // DB then just fill the Id and return false
00200 
00201         if(fillByCuts(cuts)) return false;
00202         
00203         return writeCheckedCutCollection(cuts);
00204         }
00205 
00206     }catch(SQLException err){
00207         throw new JetWebException(err);
00208     }
00209 
00210     return false;
00211     }
00212 
00213     private static synchronized boolean fillById(CutCollection cuts)
00214     throws SQLException{
00215 
00216     Integer id = new Integer(cuts.getId());
00217 
00218     String select = 
00219         "SELECT cut_id FROM cut_collection WHERE cut_collection_id=" + 
00220         id;
00221 
00222     Statement stmt = DBConfig.getConnection().createStatement();
00223     ResultSet rs = stmt.executeQuery(select);
00224 
00225     cuts.clear();
00226 
00227     boolean filled = false;
00228 
00229     while(rs.next()){
00230         filled = true;
00231         Cut cut = new Cut(rs.getInt(1));
00232         cuts.addCut(cut);
00233     }
00234 
00235     //reset the CutCollection Id because adding cuts sets it to default
00236 
00237     //  cuts.setId(id);
00238 
00239     return filled;
00240     }
00241 
00247     private static synchronized boolean fillByCuts(CutCollection cuts)
00248     throws SQLException, JetWebException{
00249 
00250     Vector<Integer> foundIds = new Vector<Integer>();
00251     Vector<Integer> cutIds = new Vector<Integer>();
00252 
00253     Statement stmt = DBConfig.getConnection().createStatement();
00254     ResultSet rs;
00255 
00256     boolean firstCut = true;
00257     //loop over all cuts 
00258     for(Cut cut: cuts.getCuts()){
00259 
00260         Integer id = cut.getId();
00261         //retrieve the cut id if necessary (and possible)
00262         if(id<0){
00263         cut.retrieve();
00264         id=cut.getId();
00265         if(id<0) return false;
00266 
00267         }
00268         cutIds.add(id);
00269         //get all CutCollections that contain that cut
00270 
00271         String query = 
00272         "SELECT cut_collection_id FROM cut_collection WHERE cut_id=" + 
00273         id;
00274 
00275         rs = stmt.executeQuery(query);
00276         Vector<Integer> newIds = new Vector<Integer>();
00277         while(rs.next()){
00278         newIds.add(rs.getInt(1));
00279         }
00280 
00281         // Find the list of CutCollections that contains the current cut
00282         // and all previous cuts (unless this is the first cut)
00283         Vector<Integer> tmpIds = new Vector<Integer>();
00284         if(firstCut){
00285         tmpIds = newIds;
00286         firstCut = false;
00287         }else{
00288 
00289         for(Integer i: newIds){
00290             if(foundIds.contains(i)){
00291             tmpIds.add(i);
00292             }
00293         }
00294 
00295         }
00296         //if no CutCollection contains all previous cuts then there is no
00297         //matching CutCollection in the DB
00298         if(tmpIds.size()==0) return false;
00299 
00300         foundIds = tmpIds;
00301 
00302     }
00303 
00304     //Of the found CutCollections, look for one that matches exactly
00305     //i.e. contains ^only^ this set of cuts
00306 
00307     for(Integer Id: foundIds){
00308 
00309         String select = 
00310         "SELECT cut_id FROM cut_collection WHERE cut_collection_id=" + 
00311         Id;
00312 
00313         rs = stmt.executeQuery(select);
00314         boolean carryOn = true;
00315         Integer numCuts = 0;
00316         while(rs.next() && carryOn){
00317         if(!cutIds.contains(new Integer(rs.getInt(1)))) carryOn = false;
00318         ++numCuts;
00319         }
00320 
00321         if(carryOn && numCuts==cutIds.size()){
00322         cuts.setId(Id);
00323         return true;
00324         }
00325     }
00326 
00327     return false;
00328     }
00329 
00330     private static synchronized boolean  writeCheckedCutCollection
00331     (CutCollection cuts)
00332     throws SQLException, JetWebException{
00333 
00334     Statement stmt = DBConfig.getConnection().createStatement();
00335     ResultSet rs = stmt.executeQuery
00336         ("SELECT MAX(cut_collection_id) FROM cut_collection");
00337     int newId = 1;
00338     if(rs.next()){
00339         newId = rs.getInt(1);
00340         ++newId;
00341     }
00342 
00343     if(cuts.getId()<newId) cuts.setId(newId);
00344 
00345     Vector<String> inserts = new Vector<String>();
00346 
00347     for(Cut cut:cuts.getCuts()){
00348 
00349         Integer Id = cut.getId();
00350 
00351         // If any of the cuts in the collection has no id
00352         // then we can't write it to the DB
00353         if(Id<0){
00354         cut.retrieve();
00355         Id = cut.getId();
00356         if(Id<0) return false;
00357         }
00358 
00359         inserts.add
00360         ("INSERT INTO cut_collection(cut_collection_id, cut_id)VALUES("+
00361          cuts.getId() + ", " + 
00362          cut.getId() + ")");
00363     }
00364 
00365     for(String insert:inserts){
00366         stmt.executeUpdate(insert);
00367     }
00368 
00369     return true;
00370     }
00371 
00378     public static synchronized boolean selectFromDB(Cut cut)
00379     throws JetWebException{
00380     String select;
00381     int id = cut.getId();
00382 
00383     if(id > 0){
00384         select = "SELECT * FROM cut WHERE cut_id="+id;
00385     }else{
00386         //select the cut with the same name and nearest value
00387         //select = "SELECT * FROM cut where name="+cut.getName()+
00388         //" AND ABS(value-" + cut.getValue() + 
00389         //")=MIN(ABS(value-" + cut.getValue() + "))";
00390         select = selectNearestCut(cut);
00391     }
00392 
00393     try{
00394     
00395         Statement stmt = DBConfig.getConnection().createStatement();
00396         ResultSet rs = stmt.executeQuery(select);
00397 
00398         //if(rs.isAfterLast()){
00399         if(!rs.next()){
00400         //result set contains no rows - Cut is not in database
00401         //if cut name and value present, store it
00402         
00403         if(cut.getName().equals("") || 
00404            cut.getValue()==null){
00405             return false;
00406         }
00407         return cut.store();
00408         }
00409 
00410         if(id>0){
00411         //rs.next();
00412         cut.setValue(rs.getDouble("value"));
00413         cut.setName(rs.getString("name"));
00414         return true;
00415         }else{
00416         //need to check value in result set matches value of cut
00417         rs.next();
00418         Double value = rs.getDouble("value");
00419 
00420         if(Match.compareDouble(value, cut.getValue())){
00421             cut.setId(rs.getInt("cut_id"));
00422             return true;
00423         }
00424         
00425         //if we get here then there is no row in the DB matching
00426         //that value, but there is a cut with that name.
00427 
00428         if(cut.getValue()!=null&&
00429            !cut.getName().equals("")){
00430             return cut.store();
00431         }
00432 
00433         }
00434 
00435     }catch(SQLException err){
00436         
00437     }
00438     return false;
00439     }
00440 
00441     public static synchronized boolean addToDB(Cut cut)
00442     throws JetWebException{
00443     boolean hasId = cut.getId() > 0;
00444     boolean hasName = !cut.getName().equals("");
00445     boolean hasValue = !(cut.getValue()==null);
00446 
00447     try{
00448 
00449     if(hasId){
00450         //check that a cut with this Id doesn't already exist.
00451         //If it does already exist, do nothing
00452         if(fillById(cut)) return false;
00453     }
00454 
00455     if(hasName&&hasValue){
00456 
00457         if(fillByValue(cut)) return false;
00458 
00459         // if we get here then the cut has a value and a name
00460         // and is not present in the DB
00461 
00462         writeCheckedCut(cut);
00463         return true;
00464     }
00465     
00466     }catch(SQLException err){
00467         throw new JetWebException(err);
00468     }
00469 
00470     return false;
00471     }
00472 
00478     private static synchronized boolean fillById(Cut cut)
00479     throws SQLException{
00480     
00481     String select = "SELECT * FROM cut WHERE cut_id="+cut.getId(); 
00482 
00483     Statement stmt = DBConfig.getConnection().createStatement();
00484     ResultSet rs = stmt.executeQuery(select);
00485     
00486     if(!rs.next()) return false;
00487 
00488     cut.setValue(rs.getDouble("value"));
00489     cut.setName(rs.getString("name"));
00490     
00491     return true;
00492     }
00493 
00499     private static synchronized boolean fillByValue(Cut cut)
00500     throws SQLException{
00501     String select = selectNearestCut(cut);
00502 
00503     Statement stmt = DBConfig.getConnection().createStatement();
00504     ResultSet rs = stmt.executeQuery(select);
00505     if(!rs.next())return false;
00506     
00507     if(!Match.compareDouble(cut.getValue(), rs.getDouble("value"))) 
00508         return false;
00509 
00510     cut.setId(rs.getInt("cut_id"));
00511     cut.setValue(rs.getDouble("value"));
00512     cut.setName(rs.getString("name"));
00513 
00514     return true;
00515     }
00516 
00521     private static synchronized void writeCheckedCut(Cut cut)
00522     throws SQLException{
00523 
00524     Statement stmt = DBConfig.getConnection().createStatement();
00525     ResultSet rs = stmt.executeQuery("SELECT MAX(cut_id) FROM cut");
00526     int newId = 1;
00527     if(rs.next()){
00528         newId = rs.getInt(1);
00529         ++newId;
00530     }
00531 
00532     cut.setId(newId);
00533 
00534     String insert = "INSERT INTO cut(cut_id, name, value)VALUES("+
00535         cut.getId() + ",'" + 
00536         cut.getName() + "', " +
00537         cut.getValue() +")";
00538 
00539     stmt.executeUpdate(insert);
00540 
00541     return;
00542     }
00543 
00544     private static String selectNearestCut(Cut cut){
00545 
00546     return "SELECT * FROM cut where name='" + cut.getName() +
00547         "' AND ABS(value-" + cut.getValue() + 
00548         ")=(SELECT MIN(ABS(value-" + cut.getValue() + ")) FROM cut)";
00549     }
00550 
00557     public static synchronized void selectFromDB(PendingJob job)
00558         throws JetWebException {
00559         String query = "SELECT * FROM logfile WHERE log_id=" + job.getLogId();
00560 
00561         try {
00562             Statement stmt = DBConfig.getConnection().createStatement();
00563             ResultSet rs = stmt.executeQuery(query);
00564 
00565             rs.next();
00566 
00567             if (rs.getInt("status") == 0) {
00568                 job.setValid(true);
00569             } else {
00570                 job.setValid(false);
00571             }
00572 
00573             job.setName(rs.getString("file"));
00574             job.setDate(rs.getTimestamp("time"));
00575             job.setRunSeriesId(rs.getInt("runseries_id"));
00576 
00577             job.setScriptName("unknown");
00578         rs.close();
00579         stmt.close();
00580         } catch (SQLException e) {
00581             System.out.println("DB access error in selectFromDB for PendingJob" + e);
00582             throw new JetWebDBException(e, query, "PendingJob logId:" + job.getLogId());
00583         }
00584     }
00585 
00592     public static synchronized Enumeration<PendingJob> selectPendingJobs()
00593         throws JetWebException {
00594         Vector<PendingJob> jobs = new Vector<PendingJob>();
00595         String query = "SELECT log_id FROM logfile WHERE status=0";
00596 
00597         try {
00598             Statement stmt = DBConfig.getConnection().createStatement();
00599             ResultSet rs = stmt.executeQuery(query);
00600 
00601             while (rs.next()) {
00602                 PendingJob pj = new PendingJob(rs.getInt("log_id"));
00603 
00604                 if (pj.isValid()) {
00605                     jobs.add(pj);
00606                 }
00607             }
00608         rs.close();
00609         stmt.close();
00610         } catch (SQLException e) {
00611             System.out.println("DB access error in selectPendingJobs" + e);
00612             throw new JetWebDBException(e, query, "");
00613         }
00614 
00615         return jobs.elements();
00616     }
00617 
00626     public static synchronized PendingJob reserveJobName(String suggestion)
00627         throws JetWebException {
00628         String name = "invalid";
00629         int id = 0;
00630         String query = "SELECT MAX(log_id) FROM logfile";
00631 
00632         try {
00633             Statement stmt = DBConfig.getConnection().createStatement();
00634             ResultSet rs = stmt.executeQuery(query);
00635 
00636             while (rs.next()) {
00637                 id = rs.getInt(1);
00638                 id++;
00639             }
00640 
00641         //now we do a check for existing files with a name corresponding
00642         //to the found log_id.  Keep incrementing the name until we 
00643         //find a free one
00644         boolean free = false;
00645         DecimalFormat form = new DecimalFormat("00000000000");
00646         while(!free){
00647         name = "n" + form.format(id);
00648         JetWebFile testFile = new JetWebFile(name, ".input");
00649         if(testFile.exists()){
00650             ++id;
00651         }else{
00652             free = true;
00653         }
00654         }
00655 
00656             if (id == 0) {
00657                 System.out.println
00658             ("ResultManager Error allocating Id to " + suggestion);
00659 
00660                 return null;
00661             }
00662 
00663             String ins = 
00664         "INSERT INTO logfile (log_id,file,runseries_id,status,host) " +
00665         "VALUES (" + 
00666         id + ",'" + 
00667         name + 
00668         "',0," +
00669         LogFile.RESERVED + ",'" + 
00670         SubmitScriptHandler.BATCHFACILITY +
00671                 "')";
00672 
00673             int itmp = stmt.executeUpdate(ins);
00674         rs.close();
00675         stmt.close();
00676         } catch (SQLException E) {
00677             System.out.println("ResultManager.getJobName");
00678             System.out.println("SQLException: " + E.getMessage());
00679             System.out.println("SQLState:     " + E.getSQLState());
00680             System.out.println("VendorError:  " + E.getErrorCode());
00681             throw new JetWebDBException(E, query, "suggestion:" + suggestion);
00682         }
00683 
00684         return new PendingJob(id);
00685     }
00686 
00691     public static synchronized void updateStatus(LogFile log)
00692     throws JetWebException{
00693 
00694     String update = 
00695         "UPDATE logfile " + 
00696         " SET status=" +log.getStatus() + 
00697         " WHERE log_id="+log.getId();
00698 
00699     try{
00700         Statement stmt = DBConfig.getConnection().createStatement();
00701         stmt.executeUpdate(update);
00702     }catch(SQLException err){
00703         throw new JetWebException(err);
00704     }
00705     return;
00706     }
00707 
00715     public static synchronized void checkStatus(LogFile log)
00716         throws JetWebException {
00717 
00718     JetWebFile lf = log.getFile();
00719     if(lf == null) return; 
00720 
00721     String query = "SELECT status FROM logfile WHERE file LIKE '%" +
00722         lf + "%'";
00723 
00724         //String query = "SELECT status FROM logfile WHERE file='" + 
00725     //  lf.getPath() + "'";
00726 
00727         try {
00728             // See if the file is in there.
00729             Statement stmt = DBConfig.getConnection().createStatement();
00730             ResultSet rs = stmt.executeQuery(query);
00731 
00732             while (rs.next()) {
00733 
00734         Integer dbStatus = rs.getInt("status");
00735 
00736         dbStatus = (dbStatus.equals(LogFile.SUBMITTED)&&
00737                 log.hasAidaFile())? LogFile.RUN: dbStatus; 
00738 
00739 
00740                 log.setStatus(dbStatus);
00741 
00742             }
00743 
00744             // Finish up & return.
00745             rs.close();
00746             stmt.close();
00747         } catch (SQLException E) {
00748             System.out.println("DBFitManager.checkStatus");
00749             System.out.println("SQLException: " + E.getMessage());
00750             System.out.println("SQLState:     " + E.getSQLState());
00751             System.out.println("VendorError:  " + E.getErrorCode());
00752             throw new JetWebDBException(E, query, "LogFile:" + log.getId());
00753         }
00754     }
00755 
00759     public static void removeLogFile(LogFile log) {
00760     String name = log.getFile().getPath();
00761         System.out.println("Removing logfile: " + name + " from table");
00762 
00763     String del = "delete from logfile where file like '%" + 
00764         log.getFile() + "%'";
00765 
00766         //String del = "delete from logfile where file='" + name + "'";
00767 
00768         try {
00769             Statement stmt = DBConfig.getConnection().createStatement();
00770             stmt.executeUpdate(del);
00771         stmt.close();
00772         } catch (SQLException e) {
00773             System.out.println("DBFitManager: Error executing " + del);
00774         }
00775     }
00776 
00784     public static synchronized int countJobs(String hostname)
00785         throws JetWebException {
00786         String query = "SELECT COUNT(log_id) count_rows FROM logfile WHERE host='" + hostname +
00787             "'";
00788         int nJobs = 0;
00789 
00790         try {
00791             // First see if the file is in there.
00792             Statement stmt = DBConfig.getConnection().createStatement();
00793             ResultSet rs = stmt.executeQuery(query);
00794             rs.next();
00795             nJobs = rs.getInt("count_rows");
00796 
00797             // Finish up & return.
00798             rs.close();
00799             stmt.close();
00800         } catch (SQLException E) {
00801             System.out.println("DBFitManager.countJobs");
00802             System.out.println("SQLException: " + E.getMessage());
00803             System.out.println("SQLState:     " + E.getSQLState());
00804             System.out.println("VendorError:  " + E.getErrorCode());
00805             throw new JetWebDBException(E, query, "Error counting jobs");
00806         }
00807 
00808         return nJobs;
00809     }
00810 
00818     public static synchronized int countCompletedJobs(String hostname)
00819         throws JetWebException {
00820         String query = "SELECT COUNT(log_id) count_rows FROM logfile WHERE status=1" +
00821             " AND host='" + hostname + "'";
00822         int nJobs = 0;
00823 
00824         try {
00825             // First see if the file is in there.
00826             Statement stmt = DBConfig.getConnection().createStatement();
00827             ResultSet rs = stmt.executeQuery(query);
00828             rs.next();
00829             nJobs = rs.getInt("count_rows");
00830 
00831             // Finish up & return.
00832             rs.close();
00833             stmt.close();
00834         } catch (SQLException E) {
00835             System.out.println("DBFitManager.countCompletedJobs");
00836             System.out.println("SQLException: " + E.getMessage());
00837             System.out.println("SQLState:     " + E.getSQLState());
00838             System.out.println("VendorError:  " + E.getErrorCode());
00839             throw new JetWebDBException(E, query, "Error counting completed jobs");
00840         }
00841 
00842         return nJobs;
00843     }
00844 
00852     public static synchronized void selectFromDB(LogFile log)
00853         throws JetWebException {
00854         String findLog = "SELECT * FROM logfile WHERE log_id=" + log.getId();
00855         int logId = log.getId();
00856 
00857         try {
00858             Statement stmt = DBConfig.getConnection().createStatement();
00859             ResultSet rs = stmt.executeQuery(findLog);
00860 
00861             if (rs.next()) {
00862                 fillLog(rs, log);
00863             } else {
00864                 System.out.println("No LogFile found with ID=" + logId);
00865                 throw new JetWebDBException(findLog, "logId:" + logId);
00866             }
00867         rs.close();
00868         stmt.close();
00869         } catch (SQLException e) {
00870             System.out.println("Error reading logfile table " + e);
00871             throw new JetWebDBException(e, findLog, "logId:" + logId);
00872         }
00873 
00874         return;
00875     }
00876 
00877     private static void fillLog(ResultSet rs, LogFile log)
00878         throws SQLException, JetWebException {
00879 
00880     int rsid = rs.getInt("runseries_id");
00881     int status = rs.getInt("status");
00882     Double cs = rs.getDouble("cross_section");
00883     
00884     //if(rsid!=0)log.setRunSeriesId(rsid);
00885     // If the LogFile status is reserved then no info has been filled
00886     // apart from the file name and log id
00887     if(status!=LogFile.RESERVED&&rsid!=0) log.setRunSeriesId(rsid);
00888 
00889         //log.setRunSeriesId(rs.getInt("runseries_id"));
00890         log.setStatus(status);
00891         log.setId(rs.getInt("log_id"));
00892     log.setCrossSection(cs);
00893     String fName = rs.getString("file");
00894     if(!(fName.endsWith(JetWebFile.XML + ".gz") &&
00895          fName.endsWith(JetWebFile.XML))){
00896         fName = fName + JetWebFile.XML;
00897     }
00898 
00899     JetWebFile testFile = 
00900         new JetWebFile(fName);
00901 
00902     if(!testFile.exists()){
00903         System.out.println("DBJobManager: could not find file - using " +
00904                    testFile);
00905     }
00906      
00907         log.setFile(testFile);
00908     }
00909 
00918     public static synchronized Vector<LogFile> getLogFiles(int runSeriesId)
00919         throws JetWebException {
00920         Vector<LogFile> logs = new Vector<LogFile>();
00921         String findLogs = "SELECT log_id FROM logfile WHERE runseries_id=" + runSeriesId;
00922 
00923         try {
00924             Statement stmt = DBConfig.getConnection().createStatement();
00925             ResultSet rs = stmt.executeQuery(findLogs);
00926 
00927             while (rs.next()) {
00928                 LogFile log = new LogFile(rs.getInt("log_id"));
00929                 log.retrieve();
00930                 logs.add(log);
00931             }
00932         rs.close();
00933         stmt.close();
00934         } catch (SQLException e) {
00935             System.out.println("Error reading logfile table " + e);
00936             throw new JetWebDBException(e, findLogs, "RunseriesId:" + runSeriesId);
00937         }
00938 
00939         return logs;
00940     }
00941 
00949     public static synchronized int getNLogs(int runSeriesId)
00950         throws JetWebException {
00951         String findLogs = "SELECT COUNT(log_id) count_logs  FROM logfile WHERE runseries_id=" +
00952             runSeriesId;
00953 
00954         //System.out.println(findLogs);
00955         int n = 0;
00956 
00957         try {
00958             Statement stmt = DBConfig.getConnection().createStatement();
00959             ResultSet rs = stmt.executeQuery(findLogs);
00960             rs.next();
00961             n = rs.getInt("count_logs");
00962         rs.close();
00963         stmt.close();
00964         } catch (SQLException e) {
00965             System.out.println("Error reading logfile table " + e);
00966             throw new JetWebDBException(e, findLogs, "runseriesId:" + runSeriesId);
00967         }
00968 
00969         return n;
00970     }
00971 
00972 }

Generated Wed Jan 17 09:14:27 GMT 2007