Issue #473: Properly archive text plugin records,

fix bugs in DatabaseArchiver.determineStartTime().

Change-Id: I2a7a71bcf7bdbc5ea786d949631b45342675ce1f

Former-commit-id: 8592a9a50d [formerly 526abfd36e] [formerly 04ab5d619b [formerly 6e45fc4f0eb15409a20be99c02b2ac43c8ed842e]]
Former-commit-id: 04ab5d619b
Former-commit-id: 36717c7a3e
This commit is contained in:
David Gillingham 2012-04-24 15:03:51 -05:00
parent e8fdf9d48f
commit cf74c74cc2
22 changed files with 648 additions and 305 deletions

View file

@ -137,7 +137,7 @@ public class RestoreFileSelectDlg extends Dialog {
StdTextProduct tmp = ((StdTextProduct) (obj));
Calendar createTime = Calendar.getInstance(TimeZone
.getTimeZone("GMT"));
createTime.setTimeInMillis(tmp.getCreatetime());
createTime.setTimeInMillis(tmp.getRefTime());
String label = tmp.getCccid() + tmp.getNnnid() + tmp.getXxxid()
+ " - " + createTime.getTime().toString();
fileList.add(label);

View file

@ -39,6 +39,13 @@
version="0.0.0"
unpack="false"/>
<plugin
id="com.raytheon.uf.edex.maintenance"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
<plugin
id="com.raytheon.edex.plugin.text"
download-size="0"

View file

@ -308,14 +308,14 @@ public final class TextDisplayModel {
* Getter/Accessor of Create Time.
*/
public long getCreateTime(String token) {
return getStdTextProduct(token, true).getCreatetime();
return getStdTextProduct(token, true).getRefTime();
}
/**
* Setter/Mutator of Create Time.
*/
public void setCreateTime(String token, long ct) {
getStdTextProduct(token, true).setCreatetime(ct);
getStdTextProduct(token, true).setRefTime(ct);
}
/**
@ -472,7 +472,7 @@ public final class TextDisplayModel {
tmpProduct.setXxxid(xxxid);
tmpProduct.setHdrtime(hdrtime);
tmpProduct.setBbbid(bbbid);
tmpProduct.setCreatetime(createtime);
tmpProduct.setRefTime(createtime);
tmpProduct.setProduct(product);
stdTxtProd.put(token, tmpProduct);
}

View file

@ -448,7 +448,7 @@ public class RemoteSiteRequestDlg extends CaveSWTDialog {
if (latest != null && latest.size() > 0) {
Calendar c = new GregorianCalendar(TimeZone
.getTimeZone("GMT"));
c.setTimeInMillis(latest.get(0).getCreatetime());
c.setTimeInMillis(latest.get(0).getRefTime());
req.setMostRecentTime(c.getTimeInMillis()); // default
try {
WMOHeader wmo = new WMOHeader(latest.get(0).getProduct().getBytes());

View file

@ -4605,7 +4605,7 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
updateTextEditor(body.toString());
}
storedProduct.setHdrtime(currentDate);
storedProduct.setCreatetime(System.currentTimeMillis());
storedProduct.setRefTime(System.currentTimeMillis());
if (productText.contains(AFOSParser.DRAFT_PIL)) {
int start = productText.indexOf(AFOSParser.DRAFT_PIL);
productText = productText.replace(productText.substring(start,
@ -4777,7 +4777,7 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
request.setBbbid(product.getBbbid());
request.setCccid(product.getCccid());
request.setCreatetime(product.getCreatetime());
request.setCreatetime(product.getRefTime());
request.setDataCrc(product.getDataCrc());
request.setHdrtime(product.getHdrtime());
request.setNnnid(product.getNnnid());
@ -4785,7 +4785,7 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
request.setWmoid(product.getWmoid());
request.setSite(product.getSite());
request.setXxxid(product.getXxxid());
request.setCreatetime(product.getCreatetime());
request.setCreatetime(product.getRefTime());
CAVEMode mode = CAVEMode.getMode();
boolean result = (CAVEMode.OPERATIONAL.equals(mode)
|| CAVEMode.TEST.equals(mode) ? true : false);

View file

@ -118,7 +118,7 @@ public class AviationTextUtility implements IAviationObserver {
tmpProd.setXxxid("TAF");
tmpProd.setHdrtime(currentDate);
tmpProd.setBbbid("NOR");
tmpProd.setCreatetime(System.currentTimeMillis());
tmpProd.setRefTime(System.currentTimeMillis());
tmpProd.setProduct(currentHeader + "\n" + tmpStr);
RequestConstraint rcRow;

View file

@ -139,7 +139,7 @@ public class RadarTextUtility implements IRadarObserver {
tmpProd.setXxxid(designator);
tmpProd.setHdrtime(currentDate);
tmpProd.setBbbid("NOR");
tmpProd.setCreatetime(System.currentTimeMillis());
tmpProd.setRefTime(System.currentTimeMillis());
tmpProd.setProduct(currentHeader + "\n" + strBldr.toString());
RequestConstraint rcRow;

View file

@ -0,0 +1,18 @@
#!/bin/sh
# This script should be run on dx1 as part of next delivery to update the definitions for
# the stdtextproducts and practicestdtextproducts tables.
psql -U awips -d fxa -c "ALTER TABLE stdtextproducts RENAME COLUMN createtime to reftime;"
psql -U awips -d fxa -c "ALTER TABLE practicestdtextproducts RENAME COLUMN createtime to reftime;"
psql -U awips -d fxa -c "ALTER TABLE stdtextproducts ADD COLUMN inserttime timestamp without time zone;"
psql -U awips -d fxa -c "ALTER TABLE practicestdtextproducts ADD COLUMN inserttime timestamp without time zone;"
psql -U awips -d fxa -c "CREATE INDEX stdtextproductsinserttimeindex ON stdtextproducts USING btree (inserttime);"
psql -U awips -d fxa -c "CREATE INDEX practicestdtextproductsinserttimeindex ON practicestdtextproducts USING btree (inserttime);"
psql -U awips -d fxa -c "UPDATE stdtextproducts SET inserttime = CURRENT_TIMESTAMP AT TIME ZONE 'GMT' WHERE inserttime IS NULL;"
psql -U awips -d fxa -c "UPDATE practicestdtextproducts SET inserttime = CURRENT_TIMESTAMP AT TIME ZONE 'GMT' WHERE inserttime IS NULL;"
psql -U awips -d fxa -c "ALTER TABLE stdtextproducts ALTER COLUMN inserttime SET NOT NULL;"
psql -U awips -d fxa -c "ALTER TABLE practicestdtextproducts ALTER COLUMN inserttime SET NOT NULL;"

View file

@ -19,4 +19,5 @@ Export-Package: com.raytheon.edex.plugin.text,
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: com.raytheon.uf.common.dataplugin.text,
com.raytheon.uf.common.dataplugin.text.db,
com.raytheon.uf.common.dataplugin.text.request
com.raytheon.uf.common.dataplugin.text.request,
com.raytheon.uf.edex.maintenance.archive

View file

@ -41,6 +41,14 @@
<property name="maxPoolSize" value="2" />
</bean>
<!-- Special handler for text plugin archives that bases filenames off
creation time-->
<bean id="textArchiveNamer" class="com.raytheon.edex.plugin.text.maintenance.archiver.TextArchiveFileNameFormatter" />
<bean factory-bean="databaseArchiver" factory-method="registerPluginArchiveFormatter" depends-on="databaseArchiver">
<constructor-arg value="text" />
<constructor-arg ref="textArchiveNamer" />
</bean>
<camelContext id="text-camel"
xmlns="http://camel.apache.org/schema/spring"

View file

@ -144,7 +144,7 @@ public class TextDecoder extends AbstractDecoder {
pdo.setProductId(textProduct.getCccid()
+ textProduct.getNnnid() + textProduct.getXxxid());
DataTime dt = new DataTime(
TimeTools.newCalendar(textProduct.getCreatetime()));
TimeTools.newCalendar(textProduct.getRefTime()));
pdo.setDataTime(dt);
} else {
// throw new Exception("product already exists");

View file

@ -78,32 +78,33 @@ public class TextDao extends DefaultPluginDao {
throws DataAccessLayerException {
StdTextProductDao dao = new StdTextProductDao(true);
DatabaseQuery dbQuery = new DatabaseQuery(dao.getDaoClass());
dbQuery.addQueryParam("createtime", insertStartTime.getTimeInMillis(),
dbQuery.addQueryParam("insertTime", insertStartTime,
QueryOperand.GREATERTHANEQUALS);
dbQuery.addQueryParam("createtime", insertEndTime.getTimeInMillis(),
dbQuery.addQueryParam("insertTime", insertEndTime,
QueryOperand.LESSTHAN);
dbQuery.addOrder("createtime", true);
dbQuery.addOrder("insertTime", true);
return (List<PersistableDataObject>) this.queryByCriteria(dbQuery);
return (List<PersistableDataObject>) dao.queryByCriteria(dbQuery);
}
@Override
public Date getMinInsertTime(String productKey)
throws DataAccessLayerException {
DatabaseQuery query = new DatabaseQuery(this.daoClass);
StdTextProductDao dao = new StdTextProductDao(true);
DatabaseQuery query = new DatabaseQuery(dao.getDaoClass());
List<String[]> keys = this.getProductKeyParameters(productKey);
for (String[] key : keys) {
query.addQueryParam(key[0], key[1]);
}
query.addReturnedField("createime");
query.addOrder("createtime", true);
query.addReturnedField("insertTime");
query.addOrder("insertTime", true);
query.setMaxResults(1);
@SuppressWarnings("unchecked")
List<Long> result = (List<Long>) this.queryByCriteria(query);
List<Calendar> result = (List<Calendar>) dao.queryByCriteria(query);
if (result.isEmpty()) {
return null;
} else {
return new Date(result.get(0));
return result.get(0).getTime();
}
}
}

View file

@ -95,7 +95,7 @@ public class StdTextProductRequestHandler implements
if (createtime == null) {
createtime = new Date().getTime();
}
text.setCreatetime(createtime);
text.setRefTime(createtime);
text.setProduct(product);
boolean success = dao.writeProduct(text);

View file

@ -0,0 +1,126 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.edex.plugin.text.maintenance.archiver;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.raytheon.uf.common.dataplugin.persist.DefaultPathProvider;
import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject;
import com.raytheon.uf.common.dataplugin.text.db.StdTextProduct;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.edex.database.DataAccessLayerException;
import com.raytheon.uf.edex.database.plugin.PluginDao;
import com.raytheon.uf.edex.maintenance.archive.IPluginArchiveFileNameFormatter;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 20, 2012 dgilling Initial creation
*
* </pre>
*
* @author dgilling
* @version 1.0
*/
public class TextArchiveFileNameFormatter implements
IPluginArchiveFileNameFormatter {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(TextArchiveFileNameFormatter.class);
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.maintenance.archive.IPluginArchiveFileNameFormatter
* #getPdosByFile(java.lang.String,
* com.raytheon.uf.edex.database.plugin.PluginDao, java.util.Map,
* java.util.Calendar, java.util.Calendar)
*/
@Override
public Map<String, List<PersistableDataObject>> getPdosByFile(
String pluginName, PluginDao dao,
Map<String, List<PersistableDataObject>> pdoMap,
Calendar startTime, Calendar endTime)
throws DataAccessLayerException {
List<PersistableDataObject> pdos = dao.getRecordsToArchive(startTime,
endTime);
Set<String> newFileEntries = new HashSet<String>();
if (pdos != null && !pdos.isEmpty()) {
if (pdos.get(0) instanceof StdTextProduct) {
for (PersistableDataObject pdo : pdos) {
StdTextProduct casted = (StdTextProduct) pdo;
// no refTime to use, so we use creation time
Date time = new Date(casted.getRefTime());
String timeString = null;
synchronized (DefaultPathProvider.fileNameFormat) {
timeString = DefaultPathProvider.fileNameFormat
.format(time);
}
String path = pluginName + timeString;
newFileEntries.add(path);
List<PersistableDataObject> list = pdoMap.get(path);
if (list == null) {
list = new ArrayList<PersistableDataObject>(pdos.size());
pdoMap.put(path, list);
}
list.add(pdo);
}
} else {
statusHandler.error("Invalid PersistableDataObject class "
+ pdos.get(0).getClass()
+ "sent to TextArchiveFileNameFormatter to archive");
}
}
Iterator<String> iter = pdoMap.keySet().iterator();
Map<String, List<PersistableDataObject>> pdosToSave = new HashMap<String, List<PersistableDataObject>>(
pdoMap.size() - newFileEntries.size());
while (iter.hasNext()) {
String key = iter.next();
if (!newFileEntries.contains(key)) {
pdosToSave.put(key, pdoMap.get(key));
iter.remove();
}
}
return pdosToSave;
}
}

View file

@ -106,7 +106,9 @@ public class StdTextProductDao extends CoreDao {
private static final String CCC_ID = "cccid";
private static final String CREATETIME = "createtime";
private static final String REFTIME = "refTime";
private static final String INSERTTIME = "insertTime";
private static final String ProdHDRTIME = "prodId.hdrtime";
@ -128,7 +130,7 @@ public class StdTextProductDao extends CoreDao {
private static final String PRACTICE_TABLE = "practicestdtextproducts";
private static final String TM_QUERY_FMT = "select createtime from table_name where cccid='%s' and nnnid='%s' and xxxid='%s';";
private static final String TM_QUERY_FMT = "select refTime from table_name where cccid='%s' and nnnid='%s' and xxxid='%s';";
private static final String AFOS_QUERY_STMT = "from StdTextProduct prod where "
+ ProdCCC_ID
@ -143,7 +145,7 @@ public class StdTextProductDao extends CoreDao {
+ " = :"
+ XXX_ID
+ " order by "
+ CREATETIME + " desc";
+ REFTIME + " desc" + ", " + INSERTTIME + " desc";
private Log logger = LogFactory.getLog(getClass());
@ -183,7 +185,7 @@ public class StdTextProductDao extends CoreDao {
prodId.setXxxid(xxx);
try {
Query query = this.getSession().createQuery(
"SELECT createtime from "
"SELECT refTime from "
+ textProduct.getClass().getSimpleName()
+ " where prodId = :prodid");
query.setParameter("prodid", prodId);
@ -391,11 +393,12 @@ public class StdTextProductDao extends CoreDao {
Criteria criteria = session
.createCriteria(getStdTextProductInstance().getClass());
criteria.add(Restrictions.allEq(tmp));
criteria.add(Restrictions.gt(CREATETIME, new Long(searchTime)));
criteria.add(Restrictions.gt(REFTIME, new Long(searchTime)));
criteria.addOrder(Order.asc(ProdCCC_ID));
criteria.addOrder(Order.asc(ProdNNN_ID));
criteria.addOrder(Order.asc(ProdXXX_ID));
criteria.addOrder(Order.desc(CREATETIME));
criteria.addOrder(Order.desc(REFTIME));
criteria.addOrder(Order.desc(INSERTTIME));
criteria.addOrder(Order.desc(ProdHDRTIME));
Iterator<?> iter = criteria.list().iterator();
@ -467,7 +470,7 @@ public class StdTextProductDao extends CoreDao {
Criteria criteria = sess.createCriteria(getStdTextProductInstance()
.getClass());
criteria.setProjection(Projections.max(CREATETIME));
criteria.setProjection(Projections.max(REFTIME));
criteria.add(Restrictions.allEq(tmp));
List<?> list = criteria.list();
@ -602,8 +605,8 @@ public class StdTextProductDao extends CoreDao {
}
/**
* Simple purge routine. Deletes all data that has a createtime older than
* that specified.
* Simple purge routine. Deletes all data that has a refTime older than that
* specified.
*/
public int versionPurge() {
return versionPurge(null);
@ -650,20 +653,21 @@ public class StdTextProductDao extends CoreDao {
String nnnid = null;
String xxxid = null;
String cTimeQueryString = null;
String refTimeQueryString = null;
{
StringBuilder cTimeQueryBuilder = new StringBuilder(200);
cTimeQueryBuilder.append("SELECT createtime FROM ");
cTimeQueryBuilder.append(getStdTextProductInstance()
StringBuilder refTimeQueryBuilder = new StringBuilder(200);
refTimeQueryBuilder.append("SELECT refTime FROM ");
refTimeQueryBuilder.append(getStdTextProductInstance()
.getClass().getSimpleName());
cTimeQueryBuilder.append(" WHERE ");
cTimeQueryBuilder.append(ProdCCC_ID).append(" = :cccid")
refTimeQueryBuilder.append(" WHERE ");
refTimeQueryBuilder.append(ProdCCC_ID).append(" = :cccid")
.append(" AND ");
cTimeQueryBuilder.append(ProdNNN_ID).append(" = :nnnid")
refTimeQueryBuilder.append(ProdNNN_ID).append(" = :nnnid")
.append(" AND ");
cTimeQueryBuilder.append(ProdXXX_ID).append(" = :xxxid");
cTimeQueryBuilder.append(" ORDER BY createtime DESC");
cTimeQueryString = cTimeQueryBuilder.toString();
refTimeQueryBuilder.append(ProdXXX_ID).append(" = :xxxid");
refTimeQueryBuilder.append(" ORDER BY refTime DESC");
refTimeQueryBuilder.append(", insertTime DESC");
refTimeQueryString = refTimeQueryBuilder.toString();
}
String delQueryString = null;
@ -679,7 +683,7 @@ public class StdTextProductDao extends CoreDao {
.append(" AND ");
delQueryBuilder.append(ProdXXX_ID).append(" = :xxxid")
.append(" AND ");
delQueryBuilder.append("createtime < :createtime");
delQueryBuilder.append("refTime < :refTime");
delQueryString = delQueryBuilder.toString();
}
@ -693,29 +697,29 @@ public class StdTextProductDao extends CoreDao {
try {
tx = session.beginTransaction();
Query cTimeQuery = session
.createQuery(cTimeQueryString);
cTimeQuery.setString("cccid", cccid);
cTimeQuery.setString("nnnid", nnnid);
cTimeQuery.setString("xxxid", xxxid);
cTimeQuery.setMaxResults(prodInfo.getVersionstokeep());
List<?> createTimes = cTimeQuery.list();
if (createTimes.size() >= prodInfo.getVersionstokeep()) {
long createTime = ((Number) createTimes
.get(prodInfo.getVersionstokeep() - 1))
.longValue();
Query refTimeQuery = session
.createQuery(refTimeQueryString);
refTimeQuery.setString("cccid", cccid);
refTimeQuery.setString("nnnid", nnnid);
refTimeQuery.setString("xxxid", xxxid);
refTimeQuery
.setMaxResults(prodInfo.getVersionstokeep());
List<?> refTimes = refTimeQuery.list();
if (refTimes.size() >= prodInfo.getVersionstokeep()) {
long refTime = ((Number) refTimes.get(prodInfo
.getVersionstokeep() - 1)).longValue();
Query delQuery = session
.createQuery(delQueryString);
delQuery.setString("cccid", cccid);
delQuery.setString("nnnid", nnnid);
delQuery.setString("xxxid", xxxid);
delQuery.setLong("createtime", createTime);
delQuery.setLong("refTime", refTime);
if (PurgeLogger.isDebugEnabled()) {
PurgeLogger.logDebug("Purging records for ["
+ cccid + nnnid + xxxid
+ "] before createTime [" + createTime
+ "]", PLUGIN_NAME);
+ "] before refTime [" + refTime + "]",
PLUGIN_NAME);
}
int rowsDeleted = delQuery.executeUpdate();
@ -876,7 +880,7 @@ public class StdTextProductDao extends CoreDao {
ProjectionList projectionList = Projections.projectionList();
projectionList.add(Projections.distinct(Projections
.property(ProdWMO_ID)));
projectionList.add(Projections.max(CREATETIME));
projectionList.add(Projections.max(REFTIME));
projectionList.add(Projections.groupProperty(ProdWMO_ID));
projectionList.add(Projections.groupProperty(ProdSITE));
projectionList.add(Projections.groupProperty(ProdCCC_ID));
@ -894,24 +898,18 @@ public class StdTextProductDao extends CoreDao {
List<StdTextProduct> tmpProducts = new ArrayList<StdTextProduct>();
for (int i = 0; i < products.size(); i++) {
StdTextProduct stdTextProduct = getStdTextProductInstance();
stdTextProduct.setWmoid((String) ((Object[]) (products
.toArray())[i])[0]);
stdTextProduct.setRefTime((Long) ((Object[]) (products
.toArray())[i])[1]);
stdTextProduct
.setWmoid((String) ((Object[]) ((Object[]) products
.toArray())[i])[0]);
stdTextProduct
.setCreatetime((Long) ((Object[]) ((Object[]) products
.toArray())[i])[1]);
stdTextProduct
.setSite((String) ((Object[]) ((Object[]) products
.toArray())[i])[3]);
stdTextProduct
.setCccid((String) ((Object[]) ((Object[]) products
.toArray())[i])[4]);
stdTextProduct
.setNnnid((String) ((Object[]) ((Object[]) products
.toArray())[i])[5]);
stdTextProduct
.setXxxid((String) ((Object[]) ((Object[]) products
.toArray())[i])[6]);
.setSite((String) ((Object[]) (products.toArray())[i])[3]);
stdTextProduct.setCccid((String) ((Object[]) (products
.toArray())[i])[4]);
stdTextProduct.setNnnid((String) ((Object[]) (products
.toArray())[i])[5]);
stdTextProduct.setXxxid((String) ((Object[]) (products
.toArray())[i])[6]);
tmpProducts.add(stdTextProduct);
}
@ -949,7 +947,7 @@ public class StdTextProductDao extends CoreDao {
projectionList.add(Projections.distinct(Projections
.property(BBB_ID)));
projectionList.add(Projections.property(ProdWMO_ID));
projectionList.add(Projections.property(CREATETIME));
projectionList.add(Projections.property(REFTIME));
projectionList.add(Projections.property(ProdSITE));
projectionList.add(Projections.property(ProdCCC_ID));
projectionList.add(Projections.property(ProdNNN_ID));
@ -961,10 +959,10 @@ public class StdTextProductDao extends CoreDao {
.createCriteria(getStdTextProductInstance().getClass());
if (readAllVersions && startTimeMillis != null) {
criteria.add(Restrictions.and(Restrictions.allEq(map),
Restrictions.ge(CREATETIME, startTimeMillis)));
Restrictions.ge(REFTIME, startTimeMillis)));
} else {
criteria.add(Restrictions.and(Restrictions.allEq(map),
Restrictions.eq(CREATETIME, p.getCreatetime())));
Restrictions.eq(REFTIME, p.getRefTime())));
}
criteria.setProjection(projectionList);
@ -977,33 +975,24 @@ public class StdTextProductDao extends CoreDao {
List<StdTextProduct> tmpProducts = new ArrayList<StdTextProduct>();
for (int i = 0; i < list.size(); i++) {
StdTextProduct stdTextProduct = getStdTextProductInstance();
stdTextProduct.setBbbid((String) ((Object[]) (list
.toArray())[i])[0]);
stdTextProduct.setWmoid((String) ((Object[]) (list
.toArray())[i])[1]);
stdTextProduct.setRefTime((Long) ((Object[]) (list
.toArray())[i])[2]);
stdTextProduct
.setBbbid((String) ((Object[]) ((Object[]) list
.toArray())[i])[0]);
stdTextProduct
.setWmoid((String) ((Object[]) ((Object[]) list
.toArray())[i])[1]);
stdTextProduct
.setCreatetime((Long) ((Object[]) ((Object[]) list
.toArray())[i])[2]);
stdTextProduct
.setSite((String) ((Object[]) ((Object[]) list
.toArray())[i])[3]);
stdTextProduct
.setCccid((String) ((Object[]) ((Object[]) list
.toArray())[i])[4]);
stdTextProduct
.setNnnid((String) ((Object[]) ((Object[]) list
.toArray())[i])[5]);
stdTextProduct
.setXxxid((String) ((Object[]) ((Object[]) list
.toArray())[i])[6]);
stdTextProduct
.setHdrtime((String) ((Object[]) ((Object[]) list
.toArray())[i])[7]);
stdTextProduct
.setProduct((String) ((Object[]) ((Object[]) list
.toArray())[i])[8]);
.setSite((String) ((Object[]) (list.toArray())[i])[3]);
stdTextProduct.setCccid((String) ((Object[]) (list
.toArray())[i])[4]);
stdTextProduct.setNnnid((String) ((Object[]) (list
.toArray())[i])[5]);
stdTextProduct.setXxxid((String) ((Object[]) (list
.toArray())[i])[6]);
stdTextProduct.setHdrtime((String) ((Object[]) (list
.toArray())[i])[7]);
stdTextProduct.setProduct((String) ((Object[]) (list
.toArray())[i])[8]);
tmpProducts.add(stdTextProduct);
}
list.clear();
@ -1053,11 +1042,11 @@ public class StdTextProductDao extends CoreDao {
int version = 0;
final String query1 = "SELECT DISTINCT site FROM stdTextProducts "
+ "WHERE wmoId = ? ORDER BY site ASC";
final String query2 = "SELECT MAX(createTime) FROM stdTextProducts "
final String query2 = "SELECT MAX(refTime) FROM stdTextProducts "
+ "WHERE site = ? and wmoId = ?";
final String query3 = "SELECT cccId, nnnId, xxxId, hdrTime, bbbId, version "
+ "FROM stdTextProducts "
+ "WHERE site = ? AND wmoId = ? AND createTime = ? "
+ "WHERE site = ? AND wmoId = ? AND refTime = ? "
+ "ORDER BY cccId ASC, nnnId ASC, xxxId ASC, hdrTime DESC, bbbId DESC";
List<String> retVal = new ArrayList<String>();
@ -1077,10 +1066,10 @@ public class StdTextProductDao extends CoreDao {
rs2 = ps2.executeQuery();
if (rs2.next()) {
int createTime = rs2.getInt("createTime");
int refTime = rs2.getInt("refTime");
ps3.setString(1, site);
ps3.setString(2, wmoId);
ps3.setInt(3, createTime);
ps3.setInt(3, refTime);
rs3 = ps3.executeQuery();
while (rs3.next()) {
@ -1158,7 +1147,7 @@ public class StdTextProductDao extends CoreDao {
*/
public List<String> read_wh(String site, long startTimeMillis) {
return read_wh(site,
(int) (Math.round(startTimeMillis / (float) MILLIS_PER_SECOND)));
(Math.round(startTimeMillis / (float) MILLIS_PER_SECOND)));
}
/*
@ -1181,8 +1170,8 @@ public class StdTextProductDao extends CoreDao {
ResultSet rs1 = null;
String product = null;
final String query = "SELECT product "
+ "FROM stdTextProducts WHERE wmoId = ? AND createTime >= ? "
+ "ORDER BY createTime DESC";
+ "FROM stdTextProducts WHERE wmoId = ? AND refTime >= ? "
+ "ORDER BY refTime DESC, insertTime DESC";
List<String> retVal = new ArrayList<String>();
try {
@ -1244,11 +1233,11 @@ public class StdTextProductDao extends CoreDao {
int version = 0;
final String query1 = "SELECT DISTINCT wmoId "
+ "FROM stdTextProducts WHERE site = ? " + "ORDER BY wmoId ASC";
final String query2 = "SELECT MAX(createTime) "
final String query2 = "SELECT MAX(refTime) "
+ "FROM stdTextProducts WHERE site = ? and wmoId = ?";
final String query3 = "SELECT cccId, nnnId, xxxId, hdrTime, bbbId, version "
+ "FROM stdTextProducts "
+ "WHERE site = ? AND wmoId = ? AND createTime = ? "
+ "WHERE site = ? AND wmoId = ? AND refTime = ? "
+ "ORDER BY cccId ASC, nnnId ASC, xxxId ASC, hdrTime DESC, bbbId DESC";
List<String> retVal = new ArrayList<String>();
@ -1268,11 +1257,11 @@ public class StdTextProductDao extends CoreDao {
rs2 = ps2.executeQuery();
if (rs2.next()) {
int createTime = rs2.getInt("createTime");
int refTime = rs2.getInt("refTime");
ps3 = c.prepareStatement(query3);
ps3.setString(1, site);
ps3.setString(2, wmoId);
ps3.setInt(3, createTime);
ps3.setInt(3, refTime);
rs3 = ps3.executeQuery();
while (rs3.next()) {
@ -1349,7 +1338,7 @@ public class StdTextProductDao extends CoreDao {
*/
public List<String> read_sh(String site, long startTimeMillis) {
return read_sh(site,
(int) (Math.round(startTimeMillis / (float) MILLIS_PER_SECOND)));
(Math.round(startTimeMillis / (float) MILLIS_PER_SECOND)));
}
/*
@ -1372,8 +1361,8 @@ public class StdTextProductDao extends CoreDao {
ResultSet rs1 = null;
String product = null;
final String query = "SELECT product "
+ "FROM stdTextProducts WHERE site = ? AND createTime >= ? "
+ "ORDER BY createTime DESC";
+ "FROM stdTextProducts WHERE site = ? AND refTime >= ? "
+ "ORDER BY refTime DESC, insertTime DESC";
List<String> retVal = new ArrayList<String>();
try {
@ -1441,7 +1430,7 @@ public class StdTextProductDao extends CoreDao {
final String query2 = "SELECT cccId, hdrTime, bbbId, version "
+ "FROM stdTextProducts "
+ "WHERE site = ? AND wmoId = ? AND nnnId = ? AND xxxId = ? "
+ "ORDER BY cccId ASC, createTime DESC";
+ "ORDER BY cccId ASC, refTime DESC, insertTime DESC";
try {
session = getSession();
@ -1519,10 +1508,9 @@ public class StdTextProductDao extends CoreDao {
*
* PDL: Read the version that matches the input Return
*
* Note: The MAX function was used just in case createTimes are same. Since
* the product createTime is the UNIX time which has the unit of
* microseconds, it is assumed there should not have two products with the
* same createTime.
* Note: The MAX function was used just in case refTimes are same. Since the
* product refTime is the UNIX time which has the unit of microseconds, it
* is assumed there should not have two products with the same refTime.
* ====================================================================
*/
public int readLatestIntr(String wmoId, String site) {
@ -1533,12 +1521,12 @@ public class StdTextProductDao extends CoreDao {
ResultSet rs1 = null;
ResultSet rs2 = null;
int version = -1;
final String query1 = "SELECT MAX(createTime) "
final String query1 = "SELECT MAX(refTime) "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? AND cccId = 'NOA' AND nnnId = 'FOS' AND xxxId = 'PIL'";
final String query2 = "SELECT MAX(version) "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? AND cccId = 'NOA' AND nnnId = 'FOS' AND xxxId = 'PIL' AND createTime = ?";
+ "WHERE wmoId = ? AND site = ? AND cccId = 'NOA' AND nnnId = 'FOS' AND xxxId = 'PIL' AND refTime = ?";
try {
session = getSession();
@ -1549,11 +1537,11 @@ public class StdTextProductDao extends CoreDao {
rs1 = ps1.executeQuery();
if (rs1.next()) {
int createTime = rs1.getInt("createTime");
int refTime = rs1.getInt("refTime");
ps2 = c.prepareStatement(query2);
ps2.setString(1, site);
ps2.setString(2, wmoId);
ps2.setInt(3, createTime);
ps2.setInt(3, refTime);
rs2 = ps2.executeQuery();
if (rs2.next()) {
@ -1586,10 +1574,9 @@ public class StdTextProductDao extends CoreDao {
*
* PDL: Read the version that matches the input Return
*
* Note: The MAX function was used just in case createTimes are same. Since
* the product createTime is the UNIX time which has the unit of
* microseconds, it is assumed there should not have two products with the
* same createTim
* Note: The MAX function was used just in case refTimes are same. Since the
* product refTime is the UNIX time which has the unit of microseconds, it
* is assumed there should not have two products with the same createTim
* ====================================================================
*/
public int readLatest(String wmoId, String site, String cccId,
@ -1601,12 +1588,12 @@ public class StdTextProductDao extends CoreDao {
ResultSet rs1 = null;
ResultSet rs2 = null;
int version = -1;
final String query1 = "SELECT MAX(createTime) "
final String query1 = "SELECT MAX(refTime) "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? AND cccId = ? AND nnnId = ? AND xxxId = ? AND hdrTime = ?";
final String query2 = "SELECT MAX(version) "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? AND cccId = ? AND nnnId = ? AND xxxId = ? AND hdrTime = ? AND createTime = ?";
+ "WHERE wmoId = ? AND site = ? AND cccId = ? AND nnnId = ? AND xxxId = ? AND hdrTime = ? AND refTime = ?";
try {
session = getSession();
@ -1621,7 +1608,7 @@ public class StdTextProductDao extends CoreDao {
rs1 = ps1.executeQuery();
if (rs1.next()) {
int createTime = rs1.getInt("createTime");
int refTime = rs1.getInt("refTime");
ps2 = c.prepareStatement(query2);
ps2.setString(1, wmoId);
ps2.setString(2, site);
@ -1629,7 +1616,7 @@ public class StdTextProductDao extends CoreDao {
ps2.setString(4, nnnId);
ps2.setString(5, xxxId);
ps2.setString(6, hdrTime);
ps2.setInt(7, createTime);
ps2.setInt(7, refTime);
rs2 = ps2.executeQuery();
if (rs2.next()) {
@ -1696,10 +1683,10 @@ public class StdTextProductDao extends CoreDao {
final String abbrIdQuery = "SELECT DISTINCT nnnId, xxxId "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? ORDER BY nnnId ASC, xxxId ASC";
final String hdrQuery = "SELECT DISTINCT cccId, hdrTime, bbbId, version, createTime "
final String hdrQuery = "SELECT DISTINCT cccId, hdrTime, bbbId, version, refTime "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? AND nnnId = ? AND xxxId = ? "
+ "ORDER by cccId ASC, createTime DESC";
+ "ORDER by cccId ASC, refTime DESC, insertTime DESC";
try {
session = getSession();
@ -1767,10 +1754,12 @@ public class StdTextProductDao extends CoreDao {
bbbId = rs2.getString("bbbId");
version = rs2.getInt("version");
if (bbbId == null || bbbId.length() > 0)
if (bbbId == null || bbbId.length() > 0) {
bbbId = "-";
if (cccId == null)
}
if (cccId == null) {
cccId = "";
}
retVal.add(generateHeader(wmoId, site, hdrTime, bbbId,
cccId, nnnId, xxxId));
@ -1821,7 +1810,7 @@ public class StdTextProductDao extends CoreDao {
*/
public List<String> read_wsh(String wmoId, String site, long startTimeMillis) {
return read_wsh(wmoId, site,
(int) (Math.round(startTimeMillis / (float) MILLIS_PER_SECOND)));
(Math.round(startTimeMillis / (float) MILLIS_PER_SECOND)));
}
/*
@ -1844,8 +1833,8 @@ public class StdTextProductDao extends CoreDao {
ResultSet rs1 = null;
String product = null;
final String query = "SELECT product FROM stdTextProducts "
+ "WHERE wmoId = ? site = ? AND createTime >= ? "
+ "ORDER BY createTime DESC";
+ "WHERE wmoId = ? site = ? AND refTime >= ? "
+ "ORDER BY refTime DESC, insertTime DESC";
List<String> retVal = new ArrayList<String>();
try {
@ -1903,7 +1892,7 @@ public class StdTextProductDao extends CoreDao {
final String hdrQuery = "SELECT cccId, nnnId, xxxId, hdrTime, bbbId, version "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? "
+ "ORDER BY cccId ASC, nnnId ASC, xxxId ASC, createTime DESC";
+ "ORDER BY cccId ASC, nnnId ASC, xxxId ASC, refTime DESC, insertTime DESC";
List<String> retVal = new ArrayList<String>();
try {
@ -1922,14 +1911,18 @@ public class StdTextProductDao extends CoreDao {
bbbId = rs1.getString("bbbId");
version = rs1.getInt("version");
if (bbbId == null || bbbId.length() > 0)
if (bbbId == null || bbbId.length() > 0) {
bbbId = "-";
if (cccId == null)
}
if (cccId == null) {
cccId = "";
if (nnnId == null || nnnId.length() > 0)
}
if (nnnId == null || nnnId.length() > 0) {
nnnId = "-";
if (xxxId == null)
}
if (xxxId == null) {
xxxId = "";
}
retVal.add(generateHeader(wmoId, site, hdrTime, bbbId, cccId,
nnnId, xxxId));
@ -1990,7 +1983,7 @@ public class StdTextProductDao extends CoreDao {
final String hdrQuery = "SELECT cccId, hdrTime, bbbId, version "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? AND nnnId = ? AND xxxId = ? "
+ "ORDER BY cccId ASC, createTime DESC";
+ "ORDER BY cccId ASC, refTime DESC, insertTime DESC";
try {
session = getSession();
@ -2008,10 +2001,12 @@ public class StdTextProductDao extends CoreDao {
bbbId = rs1.getString("bbbId");
version = rs1.getInt("version");
if (bbbId == null || bbbId.length() > 0)
if (bbbId == null || bbbId.length() > 0) {
bbbId = "-";
if (cccId == null)
}
if (cccId == null) {
cccId = "";
}
retVal.add(generateHeader(wmoId, site, hdrTime, bbbId,
cccId, nnnId, xxxId));
@ -2076,12 +2071,12 @@ public class StdTextProductDao extends CoreDao {
final String hdrQuery = "SELECT cccId, hdrTime, bbbId, version "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? AND nnnId = ? AND xxxId = ? "
+ "ORDER BY cccId ASC, createTime DESC";
+ "ORDER BY cccId ASC, refTime DESC, insertTime DESC";
final String noXxxQuery = "SELECT cccId, xxxId hdrTime, bbbId, version "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? AND nnnId = ? "
+ "ORDER BY cccId ASC, xxxId ASC, createTime DESC";
+ "ORDER BY cccId ASC, xxxId ASC, refTime DESC, insertTime DESC";
if (abbrId.length() > 3) {
xxxId = abbrId.substring(3);
@ -2115,10 +2110,12 @@ public class StdTextProductDao extends CoreDao {
xxxId = rs1.getString("xxxId");
}
if (bbbId == null || bbbId.length() > 0)
if (bbbId == null || bbbId.length() > 0) {
bbbId = "-";
if (cccId == null)
}
if (cccId == null) {
cccId = "";
}
retVal.add(generateHeader(wmoId, site, hdrTime, bbbId,
cccId, nnnId, xxxId));
@ -2184,7 +2181,7 @@ public class StdTextProductDao extends CoreDao {
final String hdrQuery = "SELECT cccId, bbbId, version "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? AND nnnId = ? AND xxxId = ? AND hdrTime = ?"
+ "ORDER BY cccId ASC, createTime DESC, version DESC";
+ "ORDER BY cccId ASC, refTime DESC, insertTime DESC, version DESC";
try {
session = getSession();
@ -2204,15 +2201,17 @@ public class StdTextProductDao extends CoreDao {
bbbId = rs1.getString("bbbId");
version = rs1.getInt("version");
if (bbbId == null || bbbId.length() > 0)
if (bbbId == null || bbbId.length() > 0) {
bbbId = "-";
if (cccId == null)
}
if (cccId == null) {
cccId = "";
}
String hdr = generateHeader(wmoId, site, hdrTime, bbbId,
cccId, nnnId, xxxId);
// order by ensures MAX(createTime) and MAX(version) is
// order by ensures MAX(refTime) and MAX(version) is
// loaded first
if (retVal.size() > 0) {
if (!retVal.get(retVal.size() - 1).equals(hdr)) {
@ -2279,7 +2278,7 @@ public class StdTextProductDao extends CoreDao {
final String hdrQuery = "SELECT cccId, version "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? AND nnnId = ? AND xxxId = ? AND hdrTime = ? AND bbbId = ? "
+ "ORDER BY cccId ASC, createTime DESC, version DESC";
+ "ORDER BY cccId ASC, refTime DESC, insertTime DESC, version DESC";
try {
session = getSession();
@ -2299,13 +2298,14 @@ public class StdTextProductDao extends CoreDao {
cccId = rs1.getString("cccId");
version = rs1.getInt("version");
if (cccId == null)
if (cccId == null) {
cccId = "";
}
String hdr = generateHeader(wmoId, site, hdrTime, bbbId,
cccId, nnnId, xxxId);
// order by ensures MAX(createTime) and MAX(version) is
// order by ensures MAX(refTime) and MAX(version) is
// loaded first
if (retVal.size() > 0) {
if (!retVal.get(retVal.size() - 1).equals(hdr)) {
@ -2390,7 +2390,7 @@ public class StdTextProductDao extends CoreDao {
final String hdrQuery = "SELECT cccId, nnnId, xxxId, bbbId, version "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? AND hdrTime = ? AND cccId IS NOT NULL AND nnnId IS NOT NULL AND xxxId IS NOT NULL "
+ "ORDER BY cccId ASC, nnnId ASC, xxxId ASC, bbbId DESC, createTime DESC, version DESC";
+ "ORDER BY cccId ASC, nnnId ASC, xxxId ASC, bbbId DESC, refTime DESC, insertTime DESC, version DESC";
ps1 = c.prepareStatement(hdrQuery);
break;
}
@ -2398,7 +2398,7 @@ public class StdTextProductDao extends CoreDao {
final String hdrQuery = "SELECT version "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? AND hdrTime = ? AND cccId = 'NOA' AND nnnId = 'FOS' AND xxxId = 'PIL' "
+ "ORDER BY createTime DESC, version DESC";
+ "ORDER BY refTime DESC, insertTime DESC, version DESC";
ps1 = c.prepareStatement(hdrQuery);
break;
}
@ -2406,7 +2406,7 @@ public class StdTextProductDao extends CoreDao {
final String hdrQuery = "SELECT version "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? AND hdrTime = ? AND cccId = 'NOA' AND nnnId = 'FOS' AND xxxId = 'PIL' "
+ "ORDER BY createTime DESC, version DESC";
+ "ORDER BY refTime DESC, insertTime DESC, version DESC";
ps1 = c.prepareStatement(hdrQuery);
break;
}
@ -2440,7 +2440,7 @@ public class StdTextProductDao extends CoreDao {
String hdr = generateHeader(wmoId, site, hdrTime, bbbId, cccId,
nnnId, xxxId);
// order by ensures MAX(createTime) and MAX(version) is
// order by ensures MAX(refTime) and MAX(version) is
// loaded first
if (retVal.size() > 0) {
if (!retVal.get(retVal.size() - 1).equals(hdr)) {
@ -2514,7 +2514,7 @@ public class StdTextProductDao extends CoreDao {
final String hdrQuery = "SELECT cccId, nnnId, xxxId, version "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? AND hdrTime = ? AND bbbId = ? AND cccId IS NOT NULL AND nnnId IS NOT NULL AND xxxId IS NOT NULL "
+ "ORDER BY cccId ASC, nnnId ASC, xxxId ASC, createTime DESC";
+ "ORDER BY cccId ASC, nnnId ASC, xxxId ASC, refTime DESC, insertTime DESC";
ps1 = c.prepareStatement(hdrQuery);
break;
}
@ -2522,7 +2522,7 @@ public class StdTextProductDao extends CoreDao {
final String hdrQuery = "SELECT version "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? AND hdrTime = ? AND bbbId = ? AND cccId = 'NOA' AND nnnId = 'FOS' AND xxxId = 'PIL' "
+ "ORDER BY createTime DESC";
+ "ORDER BY refTime DESC, insertTime DESC";
ps1 = c.prepareStatement(hdrQuery);
break;
}
@ -2530,7 +2530,7 @@ public class StdTextProductDao extends CoreDao {
final String hdrQuery = "SELECT version "
+ "FROM stdTextProducts "
+ "WHERE wmoId = ? AND site = ? AND hdrTime = ? AND bbbId = ? AND cccId = 'NOA' AND nnnId = 'FOS' AND xxxId = 'PIL' "
+ "ORDER BY createTime DESC";
+ "ORDER BY refTime DESC, insertTime DESC";
ps1 = c.prepareStatement(hdrQuery);
break;
}
@ -2560,7 +2560,7 @@ public class StdTextProductDao extends CoreDao {
String hdr = generateHeader(wmoId, site, hdrTime, bbbId, cccId,
nnnId, xxxId);
// order by ensures MAX(createTime) and MAX(version) is
// order by ensures MAX(refTime) and MAX(version) is
// loaded first
if (retVal.size() > 0) {
if (!retVal.get(retVal.size() - 1).equals(hdr)) {
@ -2769,7 +2769,7 @@ public class StdTextProductDao extends CoreDao {
public static final void main(String[] args) {
long time = System.currentTimeMillis() / 1000L;
final String TM_QUERY_FMT = "delete from table_name where createtime < %d;";
final String TM_QUERY_FMT = "delete from table_name where refTime < %d;";
Matcher m = Pattern.compile("table_name").matcher(TM_QUERY_FMT);
String tempQuery = m.replaceAll(TM_QUERY_FMT);

View file

@ -797,9 +797,11 @@ public class TextDB {
StdTextProductDao dao = new StdTextProductDao(operationalMode);
boolean success = false;
try {
if (textProduct.getCreatetime() == null) {
textProduct.setCreatetime(System.currentTimeMillis());
if (textProduct.getRefTime() == null) {
textProduct.setRefTime(System.currentTimeMillis());
}
textProduct.setInsertTime(Calendar.getInstance(TimeZone
.getTimeZone("GMT")));
success = dao.write(textProduct);
} catch (Exception e) {
logger.error(e);
@ -857,7 +859,7 @@ public class TextDB {
product.append(reportData);
Long writeTime = new Long(System.currentTimeMillis());
if(TimeTools.allowArchive()) {
if (TimeTools.allowArchive()) {
Calendar c = header.getHeaderDate();
writeTime = new Long(c.getTimeInMillis());
@ -872,7 +874,7 @@ public class TextDB {
textProduct.setNnnid(prodId.getNnn());
textProduct.setHdrtime(hdrTime);
textProduct.setBbbid(bbbIndicator);
textProduct.setCreatetime(writeTime);
textProduct.setRefTime(writeTime);
textProduct.setProduct(product.toString());
boolean success = writeProduct(textProduct);
if (success) {
@ -953,8 +955,9 @@ public class TextDB {
boolean operationalMode, Headers headers) {
// Look for a WMO heading on the first line
String[] pieces = reportData.split("\r*\n", 2);
if (pieces.length > 1)
if (pieces.length > 1) {
pieces[0] += "\n"; // WMOHeader expects this
}
WMOHeader header = new WMOHeader(pieces[0].getBytes(), headers);
// Need to construct an AFOSProductId from the productId

View file

@ -167,7 +167,7 @@ public class RadarTextProductUtil {
textProd.setCccid(afosId.getCcc());
textProd.setNnnid(afosId.getNnn());
textProd.setXxxid(afosId.getXxx());
textProd.setCreatetime(System.currentTimeMillis());
textProd.setRefTime(System.currentTimeMillis());
textProd.setProduct(text);
EDEXUtil.getMessageProducer().sendAsync(textEndpoint, textProd);
}

View file

@ -19,6 +19,7 @@
**/
package com.raytheon.uf.common.dataplugin.text.db;
import java.util.Calendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.CRC32;
@ -36,6 +37,7 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.Index;
import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject;
import com.raytheon.uf.common.serialization.ISerializableObject;
@ -92,7 +94,14 @@ public abstract class StdTextProduct extends PersistableDataObject implements
@Column(nullable = false)
@DynamicSerializeElement
@XmlAttribute
private Long createtime;
private Long refTime;
/** The timestamp denoting when this record was inserted into the database */
@Column(columnDefinition = "timestamp without time zone", nullable = false)
@Index(name = "insertTimeIndex")
@XmlAttribute
@DynamicSerializeElement
private Calendar insertTime;
/** persistent field */
@Column(nullable = false)
@ -131,7 +140,7 @@ public abstract class StdTextProduct extends PersistableDataObject implements
setProdId(new StdTextProductId(wmoid, site, cccid, nnnid, xxxid,
hdrtime));
setProduct(product);
setCreatetime(createtime);
setRefTime(createtime);
setBbbid(bbbid);
}
@ -152,7 +161,7 @@ public abstract class StdTextProduct extends PersistableDataObject implements
*/
public StdTextProduct(StdTextProduct aProductToCopy) {
this(aProductToCopy.getProdId(), aProductToCopy.getBbbid(),
aProductToCopy.getCreatetime(), aProductToCopy.getProduct());
aProductToCopy.getRefTime(), aProductToCopy.getProduct());
}
public String getBbbid() {
@ -163,12 +172,20 @@ public abstract class StdTextProduct extends PersistableDataObject implements
this.bbbid = bbbid;
}
public Long getCreatetime() {
return this.createtime;
public Long getRefTime() {
return this.refTime;
}
public void setCreatetime(Long createtime) {
this.createtime = createtime;
public void setRefTime(Long refTime) {
this.refTime = refTime;
}
public void setInsertTime(Calendar insertTime) {
this.insertTime = insertTime;
}
public Calendar getInsertTime() {
return insertTime;
}
public String getProduct() {
@ -299,8 +316,7 @@ public abstract class StdTextProduct extends PersistableDataObject implements
final int prime = 31;
int result = 1;
result = prime * result + ((bbbid == null) ? 0 : bbbid.hashCode());
result = prime * result
+ ((createtime == null) ? 0 : createtime.hashCode());
result = prime * result + ((refTime == null) ? 0 : refTime.hashCode());
result = prime * result + ((prodId == null) ? 0 : prodId.hashCode());
result = prime * result + ((product == null) ? 0 : product.hashCode());
return result;
@ -308,33 +324,44 @@ public abstract class StdTextProduct extends PersistableDataObject implements
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
StdTextProduct other = (StdTextProduct) obj;
if (bbbid == null) {
if (other.bbbid != null)
if (other.bbbid != null) {
return false;
} else if (!bbbid.equals(other.bbbid))
}
} else if (!bbbid.equals(other.bbbid)) {
return false;
if (createtime == null) {
if (other.createtime != null)
}
if (refTime == null) {
if (other.refTime != null) {
return false;
} else if (!createtime.equals(other.createtime))
}
} else if (!refTime.equals(other.refTime)) {
return false;
}
if (prodId == null) {
if (other.prodId != null)
if (other.prodId != null) {
return false;
} else if (!prodId.equals(other.prodId))
}
} else if (!prodId.equals(other.prodId)) {
return false;
}
if (product == null) {
if (other.product != null)
if (other.product != null) {
return false;
} else if (!product.equals(other.product))
}
} else if (!product.equals(other.product)) {
return false;
}
return true;
}

View file

@ -23,3 +23,4 @@ Import-Package: com.raytheon.uf.common.dataplugin,
com.raytheon.uf.edex.database.plugin,
com.raytheon.uf.edex.pointdata,
org.springframework.orm.hibernate3.support
Export-Package: com.raytheon.uf.edex.maintenance.archive

View file

@ -23,12 +23,10 @@ import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -37,8 +35,6 @@ import java.util.TimeZone;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.dataplugin.PluginException;
import com.raytheon.uf.common.dataplugin.PluginProperties;
import com.raytheon.uf.common.dataplugin.persist.DefaultPathProvider;
import com.raytheon.uf.common.dataplugin.persist.IHDFFilePathProvider;
import com.raytheon.uf.common.dataplugin.persist.IPersistable;
import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject;
import com.raytheon.uf.common.datastorage.DataStoreFactory;
@ -93,9 +89,15 @@ public class DatabaseArchiver implements IPluginArchiver {
private static final int CLUSTER_LOCK_TIMEOUT = 60000;
private final Map<String, IPluginArchiveFileNameFormatter> pluginArchiveFormatters;
public DatabaseArchiver() {
DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
pluginArchiveFormatters = new HashMap<String, IPluginArchiveFileNameFormatter>();
pluginArchiveFormatters.put("default",
new DefaultPluginArchiveFileNameFormatter());
}
@Override
@ -157,9 +159,16 @@ public class DatabaseArchiver implements IPluginArchiver {
Calendar endTime = determineEndTime(startTime, runTime);
Map<String, List<PersistableDataObject>> pdoMap = new HashMap<String, List<PersistableDataObject>>();
IPluginArchiveFileNameFormatter archiveFormatter = pluginArchiveFormatters
.get(pluginName);
if (archiveFormatter == null) {
archiveFormatter = pluginArchiveFormatters.get("default");
}
while (startTime != null && endTime != null) {
Map<String, List<PersistableDataObject>> pdosToSave = getPdosByFile(
pluginName, dao, pdoMap, startTime, endTime);
Map<String, List<PersistableDataObject>> pdosToSave = archiveFormatter
.getPdosByFile(pluginName, dao, pdoMap, startTime,
endTime);
if (pdosToSave != null && !pdosToSave.isEmpty()) {
savePdoMap(pluginName, archivePath, pdosToSave);
@ -258,98 +267,6 @@ public class DatabaseArchiver implements IPluginArchiver {
return true;
}
/**
*
* @param pdoMap
* The current pdos by file. This map will be merged with pdos,
* if a key was not referenced by pdos it will be removed and
* returned in the returned map for storage.
* @param pdos
* The pdos to sort by file
* @return The pdos to save to disk. If sortPdosByFiles did not store any
* entries from pdos into a file listed in currentPdoMap then that
* entry will be returned in a new map and removed from
* currentPdoMap.
*/
protected Map<String, List<PersistableDataObject>> getPdosByFile(
String pluginName, PluginDao dao,
Map<String, List<PersistableDataObject>> pdoMap,
Calendar startTime, Calendar endTime)
throws DataAccessLayerException {
List<PersistableDataObject> pdos = dao.getRecordsToArchive(startTime,
endTime);
Set<String> newFileEntries = new HashSet<String>();
if (pdos != null && !pdos.isEmpty()) {
if (pdos.get(0) instanceof IPersistable) {
IHDFFilePathProvider pathProvider = dao.pathProvider;
for (PersistableDataObject pdo : pdos) {
IPersistable persistable = (IPersistable) pdo;
String path = pathProvider.getHDFPath(pluginName,
persistable)
+ File.separator
+ pathProvider.getHDFFileName(pluginName,
persistable);
newFileEntries.add(path);
List<PersistableDataObject> list = pdoMap.get(path);
if (list == null) {
list = new ArrayList<PersistableDataObject>(pdos.size());
pdoMap.put(path, list);
}
list.add(pdo);
}
} else {
// order files by refTime hours
for (PersistableDataObject pdo : pdos) {
String timeString = null;
if (pdo instanceof PluginDataObject) {
PluginDataObject pluginDataObj = (PluginDataObject) pdo;
Date time = pluginDataObj.getDataTime()
.getRefTimeAsCalendar().getTime();
synchronized (DefaultPathProvider.fileNameFormat) {
timeString = DefaultPathProvider.fileNameFormat
.format(time);
}
} else {
// no refTime to use bounded insert query bounds
Date time = startTime.getTime();
synchronized (DefaultPathProvider.fileNameFormat) {
timeString = DefaultPathProvider.fileNameFormat
.format(time);
}
}
String path = pluginName + timeString;
newFileEntries.add(path);
List<PersistableDataObject> list = pdoMap.get(path);
if (list == null) {
list = new ArrayList<PersistableDataObject>(pdos.size());
pdoMap.put(path, list);
}
list.add(pdo);
}
}
}
Iterator<String> iter = pdoMap.keySet().iterator();
Map<String, List<PersistableDataObject>> pdosToSave = new HashMap<String, List<PersistableDataObject>>(
pdoMap.size() - newFileEntries.size());
while (iter.hasNext()) {
String key = iter.next();
if (!newFileEntries.contains(key)) {
pdosToSave.put(key, pdoMap.get(key));
iter.remove();
}
}
return pdosToSave;
}
protected void savePdoMap(String pluginName, String archivePath,
Map<String, List<PersistableDataObject>> pdoMap)
throws SerializationException, IOException {
@ -422,8 +339,7 @@ public class DatabaseArchiver implements IPluginArchiver {
// startTime has never been set lookup earliest start time
Date minInsert = dao.getMinInsertTime("");
if (minInsert != null) {
startTime = Calendar.getInstance();
startTime.setTimeZone(TimeZone.getTimeZone("GMT"));
startTime = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
startTime.setTimeInMillis(minInsert.getTime());
} else {
// if no data for plugin in db, set startTime to runTime
@ -432,13 +348,13 @@ public class DatabaseArchiver implements IPluginArchiver {
}
// earliest time based on default retention
long earliestTime = System.currentTimeMillis()
- (conf.getHoursToKeep() * 60 * 60 * 1000);
if (startTime.getTimeInMillis() < earliestTime) {
startTime.setTimeInMillis(earliestTime);
}
Calendar earliestTime = Calendar.getInstance(TimeZone
.getTimeZone("GMT"));
earliestTime
.add(Calendar.HOUR, (-1 * conf.getHoursToKeep().intValue()));
return startTime;
return (startTime.compareTo(earliestTime) < 0) ? earliestTime
: startTime;
}
/**
@ -467,4 +383,17 @@ public class DatabaseArchiver implements IPluginArchiver {
return endTime;
}
public Object registerPluginArchiveFormatter(String pluginName,
IPluginArchiveFileNameFormatter archiveFormatter) {
if (!pluginArchiveFormatters.containsKey(pluginName)) {
pluginArchiveFormatters.put(pluginName, archiveFormatter);
} else {
statusHandler
.warn("Plugin archive formatter already registered for: "
+ pluginName);
}
return this;
}
}

View file

@ -0,0 +1,150 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.edex.maintenance.archive;
import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.raytheon.uf.common.dataplugin.PluginDataObject;
import com.raytheon.uf.common.dataplugin.persist.DefaultPathProvider;
import com.raytheon.uf.common.dataplugin.persist.IHDFFilePathProvider;
import com.raytheon.uf.common.dataplugin.persist.IPersistable;
import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject;
import com.raytheon.uf.edex.database.DataAccessLayerException;
import com.raytheon.uf.edex.database.plugin.PluginDao;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 20, 2012 dgilling Initial creation
*
* </pre>
*
* @author dgilling
* @version 1.0
*/
public class DefaultPluginArchiveFileNameFormatter implements
IPluginArchiveFileNameFormatter {
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.edex.maintenance.archive.IPluginArchiveFileNameFormatter
* #getPdosByFile(java.lang.String,
* com.raytheon.uf.edex.database.plugin.PluginDao, java.util.Map,
* java.util.Calendar, java.util.Calendar)
*/
@Override
public Map<String, List<PersistableDataObject>> getPdosByFile(
String pluginName, PluginDao dao,
Map<String, List<PersistableDataObject>> pdoMap,
Calendar startTime, Calendar endTime)
throws DataAccessLayerException {
List<PersistableDataObject> pdos = dao.getRecordsToArchive(startTime,
endTime);
Set<String> newFileEntries = new HashSet<String>();
if (pdos != null && !pdos.isEmpty()) {
if (pdos.get(0) instanceof IPersistable) {
IHDFFilePathProvider pathProvider = dao.pathProvider;
for (PersistableDataObject pdo : pdos) {
IPersistable persistable = (IPersistable) pdo;
String path = pathProvider.getHDFPath(pluginName,
persistable)
+ File.separator
+ pathProvider.getHDFFileName(pluginName,
persistable);
newFileEntries.add(path);
List<PersistableDataObject> list = pdoMap.get(path);
if (list == null) {
list = new ArrayList<PersistableDataObject>(pdos.size());
pdoMap.put(path, list);
}
list.add(pdo);
}
} else {
// order files by refTime hours
for (PersistableDataObject pdo : pdos) {
String timeString = null;
if (pdo instanceof PluginDataObject) {
PluginDataObject pluginDataObj = (PluginDataObject) pdo;
Date time = pluginDataObj.getDataTime()
.getRefTimeAsCalendar().getTime();
synchronized (DefaultPathProvider.fileNameFormat) {
timeString = DefaultPathProvider.fileNameFormat
.format(time);
}
} else {
// no refTime to use bounded insert query bounds
Date time = startTime.getTime();
synchronized (DefaultPathProvider.fileNameFormat) {
timeString = DefaultPathProvider.fileNameFormat
.format(time);
}
}
String path = pluginName + timeString;
newFileEntries.add(path);
List<PersistableDataObject> list = pdoMap.get(path);
if (list == null) {
list = new ArrayList<PersistableDataObject>(pdos.size());
pdoMap.put(path, list);
}
list.add(pdo);
}
}
}
Iterator<String> iter = pdoMap.keySet().iterator();
Map<String, List<PersistableDataObject>> pdosToSave = new HashMap<String, List<PersistableDataObject>>(
pdoMap.size() - newFileEntries.size());
while (iter.hasNext()) {
String key = iter.next();
if (!newFileEntries.contains(key)) {
pdosToSave.put(key, pdoMap.get(key));
iter.remove();
}
}
return pdosToSave;
}
}

View file

@ -0,0 +1,72 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.edex.maintenance.archive;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject;
import com.raytheon.uf.edex.database.DataAccessLayerException;
import com.raytheon.uf.edex.database.plugin.PluginDao;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 20, 2012 dgilling Initial creation
*
* </pre>
*
* @author dgilling
* @version 1.0
*/
public interface IPluginArchiveFileNameFormatter {
/**
*
* @param pluginName
* @param dao
* @param pdoMap
* The current pdos by file. This map will be merged with pdos,
* if a key was not referenced by pdos it will be removed and
* returned in the returned map for storage.
* @param startTime
* @param endTime
* @return The pdos to save to disk. If sortPdosByFiles did not store any
* entries from pdos into a file listed in currentPdoMap then that
* entry will be returned in a new map and removed from
* currentPdoMap.
* @throws DataAccessLayerException
* If the DAO is unable to retrieve the records from the
* database.
*/
public abstract Map<String, List<PersistableDataObject>> getPdosByFile(
String pluginName, PluginDao dao,
Map<String, List<PersistableDataObject>> pdoMap,
Calendar startTime, Calendar endTime)
throws DataAccessLayerException;
}