#!/usr/bin/env jython

import re
import sys
import os
import logging

from mysql import MySql
from java.sql import *

'''
Class for CzarDb database connectivity
'''
class CzarDb(MySql):

    '''
    Constructor
    '''
    def __init__(self, logger, config):
        super(CzarDb, self).__init__(logger, config, "czardatabase")


    '''
    Updates a stage table with pending, processed, faults and config name
    '''
    def insertStats(self, stage, config, batchType, pending, processed, faults):

        sql = "INSERT INTO " + stage + " \
               (label, pending, processed, faults) \
               VALUES ('" + config + "_" + batchType + "', \
                       " + str(pending) + ", \
                       " + str(processed) + ", \
                       " + str(faults) + ")"

        try:
            self.execute(sql)
        except:
            pass

    '''
    Destructor
    '''
    def __del__(self):

        self.logger.debug("CzarDb Desstructor")
        self.stmt.close()
        self.con.close()



