/** Execute the query and get the results. */ public void load(int startRow, int length) throws KExceptionClass { bindDBtransaction( dbTransactionClient, " SELECT " + selectSQL + " FROM " + tableName + finalWhere + finalOrder); // Query DB try { KMetaUtilsClass.cursorWait(parentWindow); KMetaUtilsClass.setProgressBarValue1(60); dbTransactionClient.executeQuery(startRow, length); KMetaUtilsClass.setProgressBarValue1(100); } finally { KMetaUtilsClass.cursorNormal(parentWindow); } if (!dbTransactionClient.columnNamesList.contains(keyField)) { throw new KExceptionClass( "*** Could not load data **** \n" + "Key field [" + keyField + "] was not found in result set", null); } firstLoadReady = true; log.log(this, "dbTransactionClient rowCount = " + dbTransactionClient.rowCount()); log.log(this, "dbTransactionClient startRow = " + dbTransactionClient.resultSetStart()); }
/** make SQL query for certain operation and return the result. */ public Map executeSQLOperation(String operation, boolean reflectCustomFilter) throws KExceptionClass { dbTransactionClientClass dbTransaction = new dbTransactionClientClass(configuration, log); String sql; if (reflectCustomFilter) { // do bind custom parameters sql = " SELECT " + operation + " FROM " + tableName + finalWhere; bindDBtransaction(dbTransaction, sql); } else { // do NOT bind custom parameters sql = " SELECT " + operation + " FROM " + tableName + defaultWhere; bindDefaultDBtransaction(dbTransaction, sql); } ; // Query to DB dbTransaction.executeQuery(0, 10); if (!dbTransaction.fetch()) throw new KExceptionClass( "*** SQL total error **** \n" + "No row was returned." + "SQL: [" + sql + "]\n ", null); return (dbTransaction); }
/** prepare DB transaction */ private void bindDBtransaction(dbTransactionClientClass dbTransaction, String sql) throws KExceptionClass { dbTransaction.reset(); // Prepares the SQL string dbTransaction.prepare(sql); // binding main parameters Iterator parameters = mainBindingParameterList.iterator(); while (parameters.hasNext()) { // save sql parameters boundParameterClass currentBoundParameter = (boundParameterClass) parameters.next(); dbTransaction.dynamicBind( currentBoundParameter.parameterIndex, currentBoundParameter.parameterValue); } // binding sub parameters parameters = customBindingParameterList.iterator(); while (parameters.hasNext()) { // save sql parameters boundParameterClass currentBoundParameter = (boundParameterClass) parameters.next(); dbTransaction.dynamicBind( currentBoundParameter.parameterIndex, currentBoundParameter.parameterValue); } }
/** get number of rows being loaded */ public int getloadedRowCount() throws KExceptionClass { if (!firstLoadReady) throw new KExceptionClass( "*** Data Loading error **** \n" + "Can not return row count before data loading...", null); return dbTransactionClient.rowCount(); }
/** get first loaded row index in DB table */ public int getloadedStartRowIndex() throws KExceptionClass { if (!firstLoadReady) throw new KExceptionClass( "*** Data Loading error **** \n" + "Can not return start row before data loading...", null); return dbTransactionClient.resultSetStart(); }
/** get next loaded value */ public void getRowValue(recordClass record) throws KExceptionClass { if (record == null) throw new KExceptionClass( "*** Object reference error **** \n" + "The reference is null.", null); int fieldIndex = 0; Iterator columnNames = dbTransactionClient.columnNamesList.iterator(); // build current row while (columnNames.hasNext()) { String column_name = (String) columnNames.next(); // Add the key value to the last record field if (column_name.equals(keyField)) record.setValueAt( record.getRecordLength() - 1, dbTransactionClient.getProperty(column_name)); if (showKeyField || !column_name.equals(keyField)) { record.setValueAt(fieldIndex++, dbTransactionClient.getProperty(column_name)); } } }
/** check whether therer is any loaded value */ public boolean nextRowValue() throws KExceptionClass { return dbTransactionClient.fetch(); }
public boolean isFieldNumeric(int columnIndex) throws KExceptionClass { return (dbTransactionClient.isColumnNumeric(columnIndex)); }
/** get related dbfield name via displayFieldName name */ public int getFieldType2(int columnIndex) throws KExceptionClass { return (dbTransactionClient.getColumnType(columnIndex)); }