📄 channeltn.java
字号:
}
/**
* Appends this SQL where clause to the statement
* "Select * from Channel_Data ". Example: "where net = 'CI'"
*/
ChannelList readListWhere(String whereClause) {
return (ChannelList) getWhere(DataSource.getConnection(), whereClause);
}
/**
* Get an array of this object given an SQL query.
*/
ChannelList getBySQL(String sql)
{
return getBySQL(DataSource.getConnection(), sql);
}
/**
* Get an array of this object given an SQL query.
*/
ChannelList getBySQL(Connection conn, String sql)
{
//ArrayList chanList = new ArrayList();
ChannelList chanList = new ChannelList();
// Debug
if (debug) System.out.println ("SQL: "+sql);
try {
if ( conn.isClosed() ) // check that valid connection exists
{
System.err.println ("* Connection is closed");
return null;
}
Statement sm = conn.createStatement();
ResultSet rs = org.trinet.jdbc.table.ExecuteSQL.rowQuery(sm, sql);
if (rs == null) return null; // nothing found
// parse and add rows one-at-a-time
while ( rs.next() ) {
chanList.add(parseResultSet(rs));
}
sm.close();
}
catch (SQLException ex) {
System.err.println(ex);
ex.printStackTrace();
}
// convert vector to array
// if (wfList.size() == 0) return null;
return chanList;
}
/**
* Parse a resultset row that contains the results of a join + some
* stored procedures
*/
static ChannelData cdInst = new ChannelData();
Channel parseResultSet (ResultSet rs){
int offset = 0;
// parse the first part of the return that is just a Waveform table row
ResultSetDb rsdb = new ResultSetDb(rs);
Channel ch =
parseChannelRow((ChannelData) cdInst.parseOneRow(rsdb, offset));
// Now, pick up the "extra" columns specified by the SQL query.
// See SelectJoinString for a list of fields
offset += cdInst.MAX_FIELDS;
try {
// must get as objects because they might be null
// If I used getDouble an null field returns 0.0!
ch.gain.setValue (rs.getObject(++offset));
ch.mlCorr.setValue(rs.getObject(++offset));
/* Check state of correction
* F = frozen mature(?)
* C = still being updated
* D = "default" seem all to be 0.0
* If the corr is unknown it is still set to 0.0 in the dbase but the
* corr_flag = "D" for default :. must check for that flag.
*/
DataString corrFlag = new DataString();
corrFlag.setValue(rs.getObject(++offset));
if (corrFlag.isNull() ||
corrFlag.toString().equalsIgnoreCase("D") ) ch.mlCorr.setNull(true);
// can't figure out a querry to get ML and Me at the same time
// ch.meCorr.setValue (rs.getObject(++offset));
}
catch (SQLException ex) {
System.err.println(ex);
ex.printStackTrace();
}
return ch;
}
/** Return the SQL join string for current channel data. */
public String getSelectJoinString () {
return getSelectJoinString("Sysdate");
}
/** Return the SQL join string for channel data at the time described by
* this java.sql.Date . */
public String getSelectJoinString (java.sql.Date date) {
return getSelectJoinString(StringSQL.valueOf(date));
}
/** Return the SQL join string for channel data at the time described by
* this SQL formatted date string. Only ML correction is read, not Me, etc.*/
/* NOTES:
o Join: note that we must do an "outer" join by using (+). Otherwise, an
channel that lacks RT_param info will NOT be seen. (see: Oracel8
Bible, McCullough-Dieter, pg. 217)
o Must qualify ALL tables with on/off dates else the outerjoin will create
a resultset row for every response or correction entry. */
public String getSelectJoinString (String dateStr) {
return "Select "+
org.trinet.jdbc.table.ChannelData.QUALIFIED_COLUMN_NAMES+","+
" SIMPLERESP.gain, staCorrections.corr, staCorrections.corr_flag "+
" from channel_data, staCorrections, SIMPLERESP "+
" Where exists( select * from Channel_Data where "+
" (Channel_Data.OFFDATE >= "+dateStr+" and Channel_Data.ONDATE <= "+dateStr+")) and "+
" ( Channel_Data.net = staCorrections.net(+) and "+
" Channel_Data.sta = staCorrections.sta(+) and "+
" Channel_Data.seedchan = staCorrections.seedchan(+) and "+
" (staCorrections.corr_type(+) = 'ml' and "+ // ml correction
" staCorrections.OFFDATE(+) >= "+dateStr+" and staCorrections.ONDATE(+) <= "+dateStr+") ) and "+
" (Channel_Data.net = SIMPLERESP.net(+) and "+
" Channel_Data.sta = SIMPLERESP.sta(+) and "+
" Channel_Data.seedchan = SIMPLERESP.seedchan(+) and "+
" SIMPLERESP.OFFDATE(+) >= "+dateStr+" and SIMPLERESP.ONDATE(+) <= "+dateStr+") " ;
}
/**
* Return Collection of ALL Channels in the DataSource that satisfy the where clause.
* Uses the given Connection.
*/
ChannelList getWhere (String whereClause)
{
return getWhere (DataSource.getConnection(), whereClause);
}
/**
* Return Collection of ALL Channels in the DataSource that satisfy the where clause.
* Uses the given Connection.
*/
ChannelList getWhere (Connection conn, String whereClause)
{
String sql = getSelectJoinString();
if (whereClause.trim().length() > 0) {
sql += " and " + whereClause;
}
return getBySQL (conn, sql);
}
/**
* Get a ChannelName description from a Channel_Data DataTableRow object.
* Use a DataTableRow because we an use this to parse ANY row type with a
* channel in it.
*/
// Must use Column names and not indexes here because every DataTableRow type
// has different indexes.
static Channel parseChannelRow (ChannelData cdr) {
Channel ch = Channel.create();
ch.setChannelObj(ChannelTN.parseNameFromDataTableRow((DataTableRow)cdr));
DataDouble lat = (DataDouble) cdr.getDataObject(cdr.LAT);
DataDouble lon = (DataDouble) cdr.getDataObject(cdr.LON);
DataDouble z = (DataDouble) cdr.getDataObject(cdr.ELEV); //km
DataDouble sampleRate = (DataDouble) cdr.getDataObject(cdr.SAMPRATE);
if (sampleRate != null) ch.setSampleRate(sampleRate.doubleValue());
if (lat != null && lon != null) {
ch.latlonz.setLat(lat.doubleValue());
ch.latlonz.setLon(lon.doubleValue());
}
if (z != null) {
// convert elevation to km, which is what LatLonZ uses.
double km = z.doubleValue()/1000.0;
ch.latlonz.setZ(km);
// This is the default but be explicite
ch.latlonz.setZUnits(GeoidalUnits.KILOMETERS);
}
return ch;
}
/**
* Get a Channelname description from a DataTableRow object.
* Use a DataTableRow because we an use this to parse ANY row type with a
* channel in it.
*/
// Must use Column names and not indexes here because every DataTableRow type
// has different indexes.
public static Channel parseNameFromDataTableRow (DataTableRow dtr) {
Channel chan = Channel.create();
try {
chan.setNet(dtr.getStringValue("NET"));
chan.setSta(dtr.getStringValue("STA"));
chan.setChannel(dtr.getStringValue("CHANNEL"));
// the Channel_Data table does NOT have these two columns
// channelId.setAuth(dtr.getStringValue("AUTH"));
// channelId.setSubsource(dtr.getStringValue("SUBSOURCE"));
chan.setChannelsrc(dtr.getStringValue("CHANNELSRC"));
chan.setSeedchan(dtr.getStringValue("SEEDCHAN"));
chan.setLocation(dtr.getStringValue("LOCATION"));
} catch (NoSuchFieldException ex)
{
System.err.println(ex);
ex.printStackTrace();
}
return chan;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -