/** * Extract a list of values from a set of records given some fields */ private static <R extends Record> List<Object> extractValues(Collection<? extends R> records, TableField<R, ?> field2) { List<Object> result = new ArrayList<Object>(records.size()); for (R record : records) result.add(record.get(field2)); return result; }
@Override public final Object fetchOne(Name fieldName) { R record = fetchOne(); return record == null ? null : record.get(fieldName); }
private final <K, E> Map<K, E> intoMap0(int kIndex, RecordMapper<? super R, E> mapper) { Map<K, E> map = new LinkedHashMap<K, E>(); for (R record : this) if (map.put((K) record.get(kIndex), mapper.map(record)) != null) throw new InvalidResultException("Key " + record.get(kIndex) + " is not unique in Result for " + this); return map; }
/** * Type-safely copy a value from one record to another */ static final <T> void setValue(Record target, Field<T> targetField, Record source, Field<?> sourceField) { setValue(target, targetField, source.get(sourceField)); }
@Override public final Object fetchOne(int fieldIndex) { R record = fetchOne(); return record == null ? null : record.get(fieldIndex); }
@Override public final Object fetchAny(Name fieldName) { R record = fetchAny(); return record == null ? null : record.get(fieldName); }
private final <K> Map<K, Result<R>> intoGroups0(int keyFieldIndex) { Map<K, Result<R>> map = new LinkedHashMap<K, Result<R>>(); for (R record : this) { K val = (K) record.get(keyFieldIndex); Result<R> result = map.get(val); if (result == null) map.put(val, result = new ResultImpl<R>(configuration, fields)); result.add(record); } return map; }
@Override public String getString(int parameterIndex) throws SQLException { String value = outParameters().get(translate(parameterIndex), String.class); resultWasNull = value == null; return value; }
@Override public boolean getBoolean(int parameterIndex) throws SQLException { Boolean value = outParameters().get(translate(parameterIndex), Boolean.class); resultWasNull = value == null; return value == null ? false : value; }
@Override public byte getByte(int parameterIndex) throws SQLException { Byte value = outParameters().get(translate(parameterIndex), Byte.class); resultWasNull = value == null; return value == null ? (byte) 0 : value; }
@Override public int getInt(int parameterIndex) throws SQLException { Integer value = outParameters().get(translate(parameterIndex), Integer.class); resultWasNull = value == null; return value == null ? 0 : value; }
@Override public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { BigDecimal value = outParameters().get(translate(parameterIndex), BigDecimal.class); resultWasNull = value == null; return value; } @Override
@Override public byte[] getBytes(int parameterIndex) throws SQLException { byte[] value = outParameters().get(translate(parameterIndex), byte[].class); resultWasNull = value == null; return value; }
@Override public Date getDate(int parameterIndex, Calendar cal) throws SQLException { Date value = outParameters().get(translate(parameterIndex), Date.class); resultWasNull = value == null; return value; }
@Override public Object getObject(int parameterIndex) throws SQLException { Object value = outParameters().get(translate(parameterIndex)); resultWasNull = value == null; return value; }
@Override public float getFloat(int parameterIndex) throws SQLException { Float value = outParameters().get(translate(parameterIndex), Float.class); resultWasNull = value == null; return value == null ? 0.0f : value; }
@Override public Date getDate(int parameterIndex) throws SQLException { Date value = outParameters().get(translate(parameterIndex), Date.class); resultWasNull = value == null; return value; }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public final void setRecord(R record) { for (int i = 0; i < record.size(); i++) if (record.changed(i)) addValue((Field) record.field(i), record.get(i)); }
private <T> T get(String columnLabel, Class<T> type) throws SQLException { checkInRange(); Converter<?, ?> converter = Converters.inverse(field(columnLabel).getConverter()); T value = Convert.convert(result.get(index - 1).get(columnLabel, converter), type); wasNull = (value == null); return value; }
private <T> T get(int columnIndex, Class<T> type) throws SQLException { checkInRange(); Converter<?, ?> converter = Converters.inverse(field(columnIndex).getConverter()); T value = Convert.convert(result.get(index - 1).get(columnIndex - 1, converter), type); wasNull = (value == null); return value; }