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

DBFitManager Class Reference

List of all members.

Detailed Description

DataBase operations for fit package.

Author:
S.Butterworth
Version:
Date
2006-11-16 15:14:11 +0000 (Thu, 16 Nov 2006)
Revision
1311

Definition at line 30 of file DBFitManager.java.


Static Public Member Functions

synchronized String selectFromDB (Fit fit) throws JetWebException
synchronized void addFit (Fit fit) throws JetWebException
synchronized void deleteAll (int fitId) throws JetWebException
void zeroFit (int fitId)
synchronized Vector< Fitselect (Model model) throws JetWebException

Static Public Attributes

final String SUCCESS = "Operation Completed Successfully"

Static Private Member Functions

String fill (Fit fit, ResultSet rs) throws JetWebException
int selectFitId (int mdlId, int cssId) throws JetWebException
String makeInsertFitString (Fit fit) throws JetWebException

Member Function Documentation

synchronized void addFit Fit  fit  )  throws JetWebException [static]
 

Writes this fit (including all its fitted points) to the DB.

Parameters:
fit to be inserted.
Exceptions:
JetWebException 

Definition at line 183 of file DBFitManager.java.

00183                                                                            {
00184         String insertFit = makeInsertFitString(fit);
00185 
00186         try {
00187             Statement stmt = DBConfig.getConnection().createStatement();
00188             stmt.executeUpdate(insertFit);
00189         stmt.close();
00190         } catch (SQLException e) {
00191             try {
00192                 System.out.println("Error inserting fit results " + e + "ModelId=" +
00193                     fit.getModel().getId() + " CSSet=" + fit.getPlotSelection().getId());
00194                 throw new JetWebDBException(e, insertFit,
00195                     "Error inserting fit results " + "ModelId=" + fit.getModel().getId() +
00196                     " CSSet=" + fit.getPlotSelection().getId());
00197             } catch (JetWebException je) {
00198                 System.out.println("Error getting model " + je);
00199                 throw je;
00200             }
00201         }
00202 
00203         try {
00204             // Set the fitId in the Fit object
00205             fit.setId(selectFitId(fit.getModel().getId(), fit.getPlotSelection().getId()));
00206         } catch (JetWebException je) {
00207             System.out.println("Error getting model " + je);
00208             throw je;
00209         }
00210     }

synchronized void deleteAll int  fitId  )  throws JetWebException [static]
 

Clears down an existing fit record from the DB.

Parameters:
fitId identifier of fit to be deleted.
Exceptions:
JetWebException 

Definition at line 246 of file DBFitManager.java.

00247                                {
00248         String deleteString = "";
00249         String deleteString1 = "DELETE FROM fitted_prediction WHERE fit_id=" + fitId;
00250         String deleteString2 = "DELETE FROM fitted_point WHERE fit_id=" + fitId;
00251         String deleteString3 = "DELETE FROM fit WHERE fit_id=" + fitId;
00252 
00253     //System.out.println("Called Fit.fit()");
00254     //JetWebException e2 = new JetWebException("help","help");
00255     //e2.printStackTrace();
00256 
00257 
00258 
00259         try {
00260             Statement stmt = DBConfig.getConnection().createStatement();
00261             deleteString = deleteString1;
00262         System.out.println(deleteString);
00263             System.out.println(stmt.executeUpdate(deleteString));
00264             deleteString = deleteString2;
00265         System.out.println(deleteString);
00266             System.out.println(stmt.executeUpdate(deleteString));
00267             deleteString = deleteString3;
00268         System.out.println(deleteString);
00269             System.out.println(stmt.executeUpdate(deleteString));
00270             stmt.close();
00271         } catch (SQLException e) {
00272             System.out.println("Error deleting fit results " + e + "FitId=" + fitId);
00273             throw new JetWebDBException(e, deleteString, "FitId:" + fitId);
00274         }
00275     }

String fill Fit  fit,
ResultSet  rs
throws JetWebException [static, private]
 

fill the Fit from the resultset

Definition at line 91 of file DBFitManager.java.

References RunSeries.getCutCollection(), Model.getDate(), Model.getId(), RunSeries.getMCProcessType(), CutCollection.isWithin(), and PlotSelection.restrictCutCollection().

00091                                                                              {
00092         String rtn = SUCCESS;
00093 
00094         try {
00095             fit.setId(rs.getInt("fit_id"));
00096         Model model = new Model(rs.getInt("mdl_id"));
00097             //fit.setModel(model);
00098             fit.setModelId(model.getId());
00099 
00100         //need to get a list of runseries that generate data for this fit
00101         String select  = 
00102         "SELECT runseries_id FROM runseries_collection, model "+
00103         "WHERE " + 
00104         "runseries_collection.runseries_collection_id = " +
00105         "model.runseries_collection_id AND " + 
00106         "model.mdl_id = " + model.getId();
00107 
00108         Statement stmt = DBConfig.getConnection().createStatement();
00109         ResultSet runseriesRs = stmt.executeQuery(select);
00110 
00111         HashMap<MCProcessType, CutCollection> processCuts = 
00112         new HashMap<MCProcessType, CutCollection>();
00113 
00114         while(runseriesRs.next()){
00115         Integer rsid = runseriesRs.getInt(1);
00116 
00117         if(rsid!=null){
00118             //RunSeries runseries = new RunSeries(rsid);
00119             RunSeries runseries = RunSeries.Maker(rsid);
00120             MCProcessType proc = runseries.getMCProcessType();
00121             CutCollection cuts = runseries.getCutCollection();
00122 
00123             CutCollection existingCuts = 
00124             processCuts.get(proc);
00125 
00126             if(existingCuts==null ||
00127                existingCuts.isWithin(cuts)
00128                ){
00129             processCuts.put(proc, cuts);
00130             }
00131 
00132         }
00133 
00134         System.out.println("processCuts = " + processCuts);
00135 
00136         }
00137 
00138         PlotSelection selection  = 
00139         new PlotSelection(rs.getInt("csn_set_id"));
00140         
00141         for(Map.Entry entry: processCuts.entrySet()){
00142         selection.restrictCutCollection
00143             ((MCProcessType)entry.getKey(), 
00144              (CutCollection)entry.getValue());
00145         }
00146 
00147         //fit.setPlotSelection(new PlotSelection(rs.getInt("csn_set_id")));
00148         fit.setPlotSelection(selection);
00149         Date fdate = rs.getTimestamp("time");
00150             fit.setDate(fdate);
00151 
00152             if (!(model.getDate() == null)) {
00153                 if (fdate.before(model.getDate())) {
00154                     return "Fit is older than Model";
00155                 }
00156             }
00157 
00158             fit.setScale(rs.getFloat("scalefactor"));
00159 
00160             double[] tmpChi2 = { 0., 0. };
00161             tmpChi2[0] = rs.getFloat("chi2");
00162             tmpChi2[1] = rs.getFloat("dof");
00163             fit.setChi2(tmpChi2);
00164         } catch (SQLException e) {
00165             System.out.println("Error reading fit table " + e + "ModelId=" +
00166                 fit.getModel().getId() + " CSSet=" + fit.getPlotSelection().getId());
00167             throw new JetWebDBException(e, null,
00168                 "Error reading fit table " + "ModelId=" + fit.getModel().getId() + " CSSet=" +
00169                 fit.getPlotSelection().getId());
00170         } catch (JetWebException je) {
00171             System.out.println("Error getting model " + je);
00172         }
00173 
00174         return rtn;
00175     }

String makeInsertFitString Fit  fit  )  throws JetWebException [static, private]
 

Definition at line 277 of file DBFitManager.java.

References PlotSelection.getId().

00277                                                                               {
00278         String ins1 = "INSERT INTO fit (";
00279         String ins2 = "VALUES(";
00280 
00281         if (fit.getId() > 0) {
00282             ins1 = ins1 + "fit_id,";
00283             ins2 = ins2 + fit.getId() + ",";
00284         }
00285 
00286         ins1 = ins1 + "mdl_id,csn_set_id,scalefactor," + "chi2,dof)";
00287 
00288         fit.setDate(new Date());
00289 
00290         try {
00291             ins2 = ins2 + fit.getModel().getId() + "," + fit.getPlotSelection().getId() + "," + fit.getScale();
00292         } catch (JetWebException je) {
00293             System.out.println("Error getting model " + je);
00294         }
00295 
00296         ins2 = ins2 + "," + fit.getChi2()[0] + "," + fit.getChi2()[1] + ")";
00297 
00298         //System.out.println(ins1+ins2);
00299         return ins1 + ins2;
00300     }

synchronized Vector<Fit> select Model  model  )  throws JetWebException [static]
 

Get all fits to the input model.

Definition at line 331 of file DBFitManager.java.

References PlotSelection.getId().

00332                                {
00333 
00334     Vector<Fit> fits = new Vector<Fit>();
00335         String query = "";
00336 
00337         try {
00338         query = "SELECT fit_id FROM fit WHERE mdl_id=" + model.getId();
00339         } catch (Exception e) {
00340             throw new JetWebException(e,"Error getting model");
00341         }
00342 
00343         try {
00344             Statement stmt = DBConfig.getConnection().createStatement();
00345             ResultSet rs = stmt.executeQuery(query);
00346 
00347             while (rs.next()) {
00348         Fit fit = new Fit(rs.getInt("fit_id"));
00349         fits.add(fit);
00350             }
00351         rs.close();
00352         stmt.close();
00353         } catch (SQLException e) {
00354         throw new JetWebDBException(e, query, "ModelId:" + model.getId());
00355         }
00356 
00357         return fits;
00358     }

int selectFitId int  mdlId,
int  cssId
throws JetWebException [static, private]
 

Select fitId from the DB to match this model and crosssection return 0 if not found

Definition at line 216 of file DBFitManager.java.

00217                                {
00218         int fitId = 0;
00219         String query = "SELECT fit_id FROM fit WHERE mdl_id=" + mdlId + " AND csn_set_id=" + cssId;
00220 
00221         try {
00222             Statement stmt = DBConfig.getConnection().createStatement();
00223             ResultSet rs = stmt.executeQuery(query);
00224 
00225             if (rs.next()) {
00226                 fitId = rs.getInt("fit_id");
00227             }
00228         rs.close();
00229         stmt.close();
00230         } catch (SQLException e) {
00231             System.out.println("Error reading fit table " + e + "ModelId=" + mdlId + " CSSet=" +
00232                 cssId);
00233             throw new JetWebDBException(e, query,
00234                 "Error reading fit table " + "ModelId=" + mdlId + " CSSet=" + cssId);
00235         }
00236 
00237         return fitId;
00238     }

synchronized String selectFromDB Fit  fit  )  throws JetWebException [static]
 

Reads in the fit from the DB. Either the fit ID or the model and plotselection ID must be set beforehand. If the fit does not exist in the DB it builds one (and gets the MC papers). Returns SUCCESS or an error message.

Parameters:
fit specifies the fit to be retrieved
Returns:
String; SUCCESS or error string
Exceptions:
JetWebException - thrown if there is an SQL exception

Definition at line 47 of file DBFitManager.java.

00048                                {
00049         String query = "";
00050 
00051         try {
00052             if (fit.getId() >= 0) {
00053                 query = "SELECT * FROM fit WHERE fit_id=" + fit.getId();
00054             } else {
00055                 query = "SELECT * FROM fit WHERE mdl_id=" + fit.getModel().getId() +
00056                     " AND csn_set_id=" + fit.getPlotSelection().getId();
00057             }
00058         } catch (Exception e) {
00059             throw new JetWebException(e,"Error getting model");
00060         }
00061 
00062         String gotit = "";
00063 
00064         try {
00065             Statement stmt = DBConfig.getConnection().createStatement();
00066             ResultSet rs = stmt.executeQuery(query);
00067 
00068             if (rs.next()) {
00069                 gotit = fill(fit, rs);
00070             } 
00071 
00072         rs.close();
00073         stmt.close();
00074         } catch (SQLException e) {
00075             try {
00076                 System.out.println("Error reading fit table " + e + "ModelId=" +
00077                     fit.getModel().getId() + " CSSet=" + fit.getPlotSelection().getId());
00078                 throw new JetWebDBException(e, query, "FitId:" + fit.getId());
00079             } catch (JetWebException je) {
00080                 System.out.println("Error getting model " + je + "FitId:" + fit.getId());
00081                 throw je;
00082             }
00083         }
00084 
00085         return gotit;
00086     }

void zeroFit int  fitId  )  [static]
 

Zero all data associated with the given fit id, without removing the fit itself.

Definition at line 305 of file DBFitManager.java.

00305                                           {
00306         String zeroIt = "update fitted_point set y=0.0,dy_up=0.0,dy_down=0.0 where fit_id=" +
00307             fitId;
00308 
00309         try {
00310             Statement stmt = DBConfig.getConnection().createStatement();
00311             stmt.executeUpdate(zeroIt);
00312         stmt.close();
00313         } catch (SQLException e) {
00314             System.out.println("DBFitManager: Error executing " + zeroIt);
00315         }
00316 
00317         zeroIt = "update fitted_prediction set chi2=0.0,dof=0.0 where fit_id=" + fitId;
00318 
00319         try {
00320             Statement stmt = DBConfig.getConnection().createStatement();
00321             stmt.executeUpdate(zeroIt);
00322         stmt.close();
00323         } catch (SQLException e) {
00324             System.out.println("DBFitManager: Error executing " + zeroIt);
00325         }
00326     }


Member Data Documentation

final String SUCCESS = "Operation Completed Successfully" [static]
 

constant to signify successful completion of a DB Fit operation.

Definition at line 34 of file DBFitManager.java.


The documentation for this class was generated from the following file:

Generated Wed Jan 17 09:14:27 GMT 2007