use of ca.nrc.cadc.caom2.harvester.state.HarvestStateDAO in project caom2db by opencadc.
the class ObservationRemover method run.
@Override
public void run() {
// Get HarvestState record to see if this collection has actually been harvested before
HarvestStateDAO harvestStateDAO = new PostgresqlHarvestStateDAO(obsDAO.getDataSource(), target.getDatabase(), target.getSchema());
HarvestState harvestStateRec = null;
if (src != null) {
harvestStateRec = harvestStateDAO.get(src.getIdentifier(), Observation.class.getSimpleName());
// in this case, getLastModified is null
if (harvestStateRec.getLastModified() == null) {
log.error("no found: HarvestState record for " + src.getIdentifier());
return;
}
}
log.info("Using batchSize: " + batchSize);
log.info("Removing Observation(s) ...");
Progress prog = null;
int total = 0;
boolean go = true;
while (go) {
prog = deleteObservations();
if (prog.found > 0) {
log.info("finished batch: " + prog.toString());
}
if (prog.abort) {
log.error("batch aborted");
}
total += prog.found;
go = (prog.found > 0 && !prog.abort);
}
log.info("Removed " + total + " observations");
if (prog.abort) {
log.warn("Problem removing observations. Quitting...");
return;
}
log.info("Removing DeletedObservation(s)...");
total = 0;
go = true;
while (go) {
prog = deleteDeletedObservations();
if (prog.found > 0) {
log.info("finished batch: " + prog.toString());
}
if (prog.abort) {
log.error("batch aborted");
}
total += prog.found;
go = (prog.found > 0 && !prog.abort);
}
log.info("Removed " + total + " DeletedObservation(s)");
if (prog.abort) {
log.warn("Problem removing DeletedObservation(s). Quitting...");
return;
}
if (src != null) {
log.info("Removing HarvesetSkipURI(s)...");
total = 0;
go = true;
while (go) {
prog = deleteHarvestSkipURI();
if (prog.found > 0) {
log.info("finished batch: " + prog.toString());
}
if (prog.abort) {
log.error("batch aborted");
}
total += prog.found;
go = (prog.found > 0 && !prog.abort);
}
log.info("Removed " + total + " HarvesetSkipURI(s)");
if (prog.abort) {
log.warn("Problem removing HarvesetSkipURI(s). Quitting...");
return;
}
}
if (src != null) {
log.info("Deleting harvest state records...");
harvestStateDAO.delete(harvestStateRec);
harvestStateRec = harvestStateDAO.get(src.getIdentifier(), DeletedObservation.class.getSimpleName());
if (harvestStateRec.getLastModified() != null) {
harvestStateDAO.delete(harvestStateRec);
}
}
}
use of ca.nrc.cadc.caom2.harvester.state.HarvestStateDAO in project caom2db by opencadc.
the class PostgresqlHarvestStateDAOTest method testInsertDate.
@Test
public void testInsertDate() {
try {
HarvestStateDAO dao = new PostgresqlHarvestStateDAO(dataSource, database, schema);
HarvestState s = dao.get("testInsertDate", Integer.class.getName());
Assert.assertEquals("testInsertDate", s.getSource());
Assert.assertNotNull(s);
Assert.assertNull(s.curLastModified);
s.curLastModified = new Date();
dao.put(s);
HarvestState s2 = dao.get("testInsertDate", Integer.class.getName());
Assert.assertNotNull(s2);
Assert.assertEquals(s.curLastModified, s2.curLastModified);
} catch (Exception unexpected) {
log.error("unexpected exception", unexpected);
Assert.fail("unexpected exception: " + unexpected);
}
}
use of ca.nrc.cadc.caom2.harvester.state.HarvestStateDAO in project caom2db by opencadc.
the class PostgresqlHarvestStateDAOTest method testUpdateDate.
@Test
public void testUpdateDate() {
try {
HarvestStateDAO dao = new PostgresqlHarvestStateDAO(dataSource, database, schema);
HarvestState s = dao.get("testUpdateDate", Integer.class.getName());
Assert.assertEquals("testUpdateDate", s.getSource());
Assert.assertNotNull(s);
Assert.assertNull(s.curLastModified);
long t = System.currentTimeMillis();
s.curLastModified = new Date(t);
dao.put(s);
HarvestState s2 = dao.get("testUpdateDate", Integer.class.getName());
Assert.assertNotNull(s2);
Assert.assertEquals(s.curLastModified, s2.curLastModified);
s.curLastModified = new Date(t + 10L);
dao.put(s);
HarvestState s3 = dao.get("testUpdateDate", Integer.class.getName());
Assert.assertNotNull(s3);
Assert.assertEquals(s.curLastModified, s3.curLastModified);
} catch (Exception unexpected) {
log.error("unexpected exception", unexpected);
Assert.fail("unexpected exception: " + unexpected);
}
}
use of ca.nrc.cadc.caom2.harvester.state.HarvestStateDAO in project caom2db by opencadc.
the class PostgresqlHarvestStateDAOTest method testPutGetDelete.
@Test
public void testPutGetDelete() {
try {
HarvestStateDAO dao = new PostgresqlHarvestStateDAO(dataSource, database, schema);
HarvestState s = dao.get("testGet", Integer.class.getName());
Assert.assertNotNull(s);
Assert.assertEquals("testGet", s.getSource());
Assert.assertEquals(Integer.class.getName(), s.getEntityClassName());
Assert.assertNull(s.curLastModified);
// not actually stored in DB
Assert.assertNull(s.id);
s.curLastModified = new Date();
s.curID = UUID.randomUUID();
dao.put(s);
HarvestState actual = dao.get("testGet", Integer.class.getName());
Assert.assertNotNull(s);
Assert.assertEquals(s.getSource(), actual.getSource());
Assert.assertEquals(s.getEntityClassName(), actual.getEntityClassName());
Assert.assertEquals(s.curID, actual.curID);
Assert.assertEquals(s.curLastModified, actual.curLastModified);
// persisted
Assert.assertNotNull(s.id);
try {
dao.delete(s);
} catch (IllegalArgumentException expected) {
log.info("caught expected: " + expected);
}
dao.delete(actual);
s = dao.get("testGet", Integer.class.getName());
Assert.assertNotNull(s);
Assert.assertEquals("testGet", s.getSource());
Assert.assertEquals(Integer.class.getName(), s.getEntityClassName());
Assert.assertNull(s.curLastModified);
// no longer stored in DB
Assert.assertNull(s.id);
} catch (Exception unexpected) {
log.error("unexpected exception", unexpected);
Assert.fail("unexpected exception: " + unexpected);
}
}
Aggregations