[#2112] Add Row.types() and Row.dataTypes() as a convenience
This commit is contained in:
parent
7d00425231
commit
33ff9de311
@ -1134,6 +1134,7 @@ class Rows extends Generators {
|
||||
import org.jooq.BindContext;
|
||||
import org.jooq.Comparator;
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.DataType;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.Record;
|
||||
«FOR degree : (1..Constants::MAX_ROW_DEGREE)»
|
||||
@ -1229,17 +1230,39 @@ class Rows extends Generators {
|
||||
|
||||
@Override
|
||||
public final Field<?>[] fields() {
|
||||
return fields.clone();
|
||||
return fields.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int indexOf(Field<?> field) {
|
||||
return new FieldList(fields).indexOf(field);
|
||||
return new FieldList(fields).indexOf(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int indexOf(String fieldName) {
|
||||
return new FieldList(fields).indexOf(fieldName);
|
||||
return new FieldList(fields).indexOf(fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Class<?>[] types() {
|
||||
Class<?>[] result = new Class[fields.length];
|
||||
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
result[i] = fields[i].getType();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final DataType<?>[] dataTypes() {
|
||||
DataType<?>[] result = new DataType[fields.length];
|
||||
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
result[i] = fields[i].getDataType();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
«FOR degree : (1..Constants::MAX_ROW_DEGREE)»
|
||||
|
||||
@ -2122,7 +2145,7 @@ class Rows extends Generators {
|
||||
// ------------------------------------------------------------------------
|
||||
@Override
|
||||
public final Iterator<Field<?>> iterator() {
|
||||
return asList(fields).iterator();
|
||||
return asList(fields).iterator();
|
||||
}
|
||||
}
|
||||
''');
|
||||
|
||||
@ -104,6 +104,22 @@ public interface Row extends QueryPart, Iterable<Field<?>> {
|
||||
*/
|
||||
int indexOf(String fieldName);
|
||||
|
||||
/**
|
||||
* Get an array of types for this row.
|
||||
* <p>
|
||||
* Entries in the resulting array correspond to {@link Field#getType()} for
|
||||
* the corresponding <code>Field</code> in {@link #fields()}
|
||||
*/
|
||||
Class<?>[] types();
|
||||
|
||||
/**
|
||||
* Get an array of data types for this row.
|
||||
* <p>
|
||||
* Entries in the resulting array correspond to {@link Field#getDataType()}
|
||||
* for the corresponding <code>Field</code> in {@link #fields()}
|
||||
*/
|
||||
DataType<?>[] dataTypes();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// [NOT] NULL predicates
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@ -141,22 +141,6 @@ abstract class AbstractRecord extends AbstractStore implements Record {
|
||||
return fields.clone();
|
||||
}
|
||||
|
||||
final Class<?>[] getTypes() {
|
||||
return getTypes(this);
|
||||
}
|
||||
|
||||
static final Class<?>[] getTypes(Record record) {
|
||||
int size = record.size();
|
||||
Class<?>[] result = new Class[size];
|
||||
Field<?>[] fields = record.fields();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
result[i] = fields[i].getType();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// XXX: Record API
|
||||
// ------------------------------------------------------------------------
|
||||
@ -942,8 +926,8 @@ abstract class AbstractRecord extends AbstractStore implements Record {
|
||||
throw new ClassCastException(String.format("Trying to compare incomparable records (wrong degree):\n%s\n%s", this, that));
|
||||
}
|
||||
|
||||
Class<?>[] thisTypes = getTypes();
|
||||
Class<?>[] thatTypes = getTypes(that);
|
||||
Class<?>[] thisTypes = this.fieldsRow().types();
|
||||
Class<?>[] thatTypes = that.fieldsRow().types();
|
||||
|
||||
if (!asList(thisTypes).equals(asList(thatTypes))) {
|
||||
throw new ClassCastException(String.format("Trying to compare incomparable records (type mismatch):\n%s\n%s", this, that));
|
||||
|
||||
@ -71,6 +71,7 @@ import org.jooq.BetweenAndStepN;
|
||||
import org.jooq.BindContext;
|
||||
import org.jooq.Comparator;
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.DataType;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Record1;
|
||||
@ -223,17 +224,39 @@ implements
|
||||
|
||||
@Override
|
||||
public final Field<?>[] fields() {
|
||||
return fields.clone();
|
||||
return fields.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int indexOf(Field<?> field) {
|
||||
return new FieldList(fields).indexOf(field);
|
||||
return new FieldList(fields).indexOf(field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int indexOf(String fieldName) {
|
||||
return new FieldList(fields).indexOf(fieldName);
|
||||
return new FieldList(fields).indexOf(fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Class<?>[] types() {
|
||||
Class<?>[] result = new Class[fields.length];
|
||||
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
result[i] = fields[i].getType();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final DataType<?>[] dataTypes() {
|
||||
DataType<?>[] result = new DataType[fields.length];
|
||||
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
result[i] = fields[i].getDataType();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -9516,6 +9539,6 @@ implements
|
||||
// ------------------------------------------------------------------------
|
||||
@Override
|
||||
public final Iterator<Field<?>> iterator() {
|
||||
return asList(fields).iterator();
|
||||
return asList(fields).iterator();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user