[jOOQ/jOOQ#12507] More nullability annotation fixes

This commit is contained in:
Lukas Eder 2021-10-15 15:32:49 +02:00
parent a01e67c9ef
commit 68d0a9de01
17 changed files with 120 additions and 101 deletions

View File

@ -12502,7 +12502,6 @@ public interface DSLContext extends Scope {
* @throws DataAccessException if something went wrong executing the query
* @throws TooManyRowsException if the query returned more than one record
*/
@Nullable
@Support
<T> T fetchValue(Table<? extends Record1<T>> table) throws DataAccessException, TooManyRowsException;
@ -12515,7 +12514,6 @@ public interface DSLContext extends Scope {
* @throws DataAccessException if something went wrong executing the query
* @throws TooManyRowsException if the query returned more than one record
*/
@Nullable
@Support
<T, R extends Record1<T>> T fetchValue(ResultQuery<R> query) throws DataAccessException, TooManyRowsException;
@ -12528,7 +12526,6 @@ public interface DSLContext extends Scope {
* @throws DataAccessException if something went wrong executing the query
* @throws TooManyRowsException if the query returned more than one record
*/
@Nullable
@Support
<T> T fetchValue(TableField<?, T> field) throws DataAccessException, TooManyRowsException;
@ -12540,7 +12537,6 @@ public interface DSLContext extends Scope {
* @return The value or <code>null</code>, if no record was found.
* @throws DataAccessException if something went wrong executing the query
*/
@Nullable
@Support
<T> T fetchValue(SelectField<T> field) throws DataAccessException;

View File

@ -61,7 +61,7 @@ public interface Fields {
* Get all fields known to this type.
*/
@NotNull
Field<?>[] fields();
Field<?> @NotNull [] fields();
/**
* Get all fields known to this type as a {@link Row}.
@ -193,8 +193,8 @@ public interface Fields {
* {@link #field(Field)}.
* @see #field(Field)
*/
@NotNull
Field<?>[] fields(Field<?>... fields);
@Nullable
Field<?> @NotNull [] fields(Field<?>... fields);
/**
* Get all fields known to this type, filtering by some unqualified field
@ -204,8 +204,8 @@ public interface Fields {
* via {@link #field(String)}.
* @see #field(String)
*/
@NotNull
Field<?>[] fields(String... names);
@Nullable
Field<?> @NotNull [] fields(String... names);
/**
* Get all fields known to this type, filtering by some qualified field
@ -215,8 +215,8 @@ public interface Fields {
* via {@link #field(Name)}.
* @see #field(Name)
*/
@NotNull
Field<?>[] fields(Name... names);
@Nullable
Field<?> @NotNull [] fields(Name... names);
/**
* Get all fields known to this type, filtering by some field indexes.
@ -225,8 +225,8 @@ public interface Fields {
* via {@link #field(int)}.
* @see #field(int)
*/
@NotNull
Field<?>[] fields(int... indexes);
@Nullable
Field<?> @NotNull [] fields(int... indexes);
/**
* Get a field's index from this type.
@ -262,7 +262,7 @@ public interface Fields {
* the corresponding <code>Field</code> in {@link #fields()}
*/
@NotNull
Class<?>[] types();
Class<?> @NotNull [] types();
/**
* Get the field type for a given field index, or <code>null</code> if no
@ -298,7 +298,7 @@ public interface Fields {
* for the corresponding <code>Field</code> in {@link #fields()}
*/
@NotNull
DataType<?>[] dataTypes();
DataType<?> @NotNull [] dataTypes();
/**
* Get the field data type for a given field index, or <code>null</code> if

View File

@ -85,7 +85,7 @@ public interface ForeignKey<R extends Record, O extends Record> extends Key<R> {
* @see #getKeyFields()
*/
@NotNull
TableField<O, ?>[] getKeyFieldsArray();
TableField<O, ?> @NotNull [] getKeyFieldsArray();
/**
* Fetch a parent record of a given record through this foreign key

View File

@ -653,7 +653,6 @@ public interface Formattable {
* @see <a
* href="http://www.jooq.org/xsd/jooq-export-3.10.0.xsd">http://www.jooq.org/xsd/jooq-export-3.10.0.xsd</a>
*/
@NotNull
<H extends ContentHandler> H intoXML(H handler) throws SAXException;
/**
@ -665,7 +664,6 @@ public interface Formattable {
* @see <a
* href="http://www.jooq.org/xsd/jooq-export-3.10.0.xsd">http://www.jooq.org/xsd/jooq-export-3.10.0.xsd</a>
*/
@NotNull
<H extends ContentHandler> H intoXML(H handler, XMLFormat format) throws SAXException;
}

View File

@ -72,7 +72,7 @@ public interface Key<R extends Record> extends Named {
* @see #getFields()
*/
@NotNull
TableField<R, ?>[] getFieldsArray();
TableField<R, ?> @NotNull [] getFieldsArray();
/**
* Get this <code>KEY</code> as a formal {@link Constraint} specification.

View File

@ -40,6 +40,7 @@ package org.jooq;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* A context object that provides information about a loader's current state to
@ -59,8 +60,8 @@ public interface LoaderContext {
/**
* The row that will be or has been processed.
*/
@NotNull @CheckReturnValue
Object[] row();
@Nullable @CheckReturnValue
Object @NotNull [] row();
/**
* A list of errors that might have happened during the load.

View File

@ -4415,8 +4415,7 @@ public interface ResultQuery<R extends Record> extends Fields, Query, Iterable<R
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(int, Class)
*/
@NotNull
<U> U[] fetchArray(int fieldIndex, Class<? extends U> type) throws DataAccessException;
<U> U @NotNull [] fetchArray(int fieldIndex, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return all values for a field index from the
@ -4429,8 +4428,7 @@ public interface ResultQuery<R extends Record> extends Fields, Query, Iterable<R
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(int, Converter)
*/
@NotNull
<U> U[] fetchArray(int fieldIndex, Converter<?, ? extends U> converter) throws DataAccessException;
<U> U @NotNull [] fetchArray(int fieldIndex, Converter<?, ? extends U> converter) throws DataAccessException;
/**
* Execute the query and return all values for a field name from the
@ -4464,8 +4462,7 @@ public interface ResultQuery<R extends Record> extends Fields, Query, Iterable<R
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(String, Converter)
*/
@NotNull
<U> U[] fetchArray(String fieldName, Class<? extends U> type) throws DataAccessException;
<U> U @NotNull [] fetchArray(String fieldName, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return all values for a field name from the
@ -4478,8 +4475,7 @@ public interface ResultQuery<R extends Record> extends Fields, Query, Iterable<R
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(String, Class)
*/
@NotNull
<U> U[] fetchArray(String fieldName, Converter<?, ? extends U> converter) throws DataAccessException;
<U> U @NotNull [] fetchArray(String fieldName, Converter<?, ? extends U> converter) throws DataAccessException;
/**
* Execute the query and return all values for a field name from the
@ -4513,8 +4509,7 @@ public interface ResultQuery<R extends Record> extends Fields, Query, Iterable<R
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(Name, Converter)
*/
@NotNull
<U> U[] fetchArray(Name fieldName, Class<? extends U> type) throws DataAccessException;
<U> U @NotNull [] fetchArray(Name fieldName, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return all values for a field name from the
@ -4527,8 +4522,7 @@ public interface ResultQuery<R extends Record> extends Fields, Query, Iterable<R
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(Name, Class)
*/
@NotNull
<U> U[] fetchArray(Name fieldName, Converter<?, ? extends U> converter) throws DataAccessException;
<U> U @NotNull [] fetchArray(Name fieldName, Converter<?, ? extends U> converter) throws DataAccessException;
/**
* Execute the query and return all values for a field from the generated
@ -4541,8 +4535,7 @@ public interface ResultQuery<R extends Record> extends Fields, Query, Iterable<R
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(Field)
*/
@NotNull
<T> T[] fetchArray(Field<T> field) throws DataAccessException;
<T> T @NotNull [] fetchArray(Field<T> field) throws DataAccessException;
/**
* Execute the query and return all values for a field from the generated
@ -4559,8 +4552,7 @@ public interface ResultQuery<R extends Record> extends Fields, Query, Iterable<R
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(Field, Class)
*/
@NotNull
<U> U[] fetchArray(Field<?> field, Class<? extends U> type) throws DataAccessException;
<U> U @NotNull [] fetchArray(Field<?> field, Class<? extends U> type) throws DataAccessException;
/**
* Execute the query and return all values for a field from the generated
@ -4573,8 +4565,7 @@ public interface ResultQuery<R extends Record> extends Fields, Query, Iterable<R
* @throws DataAccessException if something went wrong executing the query
* @see Result#intoArray(Field, Converter)
*/
@NotNull
<T, U> U[] fetchArray(Field<T> field, Converter<? super T, ? extends U> converter) throws DataAccessException;
<T, U> U @NotNull [] fetchArray(Field<T> field, Converter<? super T, ? extends U> converter) throws DataAccessException;
/**
* Fetch results into a custom mapper callback.

View File

@ -83,22 +83,22 @@ abstract class AbstractBindContext extends AbstractContext<BindContext> implemen
@Override
public final String peekAlias() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final String nextAlias() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final String render() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final String render(QueryPart part) {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override

View File

@ -396,6 +396,22 @@ package org.jooq.impl;

View File

@ -371,6 +371,22 @@ package org.jooq.impl;

View File

@ -68,6 +68,8 @@ import org.jooq.exception.DataAccessException;
import org.jooq.exception.DataTypeException;
import org.jooq.impl.QOM.UNotYetImplemented;
import org.jetbrains.annotations.NotNull;
/**
* A wrapped DML query ({@link Insert}, {@link Update}, {@link Delete}) that
* works like a {@link ResultQuery}.
@ -139,7 +141,7 @@ implements
@Override
public final Result<R> fetch() {
delegate.execute();
return getResult();
return (@NotNull Result<R>) getResult();
}
@Override

View File

@ -4257,8 +4257,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
@Override
public <T extends Number> T nextval(Sequence<T> sequence) {
Field<T> nextval = sequence.nextval();
return select(nextval).fetchOne(nextval);
return fetchValue(sequence.nextval());
}
@Override
@ -4278,8 +4277,7 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
@Override
public <T extends Number> T currval(Sequence<T> sequence) {
Field<T> currval = sequence.currval();
return select(currval).fetchOne(currval);
return fetchValue(sequence.currval());
}
// -------------------------------------------------------------------------

View File

@ -54,14 +54,14 @@ import org.jooq.Result;
class DefaultRecordContext extends AbstractScope implements RecordContext {
private final ExecuteType type;
private final Record[] records;
private final Record record;
Exception exception;
DefaultRecordContext(Configuration configuration, ExecuteType type, Record... records) {
DefaultRecordContext(Configuration configuration, ExecuteType type, Record record) {
super(configuration);
this.type = type;
this.records = records;
this.record = record;
}
@Override
@ -71,18 +71,17 @@ class DefaultRecordContext extends AbstractScope implements RecordContext {
@Override
public final Record record() {
return records != null && records.length > 0 ? records[0] : null;
return record;
}
@Override
public final Record[] batchRecords() {
return records;
return new Record[] { record };
}
@Override
public final RecordType<?> recordType() {
Record record = record();
return record != null ? new FieldsImpl<>(record.fields()) : null;
return new FieldsImpl<>(record.fields());
}
@Override
@ -92,13 +91,8 @@ class DefaultRecordContext extends AbstractScope implements RecordContext {
@Override
public String toString() {
if (records != null && records.length > 0) {
Result<Record> result = DSL.using(configuration).newResult(records[0].fields());
result.addAll(Arrays.asList(records));
return result.toString();
}
else {
return "No Records";
}
Result<Record> result = DSL.using(configuration).newResult(record.fields());
result.add(record);
return result.toString();
}
}

View File

@ -147,9 +147,6 @@ public class DefaultRecordUnmapper<E, R extends Record> implements RecordUnmappe
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public final R unmap(E source) {
if (source == null)
return null;
if (source instanceof Object[]) { Object[] array = (Object[]) source;
int size = rowType.size();
Record record = newRecord();
@ -164,7 +161,7 @@ public class DefaultRecordUnmapper<E, R extends Record> implements RecordUnmappe
return (R) record;
}
throw new MappingException("Object[] expected. Got: " + source.getClass());
throw new MappingException("Object[] expected. Got: " + klass(source));
}
}
@ -173,9 +170,6 @@ public class DefaultRecordUnmapper<E, R extends Record> implements RecordUnmappe
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public final R unmap(E source) {
if (source == null)
return null;
if (source instanceof Iterable) { Iterable<?> iterable = (Iterable<?>) source;
Iterator<?> it = iterable.iterator();
int size = rowType.size();
@ -191,7 +185,7 @@ public class DefaultRecordUnmapper<E, R extends Record> implements RecordUnmappe
return (R) record;
}
throw new MappingException("Iterable expected. Got: " + source.getClass());
throw new MappingException("Iterable expected. Got: " + klass(source));
}
}
@ -200,8 +194,6 @@ public class DefaultRecordUnmapper<E, R extends Record> implements RecordUnmappe
@SuppressWarnings("unchecked")
@Override
public R unmap(E source) {
if (source == null)
return null;
// [#1987] Distinguish between various types to load data from
// Maps are loaded using a {field-name -> value} convention
@ -219,7 +211,7 @@ public class DefaultRecordUnmapper<E, R extends Record> implements RecordUnmappe
return (R) record;
}
throw new MappingException("Map expected. Got: " + source.getClass());
throw new MappingException("Map expected. Got: " + klass(source));
}
}
@ -228,9 +220,6 @@ public class DefaultRecordUnmapper<E, R extends Record> implements RecordUnmappe
@SuppressWarnings("unchecked")
@Override
public R unmap(E source) {
if (source == null)
return null;
Record record = newRecord();
try {
@ -268,4 +257,8 @@ public class DefaultRecordUnmapper<E, R extends Record> implements RecordUnmappe
}
}
}
private static final String klass(Object o) {
return o == null ? "null" : o.getClass().toString();
}
}

View File

@ -386,7 +386,7 @@ public final class Internal {
@NotNull
@Deprecated(since = "3.16", forRemoval = true)
public static final <R extends Record, ER extends EmbeddableRecord<ER>> Row fieldsRow(TableField<R, ER> embeddableField) {
return embeddableField.getDataType().getRow();
return (@NotNull Row) embeddableField.getDataType().getRow();
}
@Support

View File

@ -292,7 +292,7 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
if (fetchIntermediateResult(Tools.configuration(this)))
return fetch().intoResultSet();
else
return fetchLazy().resultSet();
return (@NotNull ResultSet) fetchLazy().resultSet();
}
@Override
@ -519,7 +519,8 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
}
@Override
default Object[] fetchOneArray() {
@Nullable
default Object @Nullable [] fetchOneArray() {
R record = fetchOne();
return record == null ? null : record.intoArray();
}
@ -612,7 +613,8 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
}
@Override
default Object[] fetchSingleArray() {
@Nullable
default Object @NotNull [] fetchSingleArray() {
return fetchSingle().intoArray();
}
@ -808,7 +810,8 @@ interface ResultQueryTrait<R extends Record> extends QueryPartInternal, ResultQu
}
@Override
default Object[] fetchAnyArray() {
@Nullable
default Object @Nullable [] fetchAnyArray() {
R record = fetchAny();
return record == null ? null : record.intoArray();
}

View File

@ -74,135 +74,146 @@ final class SimpleExecuteContext extends AbstractScope implements ExecuteContext
@Override
public final Connection connection() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final ExecuteType type() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final Query query() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final Query[] batchQueries() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final Routine<?> routine() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final String sql() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final void sql(String sql) {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final String[] batchSQL() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final void connectionProvider(ConnectionProvider connectionProvider) {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final PreparedStatement statement() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final void statement(PreparedStatement statement) {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final int statementExecutionCount() {
return 0;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final ResultSet resultSet() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final void resultSet(ResultSet resultSet) {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final Record record() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final void record(Record record) {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final int rows() {
return 0;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final void rows(int rows) {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final int [] batchRows() {
return null;
public final int[] batchRows() {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final Result<?> result() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final void result(Result<?> result) {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final RuntimeException exception() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final void exception(RuntimeException e) {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final SQLException sqlException() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final void sqlException(SQLException e) {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final SQLWarning sqlWarning() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final void sqlWarning(SQLWarning e) {
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final String[] serverOutput() {
return null;
throw new UnsupportedOperationException("Not implemented");
}
@Override
public final void serverOutput(String[] output) {
throw new UnsupportedOperationException("Not implemented");
}
}