⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 channeltn.java

📁 一个用java写的地震分析软件(无源码)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.trinet.jasi.TN;

import org.trinet.jasi.*;

import java.sql.*;
import java.util.*;
import java.io.*;

import org.trinet.jdbc.*;
import org.trinet.jdbc.table.*;
import org.trinet.jdbc.datatypes.*;

import org.trinet.util.gazetteer.LatLonZ;
import org.trinet.util.gazetteer.GeoidalUnits;

import org.trinet.util.DateTime;
import org.trinet.util.BenchMark;

/**
 * JASI - Java Abstract Seismic Interface
 * This is a schema specific implimentation of Channel that acts as the
 * interface to the Channel_Data table of the NCDC v1.5 schema.
 * Contains a ChannelName member which includes
 * descriptive information for the channel like location
 * of the site (latlonz) and response info. <p>
 *
 * @See: org.trinet.jasi.ChannelName
 */

public class ChannelTN extends Channel {

  public ChannelTN() {
  }
// Concrete instances of Channel abstract methods
    /**
     * Look up the given Channel in the DataSource dbase and return a fully
     * populated Channel object. This is how you look up LatLonZ and response
     * info for a single channel. Note this finds the LATEST entry if more then
     * one entry is in the dbase (largest 'ondate'). But, it does NOT require that
     * the channel be "active". If no entry is found, this
     * method return the channel name that was passed in the arg as a Channel.
     */
    public Channel lookUpChannel (Channel chan) {

        ChannelIdIF chanId = chan.getChannelId();
  String whereClause =
      " (Channel_Data.net = '"+ chanId.getNet() +"' and "+
      "Channel_Data.sta = '"+ chanId.getSta() +"' and "+
      "Channel_Data.seedchan = '"+ chanId.getSeedchan() +"' "+
      ") order by Channel_Data.ondate DESC";	// descending order so latest is first

  ArrayList list = (ArrayList) getWhere (DataSource.getConnection(), whereClause );

  // got something
  if (list != null && list.size() > 0) {

      Channel ch = (Channel) list.get(0);	// return latest entry only

      return (Channel) ch;	// return first entry only

  }

  return chan;	// return original entry

    }

  /** Return a list of currently active channels that match the list of
    * component types given in
    * the array of strings. The comp is compared to the SEEDCHAN field in the NCDC
    * schema.<p>
    *
    * SQL wildcards are allowed as follows:<br>
    * "%" match any number of characters<br>
    * "_" match one character.<p>
    *
    * For example "H%" would match HHZ, HHN, HHE, HLZ, HLN & HLE. "H_" wouldn't
    * match any of these but "H__" would match them all. "_L_" would match
    * all components with "L" in the middle of three charcters (low gains).
    * The ANSI SQL wildcards [] and ^ are not supported by Oracle.*/
    public ChannelList getByComponent(String[] compList) {

           String whereClause = "";

           whereClause = getNowWhereClause() + " and ";

           if (compList.length > 0) {
            whereClause += " (";

            for (int i = 0; i < compList.length; i++) {
               if (i > 0) whereClause += " or ";
               whereClause += "Channel_Data.seedchan like '"+compList[i]+"'";
            }
            whereClause += ") order by Channel_Data.net,Channel_Data.sta,Channel_Data.seedchan";
           }

           return getWhere(DataSource.getConnection(), whereClause);
    }
    /** Return a list of channels that were active on the given date and
    *  that match the list of component types given in
    * the array of strings. The comp is compared to the SEEDCHAN field in the NCDC
    * schema.<p>
    *
    * SQL wildcards are allowed as follows:<br>
    * "%" match any number of characters<br>
    * "_" match one character.<p>
    *
    * For example "H%" would match HHZ, HHN, HHE, HLZ, HLN & HLE. "H_" wouldn't
    * match any of these but "H__" would match them all. "_L_" would match
    * all components with "L" in the middle of three charcters (low gains).
    * The ANSI SQL wildcards [] and ^ are not supported by Oracle.*/
    public ChannelList getByComponent(String[] compList,  java.sql.Date date) {

           String whereClause = "";

           whereClause = getDateWhereClause(date) + " and ";

           if (compList.length > 0) {
            whereClause += " (";

            for (int i = 0; i < compList.length; i++) {
               if (i > 0) whereClause += " or ";
               whereClause += "Channel_Data.seedchan like '"+compList[i]+"'";
            }
            whereClause += ") order by Channel_Data.net,Channel_Data.sta,Channel_Data.seedchan";
           }

           return getWhere(DataSource.getConnection(), whereClause);
    }

/** Return count of all currently active channels in data source. */
    public int getCurrentCount () {

  // use NOW
  java.sql.Date currentTime =
      new java.sql.Date(new DateTime().getMilliSeconds());

       return getCount (currentTime);

    }

    /** Return count of all channels in data source at the given time. */
    public int getCount (java.sql.Date date) {

       return getCountBySQL (getDateWhereClause(date));

    }
/**
 * Get a count of sql rows given an SQL query.
 */
    static int getCountBySQL(String whereClause){
       return getCountBySQL(DataSource.getConnection(), whereClause);
    }
/**
 * Get a count of sql rows given an SQL query.
 */
    static int getCountBySQL(Connection conn, String whereClause){

     int count = 0;

     String sql = "SELECT count(*) from Channel_Data where "+whereClause;
  // Debug
  if (debug) System.out.println ("SQL: "+sql);

  try {
      if ( conn.isClosed() )	// check that valid connection exists
    {
        System.err.println ("* ChannelList connection is closed. *");
        return 0;
    }

      Statement sm = conn.createStatement();

      ResultSet rs = org.trinet.jdbc.table.ExecuteSQL.rowQuery(sm, sql);

      if (rs == null) return 0;	// nothing found

         rs.next();

         count = rs.getInt(1);

      sm.close();

  }
  catch (SQLException ex) {
      System.err.println(ex);
      ex.printStackTrace();
  }

  return count;
    }

    /**
     * Appends this SQL where clause to the statement
     * "Select * from Channel_Data ". Example: "where net = 'CI'"
     */
    public  ChannelList getListWhere(String whereClause) {

  return getWhere(DataSource.getConnection(), whereClause);
    }

/**
 * Return exhaustive Collection of Channels from the default DataSource.
 */
    public ChannelList readList() {
  return getWhere("");
    }

    public ChannelList readList(java.sql.Date date) {
      return readList(DataSource.getConnection(), date);
    }

    public ChannelList readList(Connection conn, java.sql.Date date) {
  return Channel.create().readList(conn, date);
//	return Channel.create().readList(Channel.getDateWhereClause(date);

    }


// Internal methods ////////////
    /** Return a where clause to select channels that were active on this date. */
    static String getDateWhereClause ( java.sql.Date date) {
  return " (Channel_Data.OFFDATE >= " + StringSQL.valueOf(date) +
                        " OR Channel_Data.OFFDATE = NULL) and "+
                        "(Channel_Data.ONDATE <= " + StringSQL.valueOf(date) +
                        " OR Channel_Data.ONDATE = NULL) ";
    }

    /** Return a where clause to select channels are were active NOW. */
    static String getDateWhereClause () {
      return getNowWhereClause();
    }

    /** Return a where clause to select channels that are currently active.
     *  This uses the database's concept of "now" just in case there is a
     *  difference in time bases between the dbase and the client. */
    static String getNowWhereClause () {
  return " (Channel_Data.OFFDATE >= SYSDATE" +
                        " OR Channel_Data.OFFDATE = NULL) and "+
                        "(Channel_Data.ONDATE <= SYSDATE" +
                        " OR Channel_Data.ONDATE = NULL) ";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -