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

📄 datatablerow.java

📁 一个用java写的地震分析软件(无源码)-used to write a seismic analysis software (without source)
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
package org.trinet.jdbc.table;
import org.trinet.jdbc.datatypes.*;
import org.trinet.jdbc.*;
import java.util.*;
import java.sql.*;
import java.math.BigDecimal;
import org.trinet.jasi.ChannelIdIF;
import org.trinet.jasi.AuthChannelIdIF;

/** Base class for all schema table classes.
* Implements methods used by class extensions to retrieve and modify database table rows.
* Class data members are initialized by the implementations that extend this class.
* The state of the object instance and its data members can be modified/checked by set/get methods in this class.
* A JDBC database Connection member has to be initialized before using any method which accesses the database.
* @see #setConnection(Connection)
* @see #setConnection(Connection, DataTableRow [])
*/
public abstract class DataTableRow implements DataTableRowStates, DataClassIds, DataClasses, Cloneable {
/** Name of database table described by this object instance. */
    private String tableName; // must have correspondingly name java Class
/** Table key column identifier sequence name. */
    private String sequenceName;
/** Number of columns in table row. */
    private int maxFields;
/** Number of index columns in table row. */
    private int keyIndexLength;
/** Column indices of table keys. */
    private int [] keyColumnIndex;
/** Names of table columns. */
    private String [] fieldNames;
/** Flags indicate table columns as nullable. */
    private boolean [] fieldNulls;
/** Column data field classes. */
    private int [] fieldClassIds;
/** Appended to query if isSelectForUpdate() == true. */
    static final String SELECT_FOR_UPDATE = " FOR UPDATE";
/** Lock table mode if isLockTableForUpdate() == true. */
    static final String ROW_EXCLUSIVE_MODE_NOWAIT = " IN ROW EXCLUSIVE MODE NOWAIT";

/** Flag set by lockTableForUpdate(boolean). */
    private boolean lockTableFlag = false;
/** Flag set by selectTableForUpdate(boolean). */
    private boolean selectForUpdateTableFlag = false;

/** Contains a DataObject element for each table column data field. */
    protected Vector fields;
/** DataTableRow object processing mode.  */
    protected int processingStatus = NONE;
/** Flag object null status. */
    protected boolean valueNull = true;
/** Flag object update status. */
    protected boolean valueUpdate = false;
/** Flag object mutable status. */
    protected boolean valueMutable = true;

/** Handle of the default JDBC connnection object used by methods when no connection argument is specified.
* @see #setConnection(Connection)
* @see #getConnection()
*/
    protected Connection connDB = null;

/** Constructor is invoked by the implementions of extending classes to define table parameters.
* Throws an IndexOutOfBoundsException if the input arguments violate any of these conditions:
*	maxFields <= 0, fieldNames.length != maxFields, fieldClassIds.length != maxFields,
*	keyColumnIndex.length < 1 or (keyColumnIndex.length > 1 && !(sequenceName==""))
*/
    protected DataTableRow(String tableName, String sequenceName, int maxFields, int [] keyColumnIndex, String[] fieldNames,
      boolean [] fieldNulls, int[] fieldClassIds) throws NullPointerException, IndexOutOfBoundsException {
  this.tableName = tableName;
  if (tableName == null) throw new NullPointerException("DataTableRow Constructor - tableName == null.");
  this.maxFields = maxFields;
  if (maxFields <= 0) {
     throw new IndexOutOfBoundsException(tableName + " DataTableRow initialize(...)  maxFields must be > 0");
  }
  if (fieldNames.length != maxFields) {
     throw new IndexOutOfBoundsException(tableName + " DataTableRow initialize(...) fieldNames:" +
       fieldNames.length  + " != "  + " maxFields:" + maxFields);
  }
  if (fieldNulls.length != maxFields) {
     throw new IndexOutOfBoundsException(tableName + " DataTableRow initialize(...) fieldNulls:" +
       fieldNulls.length  + " != "  + " maxFields:" + maxFields);
  }
  if (fieldClassIds.length != maxFields) {
     throw new IndexOutOfBoundsException(tableName + " DataTableRow initialize(...) fieldClassIds:" +
       fieldClassIds.length  + " != "  + " maxFields:" + maxFields);
  }
  if (keyColumnIndex.length < 1 ) {
     throw new IndexOutOfBoundsException(tableName + " DataTableRow initialize(...) keyColumnIndex.length:" +
     keyColumnIndex.length  + " must be > 0");
  }
/*	if (keyColumnIndex.length > 1 && ! NullValueDb.isEmpty(sequenceName)) {
     throw new IndexOutOfBoundsException(tableName +
     " DataTableRow initialize(...) keyColumnIndex length must equal 1 if a sequenceName string is specified.");
  }
*/
  this.sequenceName = sequenceName;
  this.keyColumnIndex = keyColumnIndex;
  this.keyIndexLength = keyColumnIndex.length;
  this.fieldNames = fieldNames;
  this.fieldNulls = fieldNulls;
  this.fieldClassIds = fieldClassIds;

  this.fields = new Vector(maxFields);
  this.fields.setSize(maxFields); // this is the equvalent of the loop below
//	for (int index = 0; index < maxFields; index++) {
//	    this.fields.add(null); // can't fields.set(int,Object) if no elements are added.
//	}
    }


/** Implement the cloneable interface, clones the data field members
* after invoking super.clone().
*/
    public Object clone() {
  DataTableRow obj = null;
  try {
      obj = (DataTableRow) super.clone();
  }
  catch (CloneNotSupportedException ex) {
      System.out.println(tableName + " DataTableRow Cloneable not implemented for class.");
      ex.printStackTrace();
  }
  for (int index = 0; index < maxFields; index++) {
      DataObject dataObj = (DataObject) obj.fields.get(index);
      if (dataObj != null) obj.fields.set(index, dataObj.clone());
      else obj.fields.set(index, null);
  }
  return obj;
    }

/** Resets the state flags of this object instance and those of its contained column data to the default values:
* update == false, null == true, mutable == true.
*/
    public void setDefaultStates() {
  this.setUpdate(false).setNull(true).setMutable(true);
  for (int index = 0; index < maxFields; index++) {
      DataObject obj = (DataObject) fields.get(index);
      if (obj != null) obj.setUpdate(false).setNull(true).setMutable(true);
  }
    }

/** Enables/disables table locking in ROW EXCLUSIVE MODE before table modification statement execution.
* Returns a handle to this object instance.
*/
    public DataTableRow setLockTableForUpdate(boolean value) {
  lockTableFlag = value;
  return this;
    }

/** Returns table locking status, whether it is in ROW EXCLUSIVE MODE before table modification statement execution.
*/
    public boolean isLockTableForUpdate() {
  return lockTableFlag;
    }

/** Enables FOR UPDATE option for all table queries with getRowXXXX methods.
* Returns a handle to this object instance.
*/
    public DataTableRow setSelectForUpdate(boolean value) {
  selectForUpdateTableFlag = value;
  return this;
    }

/** Returns FOR UPDATE option status for all table queries using getRowXXXX methods.
*/
    public boolean isSelectForUpdate() {
  return selectForUpdateTableFlag;
    }

/** Returns the table name string.
*/
    public String getTableName() {
  return tableName;
    }

/** Returns the table sequence name string.
*/
    public String getSequenceName() {
  return sequenceName;
    }

/** Returns the number of column fields in a single table row.
*/
    public int getMaxFields() {
  return maxFields;
    }

/** Returns an array of table row key field indices whose values are the key column position.
*/
    public int [] getKeyIndex() {
  return keyColumnIndex;
    }

/** Returns an array of table column name strings indexed by column position.
*/
    public String [] getFieldNames() {
  return fieldNames;
    }

/** Returns an array of booleans indicating which table columns are nullable indexed by column position.
*/
    public boolean [] getFieldNullables() {
  return fieldNulls;
    }

/** Returns an array of table column data Class identifiers indexed by column position.
* @see org.trinet.jdbc.datatypes.DataClassIds
* @see org.trinet.jdbc.datatypes.DataClasses
*/
    public int [] getFieldClassIds() {
  return fieldClassIds;
    }

/** Aliases the JDBC Connection for this instance to the specified Connection input argument.
* All database operation methods create, execute, and close a java.sql.Statement using this connection object.
* @see #setConnection(Connection, DataTableRow [])
* @see #getConnection()
* @see org.trinet.jdbc.JDBConnect
* @see org.trinet.jdbc.JDBConn
*/
   public void setConnection(Connection conn) {
  this.connDB = conn;
  return;
   }

/** Aliases the JDBC Connection of each of the DataTableRow objects in the input array
* to the Connection input argument.
* All database operation methods create, execute, and close a java.sql.Statement using this connection object.
* @see #setConnection(Connection)
* @see #getConnection()
* @see org.trinet.jdbc.JDBConnect
* @see org.trinet.jdbc.JDBConn
*/
   public static void setConnection(Connection conn, DataTableRow [] array) {
  for ( int index = 0; index < array.length; index++) {
      array[index].setConnection(conn);
  }
  return;
   }

/** Returns the handle of the JDBC Connection stored in this instance.
* @see #setConnection(Connection)
* @see #setConnection(Connection, DataTableRow [])
* @see org.trinet.jdbc.JDBConnect
* @see org.trinet.jdbc.JDBConn
*/
   public Connection getConnection() {
  return this.connDB;
   }

/** Returns current primary key sequence number for table from the sequence named by the implementing class.
* Requires an active non-null JDBC database Connection reference.
* Method uses the JDBC Connection object assigned with setConnection().
* Oracle requires a prior call to sequenceName.NEXTVAL.
* Returns -1 if sequence is not defined or error.
* @see #setConnection(Connection)
* @see org.trinet.jdbc.JDBConnect
* @see org.trinet.jdbc.JDBConn
*/
    public int getCurrentSeq() {
  return getCurrentSeq(connDB);
    }

/** Returns current primary key sequence number for table from the sequence named by the implementing class.
* Requires an active non-null JDBC database Connection reference.
* Oracle requires a prior call to sequenceName.NEXTVAL.
* Returns -1 if sequence is not defined or error.
* @see #setConnection(Connection)
* @see org.trinet.jdbc.JDBConnect
* @see org.trinet.jdbc.JDBConn
*/
    public int getCurrentSeq(Connection conn) {
  if (NullValueDb.isEmpty(sequenceName)) return -1;
  if (conn == null) {
      System.err.println(tableName + " DataTableRow getCurrentSeq: JDBC connection input argument null;" +
    " Application must first instantiate a connection class" +
    "; see JDBConnect(String url, String driverName, String user, String passwd)");
      return -1;
  }
  return SeqIds.getCurrSeq(conn, sequenceName);
    }

/** Returns next primary key sequence number for table from the sequence named by the implementing class.
* Requires an active non-null JDBC database Connection reference.
* Method uses the JDBC Connection object assigned with setConnection().
* Returns -1 if sequence is not defined or error.
* @see #setConnection(Connection)
*/
    public int getNextSeq() {
  return getNextSeq(connDB);
    }

/** Returns next primary key sequence number for table from the sequence named by the implementing class.
* Requires an active non-null JDBC database Connection reference.
* Returns -1 if sequence is not defined or error.
* @see #setConnection(Connection)

⌨️ 快捷键说明

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