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

DBManager Class Reference

Collaboration diagram for DBManager:

Collaboration graph
[legend]
List of all members.

Detailed Description

DataBase operations for jetweb package objects; ResultSearchPattern, Model, RunSeries and so on.

Author:
S.Butterworth
Version:
Date
2007-01-12 18:57:03 +0000 (Fri, 12 Jan 2007)
Revision
1339

Definition at line 27 of file DBManager.java.


Static Public Member Functions

synchronized Integer getId (Model model) throws JetWebException
synchronized boolean addToDB (Model model) throws JetWebException
synchronized void selectFromDB (Model model) throws JetWebException
synchronized Integer getRunSeriesCollectionId (Vector< Integer > runseries) throws JetWebException
synchronized Vector< ModelgetConsistentModels (RunSeries runseries) throws JetWebException
synchronized Vector< ModelgetConsistentModels (ResultSearchPattern pattern) throws JetWebException
void selectFromDB (RunSeries runseries) throws JetWebException
synchronized void resetLogTime (int runseriesId) throws JetWebException
synchronized void addLumi (LogFile log) throws JetWebException
Enumeration< Integer > getAllRunSeriesIds () throws JetWebDBException
void zero (RunSeries lp)
void selectFromDB (MCProcessType proc) throws JetWebException
boolean addToDB (MCProcessType proc) throws JetWebException
boolean deleteFromDB (MCProcessType proc) throws JetWebException
void selectFromDB (RunSeriesCollection rsc) throws JetWebException
Vector< MCProcessTypegetAllMCProcessTypes (boolean selectable) throws JetWebException
Vector< MCProcessTypegetAllMCProcessTypes (Collision collision, boolean selectable) throws JetWebException
boolean exists (String tableName, String fieldName, int id) throws JetWebException
void deleteFromDB (String tableName, String fieldName, int id) throws JetWebException
boolean addToDB (Collision collision) throws JetWebException
boolean selectFromDB (Collision collision) throws JetWebException
Vector< CollisiongetAllCollisions () throws JetWebException
boolean checkCollision (int collId, int procId) throws JetWebException
synchronized void deleteParms (int runseriesId) throws JetWebException
synchronized void addRunSeries (RunSeries runSeries) throws JetWebException
synchronized Vector< RunSeriesgetConsistentRunSeries (MCProcessType proc, Model model) throws JetWebException
synchronized int matchRunSeriesId (RunSeries runSeries) throws JetWebException
void selectId (Collision collision) throws JetWebException
void selectId (MCProcessType proc) throws JetWebException
boolean selectId (RunSeriesCollection rsc) throws JetWebException
synchronized boolean addToDB (RunSeriesCollection rsc) throws JetWebException
synchronized boolean updateDB (RunSeriesCollection rsc, RunSeries runseries) throws JetWebException
synchronized boolean updateDB (RunSeriesCollection rsc) throws JetWebException

Static Private Member Functions

synchronized String makeInsertModelString (Model model) throws JetWebException
synchronized void fill (ResultSearchPattern pattern, ResultSet rs) throws JetWebException
synchronized void fillCommon (ResultSearchPattern pattern, ResultSet rs) throws JetWebException
synchronized void fill (Model model, ResultSet rs) throws JetWebException
String makeModelQueryString (ResultSearchPattern pattern, int genId) throws JetWebException
void fill (RunSeries runseries, ResultSet rs) throws JetWebException
void fill (Collision collision, ResultSet rs) throws JetWebException
void addGeneratorParameters (RunSeries runSeries) throws JetWebException
void addGeneratorParameters (Model model) throws JetWebException
String makeRunSeriesQueryString (ResultSearchPattern pattern, MCProcessType proc) throws JetWebException

Static Private Attributes

DBObjectManager objManager = new DBObjectManager()

Member Function Documentation

void addGeneratorParameters Model  model  )  throws JetWebException [static, private]
 

Definition at line 1211 of file DBManager.java.

References MCProcessType.getId().

01212                                {
01213         Generator gen = model.getGenerator();
01214         String insert = "INSERT INTO generator_model (mdl_id,name,aindices,ivalue,rvalue) values ('" +
01215             model.getId() + "',";
01216 
01217         try {
01218             DBGeneratorManager.addGeneratorParameters(insert, gen);
01219         } catch (SQLException E) {
01220             System.out.println("DBManager: error adding generator model: " + insert);
01221             System.out.println("SQLException: " + E.getMessage());
01222             System.out.println("SQLState:     " + E.getSQLState());
01223             System.out.println("VendorError:  " + E.getErrorCode());
01224             throw new JetWebDBException(E, insert, "ModelId:" + model.getId());
01225         }
01226     }

void addGeneratorParameters RunSeries  runSeries  )  throws JetWebException [static, private]
 

Definition at line 1192 of file DBManager.java.

References MCProcessType.getId().

01193                                {
01194         Generator gen = runSeries.getGenerator();
01195         String insert =
01196             "INSERT INTO generator_runseries (runseries_id,name,aindices,ivalue,rvalue) values ('" +
01197             runSeries.getId() + "',";
01198 
01199         try {
01200             DBGeneratorManager.addGeneratorParameters(insert, gen);
01201         } catch (SQLException E) {
01202             System.out.println("DBManager: error adding generator parameters: " + insert);
01203             System.out.println("SQLException: " + E.getMessage());
01204             System.out.println("SQLState:     " + E.getSQLState());
01205             System.out.println("VendorError:  " + E.getErrorCode());
01206             throw new JetWebDBException(E, insert, "runSeriesId:" + runSeries.getId());
01207         }
01208     }

synchronized void addLumi LogFile  log  )  throws JetWebException [static]
 

Adds the input integrated luminosity to the total for this runseries.

Parameters:
log LogFile containing the runseries and lumi
Exceptions:
JetWebException 

Definition at line 572 of file DBManager.java.

00573                                {
00574         String sqlString = "";
00575 
00576     String select = "";
00577 
00578     int logId = log.getId();
00579 
00580     if(logId>0){
00581         select = "SELECT lumi, log_id FROM logfile WHERE log_id="+logId;
00582     }else{
00583         log.getRunSeries().getCutCollection().store();
00584         select = "SELECT lumi, log_id FROM logfile WHERE runseries_id=" + 
00585         log.getRunSeries().getId() + 
00586         " AND cut_collection_id=" + 
00587         log.getRunSeries().getGenerator().getCutCollection().getId();
00588     }
00589 
00590         //String select = 
00591     //  "SELECT lumi FROM logfile WHERE runseries_id=" + runseriesId;
00592 
00593         try {
00594             Statement stmt = DBConfig.getConnection().createStatement();
00595             sqlString = select;
00596 
00597             ResultSet rs = stmt.executeQuery(sqlString);
00598             boolean hasWeighted = false;
00599             //double total = lumi;
00600         double total = log.getLumi();
00601 
00602             if (log.getLumi() < 0) {
00603                 hasWeighted = true;
00604             }
00605 
00606         int id = -1;
00607 
00608             while (rs.next()) {
00609                 double inc = rs.getDouble("lumi");
00610         id = rs.getInt("log_id");
00611                 if (inc < 0.0) {
00612                     hasWeighted = true;
00613                 } else {
00614                     total = total + inc;
00615                 }
00616 
00617             }
00618 
00619             // Negative lumi means there are weighted events.
00620             if (hasWeighted) {
00621         System.out.println
00622             ("DBManager: Found weighted events");
00623                 total = -1.0 * total;
00624             }
00625 
00626         // Need to get the exis
00627 
00628 
00629             sqlString = "UPDATE runseries SET lumi=" + total + 
00630         " WHERE runseries_id=" + log.getRunSeries().getId();
00631                 //runseriesId;
00632 
00633             stmt.executeUpdate(sqlString);
00634         rs.close();
00635         stmt.close();
00636         } catch (SQLException e) {
00637             System.out.println("DB access error in Logfile" + e);
00638             //throw new JetWebDBException(e, sqlString, "runseriesId:" + runseriesId);
00639         throw new JetWebDBException(e, sqlString, "runseriesId:" + 
00640                     log.getRunSeries().getId());
00641         }
00642     }

synchronized void addRunSeries RunSeries  runSeries  )  throws JetWebException [static]
 

Add parameters to the runseries table and associated auxilliary tables.

Parameters:
log to be added
Exceptions:
JetWebException 

Definition at line 1086 of file DBManager.java.

References MCProcessType.getId(), MCProcessType.hasPhoton(), MCProcessType.hasProton(), MCProcessType.setId(), and CutCollection.store().

01087                                {
01088 
01089     //get a new id for the runseries:
01090 
01091     String selectMax = "SELECT MAX(runseries_id) FROM runseries";
01092 
01093     Integer newId=1;
01094 
01095     try{
01096         Statement stmt = DBConfig.getConnection().createStatement();
01097         ResultSet rs = stmt.executeQuery(selectMax);
01098 
01099         while(rs.next()){
01100         Integer tmpId = rs.getInt(1);
01101         if(tmpId!=null && tmpId>=newId) newId=tmpId+1;
01102         }
01103         
01104     }catch(SQLException err){
01105         throw new JetWebException(err);
01106     }
01107 
01108 
01109         MCProcessType proc = runSeries.getMCProcessType();
01110     
01111     CutCollection cuts = runSeries.getCutCollection();
01112     if(cuts!=null) cuts.store();
01113 
01114         // First add those things which are always defined.
01115         String ins1 = "INSERT INTO runseries " + 
01116         "(runseries_id, " + 
01117         "lumi, " + 
01118         "cross_section, " + 
01119         "generator_id, " + 
01120         "process_id, " + 
01121         "cut_collection_id";
01122 
01123         String ins2 = "values(" + newId + "," + 
01124         runSeries.getLumi() + "," 
01125         + runSeries.getCrossSection() + ",'"
01126         + runSeries.getGenerator().getGeneratorId()+ "','" 
01127             + proc.getId()+ "','" +
01128         runSeries.getCutCollection().getId() + 
01129         "'";
01130 
01131         // Now those rows which may or may not be filled.
01132         // General Photon things.
01133         if (proc.hasPhoton()) {
01134             ins1 = ins1 + ", photon_pdf";
01135             ins2 = ins2 + "," + runSeries.getPhotonPDF();
01136         }
01137 
01138         // General Proton things.
01139         if (proc.hasProton()) {
01140             ins1 = ins1 + ", proton_pdf";
01141             ins2 = ins2 + "," + runSeries.getProtonPDF() + "";
01142         }
01143 
01144         String ins = ins1 + ")" + ins2 + ")";
01145 
01146         try {
01147             Statement stmt = DBConfig.getConnection().createStatement();
01148             int rowsChanged = stmt.executeUpdate(ins);
01149             stmt.close();
01150         } catch (SQLException e) {
01151             throw new JetWebDBException(e, ins, "runSeriesId:" + runSeries.getId());
01152         }
01153 
01154         String query = "SELECT MAX(runseries_id) FROM runseries";
01155 
01156         try {
01157             Statement stmt = DBConfig.getConnection().createStatement();
01158             ResultSet rs = stmt.executeQuery(query);
01159             rs.next();
01160 
01161             int id = rs.getInt(1);
01162 
01163             runSeries.setId(id);
01164 
01165             addGeneratorParameters(runSeries);
01166 
01167             // Check there were no errors. Could get errors if we allow asynchronous
01168             // multithreaded DB access?
01169             //log.setRunSeriesId(matchRunSeriesId(log));
01170             if ((runSeries == null) || (runSeries.getId() <= 0)) {
01171                 // Something went wrong. The data added to the DB did not match the
01172                 // runseries it was supposed to come from.
01173                 // Delete the RunSeries we added, and throw an exception.
01174         rs.close();
01175         stmt.close();
01176                 deleteParms(id);
01177                 throw new JetWebDBException("Failed to add runseries", "deleted");
01178             }
01179 
01180             rs.close();
01181             stmt.close();
01182         } catch (SQLException E) {
01183             System.out.println("SQLException: " + E.getMessage());
01184             System.out.println("SQLState:     " + E.getSQLState());
01185             System.out.println("VendorError:  " + E.getErrorCode());
01186             throw new JetWebDBException(E, query, "");
01187         }
01188     }

synchronized boolean addToDB RunSeriesCollection  rsc  )  throws JetWebException [static]
 

Store a new RunSeriesCollection

Definition at line 1481 of file DBManager.java.

01482                                {
01483 
01484         if (selectId(rsc)) {
01485             if (exists
01486         ("runseries_collection", "runseries_collection_id", 
01487          rsc.getId())) {
01488                 throw new JetWebException
01489             ("Attempt to re-store an existing run series collection.",
01490                     "id = " + rsc.getId());
01491             }
01492         }
01493 
01494     Statement stmt;
01495     //ResultSet rs;
01496     
01497     //make sure we don't store the same runseries in the collection twice
01498     Vector<Integer> storedRunSeries = new Vector<Integer>();
01499 
01500     for (RunSeries runSeries : rsc.getRunSeriesList()){
01501         if(!storedRunSeries.contains(runSeries.getId())){
01502         String ins = 
01503             "INSERT INTO runseries_collection (runseries_collection_id,runseries_id) VALUES('" 
01504             + rsc.getId() + "','" 
01505             + runSeries.getId() + "')";
01506         
01507         try {
01508             stmt = DBConfig.getConnection().createStatement();
01509             int result = stmt.executeUpdate(ins);
01510             storedRunSeries.add(runSeries.getId());
01511             //rs.close();
01512             stmt.close();
01513         } catch (SQLException E) {
01514             throw new JetWebDBException(E, ins, "Id:" + rsc.getId());
01515         }
01516         }
01517     }
01518 
01519         return true;
01520     }

boolean addToDB Collision  collision  )  throws JetWebException [static]
 

Note that collisions cannot be changed, so if you try to store one with an ID which already exists, an exception will be thrown.

Definition at line 941 of file DBManager.java.

00942                                {
00943         if (collision.getId() > 0) {
00944             if (exists("collision", "collision_id", collision.getId())) {
00945                 throw new JetWebException("Attempt to re-store an existing collision.",
00946                     "id = " + collision.getId());
00947             }
00948         }
00949 
00950         String ins = "INSERT INTO collision" + "(particle1,particle2,energy1,energy2) VALUES('" +
00951             collision.getParticle1().getName() + "','" +
00952             collision.getParticle2().getName() + "','" +
00953             collision.getParticle1().getEnergy() + "','" + collision.getParticle2().getEnergy() +
00954             "')";
00955 
00956         try {
00957             Statement stmt = DBConfig.getConnection().createStatement();
00958             int result = stmt.executeUpdate(ins);
00959             stmt.close();
00960         } catch (SQLException E) {
00961             throw new JetWebDBException(E, ins, "Id:" + collision.getId());
00962         }
00963 
00964         return true;
00965     }

boolean addToDB MCProcessType  proc  )  throws JetWebException [static]
 

Write an MCProcessType to the DB. If the ID exists it is replaced and return false. Otherwise it is inserted and return true.

Definition at line 768 of file DBManager.java.

References DBObjectManager.getDBConnection(), DBObjectManager.passDBConnection(), and DBObjectManager.writeObject().

00769                                {
00770 
00771     boolean newRow = false; 
00772         if (proc.getId() > 0) {
00773             if (exists("process_type", "process_id", proc.getId())) {
00774         deleteFromDB("process_type","process_id",proc.getId());
00775         newRow = true;
00776             }
00777         }
00778     if(objManager.getDBConnection()==null){
00779         objManager.passDBConnection
00780         (DBConfig.getDBConnectionManager());
00781     }   
00782     objManager.writeObject(proc,"process_type",DBConfig.JETWEB);
00783 
00784         return newRow;
00785     }

synchronized boolean addToDB Model  model  )  throws JetWebException [static]
 

Definition at line 92 of file DBManager.java.

00093                                {
00094         // Firstly, if this model has an ID already, see if it exists in the
00095         // DB. If it does, return false.
00096 
00097     if(exists("model", "mdl_id", model.getId()))return false;
00098 
00099         // Ok, this really is a new Model. Store it.
00100 
00101     // Now the model itself.
00102         String insertString = makeInsertModelString(model);
00103         int modelsFound = 0;
00104 
00105         try {
00106             Statement stmt = DBConfig.getConnection().createStatement();
00107             int result = stmt.executeUpdate(insertString);
00108         stmt.close();
00109             // Now store the generator parameters.
00110             addGeneratorParameters(model);
00111 
00112         } catch (SQLException E) {
00113             System.out.println("Error inserting model");
00114             System.out.println("SQLException: " + E.getMessage());
00115             System.out.println("SQLState:     " + E.getSQLState());
00116             System.out.println("VendorError:  " + E.getErrorCode());
00117             throw new JetWebDBException
00118         (E, insertString, "modelId:" + model.getId());
00119         }
00120 
00121         return (modelsFound > 0);
00122     }

boolean checkCollision int  collId,
int  procId
throws JetWebException [static]
 

Lightweight way of checking that the input collisionId is consistent with the input processId without instantiating either the Collision or the MCProcessType.

Definition at line 1025 of file DBManager.java.

01026                                {
01027         String query = "SELECT * FROM process_type WHERE process_id='" + procId +
01028             "' AND collision_id='" + collId + "'";
01029 
01030         try {
01031             Statement stmt = DBConfig.getConnection().createStatement();
01032             ResultSet rs = stmt.executeQuery(query);
01033 
01034             if (rs.next()) {
01035                 rs.close();
01036                 stmt.close();
01037 
01038                 return true;
01039             }
01040 
01041             rs.close();
01042             stmt.close();
01043 
01044             return false;
01045         } catch (SQLException e) {
01046             System.out.println("Error reading process_type table " + e);
01047             throw new JetWebDBException(e, query, "?");
01048         }
01049     }

void deleteFromDB String  tableName,
String  fieldName,
int  id
throws JetWebException [static]
 

delete entry with field fieldName value id from table tableName.

Parameters:
tableName 
fieldName 
id 

Definition at line 917 of file DBManager.java.

00918                                {
00919 
00920         String query = " ";
00921 
00922         try {
00923             Statement stmt = DBConfig.getConnection().createStatement();
00924             query = "DELETE FROM " + tableName + " where " + fieldName + "=" + id;
00925 
00926             int res = stmt.executeUpdate(query);
00927 
00928             stmt.close();
00929 
00930         } catch (SQLException E) {
00931             throw new JetWebDBException(E, query, "dbmanager");
00932         }
00933     }

boolean deleteFromDB MCProcessType  proc  )  throws JetWebException [static]
 

Delete an MCProcessType from the DB. return true if onewas deleted.

Definition at line 790 of file DBManager.java.

00791                                {
00792 
00793     boolean success = false;
00794         if (proc.getId() > 0) {
00795             if (exists("process_type", "process_id", proc.getId())) {
00796         deleteFromDB("process_type","process_id",proc.getId());
00797         success = true;
00798             }
00799         }
00800         return success;
00801     }

synchronized void deleteParms int  runseriesId  )  throws JetWebException [static]
 

Clears down an existing runseries record from the DB.

Parameters:
id of runseries to be deleted.
Exceptions:
JetWebException 

Definition at line 1057 of file DBManager.java.

01058                                {
01059         System.out.println("DBManager: Deleting runseries ID=" + runseriesId);
01060 
01061         String deleteString = "";
01062         String deleteString1 = "DELETE FROM runseries WHERE runseries_id=" + runseriesId;
01063         String deleteString2 = "DELETE FROM generator_runseries WHERE runseries_id=" + runseriesId;
01064 
01065         try {
01066             Statement stmt = DBConfig.getConnection().createStatement();
01067             deleteString = deleteString1;
01068             stmt.executeUpdate(deleteString);
01069             deleteString = deleteString2;
01070             stmt.executeUpdate(deleteString);
01071             stmt.close();
01072         } catch (SQLException e) {
01073             System.out.println("Error deleting incorrect runseries " + e + "RunSeriesId=" +
01074                 runseriesId);
01075             throw new JetWebDBException(e, deleteString, "id=" + runseriesId);
01076         }
01077     }

boolean exists String  tableName,
String  fieldName,
int  id
throws JetWebException [static]
 

Return true if an entry with field fieldName value id exists in table tableName.

Definition at line 886 of file DBManager.java.

00887                                {
00888         boolean exists = false;
00889         String query = " ";
00890 
00891         try {
00892             Statement stmt = DBConfig.getConnection().createStatement();
00893             query = "SELECT * FROM " + tableName + " where " + fieldName + "=" + id;
00894 
00895             ResultSet rs = stmt.executeQuery(query);
00896 
00897             if (rs.next()) {
00898                 exists = true;
00899             }
00900 
00901             rs.close();
00902             stmt.close();
00903 
00904             return exists;
00905         } catch (SQLException E) {
00906             throw new JetWebDBException(E, query, "modelId:" + id);
00907         }
00908     }

void fill Collision  collision,
ResultSet  rs
throws JetWebException [static, private]
 

Definition at line 523 of file DBManager.java.

References Particle.setEnergy(), and Particle.setName().

00524                                {
00525         try {
00526             Particle p1 = new Particle();
00527             p1.setName(rs.getString("particle1"));
00528             p1.setEnergy(rs.getFloat("energy1"));
00529 
00530             Particle p2 = new Particle();
00531             p2.setName(rs.getString("particle2"));
00532             p2.setEnergy(rs.getFloat("energy2"));
00533 
00534             collision.setId(rs.getInt("collision_id"));
00535             collision.addParticle(p1);
00536             collision.addParticle(p2);
00537         } catch (SQLException e) {
00538             System.out.println("Error reading collision table " + e);
00539         }
00540     }

void fill RunSeries  runseries,
ResultSet  rs
throws JetWebException [static, private]
 

Definition at line 500 of file DBManager.java.

00501                                {
00502         fillCommon(runseries, rs);
00503 
00504         try {
00505 
00506 
00507             runseries.setMCProcessType(new MCProcessType(rs.getInt("process_id")));
00508             runseries.setDate(rs.getTimestamp("time"));
00509             runseries.setLumi(rs.getDouble("lumi"));
00510         runseries.setCrossSection(rs.getDouble("cross_section"));
00511         int cutCollectionId = rs.getInt("cut_collection_id");
00512 
00513         if(cutCollectionId!=0){
00514 
00515         runseries.getGenerator().setCutCollection
00516         (new CutCollection(cutCollectionId));
00517         }
00518         } catch (SQLException e) {
00519             System.out.println("Error reading runseries table " + e);
00520         }
00521     }

synchronized void fill Model  model,
ResultSet  rs
throws JetWebException [static, private]
 

Definition at line 220 of file DBManager.java.

00221                                {
00222         fillCommon(model, rs);
00223     //System.out.println(model.getGenerator());
00224 
00225         try {
00226             RunSeriesCollection rsc = 
00227         new RunSeriesCollection(rs.getInt("runseries_collection_id"));
00228         
00229             model.setRunSeriesCollection(rsc);
00230         model.setDescription(rs.getString("description"));
00231         
00232         } catch (SQLException e) {
00233             System.out.println("Error reading model table " + e);
00234             throw new JetWebDBException(e, "", "modelId:" + model.getId());
00235         }
00236     }

synchronized void fill ResultSearchPattern  pattern,
ResultSet  rs
throws JetWebException [static, private]
 

Definition at line 180 of file DBManager.java.

00181                                {
00182         fillCommon(pattern, rs);
00183     }

synchronized void fillCommon ResultSearchPattern  pattern,
ResultSet  rs
throws JetWebException [static, private]
 

Definition at line 187 of file DBManager.java.

00188                                {
00189 
00190         try {
00191 
00192         Object tmp = rs.getObject("photon_pdf");
00193 
00194             if (!rs.wasNull()&&tmp!=null) {
00195                 pattern.getPhotonPDFList().clear();
00196                 pattern.getPhotonPDFList().add
00197             (new PDF((Integer)tmp));
00198             }
00199 
00200             tmp = rs.getObject("proton_pdf");
00201 
00202             if (!rs.wasNull()&&tmp!=null) {
00203                 pattern.getProtonPDFList().clear();
00204                 pattern.getProtonPDFList().add
00205             (new PDF((Integer)tmp));
00206             }
00207 
00208         int generatorId    = rs.getInt("generator_id");
00209         Generator gen = Generator.Maker(generatorId);
00210             pattern.setGenerator(gen);
00211         } catch (SQLException E) {
00212             System.out.println("DBManager: error filling common variables");
00213             System.out.println("SQLException: " + E.getMessage());
00214             System.out.println("SQLState:     " + E.getSQLState());
00215             System.out.println("VendorError:  " + E.getErrorCode());
00216             throw new JetWebDBException(E, "", "Pattern:" + pattern.getParms());
00217         }
00218     }

Vector<Collision> getAllCollisions  )  throws JetWebException [static]
 

Returns a Vector of all valid Collisions from the Database.

Definition at line 996 of file DBManager.java.

00996                                                                               {
00997         Vector<Collision> list = new Vector<Collision>();
00998         String query = "SELECT * FROM collision";
00999 
01000         try {
01001             Statement stmt = DBConfig.getConnection().createStatement();
01002             ResultSet rs = stmt.executeQuery(query);
01003 
01004             while (rs.next()) {
01005                 Collision collision = new Collision();
01006                 fill(collision, rs);
01007                 list.add(collision);
01008             }
01009 
01010             rs.close();
01011             stmt.close();
01012         } catch (SQLException e) {
01013             System.out.println("Error reading process_type table " + e);
01014             throw new JetWebDBException(e, query, "?");
01015         }
01016 
01017         return list;
01018     }

Vector<MCProcessType> getAllMCProcessTypes Collision  collision,
boolean  selectable
throws JetWebException [static]
 

Returns a Vector of all valid MCProcessTypes from the Database matching the given Collision.

Definition at line 849 of file DBManager.java.

References DBObjectManager.fillObject().

00850                                {
00851 
00852         Vector<MCProcessType> procList = new Vector<MCProcessType>();
00853 
00854     StringBuffer query = new StringBuffer("SELECT * FROM process_type ");
00855     if ((collision!=null)|| selectable) {query.append(" WHERE ");}
00856     if (collision!=null) {
00857         query.append("collision_id='" + collision.getId()+"'");
00858         if (selectable) {query.append(" AND ");}
00859     }
00860     if (selectable) query.append(" is_valid='1'");
00861 
00862         try {
00863             Statement stmt = DBConfig.getConnection().createStatement();
00864             ResultSet rs = stmt.executeQuery(query.toString());
00865 
00866             while (rs.next()) {
00867                 MCProcessType proc = new MCProcessType();
00868         objManager.fillObject(proc, rs);
00869                 procList.add(proc);
00870             }
00871 
00872             rs.close();
00873             stmt.close();
00874         } catch (SQLException e) {
00875             System.out.println("Error reading process_type table " + e);
00876             throw new JetWebDBException(e, query.toString(), "?");
00877         }
00878 
00879         return procList;
00880     }

Vector<MCProcessType> getAllMCProcessTypes boolean  selectable  )  throws JetWebException [static]
 

Returns a Vector of all valid MCProcessTypes from the Database.

Parameters:
selectable if true, only those processes which can be generated on their own and which have relevant real data to compare to are returned.

Definition at line 839 of file DBManager.java.

00840                            {
00841 
00842     return getAllMCProcessTypes(null,selectable);
00843     }

Enumeration<Integer> getAllRunSeriesIds  )  throws JetWebDBException [static]
 

Get all the unique id numbers of all RunSeries in the DB.

Definition at line 647 of file DBManager.java.

00647                                                                                      {
00648         Vector<Integer> ids = new Vector<Integer>();
00649         String sqlString = "";
00650         String select = "SELECT runseries_id FROM runseries";
00651 
00652         try {
00653             Statement stmt = DBConfig.getConnection().createStatement();
00654             sqlString = select;
00655 
00656             ResultSet rs = stmt.executeQuery(sqlString);
00657 
00658             while (rs.next()) {
00659                 Integer id = new Integer(rs.getInt("runseries_id"));
00660                 ids.add(id);
00661             }
00662         rs.close();
00663         stmt.close();
00664         } catch (SQLException e) {
00665             System.out.println("DB access error in RunSeries" + e);
00666             throw new JetWebDBException(e, sqlString, "getAllRunSeriesIds");
00667         }
00668 
00669         return ids.elements();
00670     }

synchronized Vector<Model> getConsistentModels ResultSearchPattern  pattern  )  throws JetWebException [static]
 

Returns a Vector of all existing models which are consistent with the given ResultSearchPattern. Does not change the database in any way.

Parameters:
pattern specifies parameters for a model search
Returns:
a vector of models retrieved by the database search
Exceptions:
JetWebException 

Definition at line 381 of file DBManager.java.

00382                                {
00383         Vector<Model> models = new Vector<Model>();
00384 
00385     int genIndex=0;
00386     for (Generator gen : pattern.getGeneratorList()){
00387 
00388         String query = makeModelQueryString(pattern,genIndex);
00389         genIndex++;
00390 
00391         try {
00392         Statement stmt = DBConfig.getConnection().createStatement();
00393         ResultSet rs = stmt.executeQuery(query);
00394         
00395         while (rs.next()) {
00396             int modelId = rs.getInt("mdl_id");
00397             
00398             Model mdl = new Model(modelId);
00399 
00400             //if (mdl.getGenerator().isConsistentWith(gen)){
00401             if(pattern.matches(mdl)){
00402             models.add(mdl);
00403             }
00404         }
00405 
00406         rs.close();
00407         stmt.close();
00408         } catch (SQLException E) {
00409         System.out.println("DBManager: error finding consistent models for pattern.");
00410         System.out.println("SQLException: " + E.getMessage());
00411         System.out.println("SQLState:     " + E.getSQLState());
00412         System.out.println("VendorError:  " + E.getErrorCode());
00413         throw new JetWebDBException(E, query, pattern.getParms());
00414         }
00415     }
00416 
00417         return models;
00418     }

synchronized Vector<Model> getConsistentModels RunSeries  runseries  )  throws JetWebException [static]
 

Returns a Vector of all existing models which match the given RunSeries.

Also adds this runSeries to the Models, if they don't already have it in their list.

Also checks the models to see if there are any consistent RunSeries they don't use. If this is the case, add the RunSeries to the model.

Parameters:
force if true, also checks for any new & distinct models which can be built using this set of parameters and creates a new model consistent with this runseries if none already exists.
Returns:
a vector of models
Exceptions:
JetWebException 

Definition at line 332 of file DBManager.java.

References Model.getId(), and ResultSearchPattern.matches().

00333                                {
00334 
00335         Vector<Model> models = new Vector<Model>();
00336     //System.out.print(runseries.getGenerator()+"  "+runseries.getGenerator(0));
00337         String query = makeModelQueryString(runseries,0);
00338 
00339         try {
00340             Statement stmt = DBConfig.getConnection().createStatement();
00341             ResultSet rs = stmt.executeQuery(query);
00342 
00343         System.out.println("Looking for models matching runseries");
00344         System.out.println(query);
00345 
00346             while (rs.next()) {
00347                 int modelId = rs.getInt("mdl_id");
00348         System.out.println("trying model "+modelId);
00349                 Model mdl = new Model(modelId);
00350         if(mdl.matches(runseries)){
00351             //if (mdl.getGenerator().isConsistentWith(runseries.getGenerator())){
00352             System.out.println("Adding model " + mdl.getId() +
00353                        " to list of consistent models");
00354             models.add(mdl);
00355         }
00356             }
00357 
00358 
00359             rs.close();
00360             stmt.close();
00361         } catch (SQLException E) {
00362             System.out.println("DBManager: error finding consistent models for runseries.");
00363             System.out.println("SQLException: " + E.getMessage());
00364             System.out.println("SQLState:     " + E.getSQLState());
00365             System.out.println("VendorError:  " + E.getErrorCode());
00366             throw new JetWebDBException(E, query, "RunseriesId:" + runseries.getId());
00367         }
00368 
00369         return models;
00370     }

synchronized Vector<RunSeries> getConsistentRunSeries MCProcessType  proc,
Model  model
throws JetWebException [static]
 

Returns a Vector of RunSeries which are consistent with the given Model and MCProcessType.

Parameters:
proc 
model 
Returns:
vector of RunSeries
Exceptions:
JetWebException 

Definition at line 1236 of file DBManager.java.

References ResultSearchPattern.matches(), and MCProcessType.matches().

01237                                {
01238     HashMap<Integer, RunSeries> foundRunSeries = 
01239         new HashMap<Integer, RunSeries>();
01240         //Vector<RunSeries> matchedList = new Vector<RunSeries>();
01241 
01242         String query = makeRunSeriesQueryString(model, proc);
01243 
01244         try {
01245             Statement stmt = DBConfig.getConnection().createStatement();
01246             ResultSet rs = stmt.executeQuery(query);
01247         
01248             while (rs.next()) {
01249                 // We have a matching row. Get the id.
01250                 int rsid = rs.getInt("runseries_id");
01251         boolean procMatch = true;
01252 
01253         if (rsid>=0 && !foundRunSeries.containsKey(rsid)) {
01254             // Check the processtype, in case the process_id 
01255             // was not already specified.
01256             if (rsid >= 0 && proc !=null && proc.getId()<0) {
01257             // Check the MCProcessType. If the
01258             // MCProcessType has a valid Id, then the check
01259             // was done in the original query. If not, then
01260             // the MCProcessType must have been only partially
01261             // specified, so lets see if the MCProcessType
01262             // belonging to this RunSeries matches it.
01263             int procId = rs.getInt("process_id");
01264             MCProcessType thisProc = new MCProcessType(procId);
01265             if (thisProc.matches(proc)) {
01266                 procMatch = false;
01267             }
01268             }
01269 
01270             if (procMatch) {
01271             // Now build the runSeries.
01272             //RunSeries runSeries = new RunSeries(rsid);
01273             RunSeries runSeries = RunSeries.Maker(rsid);
01274 
01275             //if (runSeries.getGenerator().isConsistentWith(model.getGenerator())){
01276             if(runSeries.matches(model)){
01277                 //matchedList.add(new RunSeries(rsid));
01278                 //matchedList.add(runSeries);
01279                 foundRunSeries.put(rsid, runSeries);
01280             }else{
01281                 System.out.println
01282                 ("Runseries is not consistent with model");
01283             }
01284             }
01285                 }
01286             }
01287         rs.close();
01288             stmt.close();
01289         } catch (SQLException E) {
01290             System.out.println("SQLException: " + E.getMessage());
01291             System.out.println("SQLState:     " + E.getSQLState());
01292             System.out.println("VendorError:  " + E.getErrorCode());
01293             throw new JetWebDBException(E, query, "ModelId:" + model.getId());
01294         }
01295 
01296         return new Vector<RunSeries>(foundRunSeries.values());
01297     }

synchronized Integer getId Model  model  )  throws JetWebException [static]
 

Definition at line 42 of file DBManager.java.

00043                           {
00044     
00045     //if model already has valid id then just return that
00046     if(model.getId()>0){
00047      
00048         return model.getId();
00049     }
00050 
00051     //If matching model exists in database then return that id
00052     Vector<Model> matches = getConsistentModels(model);
00053     
00054     if(matches.size()==1){
00055         return matches.firstElement().getId();
00056     }else if(matches.size()>1){
00057         throw new JetWebException
00058         ("More than one model matches this Model!", 
00059          "Found Id"+matches.firstElement().getId());
00060     }
00061 
00062     //if we've got here then we need a new model id
00063     //use the next highest available id
00064     
00065     Integer mId;
00066 
00067     String query  = "SELECT MAX(mdl_id) from model";
00068     try{
00069         Statement stmt = DBConfig.getConnection().createStatement();
00070         ResultSet rs = stmt.executeQuery(query);
00071         if(rs.next()){
00072         mId = rs.getInt(1);
00073 
00074         if(mId==null){
00075             mId = 1;
00076         }else{
00077             ++mId;
00078         }
00079         rs.close();
00080         stmt.close();
00081         return mId;
00082         }
00083     }catch(Throwable err){
00084         System.out.println(err.getMessage());
00085         throw new JetWebException("Unable to query model table", 
00086                       "DBManager.getId(Model)");
00087     }
00088     return -1;
00089     }

synchronized Integer getRunSeriesCollectionId Vector< Integer >  runseries  )  throws JetWebException [static]
 

Definition at line 239 of file DBManager.java.

00240                           {
00241 
00242         Vector<Integer> foundIds = new Vector<Integer>();
00243 
00244         try{
00245         PreparedStatement pstmt = 
00246         DBConfig.getConnection().prepareStatement("SELECT runseries_collection_id FROM runseries_collection WHERE runseries_id=?");
00247 
00248         boolean firstrow = true;
00249 
00250         for(Integer rs: runseries){
00251         pstmt.setInt(1, rs);
00252         ResultSet dbrs = pstmt.executeQuery();
00253 
00254         Vector<Integer> newIds = new Vector<Integer>();
00255         Vector<Integer> oldIds = new Vector<Integer>(foundIds);
00256 
00257         while(dbrs.next()){
00258             newIds.add(dbrs.getInt(1));
00259         }
00260 
00261         if(firstrow){
00262             foundIds = newIds;
00263             firstrow = false;
00264         }else{
00265             foundIds.clear();
00266             for(Integer id: newIds){
00267             if(oldIds.contains(id)){
00268                 foundIds.add(id);
00269             }
00270             }
00271         }
00272 
00273         }
00274 
00275         
00276         }catch(SQLException err){
00277         throw new JetWebException(err);
00278         }
00279 
00280         if(foundIds.size()==1){
00281         return foundIds.get(0);
00282         }else if(foundIds.size()>1){
00283         Integer idRet = -1;
00284         Integer min = Integer.MAX_VALUE;
00285         try{
00286             PreparedStatement pstmt = 
00287             DBConfig.getConnection().prepareStatement
00288             ("SELECT COUNT(runseries_id) FROM " + 
00289              "runseries_collection WHERE " +
00290              "runseries_collection_id=?");
00291 
00292             for(Integer id: foundIds){
00293             pstmt.setInt(1, id);
00294             ResultSet dbrs = pstmt.executeQuery();
00295             if(dbrs.next()){
00296                 Integer count = dbrs.getInt(1);
00297                 if(count<min){
00298                 min = count;
00299                 idRet = id;
00300                 }
00301             }
00302             }
00303                         
00304         }catch(SQLException err){
00305             throw new JetWebException(err);
00306         }
00307         return idRet;
00308         }
00309         
00310         return -1;
00311     }

synchronized String makeInsertModelString Model  model  )  throws JetWebException [static, private]
 

Definition at line 124 of file DBManager.java.

00125                                {
00126         String ins1 = "INSERT INTO model" + 
00127         "(mdl_id, generator_id";
00128         String ins2 = ") VALUES('" + 
00129         model.getId() + "', '" +
00130         model.getGenerator().getGeneratorId()+ "'";
00131         ins1 = ins1 + ",photon_pdf";
00132         ins2 = ins2 + "," + model.getPhotonPDF(0);
00133 
00134         ins1 = ins1 + ",proton_pdf";
00135         ins2 = ins2 + "," + model.getProtonPDF(0);
00136 
00137         // Now add the RunSeriesCollectionId
00138         ins1 = ins1 + ",runseries_collection_id";
00139         ins2 = ins2 + ",'" + model.getRunSeriesCollection().getId()+ "'";
00140 
00141     ins1 = ins1 + ", description";
00142     ins2 = ins2 + ", '" + model.getDescription() + "' )";
00143 
00144         return ins1 + ins2;
00145     }

String makeModelQueryString ResultSearchPattern  pattern,
int  genId
throws JetWebException [static, private]
 

Definition at line 422 of file DBManager.java.

00423                                {
00424         String query = "SELECT mdl_id FROM model ";
00425         StringBuffer q1 = new StringBuffer();
00426         boolean anything = false;
00427 
00428     Generator gen = pattern.getGenerator(genId);
00429     
00430     q1.append("(generator_id='" + gen.getGeneratorId() +"') AND ");
00431 
00432         if (pattern.getPhotonPDFList().size() == 1) {
00433         if(pattern.getPhotonPDF()!=null){
00434         q1.append("photon_pdf=" + pattern.getPhotonPDF() + " AND ");
00435         }
00436         }
00437 
00438         if (pattern.getPhotonPDFList().size() == 2) {
00439             q1.append
00440         ("(photon_pdf=" + 
00441          pattern.getPhotonPDF() + 
00442          " OR photon_pdf=" +
00443                 pattern.getPhotonPDF(1) + ") AND ");
00444         }
00445 
00446         if (pattern.getProtonPDFList().size() == 1) {
00447         if(pattern.getProtonPDF()!=null){
00448         q1.append("proton_pdf=" + pattern.getProtonPDF() + " AND ");
00449         }
00450         }
00451 
00452         if (pattern.getProtonPDFList().size() == 2) {
00453             q1.append("(proton_pdf=" + pattern.getProtonPDF() + " OR proton_pdf=" +
00454                 pattern.getProtonPDF(1) + ") AND ");
00455         }
00456 
00457     String query1 = q1.toString();
00458         if (query1.trim().length() != 0) {
00459             query1 = query1.substring(0, query1.lastIndexOf("AND"));
00460             query = query + " WHERE " + query1;
00461         }
00462 
00463         return query;
00464     }

String makeRunSeriesQueryString ResultSearchPattern  pattern,
MCProcessType  proc
throws JetWebException [static, private]
 

Make a SQL query string for the runseries table based on the parameters in the pattern.

Definition at line 1353 of file DBManager.java.

References MCProcessType.toString().

01354                                {
01355         StringBuffer query = new StringBuffer
01356         ("SELECT * FROM runseries WHERE generator_id='" +
01357             pattern.getGenerator().getGeneratorId() + 
01358          "'");
01359 
01360         if (proc.getId() > 0) {
01361             query.append(" AND process_id='" + proc.getId() + "'");
01362         }
01363 
01364         if (proc.hasPhoton()) {
01365             // add test on photon variables
01366             query.append(" AND photon_pdf=" + pattern.getPhotonPDF());
01367         }
01368 
01369         if (proc.hasProton()) {
01370             // add test on proton variables
01371             query.append(" AND proton_pdf=" + pattern.getProtonPDF());
01372         }
01373 
01374     //  query.append("'");
01375 
01376         return query.toString();
01377     }

synchronized int matchRunSeriesId RunSeries  runSeries  )  throws JetWebException [static]
 

Is there a DB entry in runseries to match the input runSeries? if so, return its Id.

Parameters:
object for which runseries id is to be found
Returns:
runseriesId
Exceptions:
JetWebException 

Definition at line 1307 of file DBManager.java.

References RunSeries.getGenerator().

01308                                {
01309 
01310         int rtn = -1;
01311         String query = makeRunSeriesQueryString
01312         (runSeries, runSeries.getMCProcessType());
01313 
01314 
01315         try {
01316             Statement stmt = DBConfig.getConnection().createStatement();
01317 
01318             // query the runseries table for rows matching the parameters of 
01319             // the input runseries.
01320             ResultSet rs = stmt.executeQuery(query);
01321 
01322             while (rs.next() && (rtn <= 0)) {
01323                 // We have a matching row. Get the id.
01324                 rtn = rs.getInt("runseries_id");
01325 
01326                 if (rtn >= 0) {
01327                     // Now check generator specific auxilliary tables.
01328                                 
01329             //RunSeries matchRunSeries = new RunSeries(rtn);
01330             RunSeries matchRunSeries = RunSeries.Maker(rtn);
01331             if (!(matchRunSeries.getGenerator().isConsistentWith(runSeries.getGenerator()))){
01332             rtn = -1;
01333             }
01334                 }
01335             }
01336         rs.close();
01337             stmt.close();
01338         } catch (SQLException E) {
01339             System.out.println("DBManager.matchRunSeriesId ");
01340             System.out.println(query);
01341             System.out.println("SQLException: " + E.getMessage());
01342             System.out.println("SQLState:     " + E.getSQLState());
01343             System.out.println("VendorError:  " + E.getErrorCode());
01344             throw new JetWebDBException(E, query, "runseries Id:" + runSeries.getId());
01345         }
01346 
01347         return rtn;
01348     }

synchronized void resetLogTime int  runseriesId  )  throws JetWebException [static]
 

Sets the timestamp in the runseries table to mark new data. Setting timestamp to null has the effect of setting it to NOW

Parameters:
runseriesId of record to be timestamped
Exceptions:
JetWebException 

Definition at line 549 of file DBManager.java.

00550                                {
00551         String update = "UPDATE runseries SET time=NULL WHERE runseries_id=" + runseriesId;
00552 
00553         try {
00554             Statement stmt = DBConfig.getConnection().createStatement();
00555             stmt.executeUpdate(update);
00556         stmt.close();
00557         } catch (SQLException e) {
00558             System.out.println("DB access error in Logfile" + e);
00559             throw new JetWebDBException(e, update, "runseriesId:" + runseriesId);
00560         }
00561     }

boolean selectFromDB Collision  collision  )  throws JetWebException [static]
 

Definition at line 967 of file DBManager.java.

00968                                {
00969         if (collision.getId() <= 0) {
00970             throw new JetWebException("Attempt to select collision with id not defined",
00971                 "id was " + collision.getId());
00972         }
00973 
00974         String query = "SELECT * FROM collision WHERE collision_id=" + collision.getId();
00975 
00976         try {
00977             Statement stmt = DBConfig.getConnection().createStatement();
00978             ResultSet rs = stmt.executeQuery(query);
00979 
00980             while (rs.next()) {
00981                 fill(collision, rs);
00982             }
00983 
00984             rs.close();
00985             stmt.close();
00986         } catch (SQLException e) {
00987             throw new JetWebDBException(e, query, "collision_id:" + collision.getId());
00988         }
00989 
00990         return true;
00991     }

void selectFromDB RunSeriesCollection  rsc  )  throws JetWebException [static]
 

Populates the input RunSeriesCollection object from the DB

Parameters:
rsc RunSeriesCollection object to be populated
Exceptions:
JetWebDBException 

Definition at line 808 of file DBManager.java.

00809                                {
00810         String query = "SELECT * FROM runseries_collection WHERE runseries_collection_id=" +
00811             rsc.getId();
00812 
00813         try {
00814             Statement stmt = DBConfig.getConnection().createStatement();
00815             ResultSet rs = stmt.executeQuery(query);
00816 
00817             while (rs.next()) {
00818                 int rsId = rs.getInt("runseries_id");
00819                 //RunSeries runSeries = new RunSeries(rsId);
00820         RunSeries runSeries  = RunSeries.Maker(rsId);
00821                 //rsc.getRunSeriesList().add(runSeries);
00822         rsc.add(runSeries);
00823             }
00824 
00825             rs.close();
00826             stmt.close();
00827         } catch (SQLException e) {
00828             System.out.println("Error reading runseries_collection table " + e);
00829             throw new JetWebDBException(e, query, "runseries_collection_id:" + rsc.getId());
00830         }
00831     }

void selectFromDB MCProcessType  proc  )  throws JetWebException [static]
 

Populates the input MCProcessType object from the DB

Parameters:
proc MCProcessType object to be populated
Exceptions:
JetWebDBException 

Definition at line 737 of file DBManager.java.

References DBObjectManager.fillObject(), DBObjectManager.getDBConnection(), RunSeries.getId(), and DBObjectManager.passDBConnection().

00738                                {
00739         String query = 
00740         "SELECT * FROM process_type WHERE process_id=" + proc.getId();
00741 
00742         try {
00743             Statement stmt = DBConfig.getConnection().createStatement();
00744             ResultSet rs = stmt.executeQuery(query);
00745 
00746         if(objManager.getDBConnection()==null){
00747         objManager.passDBConnection
00748             (DBConfig.getDBConnectionManager());
00749         }
00750 
00751             while (rs.next()) {
00752         objManager.fillObject(proc, rs);
00753             }
00754 
00755             rs.close();
00756             stmt.close();
00757         } catch (SQLException e) {
00758             System.out.println("Error reading process_type table " + e);
00759             throw new JetWebDBException(e, query, "processId:" + proc.getId());
00760         }
00761     }

void selectFromDB RunSeries  runseries  )  throws JetWebException [static]
 

Populates the input RunSeries object from the DB

Parameters:
runseries RunSeries object to be populated
Exceptions:
JetWebDBException 

Definition at line 472 of file DBManager.java.

00473                                {
00474         String query = "SELECT * FROM runseries WHERE runseries_id=" + runseries.getId();
00475 
00476         try {
00477             Statement stmt = DBConfig.getConnection().createStatement();
00478             ResultSet rs = stmt.executeQuery(query);
00479 
00480             while (rs.next()) {
00481                 fill(runseries, rs);        
00482             }
00483 
00484             rs.close();
00485             stmt.close();
00486         } catch (SQLException e) {
00487             System.out.println("Error reading runseries table " + e);
00488             throw new JetWebDBException(e, query, "runseriesId:" + runseries.getId());
00489         }
00490 
00491         // Now fill the generator specific parameters.
00492         try {
00493             DBGeneratorManager.selectGeneratorParameters(runseries);
00494         } catch (JetWebException jwe) {
00495             throw jwe;
00496         }
00497     }

synchronized void selectFromDB Model  model  )  throws JetWebException [static]
 

Populates the input Model from the DB

Parameters:
model the model to be populated
Exceptions:
JetWebException 

Definition at line 153 of file DBManager.java.

00154                                {
00155         String query = "SELECT * FROM model WHERE mdl_id=" + model.getId();
00156 
00157         try {
00158             Statement stmt = DBConfig.getConnection().createStatement();
00159             ResultSet rs = stmt.executeQuery(query);
00160 
00161             if (rs.next()) {
00162                 fill(model, rs);
00163             } else {
00164         rs.close();
00165         stmt.close();
00166         throw new JetWebException("No such Model exists","ID="+model.getId());
00167         }
00168 
00169             rs.close();
00170             stmt.close();
00171         } catch (SQLException e) {
00172             System.out.println("Error reading model table " + e + "ModelId=" + model.getId());
00173             throw new JetWebDBException(e, query, "modelId:" + model.getId());
00174         }
00175 
00176         // Now fill the generator specific parameters.
00177         DBGeneratorManager.selectGeneratorParameters(model);
00178     }

boolean selectId RunSeriesCollection  rsc  )  throws JetWebException [static]
 

Selects a new Id for a new RunSeriesCollection

Returns:
true if RunSeriesCollection was already present in DB, so had no need of new ID

Definition at line 1453 of file DBManager.java.

01454                           {
01455     
01456     if(rsc.getId() >=0) return true;
01457 
01458     Statement stmt;
01459     ResultSet rs;
01460     String query = 
01461         "SELECT MAX(runseries_collection_id) FROM runseries_collection";
01462 
01463     try {
01464         stmt = DBConfig.getConnection().createStatement();
01465         rs = stmt.executeQuery(query);
01466         if (rs.next()){
01467         rsc.setId(rs.getInt(1)+1);
01468         } else {
01469         rsc.setId(1);
01470         }
01471     } catch (SQLException E) {
01472         throw new JetWebDBException(E, query, "Id:" + rsc.getId());
01473     }
01474 
01475     return false;
01476     }

void selectId MCProcessType  proc  )  throws JetWebException [static]
 

Select & set the process Id. Return true if one is found, otherwise false.

Definition at line 1412 of file DBManager.java.

References DBObjectManager.fillObject(), MCProcessType.getCollision(), DBObjectManager.getDBConnection(), Collision.getId(), and DBObjectManager.passDBConnection().

01412                                                                            {
01413         String checkquery = "SELECT * FROM process_type WHERE collision_id='" +
01414             proc.getCollision().getId() + "' AND process_name='" + proc.getMCProcessName() + "'";
01415 
01416         try {
01417             Statement stmt = DBConfig.getConnection().createStatement();
01418             ResultSet rs = stmt.executeQuery(checkquery);
01419 
01420         /*
01421             if (rs.next()) {
01422                 proc.setId(rs.getInt("process_id"));
01423                 rs.close();
01424                 stmt.close();
01425             }
01426         */
01427 
01428         if(objManager.getDBConnection()==null){
01429         objManager.passDBConnection
01430             (DBConfig.getDBConnectionManager());
01431         }
01432 
01433         if(rs.next()){
01434         objManager.fillObject(proc, rs);
01435         rs.close();
01436         stmt.close();
01437         }
01438 
01439             rs.close();
01440             stmt.close();
01441         } catch (SQLException E) {
01442             throw new JetWebDBException(E, "failed to select ID", checkquery);
01443         }
01444     }

void selectId Collision  collision  )  throws JetWebException [static]
 

Select & set the collision Id. Return true if one is found, otherwise false.

Definition at line 1383 of file DBManager.java.

References MCProcessType.setId().

01383                                                                             {
01384 
01385         String checkquery = "SELECT * FROM collision WHERE particle1='" +
01386             collision.getParticle1().getName() + "' AND particle2='" +
01387             collision.getParticle2().getName() + "' AND energy1='" +
01388             collision.getParticle1().getEnergy() + "' AND energy2='" +
01389             collision.getParticle2().getEnergy() + "'";
01390 
01391         try {
01392             Statement stmt = DBConfig.getConnection().createStatement();
01393             ResultSet rs = stmt.executeQuery(checkquery);
01394 
01395             if (rs.next()) {
01396                 collision.setId(rs.getInt("collision_id"));
01397                 rs.close();
01398                 stmt.close();
01399             }
01400 
01401             rs.close();
01402             stmt.close();
01403         } catch (SQLException E) {
01404             throw new JetWebDBException(E, "failed to select ID", checkquery);
01405         }
01406     }

synchronized boolean updateDB RunSeriesCollection  rsc  )  throws JetWebException [static]
 

Store a new RunSeriesCollection

Definition at line 1558 of file DBManager.java.

01559                                {
01560 
01561         if (rsc.getId() < 0 || 
01562         !exists("runseries_collection", "runseries_collection_id", 
01563             rsc.getId())) {
01564         addToDB(rsc);
01565         //throw new JetWebException("Attempt to update a non-existant run series collection.",
01566         //            "id = " + rsc.getId());
01567     }
01568 
01569     String sql = "";
01570 
01571     try {
01572         
01573         Statement stmt = DBConfig.getConnection().createStatement();
01574         ResultSet rs;
01575         
01576         for (RunSeries runSeries : rsc.getRunSeriesList()){
01577         
01578         sql = "SELECT * FROM runseries_collection WHERE runseries_collection_id="
01579             +rsc.getId()+" AND runseries_id="+runSeries.getId();
01580 
01581         rs = stmt.executeQuery(sql);
01582         if (!rs.next()) {
01583             
01584             sql = 
01585             "INSERT INTO runseries_collection (runseries_collection_id,runseries_id) VALUES('" 
01586             + rsc.getId() + "','" 
01587             + runSeries.getId() + "')";
01588             int result = stmt.executeUpdate(sql);
01589         }
01590         rs.close();
01591         }
01592 
01593         stmt.close();
01594     } catch (SQLException E) {
01595         throw new JetWebDBException(E, sql, "Id:" + rsc.getId());
01596     }
01597 
01598         return true;
01599     }

synchronized boolean updateDB RunSeriesCollection  rsc,
RunSeries  runseries
throws JetWebException [static]
 

Definition at line 1523 of file DBManager.java.

01524                           {
01525     
01526 
01527     try{
01528 
01529         String sql = "SELECT * FROM runseries_collection WHERE " +
01530         "runseries_collection_id = " + rsc.getId() + 
01531         " AND runseries_id="+runseries.getId();
01532 
01533         Statement stmt = DBConfig.getConnection().createStatement();
01534         ResultSet rs = stmt.executeQuery(sql);
01535         if(rs.next()){
01536         rs.close();
01537         stmt.close();
01538         return false;
01539         }
01540         rs.close();
01541         sql= "INSERT INTO runseries_collection(" + 
01542         "runseries_collection_id, runseries_id) VALUES ("+
01543         rsc.getId()+"," + runseries.getId() +")";
01544 
01545         stmt.executeUpdate(sql);
01546         stmt.close();
01547     }catch(SQLException err){
01548         throw new JetWebException(err);
01549     }
01550 
01551     return true;
01552     }

void zero RunSeries  lp  )  [static]
 

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

Definition at line 704 of file DBManager.java.

References RunSeries.getId().

00704                                           {
00705         if (lp != null) {
00706             String zeroIt =
00707                 "update predicted_point set y=0.0,dy_up=0.0,dy_down=0.0 where runseries_id=" +
00708                 lp.getId();
00709 
00710             try {
00711                 Statement stmt = DBConfig.getConnection().createStatement();
00712                 stmt.executeUpdate(zeroIt);
00713         stmt.close();
00714         } catch (SQLException e) {
00715         System.out.println("DBManager: Error executing " + zeroIt);
00716             }
00717 
00718             zeroIt = "update runseries set lumi=0.0 where runseries_id=" + lp.getId();
00719 
00720             try {
00721                 Statement stmt = DBConfig.getConnection().createStatement();
00722                 stmt.executeUpdate(zeroIt);
00723         stmt.close();
00724             } catch (SQLException e) {
00725                 System.out.println("DBManager: Error executing " + zeroIt);
00726             }
00727         } else {
00728             System.out.println("DBManager: trapped attempt to zero a null runseries");
00729         }
00730     }


Member Data Documentation

DBObjectManager objManager = new DBObjectManager() [static, private]
 

Inserts a model into the DB.

If you try to store a Model which already exists, set the ID to the ID of the existing Model and return false.

Parameters:
model representing the model to be inserted
pattern containing required parameters for new model
Returns:
true if model is inserted, false otherwise
Exceptions:
JetWebException 

Definition at line 40 of file DBManager.java.


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

Generated Wed Jan 17 09:14:27 GMT 2007