/** @throws ReadDriverException TODO */ public void order() throws ReadDriverException { int rowCount = (int) dataSource.getRowCount(); columnCache = new Value[rowCount][fieldIndexes.length]; for (int field = 0; field < fieldIndexes.length; field++) { for (int i = 0; i < rowCount; i++) { columnCache[i][field] = dataSource.getFieldValue(i, fieldIndexes[field]); } } TreeSet set = new TreeSet(new SortComparator()); for (int i = 0; i < dataSource.getRowCount(); i++) { set.add(new Integer(i)); } orderIndexes = new long[(int) dataSource.getRowCount()]; int index = 0; Iterator it = set.iterator(); while (it.hasNext()) { Integer integer = (Integer) it.next(); orderIndexes[index] = integer.intValue(); index++; } }
/** * DOCUMENT ME! * * @param ret * @param fieldNames * @param types * @throws ReadDriverException TODO */ public OrderedDataSource(OperationDataSource ret, String[] fieldNames, int[] types) throws ReadDriverException { this.dataSource = ret; fieldIndexes = new int[fieldNames.length]; for (int i = 0; i < fieldNames.length; i++) { fieldIndexes[i] = dataSource.getFieldIndexByName(fieldNames[i]); } orders = new int[types.length]; for (int i = 0; i < types.length; i++) { orders[i] = (types[i] == SelectAdapter.ORDER_ASC) ? 1 : -1; } }
/** @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldType(int) */ public int getFieldType(int i) throws ReadDriverException { return dataSource.getFieldType(i); }
/** @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getRowCount() */ public long getRowCount() throws ReadDriverException { return dataSource.getRowCount(); }
/** @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldName(int) */ public String getFieldName(int fieldId) throws ReadDriverException { return dataSource.getFieldName(fieldId); }
/** @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldCount() */ public int getFieldCount() throws ReadDriverException { return dataSource.getFieldCount(); }
/** @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldValue(long, int) */ public Value getFieldValue(long rowIndex, int fieldId) throws ReadDriverException { return dataSource.getFieldValue(orderIndexes[(int) rowIndex], fieldId); }
/** @see com.hardcode.gdbms.engine.data.DataSource#getFieldIndexByName(java.lang.String) */ public int getFieldIndexByName(String fieldName) throws ReadDriverException { return dataSource.getFieldIndexByName(fieldName); }
/** @see com.hardcode.gdbms.engine.data.DataSource#getMemento() */ public Memento getMemento() throws MementoException { return new OperationLayerMemento(getName(), new Memento[] {dataSource.getMemento()}, getSQL()); }
/** @see com.hardcode.gdbms.engine.data.DataSource#stop() */ public void stop() throws ReadDriverException { dataSource.stop(); }