source: ccr/trunk/nhin-vista/projects/NHINC/Current/Product/Production/Gateway/AggregatorLib/src/gov/hhs/fha/nhinc/gateway/aggregator/persistence/GarbageCollectorThread.java@ 507

Last change on this file since 507 was 507, checked in by George Lilly, 15 years ago

NHIN gateway and adaptor for use on linux with VistA EHR and RPMS

File size: 2.3 KB
Line 
1package gov.hhs.fha.nhinc.gateway.aggregator.persistence;
2
3import gov.hhs.fha.nhinc.gateway.aggregator.dao.AggTransactionDao;
4import gov.hhs.fha.nhinc.gateway.aggregator.model.AggTransaction;
5import java.util.Date;
6import org.apache.commons.logging.Log;
7import org.apache.commons.logging.LogFactory;
8
9
10/**
11 *
12 * @author westbergl
13 */
14public class GarbageCollectorThread extends Thread
15{
16 private static Log log = LogFactory.getLog(GarbageCollectorThread.class);
17 private Date pivotDate = null;
18
19 /**
20 * Construct a garbage collector that will clean anything
21 * older than the specified date.
22 */
23 public GarbageCollectorThread(Date dtPivotDate)
24 {
25 pivotDate = dtPivotDate;
26 }
27
28
29 /**
30 * This runs the GarbageColletor against the aggregator tables. It will
31 * delete anything that is older than the pivot date.
32 *
33 */
34 @Override
35 public void run()
36 {
37 if (pivotDate != null)
38 {
39 AggTransactionDao oAggTransactionDao = new AggTransactionDao();
40
41 try
42 {
43 int iNumTrans = 0;
44 AggTransaction[] oaAggTransaction = oAggTransactionDao.findOlderThan(pivotDate);
45 if ((oaAggTransaction != null) &&
46 (oaAggTransaction.length > 0))
47 {
48 for (AggTransaction oAggTransaction : oaAggTransaction)
49 {
50 oAggTransactionDao.delete(oAggTransaction);
51 iNumTrans++;
52 }
53 }
54
55 log.debug("Aggregator garbage collector cleaned out " + iNumTrans + " stale transactions.");
56 }
57 catch (Exception e)
58 {
59 String sErrorMessage = "Aggregator garbage collector failed to read entries from the aggregation tables. " +
60 "Garbage collection is not being done. Error: " + e.getMessage();
61 log.error(sErrorMessage, e);
62 return;
63 }
64
65 }
66 else
67 {
68 String sErrorMessage = "Cannot run Aggregator garbage collection - pivot date was not set.";
69 log.error(sErrorMessage);
70 return;
71 }
72
73 return;
74 }
75}
Note: See TracBrowser for help on using the repository browser.