📄 codatn.java
字号:
setRowChannelId(codaRow, getChannelObj());
codaRow.setValue(org.trinet.jdbc.table.Coda.DATETIME, datetime);
codaRow.setValue(org.trinet.jdbc.table.Coda.AUTH, getAuthority());
codaRow.setValue(org.trinet.jdbc.table.Coda.CODATYPE, descriptor.getCodaType());
codaRow.setValue(org.trinet.jdbc.table.Coda.DURTYPE, descriptor.getDurationType());
String desc = descriptor.getDescription();
if (! NullValueDb.isBlank(desc)) codaRow.setValue(org.trinet.jdbc.table.Coda.IPHASE, desc);
if (! source.isNull()) codaRow.setValue(org.trinet.jdbc.table.Coda.SUBSOURCE, source);
if (! tau.isNull()) codaRow.setValue(org.trinet.jdbc.table.Coda.TAU, tau);
if (! aFix.isNull()) codaRow.setValue(org.trinet.jdbc.table.Coda.AFIX, aFix);
if (! aFree.isNull()) codaRow.setValue(org.trinet.jdbc.table.Coda.AFREE, aFree);
if (! qFix.isNull()) codaRow.setValue(org.trinet.jdbc.table.Coda.QFIX, qFix);
if (! qFree.isNull()) codaRow.setValue(org.trinet.jdbc.table.Coda.QFREE, qFree);
if (! algorithm.isNull()) codaRow.setValue(org.trinet.jdbc.table.Coda.ALGORITHM, algorithm);
if (! uncertainty.isNull()) codaRow.setValue(org.trinet.jdbc.table.Coda.ERAMP, uncertainty);
if (! ampUnits.isNull()) codaRow.setValue(org.trinet.jdbc.table.Coda.UNITS, ampUnits);
if (! windowSize.isNull()) codaRow.setValue(org.trinet.jdbc.table.Coda.WINSIZE, windowSize);
if (! windowCount.isNull()) codaRow.setValue(org.trinet.jdbc.table.Coda.NSAMPLE, windowCount);
if (! weightIn.isNull()) codaRow.setValue(org.trinet.jdbc.table.Coda.QUALITY, weightIn);
if (! residual.isNull()) codaRow.setValue(org.trinet.jdbc.table.Coda.RMS, residual);
if (! processingState.isNull()) codaRow.setValue(org.trinet.jdbc.table.Coda.RFLAG, processingState);
timeAmpsToCodaRow(codaRow);
if (debug) {
System.out.println ("CodaTN.toCodaRow output row: "+codaRow.toString());
}
return codaRow;
}
protected void timeAmpsToCodaRow(org.trinet.jdbc.table.Coda codaRow) {
if (windowTimeAmpPairs == null) return;
int size = windowTimeAmpPairs.size();
if (size == 0) return;
int idx = 0;
TimeAmp ta = (TimeAmp) windowTimeAmpPairs.get(idx);
double value = ta.getTime();
if (value > 0.d) codaRow.setValue(org.trinet.jdbc.table.Coda.TIME1, value);
else return;
value = ta.getAmp();
if (value > 0.d) codaRow.setValue(org.trinet.jdbc.table.Coda.AMP1, value);
idx++;
if (idx == size) return;
ta = (TimeAmp) windowTimeAmpPairs.get(idx);
value = ta.getTime();
if (value > 0.d) codaRow.setValue(org.trinet.jdbc.table.Coda.TIME2, value);
else return;
value = ta.getAmp();
if (value > 0.d) codaRow.setValue(org.trinet.jdbc.table.Coda.AMP2, value);
idx++;
if (idx == size) return;
ta = (TimeAmp) windowTimeAmpPairs.get(idx);
value = ta.getTime();
if (value > 0.d) codaRow.setValue(org.trinet.jdbc.table.Coda.TIME3, value);
else return;
value = ta.getAmp();
if (value > 0.d) codaRow.setValue(org.trinet.jdbc.table.Coda.AMP3, value);
idx++;
if (idx == size) return;
ta = (TimeAmp) windowTimeAmpPairs.get(idx);
value = ta.getTime();
if (value > 0.d) codaRow.setValue(org.trinet.jdbc.table.Coda.TIME4, value);
else return;
value = ta.getAmp();
if (value > 0.d) codaRow.setValue(org.trinet.jdbc.table.Coda.AMP4, value);
idx++;
if (idx == size) return;
ta = (TimeAmp) windowTimeAmpPairs.get(idx);
value = ta.getTime();
if (value > 0.d) codaRow.setValue(org.trinet.jdbc.table.Coda.TIME5, value);
else return;
value = ta.getAmp();
if (value > 0.d) codaRow.setValue(org.trinet.jdbc.table.Coda.AMP5, value);
idx++;
if (idx == size) return;
ta = (TimeAmp) windowTimeAmpPairs.get(idx);
value = ta.getTime();
if (value > 0.d) codaRow.setValue(org.trinet.jdbc.table.Coda.TIME6, value);
else return;
value = ta.getAmp();
if (value > 0.d) codaRow.setValue(org.trinet.jdbc.table.Coda.AMP6, value);
}
/** Returns String code for the authority of this observation */
// Move up to or override in JasiReading
protected String getAuthority() {
if (! authority.isNull()) return authority.toString();
else if (getChannelObj() != null) {
String authStr = getChannelObj().getChannelId().getAuth();
if (NullValueDb.isBlank(authStr)) return EnvironmentInfo.getNetworkCode();
else return authStr;
}
return EnvironmentInfo.getNetworkCode();
}
/** Put the channel name attributes in the Coda DataTableRow */
protected void setRowChannelId(org.trinet.jdbc.table.Coda row, Channel channel) {
ChannelName cn = channel.getChannelName();
row.setValue(org.trinet.jdbc.table.Coda.STA, cn.getSta()); // this attribute can't be null
String testStr = cn.getNet();
if (! NullValueDb.isBlank(testStr)) row.setValue(org.trinet.jdbc.table.Coda.NET, testStr);
testStr = cn.getAuth();
if (! NullValueDb.isBlank(testStr)) row.setValue(org.trinet.jdbc.table.Coda.AUTH, testStr);
testStr = cn.getSubsource();
if (! NullValueDb.isBlank(testStr)) row.setValue(org.trinet.jdbc.table.Coda.SUBSOURCE, testStr);
testStr = cn.getChannel();
if (! NullValueDb.isBlank(testStr)) row.setValue(org.trinet.jdbc.table.Coda.CHANNEL, testStr);
testStr = cn.getChannelsrc();
if (! NullValueDb.isBlank(testStr)) row.setValue(org.trinet.jdbc.table.Coda.CHANNELSRC, testStr);
testStr = cn.getSeedchan();
if (! NullValueDb.isBlank(testStr)) row.setValue(org.trinet.jdbc.table.Coda.SEEDCHAN, testStr);
testStr = cn.getLocation();
if (! NullValueDb.isBlank(testStr)) row.setValue(org.trinet.jdbc.table.Coda.LOCATION, testStr);
}
/**
* Copy DataObjects out of a jdbc.table.AssocCoO object into a Coda.
*/
protected void parseAssocCoO(AssocCoO assoc) {
this.orid = (DataLong) assoc.getDataObject(AssocCoO.ORID);
this.getChannelObj().dist = (DataDouble) assoc.getDataObject(AssocCoO.DELTA);
this.getChannelObj().azimuth = (DataDouble) assoc.getDataObject(AssocCoO.SEAZ);
}
/** Copy DataObjects out of a jdbc.table.AssocCoM object into a Coda. */
protected void parseAssocCoM(AssocCoM assoc) {
channelMag.value = (DataDouble) assoc.getDataObject(AssocCoM.MAG);
channelMag.residual = (DataDouble) assoc.getDataObject(AssocCoM.MAGRES);
//?channelMag.quality = (DataDouble) assoc.getDataObject(AssocCoM.IMPORTANCE);
channelMag.correction = (DataDouble) assoc.getDataObject(AssocCoM.MAGCORR);
channelMag.weight = (DataDouble) assoc.getDataObject(AssocCoM.WEIGHT);
this.weightIn = (DataDouble) assoc.getDataObject(AssocCoM.IN_WGT);
}
/** Copy DataObjects out of a jdbc.AssocCoM object into a Coda. */
protected org.trinet.jdbc.table.AssocCoM toAssocCoMRow() {
if ( ! isAssociatedWithMag() || magnitude.magid.isNull() || coid.isNull()) return null; // no magid or no coid!
AssocCoM assocRow = new AssocCoM();
assocRow.setValue(AssocCoM.MAGID, magnitude.magid); // Constrained "NOT NULL" in schema, keys are magid, coid
assocRow.setValue(AssocCoM.COID, coid);
assocRow.setValue(AssocCoM.AUTH, getAuthority());
// Can be NULL
if (! source.isNull()) assocRow.setValue(AssocCoM.SUBSOURCE, source);
if (! weightIn.isNull()) assocRow.setValue(AssocCoM.IN_WGT, weightIn);
if (! channelMag.value.isNull()) assocRow.setValue(AssocCoM.MAG, channelMag.value);
if (! channelMag.residual.isNull()) assocRow.setValue(AssocCoM.MAGRES, channelMag.residual);
if (! channelMag.weight.isNull()) assocRow.setValue(AssocCoM.WEIGHT, channelMag.weight);
if (! channelMag.correction.isNull()) assocRow.setValue(AssocCoM.MAGCORR, channelMag.correction);
if (! processingState.isNull()) assocRow.setValue(AssocCoM.RFLAG, processingState);
//? if (! channelMag.quality.isNull()) assocRow.setValue(AssocCoM.IMPORTANCE, channelMag.quality);
if (debug) {
System.out.println ("assocRow: "+assocRow.toString());
}
assocRow.setUpdate(true); // set flag to enable processing
return assocRow;
}
/**
* Copy DataObjects out of a jdbc.AssocCoO object into a Coda.
*/
protected AssocCoO toAssocCoORow() {
if (! isAssociated() ) return null;
long assocOrid = ((SolutionTN)sol).getOrid();
if (assocOrid == 0 || coid.isNull()) return null; // no orid or no coid!
this.orid.setValue(assocOrid);
AssocCoO assocRow = new AssocCoO();
// Constrained "NOT NULL" in schema
assocRow.setValue(AssocCoO.COID, coid);
assocRow.setValue(AssocCoO.ORID, assocOrid);
assocRow.setValue(AssocCoO.AUTH, getAuthority());
// Can be NULL
if (! source.isNull()) assocRow.setValue(AssocCoO.SUBSOURCE, source);
if (! getChannelObj().dist.isNull()) assocRow.setValue(AssocCoO.DELTA, getDistance());
if (! getChannelObj().azimuth.isNull()) assocRow.setValue(AssocCoO.SEAZ, getChannelObj().azimuth);
if (! processingState.isNull()) assocRow.setValue(AssocCoO.RFLAG, processingState);
if (debug) {
System.out.println ("assocRow: "+assocRow.toString());
}
assocRow.setUpdate(true); // set flag to enable processing
return assocRow;
}
public static void doWriteBackTest (Solution sol, org.trinet.jasi.Coda coda) {
System.out.println ("ExecuteSQL.isSelectForUpdate = "+
ExecuteSQL.isSelectForUpdate());
boolean status = true;
long evid = 9691944;
Solution solx = Solution.create().getById(evid);
System.out.println ("\n----- New associate test ----- old id = "+
sol.id.toString()+" new evid= "+evid);
coda.associate(solx);
status = coda.commit();
if (status) {
long coid = ((CodaTN) coda).getCoid();
System.out.println ("<><><><> commit (insert) status = "+status+
"(coid = "+coid+" )");
// readback check
System.out.println ("Readback from dbase...");
coda = (org.trinet.jasi.Coda) getByCoid(coid);
System.out.println (coda.toString());
} else {
System.out.println ("<><><><> commit FAILED (insert) status = "+status);
}
System.out.println ("\n----- Insert new coda test -----");
// Make an new coda
org.trinet.jasi.Coda newCoda = org.trinet.jasi.Coda.create();
java.util.Calendar cal = java.util.Calendar.getInstance();
java.util.Date date = cal.getTime(); // current epoch millisec
long now = date.getTime()/1000; // current epoch sec (millisecs -> seconds)
newCoda.datetime.setValue(now);
newCoda.authority.setValue(EnvironmentInfo.getNetworkCode());
// newCoda.source.setValue("RT1");
newCoda.source.setValue("Test");
// need to associate with a solution
newCoda.associate(sol);
newCoda.changeDescriptor(new CodaPhaseDescriptorTN("P"));
newCoda.setChannelObj(Channel.create().setChannelName("CI", "XYZ", "BHZ"));
System.out.println (newCoda.toString());
status = newCoda.commit();
if (status) {
long coid = ((CodaTN) newCoda).getCoid();
System.out.println ("<><><><> commit (insert) status = "+status+
"(coid = "+coid+" )");
// readback check
System.out.println ("Readback from dbase...");
coda = (org.trinet.jasi.Coda) getByCoid(coid);
System.out.println (coda.toString());
} else {
System.out.println ("<><><><> commit (insert) status = "+status);
}
System.out.println ("\n----- No Change test -----");
// commit again with no changes made, nothing should happen
status = newCoda.commit();
if (status) {
long coid = ((CodaTN) newCoda).getCoid();
System.out.println ("<><><><> commit (insert) status = "+status+
"(coid = "+coid+" )");
// readback check
System.out.println ("Readback from dbase...");
org.trinet.jasi.Coda codaTest = (org.trinet.jasi.Coda) getByCoid(coid);
System.out.println (codaTest.toString());
} else {
System.out.println ("<><><><> commit (insert) status = "+status);
}
// DataSource.commit();
}
public DataLong getorid()
{
return orid;
}
// ///////////////////////////////////////////////////////
public static void main (String args[]) {
// hardwired database info (oracle classes must be in classpath)
String url = "jdbc:oracle:thin:@quake.gps.caltech.edu:1521:quakedb";
String driver = "oracle.jdbc.driver.OracleDriver";
String user = "trinetdb";
String passwd = "calgs";
boolean writeBackEnabled= true;
System.err.println ("Making DataSource connection...");
new DataSource(url, driver, user, passwd, writeBackEnabled); // make connection
System.err.println ("Setting ExecuteSQL.setSelectForUpdate = true");
System.out.println ("DataSource.isReadonly = "+
DataSource.isReadOnly());
System.out.println ("DataSource.isWriteBackEnabled = "+
DataSource.isWriteBackEnabled());
System.out.println ("ExecuteSQL.isSelectForUpdate()= "+
ExecuteSQL.isSelectForUpdate());
// long evid = 9526705;
long evid = 9691940;
System.out.println (" Getting coda for evid = "+evid);
Solution sol = Solution.create().getById(evid);
ArrayList codaList = (ArrayList) org.trinet.jasi.Coda.create().getBySolution(sol);
System.out.println ("Coda count = " + codaList.size());
for (int i = 0; i<codaList.size(); i++)
{
System.err.println (codaList.get(i).toString());
}
doWriteBackTest(sol, (org.trinet.jasi.Coda) codaList.get(0));
DataSource.close();
}
} // End of CodaTN class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -