Index: trunk/ippToPsps/jython/ipptopspsdb.py
===================================================================
--- trunk/ippToPsps/jython/ipptopspsdb.py	(revision 35217)
+++ trunk/ippToPsps/jython/ipptopspsdb.py	(revision 35311)
@@ -30,8 +30,8 @@
 
     '''
-    Returns a list of merged batch IDs that are merged but not yet deleted
-    '''
-    def getMergedButNotDeletedBatchIDs(self, batchType, column):
-
+    Returns a list of merged batch IDs that are merged but not yet deleted (but allowed to be deleted)
+    '''
+    def getMergedReadyToDeleteFromLocalDisk(self, batchType):
+    
         sql = "SELECT DISTINCT batch_id \
                FROM batch \
@@ -40,6 +40,7 @@
                AND dvo_db = '" + self.skychunk.dvoLabel + "' \
                AND merged = 1 \
-               AND " + column + " = 0"
-
+               AND deleted_local = 0 \
+               AND block_delete_local = 0 "
+    
         ids = []
         try:
@@ -49,14 +50,14 @@
         except:
             self.logger.exception("Can't query for merged batch ids in ipptopsps Db")
-
+    
         self.logger.debug("Found %d merged but un-deleted items" % len(ids))
-
+    
         return ids
 
     '''
-    Returns a list of batch IDs marked as 'purged' but not yet deleted
-    '''
-    def getPurgedButNotDeletedBatchIDs(self, batchType, column):
-
+    Returns a list of batch IDs marked as 'purged' but not yet deleted (but allowed to be deleted)
+    '''
+    def getPurgedReadyToDeleteFromLocalDisk(self, batchType):
+    
         sql = "SELECT DISTINCT batch_id \
                FROM batch \
@@ -65,6 +66,7 @@
                AND dvo_db = '" + self.skychunk.dvoLabel + "' \
                AND purged = 1 \
-               AND " + column + " = 0"
-
+               AND deleted_local = 0 \
+               AND block_delete_local = 0 "
+    
         ids = []
         try:
@@ -74,15 +76,15 @@
         except:
             self.logger.exception("Can't query for merged batch ids in ipptopsps Db")
-
-
+    
+    
         self.logger.debug("Found %d merged but un-deleted items" % len(ids))
-
+    
         return ids
 
     '''
-    Returns a list of processed batch IDs that have been loaded to the ODM but not yet deleted
-    '''
-    def getLoadedToODMButNotDeletedBatchIDs(self, batchType, column):
-
+    Returns a list of batch IDs marked as 'purged' but not yet deleted (but allowed to be deleted)
+    '''
+    def getPurgedReadyToDeleteFromDatastore(self, batchType):
+    
         sql = "SELECT DISTINCT batch_id \
                FROM batch \
@@ -90,6 +92,33 @@
                AND batch_type = '" + batchType + "' \
                AND dvo_db = '" + self.skychunk.dvoLabel + "' \
+               AND purged = 1 \
+               AND deleted_datastore = 0 \
+               AND block_delete_datastore = 0 "
+    
+        ids = []
+        try:
+            rs = self.executeQuery(sql)
+            while (rs.next()): ids.append(rs.getInt(1))
+            rs.close()
+        except:
+            self.logger.exception("Can't query for merged batch ids in ipptopsps Db")
+    
+    
+        self.logger.debug("Found %d merged but un-deleted items" % len(ids))
+    
+        return ids
+
+    '''
+    Returns a list of processed batch IDs that have been loaded to the ODM but not yet deleted from the datastore
+    '''
+    def getLoadedToODMReadyToDeleteFromDatastore(self, batchType):
+
+        sql = "SELECT DISTINCT batch_id \
+               FROM batch \
+               WHERE timestamp > '" + self.skychunk.epoch + "' \
+               AND batch_type = '" + batchType + "' \
+               AND dvo_db = '" + self.skychunk.dvoLabel + "' \
                AND (loaded_to_ODM = -1 OR merge_worthy = 1) \
-               AND " + column + " = 0"
+               AND deleted_datastore = 0 AND block_delete_datastore = 0"
 
         ids = []
@@ -106,38 +135,141 @@
 
     '''
-    Returns a list of merged batch IDs that are not deleted from local disk
-    '''
-    def getMergedButNotDeletedFromLocalDisk(self, batchType):
-        return self.getMergedButNotDeletedBatchIDs(batchType, "deleted_local")
-
-    '''
-    Returns a list of processed batch IDs that are loaded to the ODM, but not deleted from local disk
-    '''
-    def getLoadedToODMButNotDeletedFromLocalDisk(self, batchType):
-        return self.getLoadedToODMButNotDeletedBatchIDs(batchType, "deleted_local")
-
-    '''
-    Returns a list of processed batch IDs that are loaded to the ODM, but not deleted from datastore
-    '''
-    def getLoadedToODMButNotDeletedFromDatastore(self, batchType):
-        return self.getLoadedToODMButNotDeletedBatchIDs(batchType, "deleted_datastore")
-
-    '''
-    Returns a list of processed batch IDs that are loaded to the ODM, but not deleted from DXLayer
-    '''
-    def getLoadedToODMButNotDeletedFromDXLayer(self, batchType):
-        return self.getLoadedToODMButNotDeletedBatchIDs(batchType, "deleted_dxlayer")
-
-    '''
-    Returns a list of purged  batch IDs that not deleted from local disk
-    '''
-    def getPurgedButNotDeletedFromLocalDisk(self, batchType):
-        return self.getPurgedButNotDeletedBatchIDs(batchType, "deleted_local")
-
-    '''
-    Returns a list of purged batch IDs that are not deleted from datastore
-    '''
-    def getPurgedButNotDeletedFromDatastore(self, batchType):
-        return self.getPurgedButNotDeletedBatchIDs(batchType, "deleted_datastore")
+    Returns a list of processed batch IDs that have been loaded to the ODM but not yet deleted from the dxlayer
+    '''
+    def getLoadedToODMReadyToDeleteFromDxLayer(self, batchType):
+
+        sql = "SELECT DISTINCT batch_id \
+               FROM batch \
+               WHERE timestamp > '" + self.skychunk.epoch + "' \
+               AND batch_type = '" + batchType + "' \
+               AND dvo_db = '" + self.skychunk.dvoLabel + "' \
+               AND (loaded_to_ODM = -1 OR merge_worthy = 1) \
+               AND deleted_dxlayer = 0 and block_delete_dxlayer = 0"
+
+        ids = []
+        try:
+            rs = self.executeQuery(sql)
+            while (rs.next()): ids.append(rs.getInt(1))
+            rs.close()
+        except:
+            self.logger.exception("Can't query for merged batch ids in ipptopsps Db")
+
+        self.logger.debug("Found %d merged but un-deleted items" % len(ids))
+
+        return ids
+
+    ## '''
+    ## XXX EAM : removed this function and made it more explicit (with an additional block)
+    ## Returns a list of merged batch IDs that are merged but not yet deleted
+    ## '''
+    ## def getMergedButNotDeletedBatchIDs(self, batchType, column):
+    ## 
+    ##     sql = "SELECT DISTINCT batch_id \
+    ##            FROM batch \
+    ##            WHERE timestamp > '" + self.skychunk.epoch + "' \
+    ##            AND batch_type = '" + batchType + "' \
+    ##            AND dvo_db = '" + self.skychunk.dvoLabel + "' \
+    ##            AND merged = 1 \
+    ##            AND " + column + " = 0"
+    ## 
+    ##     ids = []
+    ##     try:
+    ##         rs = self.executeQuery(sql)
+    ##         while (rs.next()): ids.append(rs.getInt(1))
+    ##         rs.close()
+    ##     except:
+    ##         self.logger.exception("Can't query for merged batch ids in ipptopsps Db")
+    ## 
+    ##     self.logger.debug("Found %d merged but un-deleted items" % len(ids))
+    ## 
+    ##     return ids
+
+    ## '''
+    ## Returns a list of batch IDs marked as 'purged' but not yet deleted
+    ## XXX EAM : removed this function and made it more explicit (with an additional block)
+    ## '''
+    ## def getPurgedButNotDeletedBatchIDs(self, batchType, column):
+    ## 
+    ##     sql = "SELECT DISTINCT batch_id \
+    ##            FROM batch \
+    ##            WHERE timestamp > '" + self.skychunk.epoch + "' \
+    ##            AND batch_type = '" + batchType + "' \
+    ##            AND dvo_db = '" + self.skychunk.dvoLabel + "' \
+    ##            AND purged = 1 \
+    ##            AND " + column + " = 0"
+    ## 
+    ##     ids = []
+    ##     try:
+    ##         rs = self.executeQuery(sql)
+    ##         while (rs.next()): ids.append(rs.getInt(1))
+    ##         rs.close()
+    ##     except:
+    ##         self.logger.exception("Can't query for merged batch ids in ipptopsps Db")
+    ## 
+    ## 
+    ##     self.logger.debug("Found %d merged but un-deleted items" % len(ids))
+    ## 
+    ##     return ids
+
+    ## '''
+    ## Returns a list of processed batch IDs that have been loaded to the ODM but not yet deleted
+    ## '''
+    ## def getLoadedToODMButNotDeletedBatchIDs(self, batchType, column):
+    ## 
+    ##     sql = "SELECT DISTINCT batch_id \
+    ##            FROM batch \
+    ##            WHERE timestamp > '" + self.skychunk.epoch + "' \
+    ##            AND batch_type = '" + batchType + "' \
+    ##            AND dvo_db = '" + self.skychunk.dvoLabel + "' \
+    ##            AND (loaded_to_ODM = -1 OR merge_worthy = 1) \
+    ##            AND " + column + " = 0"
+    ## 
+    ##     ids = []
+    ##     try:
+    ##         rs = self.executeQuery(sql)
+    ##         while (rs.next()): ids.append(rs.getInt(1))
+    ##         rs.close()
+    ##     except:
+    ##         self.logger.exception("Can't query for merged batch ids in ipptopsps Db")
+    ## 
+    ##     self.logger.debug("Found %d merged but un-deleted items" % len(ids))
+    ## 
+    ##     return ids
+
+    # '''
+    # Returns a list of merged batch IDs that are not deleted from local disk
+    # '''
+    # def getMergedButNotDeletedFromLocalDisk(self, batchType):
+    #     return self.getMergedButNotDeletedBatchIDs(batchType, "deleted_local")
+
+    ## '''
+    ## Returns a list of processed batch IDs that are loaded to the ODM, but not deleted from local disk
+    ## '''
+    ## def getLoadedToODMButNotDeletedFromLocalDisk(self, batchType):
+    ##     return self.getLoadedToODMButNotDeletedBatchIDs(batchType, "deleted_local")
+    ## 
+    ## '''
+    ## Returns a list of processed batch IDs that are loaded to the ODM, but not deleted from datastore
+    ## '''
+    ## def getLoadedToODMButNotDeletedFromDatastore(self, batchType):
+    ##     return self.getLoadedToODMButNotDeletedBatchIDs(batchType, "deleted_datastore")
+    ## 
+    ## '''
+    ## Returns a list of processed batch IDs that are loaded to the ODM, but not deleted from DXLayer
+    ## '''
+    ## def getLoadedToODMButNotDeletedFromDXLayer(self, batchType):
+    ##     return self.getLoadedToODMButNotDeletedBatchIDs(batchType, "deleted_dxlayer")
+
+    ## '''
+    ## Returns a list of purged  batch IDs that not deleted from local disk
+    ## '''
+    ## def getPurgedButNotDeletedFromLocalDisk(self, batchType):
+    ##     return self.getPurgedButNotDeletedBatchIDs(batchType, "deleted_local")
+    ## 
+    ## '''
+    ## Returns a list of purged batch IDs that are not deleted from datastore
+    ## '''
+    ## def getPurgedButNotDeletedFromDatastore(self, batchType):
+    ##     return self.getPurgedButNotDeletedBatchIDs(batchType, "deleted_datastore")
 
 
