Beispiel #1
0
    def execute(self, siteName, conn=None, transaction=False):
        """
        _execute_

        Determine if the sites already exist in the dbsbuffer_location and
        attempt to lock the table using a "FOR UPDATE" parameters on the
        select statement.  Insert any sites that do not already exist in the
        location table and return the IDs of all sites that were passed to this
        function.

        The sites will be returned as a dictionary where each key is the site
        name and the value is the site ID.

        This DAO will create it's own transaction and execute all SQL in that.
        This is done so that other transactions can pickup news sites and to
        avoid deadlocks.
        """
        mySites = copy.deepcopy(siteName)
        nameMap = {}

        if type(mySites) == str:
            mySites = [mySites]

        myTransaction = Transaction(self.dbi)
        myTransaction.begin()

        binds = []
        for location in mySites:
            binds.append({"location": location})

        results = self.dbi.processData(self.existsSQL,
                                       binds,
                                       conn=myTransaction.conn,
                                       transaction=True)
        results = self.format(results)
        for result in results:
            nameMap[result[0]] = int(result[1])
            mySites.remove(result[0])

        binds = []
        for location in mySites:
            binds.append({"location": location})

        if len(binds) > 0:
            self.dbi.processData(self.sql,
                                 binds,
                                 conn=myTransaction.conn,
                                 transaction=True)
            results = self.dbi.processData(self.existsSQL,
                                           binds,
                                           conn=myTransaction.conn,
                                           transaction=True)

            results = self.format(results)
            for result in results:
                nameMap[result[0]] = int(result[1])

        myTransaction.commit()
        return nameMap
Beispiel #2
0
    def execute(self, siteName, conn = None, transaction = False):
        """
        _execute_

        Determine if the sites already exist in the dbsbuffer_location and
        attempt to lock the table using a "FOR UPDATE" parameters on the
        select statement.  Insert any sites that do not already exist in the
        location table and return the IDs of all sites that were passed to this
        function.

        The sites will be returned as a dictionary where each key is the site
        name and the value is the site ID.

        This DAO will create it's own transaction and execute all SQL in that.
        This is done so that other transactions can pickup news sites and to
        avoid deadlocks.
        """
        mySites = copy.deepcopy(siteName)
        nameMap = {}

        if type(mySites) == str:
            mySites = [mySites]

        myTransaction = Transaction(self.dbi)
        myTransaction.begin()

        binds = []
        for location in mySites:
            binds.append({"location": location})

        results = self.dbi.processData(self.existsSQL, binds,
                                       conn = myTransaction.conn,
                                       transaction = True)
        results = self.format(results)
        for result in results:
            nameMap[result[0]] = int(result[1])
            mySites.remove(result[0])

        binds = []
        for location in mySites:
            binds.append({"location": location})

        if len(binds) > 0:
            self.dbi.processData(self.sql, binds, conn = myTransaction.conn,
                                 transaction = True)
            results = self.dbi.processData(self.existsSQL, binds,
                                           conn = myTransaction.conn,
                                           transaction = True)

            results = self.format(results)
            for result in results:
                nameMap[result[0]] = int(result[1])

        myTransaction.commit()
        return nameMap
Beispiel #3
0
    def testListSitesTransaction(self):
        """
        _testListSitesTransaction_

        Verify that select behave appropriately when dealing with transactions.
        """
        myThread = threading.currentThread()
        daoFactory = DAOFactory(package="WMCore.WMBS",
                                logger=myThread.logger,
                                dbinterface=myThread.dbi)

        myThread.transaction.begin()

        localTransaction = Transaction(myThread.dbi)
        localTransaction.begin()

        locationNew = daoFactory(classname="Locations.New")

        locationNew.execute("Satsuma",
                            conn=myThread.transaction.conn,
                            transaction=True)
        locationNew.execute("Choshu",
                            conn=myThread.transaction.conn,
                            transaction=True)

        listSites = daoFactory(classname="Locations.ListSites")
        nonTransSites = listSites.execute(conn=localTransaction.conn,
                                          transaction=True)
        transSites = listSites.execute(conn=myThread.transaction.conn,
                                       transaction=True)

        assert len(nonTransSites) == 0, \
               "Error: Wrong number of sites in non transaction list."
        assert len(transSites) == 2, \
               "Error: Wrong number of sites in transaction list."
        assert "Satsuma" in transSites, \
               "Error: Site missing in transaction list."
        assert "Choshu" in transSites, \
               "Error: Site missing in transaction list."

        localTransaction.commit()
        myThread.transaction.commit()
        return
Beispiel #4
0
    def testListSitesTransaction(self):
        """
        _testListSitesTransaction_

        Verify that select behave appropriately when dealing with transactions.
        """
        myThread = threading.currentThread()
        daoFactory = DAOFactory(package="WMCore.WMBS", logger = myThread.logger,
                                dbinterface = myThread.dbi)
        
        myThread.transaction.begin()

        localTransaction = Transaction(myThread.dbi)
        localTransaction.begin()
        
        locationNew = daoFactory(classname = "Locations.New")

        locationNew.execute("Satsuma", conn = myThread.transaction.conn, transaction = True)
        locationNew.execute("Choshu", conn = myThread.transaction.conn, transaction = True)

        listSites = daoFactory(classname = "Locations.ListSites")
        nonTransSites = listSites.execute(conn = localTransaction.conn, transaction = True)
        transSites = listSites.execute(conn = myThread.transaction.conn, transaction = True)

        assert len(nonTransSites) == 0, \
               "Error: Wrong number of sites in non transaction list."
        assert len(transSites) == 2, \
               "Error: Wrong number of sites in transaction list."
        assert "Satsuma" in transSites, \
               "Error: Site missing in transaction list."
        assert "Choshu" in transSites, \
               "Error: Site missing in transaction list."

        localTransaction.commit()
        myThread.transaction.commit()
        return
Beispiel #5
0
    def execute(self, siteName, conn = None, transaction = False):

        if type(siteName) == str:
            binds = {"location": siteName}
        else:
            binds = []
            for aLocation in siteName:
                binds.append({"location": aLocation})

        myTransaction = Transaction(self.dbi)
        myTransaction.begin()

        nameMap = {}
        self.dbi.processData(self.sql, binds, conn = conn, 
                             transaction = transaction)
        results = self.dbi.processData(self.existsSQL, binds,
                                           conn = myTransaction.conn,
                                           transaction = True)
        results = self.format(results)
        for result in results:
            nameMap[result[0]] = int(result[1])

        myTransaction.commit()
        return nameMap
Beispiel #6
0
    def execute(self, siteName, conn = None, transaction = False):
        """
        _execute_

        Determine if the sites already exist in the dbsbuffer_location and
        insert any sites that do not already exist in the location table and
        return the IDs of all sites that were passed to this function.

        The sites will be returned as a dictionary where each key is the site
        name and the value is the site ID.

        This DAO will create it's own transaction and execute all SQL in that.
        This is done so that other transactions can pickup news sites and to
        avoid deadlocks.
        """
        mySites = copy.deepcopy(siteName)
        nameMap = {}

        if type(mySites) == str:
            mySites = [mySites]

        myTransaction = Transaction(self.dbi)
        myTransaction.begin()

        binds = []
        for location in mySites:
            binds.append({"location": location})

        results = self.dbi.processData(self.existsSQL, binds,
                                       conn = myTransaction.conn,
                                       transaction = True)
        results = self.format(results)
        for result in results:
            nameMap[result[0]] = int(result[1])
            mySites.remove(result[0])

        binds = []
        for location in mySites:
            binds.append({"location": location})

        if len(binds) > 0:
            try:
                self.dbi.processData(self.sql, binds, conn = myTransaction.conn,
                                     transaction = True)
            except Exception as ex:
                if "orig" in dir(ex) and type(ex.orig) != tuple:
                    if str(ex.orig).find("ORA-00001: unique constraint") != -1 and \
                       str(ex.orig).find("DBSBUFFER_LOCATION_UNIQUE") != -1:
                        return
                raise ex

            results = self.dbi.processData(self.existsSQL, binds,
                                           conn = myTransaction.conn,
                                           transaction = True)

            results = self.format(results)
            for result in results:
                nameMap[result[0]] = int(result[1])

        myTransaction.commit()
        return nameMap
Beispiel #7
0
    def execute(self, siteName, conn=None, transaction=False):
        """
        _execute_

        Determine if the sites already exist in the dbsbuffer_location and
        insert any sites that do not already exist in the location table and
        return the IDs of all sites that were passed to this function.

        The sites will be returned as a dictionary where each key is the site
        name and the value is the site ID.

        This DAO will create it's own transaction and execute all SQL in that.
        This is done so that other transactions can pickup news sites and to
        avoid deadlocks.
        """
        mySites = copy.deepcopy(siteName)
        nameMap = {}

        if type(mySites) == str:
            mySites = [mySites]

        myTransaction = Transaction(self.dbi)
        myTransaction.begin()

        binds = []
        for location in mySites:
            binds.append({"location": location})

        results = self.dbi.processData(self.existsSQL,
                                       binds,
                                       conn=myTransaction.conn,
                                       transaction=True)
        results = self.format(results)
        for result in results:
            nameMap[result[0]] = int(result[1])
            mySites.remove(result[0])

        binds = []
        for location in mySites:
            binds.append({"location": location})

        if len(binds) > 0:
            try:
                self.dbi.processData(self.sql,
                                     binds,
                                     conn=myTransaction.conn,
                                     transaction=True)
            except Exception as ex:
                if "orig" in dir(ex) and type(ex.orig) != tuple:
                    if str(ex.orig).find("ORA-00001: unique constraint") != -1 and \
                       str(ex.orig).find("DBSBUFFER_LOCATION_UNIQUE") != -1:
                        return
                raise ex

            results = self.dbi.processData(self.existsSQL,
                                           binds,
                                           conn=myTransaction.conn,
                                           transaction=True)

            results = self.format(results)
            for result in results:
                nameMap[result[0]] = int(result[1])

        myTransaction.commit()
        return nameMap