Index: trunk/ippToPsps/perl/ippToPsps/IppToPspsDb.pm
===================================================================
--- trunk/ippToPsps/perl/ippToPsps/IppToPspsDb.pm	(revision 29990)
+++ trunk/ippToPsps/perl/ippToPsps/IppToPspsDb.pm	(revision 29991)
@@ -11,5 +11,5 @@
 ###########################################################################
 #
-# Returns a list of batches that have been processed and loaded to datastore
+# Returns a list of batches created within the provided dates
 #
 ###########################################################################
@@ -39,7 +39,5 @@
     $query->execute;
     ${$batches} = $query->fetchall_arrayref();
-    my $count = scalar @{${$batches}};
-
-   return $count;
+    return scalar @{${$batches}};
 }
 
@@ -72,7 +70,74 @@
     $query->execute;
     ${$batches} = $query->fetchall_arrayref();
-    my $count = scalar @{${$batches}};
-
-   return $count;
+    return scalar @{${$batches}};
+}
+
+###########################################################################
+#
+# Returns a count of all distinct exposures between provided limits
+#
+###########################################################################
+sub countExposures {
+    my ($self, $fromExp, $toExp, $datastoreProduct, $batchType, $dvoDb) = @_;
+
+    my $query = $self->{_db}->prepare(<<SQL);
+    SELECT COUNT(distinct exp_id) 
+        FROM batches 
+        WHERE exp_id >= $fromExp
+        AND exp_id <= $toExp 
+        AND dvo_db = '$dvoDb' 
+        AND batch_type = '$batchType' 
+        AND datastore_product = '$datastoreProduct' 
+SQL
+
+    $query->execute;
+    return scalar $query->fetchrow_array();
+}
+
+###########################################################################
+#
+# Returns a count of exposures (between provided limits) that have been merged
+#
+###########################################################################
+sub countMergedExposures {
+    my ($self, $fromExp, $toExp, $datastoreProduct, $batchType, $dvoDb) = @_;
+
+    my $query = $self->{_db}->prepare(<<SQL);
+    SELECT COUNT(distinct exp_id) 
+        FROM batches 
+        WHERE exp_id >= $fromExp
+        AND exp_id <= $toExp 
+        AND dvo_db = '$dvoDb' 
+        AND batch_type = '$batchType' 
+        AND datastore_product = '$datastoreProduct' 
+        AND merged
+SQL
+
+    $query->execute;
+    return scalar $query->fetchrow_array();
+}
+
+###########################################################################
+#
+# Returns a list of exposures (between provided limits) that have not been merged
+#
+###########################################################################
+sub getUnmergedExposures {
+    my ($self, $exposures, $fromExp, $toExp, $datastoreProduct, $batchType, $dvoDb) = @_;
+
+    my $query = $self->{_db}->prepare(<<SQL);
+    SELECT distinct exp_id 
+        FROM batches 
+        WHERE exp_id >= $fromExp
+        AND exp_id <= $toExp 
+        AND dvo_db = '$dvoDb' 
+        AND batch_type = '$batchType' 
+        AND datastore_product = '$datastoreProduct' 
+        AND !merged
+SQL
+
+    $query->execute;
+    ${$exposures} = $query->fetchall_arrayref();
+    return scalar @{${$exposures}};
 }
 
@@ -166,4 +231,103 @@
 #######################################################################################
 #
+# Checks whether this exposure failed to load to the ODM
+#
+########################################################################################
+sub didLoadFail {
+    my ($self, $expId) = @_;
+
+    my $query = $self->{_db}->prepare(<<SQL);
+    SELECT COUNT(*) 
+        FROM batches 
+        WHERE exp_id = $expId
+        AND load_failed
+SQL
+
+    $query->execute;
+
+    return scalar $query->fetchrow_array();
+}
+
+#######################################################################################
+#
+# Checks whether this exposure has a min object ID under old PSPS hard limit of 72010000000000001
+#
+########################################################################################
+sub isMinObjIdUnderLimit {
+    my ($self, $expId) = @_;
+
+    my $query = $self->{_db}->prepare(<<SQL);
+    SELECT COUNT(*) 
+        FROM batches 
+        WHERE exp_id = $expId
+        AND min_obj_id < 72010000000000001
+SQL
+
+    $query->execute;
+
+    return scalar $query->fetchrow_array();
+}
+#######################################################################################
+#
+# Checks whether this exposure has been processed
+#
+########################################################################################
+sub isExposureProcessed {
+    my ($self, $expId) = @_;
+
+    my $query = $self->{_db}->prepare(<<SQL);
+    SELECT COUNT(*) 
+        FROM batches 
+        WHERE exp_id = $expId
+        AND processed
+SQL
+
+    $query->execute;
+
+    return scalar $query->fetchrow_array();
+}
+
+#######################################################################################
+#
+# Checks whether this exposure has been merged 
+#
+########################################################################################
+sub isExposureMerged {
+    my ($self, $expId) = @_;
+
+    my $query = $self->{_db}->prepare(<<SQL);
+    SELECT COUNT(*) 
+        FROM batches 
+        WHERE exp_id = $expId
+        AND merged
+SQL
+
+    $query->execute;
+
+    return scalar $query->fetchrow_array();
+}
+
+#######################################################################################
+#
+# Checks whether this exposure has been loaded to ODM 
+#
+########################################################################################
+sub isExposureLoadedToOdm {
+    my ($self, $expId) = @_;
+
+    my $query = $self->{_db}->prepare(<<SQL);
+    SELECT COUNT(*) 
+        FROM batches 
+        WHERE exp_id = $expId
+        AND loaded_to_ODM
+SQL
+
+    $query->execute;
+
+    return scalar $query->fetchrow_array();
+}
+
+#######################################################################################
+#
 # Checks whether we have successfully processed this exposure and loaded it to the datastore 
 #
@@ -184,4 +348,5 @@
     my $processed = $query->fetchrow_array();
 
+    # TODO can use return scalar $query->fetchrow_array();
     return $processed;
 }
