[#4152] Add <T> Field<T> TableLike.field( { String | int }, { Class<T>, DataType<T>, Field<T> } )
This commit is contained in:
parent
8c4839702b
commit
b423fe316b
@ -81,6 +81,24 @@ public interface RecordType<R extends Record> {
|
||||
*/
|
||||
Field<?> field(String fieldName);
|
||||
|
||||
/**
|
||||
* Get a specific field from this record type coerced to <code>type</code>.
|
||||
*
|
||||
* @param fieldName The field to fetch
|
||||
* @param type The type to coerce the resulting field to
|
||||
* @return The field with the given name
|
||||
*/
|
||||
<T> Field<T> field(String fieldName, Class<T> type);
|
||||
|
||||
/**
|
||||
* Get a specific field from this record type coerced to <code>dataType</code>.
|
||||
*
|
||||
* @param fieldName The field to fetch
|
||||
* @param dataType The data type to coerce the resulting field to
|
||||
* @return The field with the given name
|
||||
*/
|
||||
<T> Field<T> field(String fieldName, DataType<T> dataType);
|
||||
|
||||
/**
|
||||
* Get a specific field from this record type.
|
||||
*
|
||||
@ -89,6 +107,24 @@ public interface RecordType<R extends Record> {
|
||||
*/
|
||||
Field<?> field(int fieldIndex);
|
||||
|
||||
/**
|
||||
* Get a specific field from this record type coerced to <code>type</code>.
|
||||
*
|
||||
* @param fieldIndex The field's index of the field to fetch
|
||||
* @param type The type to coerce the resulting field to
|
||||
* @return The field with the given name
|
||||
*/
|
||||
<T> Field<T> field(int fieldIndex, Class<T> type);
|
||||
|
||||
/**
|
||||
* Get a specific field from this record type coerced to <code>dataType</code>.
|
||||
*
|
||||
* @param fieldIndex The field's index of the field to fetch
|
||||
* @param dataType The data type to coerce the resulting field to
|
||||
* @return The field with the given name
|
||||
*/
|
||||
<T> Field<T> field(int fieldIndex, DataType<T> dataType);
|
||||
|
||||
/**
|
||||
* Get all fields from this record type.
|
||||
*
|
||||
|
||||
@ -96,6 +96,20 @@ public interface Result<R extends Record> extends List<R>, Attachable {
|
||||
*/
|
||||
Field<?> field(String name);
|
||||
|
||||
/**
|
||||
* Get a specific field from this Result, coerced to <code>type</code>.
|
||||
*
|
||||
* @see Row#field(String, Class)
|
||||
*/
|
||||
<T> Field<T> field(String name, Class<T> type);
|
||||
|
||||
/**
|
||||
* Get a specific field from this Result, coerced to <code>dataType</code>.
|
||||
*
|
||||
* @see Row#field(String, DataType)
|
||||
*/
|
||||
<T> Field<T> field(String name, DataType<T> dataType);
|
||||
|
||||
/**
|
||||
* Get a specific field from this Result.
|
||||
*
|
||||
@ -103,6 +117,20 @@ public interface Result<R extends Record> extends List<R>, Attachable {
|
||||
*/
|
||||
Field<?> field(int index);
|
||||
|
||||
/**
|
||||
* Get a specific field from this Result, coerced to <code>type</code>.
|
||||
*
|
||||
* @see Row#field(int, Class)
|
||||
*/
|
||||
<T> Field<T> field(int index, Class<T> type);
|
||||
|
||||
/**
|
||||
* Get a specific field from this Result, coerced to <code>dataType</code>.
|
||||
*
|
||||
* @see Row#field(int, DataType)
|
||||
*/
|
||||
<T> Field<T> field(int index, DataType<T> dataType);
|
||||
|
||||
/**
|
||||
* Get all fields from this Result.
|
||||
*
|
||||
|
||||
@ -77,6 +77,24 @@ public interface Row extends QueryPart {
|
||||
*/
|
||||
Field<?> field(String fieldName);
|
||||
|
||||
/**
|
||||
* Get a specific field from this row and coerce it to <code>type</code>.
|
||||
*
|
||||
* @param fieldName The field to fetch
|
||||
* @param type The type to coerce the resulting field to
|
||||
* @return The field with the given name
|
||||
*/
|
||||
<T> Field<T> field(String fieldName, Class<T> type);
|
||||
|
||||
/**
|
||||
* Get a specific field from this row and coerce it to <code>dataType</code>.
|
||||
*
|
||||
* @param fieldName The field to fetch
|
||||
* @param dataType The type to coerce the resulting field to
|
||||
* @return The field with the given name
|
||||
*/
|
||||
<T> Field<T> field(String fieldName, DataType<T> dataType);
|
||||
|
||||
/**
|
||||
* Get a specific field from this row.
|
||||
*
|
||||
@ -85,6 +103,24 @@ public interface Row extends QueryPart {
|
||||
*/
|
||||
Field<?> field(int fieldIndex);
|
||||
|
||||
/**
|
||||
* Get a specific field from this row and coerce it to <code>type</code>.
|
||||
*
|
||||
* @param fieldIndex The field's index of the field to fetch
|
||||
* @param type The type to coerce the resulting field to
|
||||
* @return The field with the given name
|
||||
*/
|
||||
<T> Field<T> field(int fieldIndex, Class<T> type);
|
||||
|
||||
/**
|
||||
* Get a specific field from this row and coerce it to <code>dataType</code>.
|
||||
*
|
||||
* @param fieldIndex The field's index of the field to fetch
|
||||
* @param dataType The type to coerce the resulting field to
|
||||
* @return The field with the given name
|
||||
*/
|
||||
<T> Field<T> field(int fieldIndex, DataType<T> dataType);
|
||||
|
||||
/**
|
||||
* Get all fields from this row.
|
||||
*
|
||||
|
||||
@ -67,6 +67,21 @@ public interface TableLike<R extends Record> extends QueryPart {
|
||||
*/
|
||||
Field<?> field(String name);
|
||||
|
||||
/**
|
||||
* Get a specific field from this Record and coerce it to <code>type</code>.
|
||||
*
|
||||
* @see Row#field(String, Class)
|
||||
*/
|
||||
<T> Field<T> field(String name, Class<T> type);
|
||||
|
||||
/**
|
||||
* Get a specific field from this Record and coerce it to
|
||||
* <code>dataType</code>.
|
||||
*
|
||||
* @see Row#field(String, DataType)
|
||||
*/
|
||||
<T> Field<T> field(String name, DataType<T> dataType);
|
||||
|
||||
/**
|
||||
* Get a specific field from this Record.
|
||||
*
|
||||
@ -74,6 +89,21 @@ public interface TableLike<R extends Record> extends QueryPart {
|
||||
*/
|
||||
Field<?> field(int index);
|
||||
|
||||
/**
|
||||
* Get a specific field from this Record and coerce it to <code>type</code>.
|
||||
*
|
||||
* @see Row#field(int, Class)
|
||||
*/
|
||||
<T> Field<T> field(int index, Class<T> type);
|
||||
|
||||
/**
|
||||
* Get a specific field from this Record and coerce it to
|
||||
* <code>dataType</code>.
|
||||
*
|
||||
* @see Row#field(int, DataType)
|
||||
*/
|
||||
<T> Field<T> field(int index, DataType<T> dataType);
|
||||
|
||||
/**
|
||||
* Get all fields from this Record.
|
||||
*
|
||||
|
||||
@ -98,9 +98,9 @@ abstract class AbstractTable<R extends Record> extends AbstractQueryPart impleme
|
||||
private static final long serialVersionUID = 3155496238969274871L;
|
||||
private static final Clause[] CLAUSES = { TABLE };
|
||||
|
||||
private final Schema schema;
|
||||
private final String name;
|
||||
private final String comment;
|
||||
private final Schema tableschema;
|
||||
private final String tablename;
|
||||
private final String tablecomment;
|
||||
|
||||
AbstractTable(String name) {
|
||||
this(name, null, null);
|
||||
@ -113,9 +113,9 @@ abstract class AbstractTable<R extends Record> extends AbstractQueryPart impleme
|
||||
AbstractTable(String name, Schema schema, String comment) {
|
||||
super();
|
||||
|
||||
this.schema = schema;
|
||||
this.name = name;
|
||||
this.comment = comment;
|
||||
this.tableschema = schema;
|
||||
this.tablename = name;
|
||||
this.tablecomment = comment;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@ -165,11 +165,31 @@ abstract class AbstractTable<R extends Record> extends AbstractQueryPart impleme
|
||||
return fieldsRow().field(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(String name, Class<T> type) {
|
||||
return fieldsRow().field(name, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(String name, DataType<T> dataType) {
|
||||
return fieldsRow().field(name, dataType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<?> field(int index) {
|
||||
return fieldsRow().field(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(int index, Class<T> type) {
|
||||
return fieldsRow().field(index, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(int index, DataType<T> dataType) {
|
||||
return fieldsRow().field(index, dataType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<?>[] fields() {
|
||||
return fieldsRow().fields();
|
||||
@ -196,17 +216,17 @@ abstract class AbstractTable<R extends Record> extends AbstractQueryPart impleme
|
||||
|
||||
@Override
|
||||
public final Schema getSchema() {
|
||||
return schema;
|
||||
return tableschema;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getName() {
|
||||
return name;
|
||||
return tablename;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getComment() {
|
||||
return comment;
|
||||
return tablecomment;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -811,7 +831,7 @@ abstract class AbstractTable<R extends Record> extends AbstractQueryPart impleme
|
||||
// [#2144] Non-equality can be decided early, without executing the
|
||||
// rather expensive implementation of AbstractQueryPart.equals()
|
||||
if (that instanceof AbstractTable) {
|
||||
if (StringUtils.equals(name, (((AbstractTable<?>) that).name))) {
|
||||
if (StringUtils.equals(tablename, (((AbstractTable<?>) that).tablename))) {
|
||||
return super.equals(that);
|
||||
}
|
||||
|
||||
@ -826,6 +846,6 @@ abstract class AbstractTable<R extends Record> extends AbstractQueryPart impleme
|
||||
|
||||
// [#1938] This is a much more efficient hashCode() implementation
|
||||
// compared to that of standard QueryParts
|
||||
return name.hashCode();
|
||||
return tablename.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,6 +116,18 @@ class Fields<R extends Record> extends AbstractQueryPart implements RecordType<R
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(String fieldName, Class<T> type) {
|
||||
Field<?> result = field(fieldName);
|
||||
return result == null ? null : result.coerce(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(String fieldName, DataType<T> dataType) {
|
||||
Field<?> result = field(fieldName);
|
||||
return result == null ? null : result.coerce(dataType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<?> field(int index) {
|
||||
if (index >= 0 && index < fields.length) {
|
||||
@ -125,6 +137,18 @@ class Fields<R extends Record> extends AbstractQueryPart implements RecordType<R
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(int fieldIndex, Class<T> type) {
|
||||
Field<?> result = field(fieldIndex);
|
||||
return result == null ? null : result.coerce(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(int fieldIndex, DataType<T> dataType) {
|
||||
Field<?> result = field(fieldIndex);
|
||||
return result == null ? null : result.coerce(dataType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<?>[] fields() {
|
||||
return fields;
|
||||
|
||||
@ -79,6 +79,7 @@ import org.jooq.AttachableInternal;
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Converter;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.DataType;
|
||||
import org.jooq.EnumType;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.ForeignKey;
|
||||
@ -206,11 +207,31 @@ class ResultImpl<R extends Record> implements Result<R>, AttachableInternal {
|
||||
return fields.field(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(String name, Class<T> type) {
|
||||
return fields.field(name, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(String name, DataType<T> dataType) {
|
||||
return fields.field(name, dataType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<?> field(int index) {
|
||||
return fields.field(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(int index, Class<T> type) {
|
||||
return fields.field(index, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(int index, DataType<T> dataType) {
|
||||
return fields.field(index, dataType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<?>[] fields() {
|
||||
return fields.fields().clone();
|
||||
|
||||
@ -49,7 +49,16 @@ import java.util.Collection;
|
||||
|
||||
import javax.annotation.Generated;
|
||||
|
||||
import org.jooq.BetweenAndStepN;
|
||||
import org.jooq.BetweenAndStep1;
|
||||
import org.jooq.BetweenAndStep2;
|
||||
import org.jooq.BetweenAndStep3;
|
||||
import org.jooq.BetweenAndStep4;
|
||||
import org.jooq.BetweenAndStep5;
|
||||
import org.jooq.BetweenAndStep6;
|
||||
import org.jooq.BetweenAndStep7;
|
||||
import org.jooq.BetweenAndStep8;
|
||||
import org.jooq.BetweenAndStep9;
|
||||
import org.jooq.BetweenAndStep10;
|
||||
import org.jooq.BetweenAndStep11;
|
||||
import org.jooq.BetweenAndStep12;
|
||||
@ -60,18 +69,9 @@ import org.jooq.BetweenAndStep16;
|
||||
import org.jooq.BetweenAndStep17;
|
||||
import org.jooq.BetweenAndStep18;
|
||||
import org.jooq.BetweenAndStep19;
|
||||
import org.jooq.BetweenAndStep2;
|
||||
import org.jooq.BetweenAndStep20;
|
||||
import org.jooq.BetweenAndStep21;
|
||||
import org.jooq.BetweenAndStep22;
|
||||
import org.jooq.BetweenAndStep3;
|
||||
import org.jooq.BetweenAndStep4;
|
||||
import org.jooq.BetweenAndStep5;
|
||||
import org.jooq.BetweenAndStep6;
|
||||
import org.jooq.BetweenAndStep7;
|
||||
import org.jooq.BetweenAndStep8;
|
||||
import org.jooq.BetweenAndStep9;
|
||||
import org.jooq.BetweenAndStepN;
|
||||
import org.jooq.Clause;
|
||||
import org.jooq.Comparator;
|
||||
import org.jooq.Condition;
|
||||
@ -81,6 +81,14 @@ import org.jooq.Field;
|
||||
import org.jooq.QuantifiedSelect;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Record1;
|
||||
import org.jooq.Record2;
|
||||
import org.jooq.Record3;
|
||||
import org.jooq.Record4;
|
||||
import org.jooq.Record5;
|
||||
import org.jooq.Record6;
|
||||
import org.jooq.Record7;
|
||||
import org.jooq.Record8;
|
||||
import org.jooq.Record9;
|
||||
import org.jooq.Record10;
|
||||
import org.jooq.Record11;
|
||||
import org.jooq.Record12;
|
||||
@ -91,20 +99,20 @@ import org.jooq.Record16;
|
||||
import org.jooq.Record17;
|
||||
import org.jooq.Record18;
|
||||
import org.jooq.Record19;
|
||||
import org.jooq.Record2;
|
||||
import org.jooq.Record20;
|
||||
import org.jooq.Record21;
|
||||
import org.jooq.Record22;
|
||||
import org.jooq.Record3;
|
||||
import org.jooq.Record4;
|
||||
import org.jooq.Record5;
|
||||
import org.jooq.Record6;
|
||||
import org.jooq.Record7;
|
||||
import org.jooq.Record8;
|
||||
import org.jooq.Record9;
|
||||
import org.jooq.Result;
|
||||
import org.jooq.Row;
|
||||
import org.jooq.RowN;
|
||||
import org.jooq.Row1;
|
||||
import org.jooq.Row2;
|
||||
import org.jooq.Row3;
|
||||
import org.jooq.Row4;
|
||||
import org.jooq.Row5;
|
||||
import org.jooq.Row6;
|
||||
import org.jooq.Row7;
|
||||
import org.jooq.Row8;
|
||||
import org.jooq.Row9;
|
||||
import org.jooq.Row10;
|
||||
import org.jooq.Row11;
|
||||
import org.jooq.Row12;
|
||||
@ -115,18 +123,10 @@ import org.jooq.Row16;
|
||||
import org.jooq.Row17;
|
||||
import org.jooq.Row18;
|
||||
import org.jooq.Row19;
|
||||
import org.jooq.Row2;
|
||||
import org.jooq.Row20;
|
||||
import org.jooq.Row21;
|
||||
import org.jooq.Row22;
|
||||
import org.jooq.Row3;
|
||||
import org.jooq.Row4;
|
||||
import org.jooq.Row5;
|
||||
import org.jooq.Row6;
|
||||
import org.jooq.Row7;
|
||||
import org.jooq.Row8;
|
||||
import org.jooq.Row9;
|
||||
import org.jooq.RowN;
|
||||
import org.jooq.Result;
|
||||
import org.jooq.Select;
|
||||
|
||||
/**
|
||||
@ -198,7 +198,7 @@ implements
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx
|
||||
|
||||
xx [/pro] */
|
||||
context.sql('(');
|
||||
context.sql("(");
|
||||
|
||||
String separator = "";
|
||||
for (Field<?> field : fields.fields) {
|
||||
@ -208,7 +208,7 @@ implements
|
||||
separator = ", ";
|
||||
}
|
||||
|
||||
context.sql(')');
|
||||
context.sql(")");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -235,11 +235,31 @@ implements
|
||||
return fields.field(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(String name, Class<T> type) {
|
||||
return fields.field(name, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(String name, DataType<T> dataType) {
|
||||
return fields.field(name, dataType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<?> field(int index) {
|
||||
return fields.field(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(int index, Class<T> type) {
|
||||
return fields.field(index, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(int index, DataType<T> dataType) {
|
||||
return fields.field(index, dataType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<?>[] fields() {
|
||||
return fields.fields();
|
||||
|
||||
@ -60,6 +60,7 @@ import org.jooq.Condition;
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Converter;
|
||||
import org.jooq.Cursor;
|
||||
import org.jooq.DataType;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.ForeignKey;
|
||||
import org.jooq.GroupField;
|
||||
@ -2948,11 +2949,31 @@ class SelectImpl<R extends Record, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
return getDelegate().field(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(String name, Class<T> type) {
|
||||
return getDelegate().field(name, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(String name, DataType<T> dataType) {
|
||||
return getDelegate().field(name, dataType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<?> field(int index) {
|
||||
return getDelegate().field(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(int index, Class<T> type) {
|
||||
return getDelegate().field(index, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(int index, DataType<T> dataType) {
|
||||
return getDelegate().field(index, dataType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<?>[] fields() {
|
||||
return getDelegate().fields();
|
||||
|
||||
@ -271,11 +271,31 @@ class SelectQueryImpl<R extends Record> extends AbstractResultQuery<R> implement
|
||||
return asTable().field(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(String name, Class<T> type) {
|
||||
return asTable().field(name, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(String name, DataType<T> dataType) {
|
||||
return asTable().field(name, dataType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<?> field(int index) {
|
||||
return asTable().field(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(int index, Class<T> type) {
|
||||
return asTable().field(index, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Field<T> field(int index, DataType<T> dataType) {
|
||||
return asTable().field(index, dataType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Field<?>[] fields() {
|
||||
return asTable().fields();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user