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

📄 datatablerow.java

📁 一个用java写的地震分析软件(无源码)-used to write a seismic analysis software (without source)
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
* Sets the column field null status flag, isNull() == false.
* Sets the row null status flag, isNull() == false.
* Returns a handle to this object instance.
*/
    public DataTableRow setValue(String name, double value) throws NoSuchFieldException {
  if (! isMutable()) return this;
  int index = findFieldIndex(name);
  if (index < 0)
    throw new NoSuchFieldException(tableName +
     " DataTableRow setValue(String name, double value) unknown field name:" + name);
  return setValue(index, value);
    }

/** Sets the DataObject value for the specified table column index.
* Does a no-op if isMutable() == false or if a field is null and the required initializeDataField() fails.
* Sets the column field update status flag, isUpdate() == true.
* Sets the column field null status flag, isNull() == false.
* Sets the row null status flag, isNull() == false.
* Returns a handle to this object instance.
*/
    public DataTableRow setValue(int index, double value) throws IndexOutOfBoundsException {
  if (! isMutable()) return this;
  if (index < 0 || index > fields.size())
      throw new IndexOutOfBoundsException(tableName +
     " DataTableRow setValue(int index, double value) field index out of bounds:" + index);
  DataObject dataObj = (DataObject) fields.get(index);
  if (dataObj == null) {
      dataObj = initializeDataField(index);
      dataObj.setValue(value);
      fields.set(index, dataObj);
  }
  else dataObj.setValue(value);
  return setUpdate(true).setNull(false);
    }

/** Sets the DataObject value for the specified table column name.
* Does a no-op if isMutable() == false or if a field is null and the required initializeDataField() fails.
* Sets the column field update status flag, isUpdate() == true.
* Sets the column field null status flag, isNull() == false.
* Sets the row null status flag, isNull() == false.
* Returns a handle to this object instance.
*/
    public DataTableRow setValue(String name, String value) throws NoSuchFieldException {
  if (! isMutable()) return this;
  int index = findFieldIndex(name);
  if (index < 0)
    throw new NoSuchFieldException(tableName +
     " DataTableRow setValue(String name, String value) unknown field name:" + name);
  return setValue(index, value);
    }

/** Sets the DataObject value for the specified table column index.
* Does a no-op if isMutable() == false or if a field is null and the required initializeDataField() fails.
* Sets the column field update status flag, isUpdate() == true.
* Sets the column field null status flag, isNull() == false.
* Sets the row null status flag, isNull() == false.
* Returns a handle to this object instance.
*/
    public DataTableRow setValue(int index, String value) throws IndexOutOfBoundsException {
  if (! isMutable()) return this;
//		System.out.println("***DTR setValue(int,String) after isMutable in method.");
  if (index < 0 || index > fields.size())
      throw new IndexOutOfBoundsException(tableName +
     " DataTableRow setValue(int index, String value) field index out of bounds:" + index);
  DataObject dataObj = (DataObject) fields.get(index);
  if (dataObj == null) {
//		System.out.println("***DTR setValue(int,String) null value initialize field method.");
      dataObj = initializeDataField(index);
      dataObj.setValue(value);
      fields.set(index, dataObj);
  }
  else dataObj.setValue(value);
  return setUpdate(true).setNull(false);
    }

/** Sets the DataObject value for the specified table column name.
* Does a no-op if isMutable() == false or if a field is null and the required initializeDataField() fails.
* Sets the column field update status flag, isUpdate() == true.
* Sets the column field null status flag, isNull() == false.
* Sets the row null status flag, isNull() == false.
* Returns a handle to this object instance.
*/
    public DataTableRow setValue(String name, Object value) throws NoSuchFieldException {
  if (! isMutable()) return this;
  int index = findFieldIndex(name);
  if (index < 0)
    throw new NoSuchFieldException(tableName +
     " DataTableRow setValue(String name, Object value) unknown field name:" + name);
  return setValue(index, value);
    }

/** Sets the DataObject value for the specified table column index.
* Does a no-op if isMutable() == false or if a field is null and the required initializeDataField() fails.
* Sets the column field update status flag, isUpdate() == true.
* Sets the column field null status flag, isNull() == false.
* Sets the row null status flag, isNull() == false.
* Returns a handle to this object instance.
*/
    public DataTableRow setValue(int index, Object value) throws IndexOutOfBoundsException {
  if (! isMutable()) return this;
//	if (value == null) throw new NullPointerException(tableName + " DataTableRow setValue(Object) argument null");
  if (index < 0 || index > fields.size())
      throw new IndexOutOfBoundsException(tableName +
     " DataTableRow setValue(int index, Object value) field index out of bounds:" + index);
  DataObject dataObj = (DataObject) fields.get(index);
  if (dataObj == null) {
      dataObj = initializeDataField(index);
      dataObj.setValue(value);
      fields.set(index, dataObj);
  }
  else dataObj.setValue(value);
  return setUpdate(true).setNull(false);
    }

/** Returns a new array object containing the results of parsing the input ResultSet rows into instances of the implementing class.
* A return == null indicates an error condition.
* Sets the mutability state of each DataTableRow instance to false if isSelectForUpdate == false.
* Sets the mutability state for the DataObject in any declared table key column to false.
*/
    protected Object parseResults(ResultSetDb rsdb) {
  return parseResults(rsdb, 0);
    }

/** Returns a new array object containing the results of parsing the input ResultSet rows into instances of the implementing class.
* Starts each row parse at the column at the specified offset.
* Iterates through the ResultSet calling ResultSet.next().
* Closes the ResultSet when upon reaching the end of the results.
* Sets the mutability state of each DataTableRow instance to false if isSelectForUpdate == false.
* Sets the mutability state for the DataObject in any declared table key column to false.
*/
    public Object parseResults(ResultSetDb rsdb, int offset) {
  if (rsdb == null) {
      System.err.println(tableName + " DataTableRow parseResults: null ResultSetDb object.");
      return null;
  }
  if (offset < 0) {
      System.err.println(tableName + " DataTableRow parseResults: invalid offset argument: " + offset);
      return null;
  }
  ResultSet rs = rsdb.getResultSet();
  if (rs == null) {
      System.err.println(tableName + " DataTableRow parseResults: null ResultSet object.");
      return null;
  }
  try {
      ResultSetMetaData rsmd = rs.getMetaData();
      if (rsmd.getColumnCount() < offset + maxFields ) {
    System.err.println(tableName +
      " DataTableRow parseResults: offset+totalRowColumns exceeds the total columns in ResultSet: " +
      " offset+rowColumns: " + (offset+maxFields)  + " resultSetColumns: " + rsmd.getColumnCount());
    return null;
      }
  }
  catch (SQLException ex) {
    SQLExceptionHandler.prtSQLException(ex);
    System.err.println(tableName + " DataTableRow parseResults: cannot get ResultSetMetaData");
    return null;
  }
  int nrows = 0;
  Vector vtr = new Vector();
  try {
      while (rs.next() ) {
    vtr.add(parseOneRow(rsdb, offset));
    nrows++;
      }
  }
  catch (SQLException ex) {
      System.err.println(tableName + " DataTableRow: parseResults ResultSet.next() SQLException");
      SQLExceptionHandler.prtSQLException(ex);
      return null;
  }
  try {
      rs.close();
  }
  catch (SQLException ex) {
      System.err.println(tableName + " DataTableRow: parseResults ResultSet.close() SQLException");
      SQLExceptionHandler.prtSQLException(ex);
      return null;
  }

  return recast(vtr);
    }

/** Returns a DataTableRow object resulting from parsing one row of the input ResultSetDb into instance of implementing class.
* Starts row parse at the column at the specified offset. After row parse, does no other JDBC operations on ResultSetDb.
* Sets the mutability state of this DataTableRow instance to false if isSelectForUpdate == false.
* Each row column value is  represented by a DataObject class.
* For a row key column, DataObject.setUpdate() == true && DataObject.isMutable() == false.
* For a row non-key column, DataObject.isUpdate() == false && DataObject.isMutable() == true.
* Returns null if input ResultSetDb is null or input offset < 0.
* Returns null if input offset+table_row_columns (i.e. TableRowXXX.MAX_FIELDS) > number of columns returned in the ResultSetDb row.
* Returns null if an SQLException occurs during processing.
* @see ExecuteSQL#parseOneRow(ResultSet, int, Class, Connection)
*/
    public DataTableRow parseOneRow(ResultSetDb rsdb, int offset) {
  if (rsdb == null ) {
      System.err.println(tableName + " DataTableRow parseOneRow: null ResultSetDb input argument.");
      return null;
  }
  if (offset < 0) {
      System.err.println(tableName + " DataTableRow parseOneRow: invalid offset input argument.");
      return null;
  }
  ResultSet rs =  rsdb.getResultSet();
  if (rs == null) {
      System.err.println(tableName + " DataTableRow parseOneRow: null ResultSet object.");
      return null;
  }
  try {
      ResultSetMetaData rsmd = rs.getMetaData();
      if (rsmd.getColumnCount() < offset + maxFields ) {
    System.err.println(tableName +
     " DataTableRow parseResults: offset+totalRowColumns exceeds the total columns in ResultSet: " +
      " offset+rowColumns: " + (offset+maxFields)  + " resultSetColumns: " + rsmd.getColumnCount());
    return null;
      }
  }
  catch (SQLException ex) {
    SQLExceptionHandler.prtSQLException(ex);
    System.err.println(tableName + " DataTableRow parseOneRow: cannot get ResultSetMetaData");
    return null;
  }
  DataTableRow row = null;
  try {
      row = (DataTableRow) this.getClass().newInstance(); // create new instance of tableName class
  }
  catch (IllegalAccessException ex) {
      System.err.println(tableName + " DataTableRow parseOneRow(ResultSetDb): class or initializer not accessible.");
      return null;
  }
  catch (InstantiationException ex) {
      System.err.println(tableName + " DataTableRow parseOneRow(ResultSetDb): cannot instantiate class check type.");
      return null;
  }
  if (connDB != null) row.connDB = this.connDB;

// Remember ResultSet column indexes start at 1, but arrays start at 0.
  for (int index = 0; index < maxFields; index++) {
      try {
//		row.fields.set(index, rsdb.getDataObject( index + 1 + offset, this.fieldNames[index], this.DATA_CLASSES[fieldClassIds[index]] ) );
    row.fields.set(index, rsdb.getDataObject(index + 1 + offset, this.DATA_CLASSES[fieldClassIds[index]] ) );
// instead of setValue() used fields.set since ResultSetDb.getDataObject(...) does a setUpdate(false) for the new DataObject.
      }
      catch ( SQLException ex) {
    SQLExceptionHandler.prtSQLException(ex);
    System.err.println(tableName + " DataTableRow parseOneRow at column index value: " + index + " fieldName: "
        + fieldNames[index] + " fieldClass: " + DATA_CLASSES[fieldClassIds[index]] + " offset: " + offset);
    return null;
      }
      catch ( NoSuchFieldException ex) {
    ex.printStackTrace();
    return null;
      }
      catch ( IndexOutOfBoundsException ex) {
        ex.printStackTrace();
    return null;
      }
  }
// key fields are not modifiable and are set as a valid update by default to be included in the WHERE cause on SQL update.
  for (int index = 0; index < keyIndexLength; index++) {
      ((DataObject) row.fields.get(keyColumnIndex[index])).setMutable(false).setUpdate(true); // ok since all fields != null
  }
  if (! isSelectForUpdate()) row.setMutable(false).setNull(false); // read-only mode, do not modify row contents
  else row.setNull(false);
  return row;
    }

/** Returns a new array of this class instance type containing the contents of the input List object.
* Returns null if the List object is null or empty.
*/
    public Object recast(List list) {
  Object retVal = null;
  if (list == null) return null;
  if ( list.size() > 0) {
      retVal = java.lang.reflect.Array.newInstance(this.getClass(), list.size());
      for (int index = 0; index < list.size(); index++) {
    java.lang.reflect.Array.set(retVal, index,  list.get(index));
      }
  }
  return retVal;
    }

/** Returns a new array of this class instance type containing the contents of the input array object.
* Returns null if the input array is null or empty.
*/
    public Object recast(DataTableRow [] dtr) {
  if (dtr == null) return null;
  if (dtr.length < 1) return null;
  Object retVal = java.lang.reflect.Array.newInstance(this.getClass(), dtr.length);
  for (int index = 0; index < dtr.length; index++) {
      java.lang.reflect.Array.set(retVal, index,  dtr[index]);
  }
  return retVal;
    }

/** Returns the count of database table rows satisfying: "SELECT COUNT( countExpression ) WHERE whereCondition".

⌨️ 快捷键说明

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