Changeset 31345 for trunk/ippToPsps/jython/ipptopspsdb.py
- Timestamp:
- Apr 22, 2011, 1:15:51 PM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/ipptopspsdb.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/ipptopspsdb.py
r31225 r31345 6 6 import logging 7 7 8 from mysql import MySql 8 9 from java.sql import * 9 from xml.etree.ElementTree import ElementTree10 10 11 11 ''' 12 12 Class for ippToPsps database connectivity 13 13 ''' 14 class IppToPspsDb(object): 15 16 driverName="com.mysql.jdbc.Driver" 14 class IppToPspsDb(MySql): 17 15 18 16 ''' 19 17 Constructor 20 21 18 ''' 22 19 def __init__(self, logger): 23 24 # setup logging 25 self.logger = logger 26 self.logger.debug("IppToPspsDb Constructor") 27 # open config 28 doc = ElementTree(file="config.xml") 29 30 # set up JDBC connection 31 dbName = doc.find("ipptopspsdatabase/name").text 32 dbHost = doc.find("ipptopspsdatabase/host").text 33 dbUser = doc.find("ipptopspsdatabase/user").text 34 dbPass = doc.find("ipptopspsdatabase/password").text 35 self.url = "jdbc:mysql://"+dbHost+"/"+dbName+"?user="+dbUser+"&password="+dbPass 36 self.con = DriverManager.getConnection(self.url) 37 self.stmt = self.con.createStatement() 20 super(IppToPspsDb, self).__init__(logger,"ipptopspsdatabase") 38 21 39 22 ''' 40 23 Creates a new batch 41 24 ''' 42 def createNewBatch(self, expID, surveyType, batchType, dvoDb, datastoreProduct):25 def createNewBatch(self, batchType, survey, dvoDb, datastoreProduct): 43 26 44 sql = "SELECT batch_id FROM batches ORDER BY batch_id DESC LIMIT 1" 27 sql = "INSERT INTO batch ( \ 28 batch_type, \ 29 survey, \ 30 dvo_db, \ 31 datastore_product \ 32 ) VALUES ( \ 33 '" + batchType + "', \ 34 '" + survey + "', \ 35 '" + dvoDb + "', \ 36 '" + datastoreProduct + "' \ 37 )" 38 39 self.stmt.execute(sql) 40 41 sql = "SELECT MAX(batch_id) FROM batch" 45 42 46 43 batchID = -1; … … 53 50 self.logger.exception("Unable to get batch ID") 54 51 55 if batchID > 0: 56 batchID = batchID + 1 57 58 sql = "INSERT INTO batches \ 59 (batch_id, \ 60 exp_id, \ 61 survey_id, \ 62 batch_type, \ 63 dvo_db, \ 64 datastore_product) \ 65 VALUES \ 66 ("+str(batchID)+", \ 67 " + str(expID) + ", \ 68 '"+surveyType+"', \ 69 '"+batchType+"', \ 70 '"+dvoDb+"', \ 71 '"+datastoreProduct+"')" 72 73 self.stmt.execute(sql) 74 75 self.logger.info("Creating new batch in ippToPsps database with batchID = %d" % batchID) 52 self.logger.info("Created new batch in ippToPsps database with batchID = %d" % batchID) 76 53 77 54 return batchID; 55 56 ''' 57 Updates min/max object ID on this table and batch 58 ''' 59 def updateMinMaxObjID(self, batchID, minObjID, maxObjID): 60 61 sql = "UPDATE batch SET \ 62 min_obj_id = " + str(minObjID) + ", \ 63 max_obj_id = " + str(maxObjID) + " \ 64 WHERE batch_id = " + str(batchID) 65 66 self.stmt.execute(sql) 67 68 ''' 69 Updates batch processed field 70 ''' 71 def updateProcessed(self, batchID, processed): 72 73 sql = "UPDATE batch \ 74 SET processed = " + str(processed) + " \ 75 WHERE batch_id = " + str(batchID) 76 77 self.stmt.execute(sql) 78 79 ''' 80 Updates batch loaded_to_datastore field 81 ''' 82 def updateLoadedToDatastore(self, batchID, loadedToDatastore): 83 84 sql = "UPDATE batch \ 85 SET loaded_to_datastore = " + str(loadedToDatastore) + " \ 86 WHERE batch_id = " + str(batchID) 87 88 self.stmt.execute(sql) 89 90 ''' 91 Inserts some stack metadata for this batch ID 92 ''' 93 def insertStackMeta(self, batchID, skyID, stackID, filter, stackType): 94 95 sql = "INSERT INTO stack ( \ 96 batch_id \ 97 ,sky_id \ 98 ,stack_id \ 99 ,filter \ 100 ,stack_type \ 101 ) VALUES ( \ 102 " + str(batchID) + " \ 103 ," + str(skyID) + " \ 104 ," + str(stackID) + " \ 105 ,'" + filter + "' \ 106 ,'" + stackType + "' \ 107 )" 108 109 self.stmt.execute(sql) 110 78 111 79 112 '''
Note:
See TracChangeset
for help on using the changeset viewer.
