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

📄 solutiontn.java

📁 一个用java写的地震分析软件(无源码)
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
 */
    // To avoid key constraint errors you must:
    // 1) First set Event row's foreign keys = null
    // 2) Then insert the Event row
    // 3) Then insert the Origin, Mec, NetMag, Comment rows
    // 4) Then set key fields & update the Event and Origin table rows

protected boolean dbaseInsert () {

    boolean status = true;

    // This will set an 'evid' if there is none (eventRow.id)
    toEventRow();
    eventRow.setProcessing(DataTableRowStates.INSERT);

    System.out.println (eventRow.toString());

    // 1)  set Event row's foreign keys = null
    eventRow.setValue(Event.PREFOR,  null);
    eventRow.setValue(Event.PREFMAG, null);
    eventRow.setValue(Event.PREFMEC, null);
    eventRow.setValue(Event.COMMID,  null);

    // 2) insert the Event row (w/ null foreign keys)
    if ( eventRow.insertRow(getConnection()) < 1) return false;

    // 3a) insert the Origin row (w/ null foreign keys)

    status = dbaseInsertOrigin();

    // would do prefmec, and commid here...

    status |= setForeignKeys();

    if (status) setUpdate(false);    // now there's a dbase row

    return status;
}
/** Insert the event comment if it is new. Do this BEFORE committing the Event row
* so the 'commid' will get written. */
 public boolean dbaseInsertComment() {

    if (!comment.isUpdate() || comment.isNull()) return false;

    // new comment ID #
    long newId = SeqIds.getNextSeq(Remark.SEQUENCE_NAME);

    // Make a dbase table object
    final long rowNum = 1;
    Remark remarkRow = new Remark(newId, rowNum, comment.toString());
    remarkRow.setProcessing(Remark.INSERT);

    if ( remarkRow.insertRow(getConnection()) < 1) {
      return false;
    } else {
      commid.setValue(newId);
      return true;
    }

 }
    /**
     * Insert the new Origin and everything connected to it (e.g. Netmag,
     * Arrivals, Amps)
     */

    // THIS IS WHERE THE REAL WORK HAPPENS

    protected boolean dbaseInsertOrigin () {

        if (originHasChanged() ) {
          // <ORIGIN> insert the Origin row (w/ null foreign keys)
          prefor.setNull(true);   // this will force an new orid to be assigned
          toOriginRow();                // will assign 'orid' if none
          originRow.setProcessing(DataTableRowStates.INSERT);

          ////// make sure foreign keys are null, else constraint error
/*
       originRow.setValue(Origin.PREFMAG, null);
       originRow.setValue(Origin.PREFMEC, null);
       originRow.setValue(Origin.COMMID, null);
*/
          // debug
          if (debug) System.out.println (originRow.toString());

          // No point in continuing if Origin row didn't go
          if ( originRow.insertRow(getConnection()) < 1) return false;

          // make sure Magnitude has the new Orid
          MagnitudeTN magtn = (MagnitudeTN) magnitude;
          if (magtn != null &&
              !magtn.isNull() &&
              magtn.getOrid() != getOrid()    // don't set if already equal
              ) magtn.setOrid(getOrid());     // because it causes hasChanged() true

          // would do prefmec, and commid here...
          phaseList.commit(this);

          // <AMPLITUDE & AssocAmO>
          // Can't use ampList.commit() because it trys to write
          // AssocAmM rows and NetMag row may not be written yet
          // so this is ONLY done on Magnitude.commit()
          commitOriginAmpList();
        }

        return true;
    }

    /** Set the Magnitude object of this Solution. Overrides
    * Solution.setPreferredMagnitude in order to update the value of prefmag. */
    public void setPreferredMagnitude (Magnitude mg)
    {
     super.setPreferredMagnitude(mg);

     prefmag = mg.magid;

    }

    /**
     * Update the Event and Origin rows.
     * Set foreign key fields in the Event and Origin table rows. This must
     * be done AFTER the Origin and NetMag rows referenced by the keys have been
     * written or you get constraint errors.
     */

    protected boolean setForeignKeys() {

  boolean status = true;

  if (debug) System.out.println ("adjusting keys: ");
        if (debug) System.out.println (eventRow.toString());

     status = dbaseSetPrefs(prefor, prefmag);

  if (debug) System.out.println ("updated origin status = "+ status);

  if (debug) System.out.println (originRow.toString());

  return status;
}

/** Set the prefor and prefmag of this solution. */
    protected boolean dbaseSetPrefs(DataObject prefOrid, DataObject prefMagid) {

  boolean status = true;

  // Set foreign keys to point at preferred origin and mag.
     // prefOr
  eventRow.setValue(Event.PREFOR, prefOrid);
     // prefMag
  if (!prefMagid.isNull()) eventRow.setValue(Event.PREFMAG, prefMagid);
     // comment
     if (!commid.isNull() && commid.isUpdate()) eventRow.setValue(Event.COMMID, commid);
  eventRow.getDataObject(Event.EVID).setUpdate(true);

  eventRow.setProcessing(DataTableRowStates.UPDATE);

  status = (eventRow.updateRow(getConnection()) > 0);

     // NOTE: this updates the Origin even if evid & prefmag didn't really change

     originRow.setValue(Origin.EVID,  id);
     if (!prefMagid.isNull()) originRow.setValue(Origin.PREFMAG, prefMagid);
  originRow.setProcessing(DataTableRowStates.UPDATE);

  status &= (originRow.updateRow(getConnection()) > 0);

  return status;
}


/** Set the prefor of this solution. */
    protected boolean dbaseSetPrefOr(DataObject prefOrid) {

     if (prefOrid.isNull()) return false;

  boolean status = true;
     this.prefor = (DataLong) prefOrid;

  // Set foreign keys to point at preferred origin and mag.
  eventRow.setValue(Event.PREFOR, prefOrid);
  eventRow.getDataObject(Event.EVID).setUpdate(true);
  eventRow.setProcessing(DataTableRowStates.UPDATE);

  status = (eventRow.updateRow(getConnection()) > 0);

     // Origin points back to the event
  originRow.setValue(Origin.EVID,  id);
  originRow.setProcessing(DataTableRowStates.UPDATE);

  status = (originRow.updateRow(getConnection()) > 0);

     if (status) prefor.setUpdate(false);

  return status;
}
/** Set the prefmag of this solution using the dbase internal logic.
* Note that this method causes a datasource commit. */
    protected boolean dbaseAutoSetPrefMag() {
       long rtn = ((MagnitudeTN)magnitude).dbaseAutoSetPrefMag( getConnection(), getId().longValue());
         return rtn > 0;
    }

/** Set the prefmag of this solution to its Magnitude object.
* Does not do a datasource.commit */
    protected boolean dbaseSetPrefMag() {
         return dbaseSetPrefMag(magnitude);
    }

/** Set the prefmag of this solution to the given Magnitude.
* Does not do a datasource.commit */
    protected boolean dbaseSetPrefMag(Magnitude prefMag) {

     DataObject prefMagid = ((MagnitudeTN)prefMag).getMagid();

     if (prefMagid.isNull())  return false;

  boolean status = true;

     //this.prefmag = (DataLong) prefMagid;

  // Assumes eventRow is already setup. Set foreign keys to point at preferred mag.
  eventRow.setValue(Event.PREFMAG, prefMagid);
     // this is a DataTableRow weirdness that must be undone below.
  eventRow.getDataObject(Event.EVID).setUpdate(true);   //!
  eventRow.setProcessing(DataTableRowStates.UPDATE);

  status = (eventRow.updateRow(getConnection()) > 0);

  originRow.setValue(Origin.PREFMAG, prefMagid);
  originRow.setProcessing(DataTableRowStates.UPDATE);

  status = (originRow.updateRow(getConnection()) > 0);

     if (status) {
     eventRow.getDataObject(Event.EVID).setUpdate(false);
        //prefmag.setUpdate(false);
     }
  return status;
}

    /**
     * Write AssocWaE rows for each Waveform in the waveformList that associates
     * them with 'this' solution (Event)
     */
/*    protected int commitWaveformList () {

  if (waveformList == null) return 0;

  Waveform wf[] = new Waveform[waveformList.size()];
  waveformList.toArray(wf);

  int knt = 0;

  for (int i = 0; i<wf.length; i++) {
      if (wf[i].commit(this)) knt++  ;
  }
  return knt;
    }
 */

    /**
    * Commits the amp list elements associtated with a new Origin.
    * Only call this for once per new origin, usually
    * right after it is committed.
    * If Amp is new (not from dbase) an Amp row will be written.
    * An AssocAmO row will be written.
    * AssocAmM rows will NOT be written because we can't tell if they have been
    * previously written or not. That is the job of the Magnitude.commit() method.
    */
    protected int commitOriginAmpList() {
        int successfulCommitCount = 0;
        if (getAmpList() != null && ! getAmpList().isEmpty()) {
            Amplitude amp[] = getAmpList().getArray();

            AmplitudeTN amptn;
            for (int i = 0; i < amp.length; i++) {

                amptn = (AmplitudeTN) amp[i];   // one cast
                if ( ! amptn.fromDbase ) {     // insert in dbase if new amp
                   // insert and assoc
                   if (amptn.dbaseInsert() ) {
                      if (amptn.dbaseAssociateWithOrigin()) successfulCommitCount++;
                   }
                } else {
                  // associate only
                  if (amptn.dbaseAssociateWithOrigin()) successfulCommitCount++;
                }
            }
        }
        return successfulCommitCount;
    }

    /**
     * Copy all the AssocWaE rows for the oldEvid to this evid. This is much
     * faster then actually writing them one-by-one but only works if this is a
     * clone and you want ALL waveforms associated. Returns true on success,
     * false on failure or noop. Uses Oracle store procedure.
     */
    protected boolean commitWaveformList() throws JasiCommitException {

      if (id.longValue() == parentId.longValue()) return false; // not a clone, don't copy self

      // The "0" means DON'T COMMIT
   String sql = "call JASI.CloneAssocWaE("+ parentId.longValue() +", "+
                                               id.longValue()+", 0)";

   return doSql(sql) ;
    }

    /**
     * Write AssocAmO rows for each Amp in the ampList that associates
     * them with 'this' solution (Origin)
     */
    /*
    protected int commitAmpList () {

  if (ampList == null) return 0;

  Amp am[] = new Amp[ampList.size()];
  ampList.toArray(am);

  int knt = 0;

  for (int i = 0; i<am.length; i++)
  {
      if (am[i].commit(this)) knt++  ;
  }
  return knt;
    }
    */

    /**
     * Copy all the AssocAmO rows for the oldOrid to this orid. This is much
     * faster then actually writing them one-by-one but only works if you
     * want ALL waveforms associated.
     */
/*
    protected int commitAmpList (long oldOrid) {

  String sql = " call jasi.CloneAssocAmO("+ oldOrid +
      ", "+getOrid() +", 0)";

  boolean status = doSql(sql);

  if (status) return 1;
  return 0;
    }
*/
    /**
    *  Commits the coda list elements, creating database Coda and AssocCoO rows.
    */
/*   USE COMMIT() IN AmpList classs
    protected int commitAmpList() {
        int successfulCommitCount = 0;
        if (ampList != null) {
            int count = ampList.size();
            if (count > 0) {
                Amplitude amp[] = (Amplitude[]) ampList.toArray(new Amplitude[count]);
                for (int index = 0; index < count; index++) {
                    if (amp[index].commit()) successfulCommitCount++;
                }
            }
        }
        return successfulCommitCount;
    }
*/
    /*
    *  Commits the coda list elements, creating database Coda and AssocCoO rows.
    */
/*    USE COMMIT() IN CodaList classs
    protected int commitCodaList() {
        int successfulCommitCount = 0;
        if (codaList != null) {
            int count = codaList.size();
            if (count > 0) {
                CodaTN coda[] = (CodaTN []) codaList.toArray(new CodaTN[count]);
                for (int in

⌨️ 快捷键说明

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