📄 solutiontn.java
字号:
String sql = sqlJoin + " and (event.evid = " + id +
") and (selectflag = 1) and (bogusflag = 0) ";
Solution sol[] = SolutionTN.getBySQL(conn, sql);
if (sol == null) return null;
return sol[0];
}
/**
* Returns the Solution with this ID number from the data source.
* Uses default DataSource.
* Returns null if no event is found.
* For the NCDC v1.5 schema ID is the 'evid' not the 'orid'.
*/
public static SolutionTN getByOrid(long orid){
return getByOrid(getConnection(), orid);
}
/**
* Returns the Solution with this ID number from the data source.
* Returns null if no event is found.
* For the NCDC v1.5 schema ID is the 'evid' not the 'orid'.
*/
public static SolutionTN getByOrid(Connection conn, long orid) {
// must do a join of Event/Origin/NetMag to get all the info we need
String sql = sqlJoin + " and (event.prefor = " + orid +")" ;
SolutionTN sol[] = SolutionTN.getBySQL(conn, sql);
if (sol == null) return null;
return sol[0];
}
/**
* Returns array of Solutions within this time window.
* Returns null if no event is found.
*/
public Solution[] getByTime(double start, double stop) {
return getByTime (getConnection(), start, stop);
}
/**
* Returns array of Solutions within this time window.
* Returns null if no event is found.
*/
public Solution[] getByTime(Connection conn, double start, double stop) {
// must do a join of Event/Origin/NetMag to get all the info we need
// String sql = sqlJoin + "and Origin.DATETIME BETWEEN " +
// StringSQL.valueOf(start) + " AND " + StringSQL.valueOf(stop) +
String sql = sqlJoin + getTimeSpanSQL(start, stop) +
" order by Origin.Datetime";
return getBySQL(conn, sql);
}
/**
* Returns array of"valid" Solutions within this time window.
* Some data sets contain solutions that have duplicates, interim, or bogus entries.
* This method filters those out and returns only VALID solutions.
*/
public Solution[] getValidByTime (double start, double stop) {
return getValidByTime (getConnection(), start, stop);
}
/**
* Returns array of"valid" Solutions within this time window.
* Some data sets contain solutions that have duplicates, interim, or bogus entries.
* This method filters those out and returns only VALID solutions.
*/
public Solution[] getValidByTime (Connection conn, double start, double stop) {
String sql = sqlJoin + " and "+getTimeSpanSQL(start, stop) +
//" and (Origin.DATETIME BETWEEN " +
// StringSQL.valueOf(start) + " AND " + StringSQL.valueOf(stop) + ") "+
" and (selectflag = 1) "+
" and (bogusflag = 0)" +
" order by Origin.Datetime";
//NOTE: bogusflag is wrongly set true for all data as of 10/13/99
return getBySQL(conn, sql);
}
/** Return the part of an sql query that specifies a time window.
* Note that "BETWEEN" is much faster that ">" */
static String getTimeSpanSQL (double start, double stop) {
return " Origin.DATETIME BETWEEN " +
StringSQL.valueOf(start) + " AND " + StringSQL.valueOf(stop);
}
/**
* Return array of solutions that match the properties defined in the
* EventSelectionProperties object */
public Solution[] getByProperties (EventSelectionProperties props) {
return getByProperties (getConnection(), props);
}
/**
* Return array of solutions that match the properties defined in the
* EventSelectionProperties object */
// TODO: this only uses time and valid and dummy flags !!!
public Solution[] getByProperties (Connection conn,
EventSelectionProperties props) {
String str;
// Get time from properties. This will handle both "absolute" and "relative"
// time definitions
TimeSpan span = props.getTimeSpan();
double start = span.getStart();
double stop = span.getEnd();
// double start = props.getDateTime("startTime").getEpochSeconds() ;
// double stop = props.getDateTime("endTime").getEpochSeconds() ;
// time bounds
String where = getTimeSpanSQL(start, stop);
// validFlag
str = props.getProperty("validFlag");
if (str != null) {
if (str.equalsIgnoreCase("TRUE")) {
where += " and (Event.selectFlag = 1) ";
} else {
where += " and (Event.selectFlag = 0) ";
}
}
// dummyFlag
str = props.getProperty("dummyFlag");
if (str != null) {
if (props.getProperty("dummyFlag").equalsIgnoreCase("TRUE")) {
where += " and (Origin.bogusFlag = 1) ";
} else {
where += " and (Origin.bogusFlag = 0) ";
}
}
// Event types (e.g. "local", "sonic", etc.) - these must be OR'ed
// These properties have the form: SelectAttribute_trigger = FALSE
// There may not be a property for each type, thus the check for != null.
String typeChoice[] = EventTypeMap.getEventTypeArray();
EventTypeMap typeMap = EventTypeMap.create();
String subStr = "";
// explicite includes, logic is OR = (property = TRUE)
for (int i = 0; i< typeChoice.length; i++) {
str = props.getProperty(EventSelectionProperties.prefix+typeChoice[i]);
if (str != null && str.equalsIgnoreCase("TRUE")) {
if (!subStr.equals("")) subStr += " or "; // need this if more then one
subStr += " Event.ETYPE = '"+typeMap.toLocalCode(typeChoice[i])+"' ";
}
}
if (!subStr.equals("")) where += " and (" + subStr + ") ";
// explicite excludes, logic is AND != (property = FALSE)
subStr = "";
for (int i = 0; i< typeChoice.length; i++) {
str = props.getProperty(EventSelectionProperties.prefix+typeChoice[i]);
if (str != null && str.equalsIgnoreCase("FALSE")) {
if (!subStr.equals("")) subStr += " and "; // need this if more then one
subStr += " Event.ETYPE != '"+typeMap.toLocalCode(typeChoice[i])+"' ";
}
}
if (!subStr.equals("")) where += " and (" + subStr + ") ";
// processing states - these must be OR'ed
subStr = "";
// get list of possible processing states (e.g. "A", "H", etc.)
String label[] = ProcessingState.getLabelArray();
String tag[] = ProcessingState.getTagArray();
for (int i = 0; i< label.length; i++)
{
// if property exists set initial state of check box
str = props.getProperty(EventSelectionProperties.prefix+label[i]);
if (str != null && str.equals("TRUE")) {
if (!subStr.equals("")) subStr += " or "; // need this if more then one
subStr += " Origin.rflag = '"+tag[i]+"' ";
}
}
if (!subStr.equals("")) where += " and (" + subStr + ")";
// sort by time
where += " order by Origin.Datetime";
return (Solution[]) SolutionTN.getWhere(where);
}
/** Get using this SQL WHERE clause */
public static SolutionTN[] getWhere (String whereClause) {
String sql = sqlJoin+ " and " + whereClause;
// debug
// System.out.println (sql);
return getBySQL(sql);
}
/** Get the comment from the dbase if 'includeComment' flag is set and
* the Event has one. */
static protected void dbFetchComment(SolutionTN sol) {
if (sol.includeComment && !sol.commid.isNull()) {
Remark rmk = new Remark(getConnection());
Remark rmks[] = rmk.getRowsByCommId(sol.commid.longValue());
String newStr = "";
for (int i = 0; i < rmks.length; i++) {
newStr += rmks[i].toStringRemark();
}
sol.comment.setValue(newStr); // this sets isUpdate(true)
sol.comment.setUpdate(false); // it shouldn't be if its from the dbase
}
}
/** Get the comment from the dbase if 'includeComment' flag is set and
* the Event has one. */
static protected void dbFetchComments(SolutionTN[] sol) {
for (int i = 0; i < sol.length; i++) {
dbFetchComment(sol[i]);
}
}
/**
* Parse a resultset row that contains a concatinated Event/Origin/NetMag
*/
protected static SolutionTN parseResultSet (ResultSetDb rsdb) {
SolutionTN sol = new SolutionTN();
// note: these are local instances
Event eventRow = new Event();
Origin originRow = new Origin();
NetMag netMagRow = new NetMag();
int offset = 0;
// note we are using the class instances of event/orgin/netmag
// System.out.println ("parsing event...");
// copy data from resultset to DataTableRow object
eventRow = (Event) eventRow.parseOneRow(rsdb, offset);
eventRow.setProcessing(Event.NONE);
// allow future changes to this DataTableRow
eventRow.setMutable(true);
offset += Event.MAX_FIELDS;
// System.out.println ("parsing origin...");
originRow = (Origin) originRow.parseOneRow(rsdb, offset);
originRow.setProcessing(Origin.NONE);
offset += Origin.MAX_FIELDS;
// don't keep a copy of NetMag in Solution, there will be one in Magnitude
// System.out.println ("parsing mag...");
netMagRow = (NetMag) netMagRow.parseOneRow(rsdb, offset);
netMagRow.setProcessing(NetMag.NONE);
sol.fromDbase = true;
sol.parseEventRow(eventRow);
sol.parseOriginRow(originRow);
// allow changes to this DataTableRow. Need to set this because we are
// not using our own rather than org.trinet.jdbc parsing methods
if (DataSource.isWriteBackEnabled()) {
eventRow.setMutable(true);
originRow.setMutable(true);
netMagRow.setMutable(true);
// allow modification of the EVENT table
eventRow.setSelectForUpdate(true);
}
// a new magnitude object
sol.magnitude = Magnitude.create();
((MagnitudeTN)sol.magnitude).parseNetMagRow(netMagRow);
sol.magnitude.associate(sol);
// remember DataTableRows for later writeback
sol.eventRow = eventRow;
sol.originRow = originRow;
// calculate the priority
SolutionTN.calcPriority(sol);
return sol;
}
/** Calculate the priority of this solution. */
static void calcPriority(Solution sol) {
//sol.priority.setValue(EventPriorityModelTN.getPriority(conn, sol));
sol.priority.setValue(EventPriorityModelTN.getPriority(sol));
}
/**
* Suck contents out of an Event TableRow to populate this Solution.
*/
// Note that this copies DataObjects not references.
protected SolutionTN parseEventRow(Event evt) {
this.id = (DataLong) evt.getDataObject(Event.EVID);
id.setUpdate(false); // DataTableRow weirdness: sets key field isUpdate = true
// parent id is not currently stored in the dbase
setParentId(id.longValue());
parentId.setUpdate(false);
// foreign keys (PROTECTED)
this.prefor = (DataLong) evt.getDataObject(Event.PREFOR);
/*
The fields prefmag, prefmec & commid exist in BOTH the Event and
Origin tables Which to use?? Made decision to use those in Origin. */
// this.prefmag = (DataLong) evt.getDataObject(Event.PREFMAG);
// this.prefmec = (DataLong) evt.getDataObject(Event.PREFMEC);
// this.commid = (DataLong) evt.getDataObject(Event.COMMID);
// This gets a NATIVE event type, must translate to generic (jasi) type
String estr = ((DataString) evt.getDataObject(Event.ETYPE)).toString();
this.setEventType(EventTypeMap.toJasiCode(estr));
this.eventType.setUpdate(false); // don't mark as changed by program
// Event auth and source are distinct from Origin's
this.eventAuthority = (DataString) evt.getDataObject(Event.AUTH);
this.eventSource = (DataString) evt.getDataObject(Event.SUBSOURCE);
this.validFlag = (DataLong) evt.getDataObject(Event.SELECTFLAG);
return this;
}
/**
* Put contents of this Solution back into the original Event TableRow object.
* If there was none, make one.
* This is the reverse of parseEvent().
*/
// Note that this copies DataObjects not references.
protected void toEventRow () {
// new evid could have been assigned already
if (id.isNull()) id.setValue(setUniqueId()); // set if not assigned
// create an Event object if there wasn't one we read from originally
if (eventRow == null) {
eventRow = new Event(id.longValue());
eventRow.setValue(Event.AUTH, getEventAuthority());
eventRow.setValue(Event.SUBSOURCE, getEventSource());
}
// allow updating the row
eventRow.setUpdate(true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -