#!/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, doc):
        super(CzarDb, self).__init__(logger, doc, "czardatabase")


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

        sql = "INSERT INTO " + stage + " \
               (label, pending, processed, faults) \
               VALUES ('" + label + "_" + 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()



