IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 22, 2011, 1:15:51 PM (15 years ago)
Author:
rhenders
Message:

Now subclass of MySql base class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/jython/ipptopspsdb.py

    r31225 r31345  
    66import logging
    77
     8from mysql import MySql
    89from java.sql import *
    9 from xml.etree.ElementTree import ElementTree
    1010
    1111'''
    1212Class for ippToPsps database connectivity
    1313'''
    14 class IppToPspsDb(object):
    15 
    16     driverName="com.mysql.jdbc.Driver"
     14class IppToPspsDb(MySql):
    1715
    1816    '''
    1917    Constructor
    20 
    2118    '''
    2219    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")
    3821
    3922    '''
    4023    Creates a new batch
    4124    '''
    42     def createNewBatch(self, expID, surveyType, batchType, dvoDb, datastoreProduct):
     25    def createNewBatch(self, batchType, survey, dvoDb, datastoreProduct):
    4326
    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"
    4542
    4643        batchID = -1;
     
    5350            self.logger.exception("Unable to get batch ID")
    5451
    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)
    7653
    7754        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
    78111
    79112    '''
Note: See TracChangeset for help on using the changeset viewer.