@Override public int getNumColumns() { return table.fields().length; }
public <U> RowReader<U> getReaderForField(Field<?> field) { Field<?>[] fields = table.fields(); for (int idx = 0; idx < fields.length; idx++) { Field<?> f = fields[idx]; if (f == field) return new SimpleRowReader<>(); } throw new IllegalArgumentException("Unknown field"); }
@Override public T readResult(Record record, int offset) { T toReturn; try { toReturn = constructor.newInstance(); } catch (Exception e) { throw new IllegalArgumentException("Cannot construct class " + table.getRecordType().getName()); } Field<?>[] fields = table.fields(); for (int idx = 0; idx < fields.length; idx++) { Field<?> f = fields[idx]; copyValueIntoRecord(toReturn, record, f, idx); } return toReturn; }
public int getIndexForField(Field<?> field) { Field<?>[] fields = table.fields(); int colIndex = 0; for (int idx = 0; idx < fields.length; idx++) { Field<?> f = fields[idx]; if (f == field) return colIndex; colIndex += getReaderForField(field).getNumColumns(); } throw new IllegalArgumentException("Unknown field"); } }
private void findMetamodelGetters(Schema schema) { for (Table<?> table: schema.getTables()) { String recordClassName = Type.getInternalName(table.getRecordType()); for (Field<?> field: table.fields()) { String name = field.getName(); String getterName = "get" + name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase(); MethodSignature methodSig = new MethodSignature( recordClassName, getterName, Type.getMethodDescriptor(Type.getType(field.getType()))); fieldMethods.put(methodSig, field); } } }
@Override public ColumnExpressions<?> handleArg(int argIndex, Type argType) throws TypedValueVisitorException { if (argIndex < numLambdaCapturedArgs) { // Currently, we only support parameters of a few small simple types. // We should also support more complex types (e.g. entities) and allow // fields/methods of those entities to be called in the query (code // motion will be used to push those field accesses or method calls // outside the query where they will be evaluated and then passed in // as a parameter) if (!ALLOWED_QUERY_PARAMETER_TYPES.contains(argType)) throw new TypedValueVisitorException("Accessing a field with unhandled type"); return ColumnExpressions.singleColumn(new SimpleRowReader<>(), DSL.val(lambda.getCapturedArg(argIndex))); } else { Table<?> table = fromList.get(argIndex - numLambdaCapturedArgs); // TODO: Should this return a single column or all the columns of the table? ColumnExpressions<?> columns = new ColumnExpressions<>(new TableRowReader<>(table)); for (Field<?> field: table.fields()) columns.columns.add(field); return columns; } }
@Override public final InsertImpl columns(Field<?>... f) { this.fields = (f == null || f.length == 0) ? into.fields() : f; return this; }
InsertSelectQueryImpl(Configuration configuration, Table<?> into, Field<?>[] fields, Select<?> select) { super(configuration); this.into = into; this.fields = (fields == null || fields.length == 0) ? into.fields() : fields; this.select = select; }
@SuppressWarnings("unchecked") private Field<Date> getRemoveField(Table<?> table) { for (String fieldName : TIMESTAMP_FIELD_NAME_PRECEDENCE) { for (Field<?> field : table.fields()) { if (fieldName.equals(field.getName())) { return (Field<Date>) field; } } } return null; }
@SuppressWarnings("unchecked") private Field<Long> getIdField(Table<?> table) { for (Field<?> field : table.fields()) { if (field.getName().equals("id")) { return (Field<Long>) field; } } return null; }
@Override final Fields<R> fields0() { return new Fields<R>(table.fields()); } }
QueryPartList<Field<?>> getUpsertFields() { if (upsertFields == null) upsertFields = new QueryPartList<Field<?>>(table.fields()); return upsertFields; }
InsertImpl(Configuration configuration, Table<R> into, Collection<? extends Field<?>> fields) { super(new InsertQueryImpl<R>(configuration, into)); this.into = into; this.fields = (fields == null || fields.size() == 0) ? into.fields() : fields.toArray(new Field[fields.size()]); }
@Override final Fields<R> fields0() { return new Fields<R>(table.fields()); } }
/** * Create a new record */ @SuppressWarnings("unchecked") static final <R extends Record> RecordDelegate<R> newRecord(boolean fetched, Table<R> type, Configuration configuration) { return (RecordDelegate<R>) newRecord(fetched, type.getRecordType(), type.fields(), configuration); }
@Override final Fields<Record> fields0() { List<Field<?>> fields = new ArrayList<Field<?>>(); for (Table<?> table : tables) for (Field<?> field : table.fields()) fields.add(DSL.field(DSL.name(field.getName()), field.getDataType())); return new Fields<Record>(fields); }
RenamedTable(Table<R> delegate, String rename) { super(rename, delegate.getSchema()); for (Field<?> field : delegate.fields()) { createField(field.getName(), field.getDataType(), this); } } }
@Override public PageResult<T> fetch(PageResult<T> page, Stream<Condition> conditions, SortField<?>... sorts) { Condition c = conditions.reduce((acc, item) -> acc.and(item)).orElse(DSL.trueCondition()); return fetch(page, e -> { return e.select(table.fields()).from(table).where(c).orderBy(sorts); }, entityClass); }
@Override public final <Z extends Record> Result<Z> into(Table<Z> table) { Result<Z> list = new ResultImpl<Z>(configuration(), table.fields()); for (R record : this) list.add(record.into(table)); return list; }