diff --git a/jOOQ/src/main/java/org/jooq/impl/CursorImpl.java b/jOOQ/src/main/java/org/jooq/impl/CursorImpl.java index 9e5048af4e..f06187592d 100644 --- a/jOOQ/src/main/java/org/jooq/impl/CursorImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/CursorImpl.java @@ -106,7 +106,7 @@ final class CursorImpl extends AbstractCursor implements Cu private final boolean keepStatement; private final boolean autoclosing; private final int maxRows; - private final RecordFactory factory; + private final F0 factory; private boolean isClosed; private transient CursorResultSet rs; @@ -1610,7 +1610,7 @@ final class CursorImpl extends AbstractCursor implements Cu rs.updateRow(); } - record = Tools.newRecord(true, (RecordFactory) factory, ((DefaultExecuteContext) ctx).originalConfiguration()) + record = Tools.newRecord(true, (F0) factory, ((DefaultExecuteContext) ctx).originalConfiguration()) .operate(new CursorRecordInitialiser(fields.fields, 0)); rows++; diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapperProvider.java b/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapperProvider.java index fa98d35742..f3a18d2a91 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapperProvider.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapperProvider.java @@ -48,7 +48,6 @@ import org.jooq.RecordMapper; import org.jooq.RecordMapperProvider; import org.jooq.RecordType; import org.jooq.impl.Tools.Cache; -import org.jooq.impl.Tools.Cache.CachedOperation; /** * A default {@link RecordMapperProvider} implementation, providing a @@ -81,9 +80,9 @@ public class DefaultRecordMapperProvider implements RecordMapperProvider, Serial @Override public final RecordMapper provide(final RecordType rowType, final Class type) { if (configuration != null && TRUE.equals(configuration.settings().isCacheRecordMappers())) - return Cache.run(configuration, new CachedOperation>() { + return Cache.run(configuration, new F0>() { @Override - public RecordMapper call() { + public RecordMapper apply() { return new DefaultRecordMapper<>(rowType, type, configuration); } }, DATA_CACHE_RECORD_MAPPERS, Cache.key(rowType, type)); diff --git a/jOOQ/src/main/java/org/jooq/impl/F.java b/jOOQ/src/main/java/org/jooq/impl/F.java index be9a51ab2a..5bcf05e06d 100644 --- a/jOOQ/src/main/java/org/jooq/impl/F.java +++ b/jOOQ/src/main/java/org/jooq/impl/F.java @@ -38,6 +38,13 @@ package org.jooq.impl; +@FunctionalInterface + +interface F0 { + R apply(); +} + + @FunctionalInterface interface F1 { diff --git a/jOOQ/src/main/java/org/jooq/impl/LoaderImpl.java b/jOOQ/src/main/java/org/jooq/impl/LoaderImpl.java index 688416e969..7ac9c842f0 100644 --- a/jOOQ/src/main/java/org/jooq/impl/LoaderImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/LoaderImpl.java @@ -313,9 +313,9 @@ final class LoaderImpl implements @Override public final LoaderRowsStep loadRecords(Iterator records) { - return loadArrays(new MappingIterator(records, new MappingIterator.Function() { + return loadArrays(new MappingIterator(records, new F1() { @Override - public final Object[] map(Record value) { + public final Object[] apply(Record value) { if (value == null) return null; diff --git a/jOOQ/src/main/java/org/jooq/impl/MappingIterator.java b/jOOQ/src/main/java/org/jooq/impl/MappingIterator.java index d065951d6d..be3c74c082 100644 --- a/jOOQ/src/main/java/org/jooq/impl/MappingIterator.java +++ b/jOOQ/src/main/java/org/jooq/impl/MappingIterator.java @@ -44,10 +44,10 @@ import java.util.Iterator; */ final class MappingIterator implements Iterator { - final Iterator delegate; - final Function mapper; + final Iterator delegate; + final F1 mapper; - MappingIterator(Iterator delegate, Function mapper) { + MappingIterator(Iterator delegate, F1 mapper) { this.delegate = delegate; this.mapper = mapper; } @@ -59,15 +59,11 @@ final class MappingIterator implements Iterator { @Override public U next() { - return mapper.map(delegate.next()); + return mapper.apply(delegate.next()); } @Override public void remove() { delegate.remove(); } - - interface Function { - U map(T value); - } } diff --git a/jOOQ/src/main/java/org/jooq/impl/RecordFactory.java b/jOOQ/src/main/java/org/jooq/impl/RecordFactory.java deleted file mode 100644 index 0eaf7a1800..0000000000 --- a/jOOQ/src/main/java/org/jooq/impl/RecordFactory.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Other licenses: - * ----------------------------------------------------------------------------- - * Commercial licenses for this work are available. These replace the above - * ASL 2.0 and offer limited warranties, support, maintenance, and commercial - * database integrations. - * - * For more information, please visit: http://www.jooq.org/licenses - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - */ -package org.jooq.impl; - -import org.jooq.Record; - -/** - * @author Lukas Eder - * @author Arnaud Roger - */ - -@FunctionalInterface - -interface RecordFactory { - - /** - * Create a new record with a given row type. - */ - R newInstance(); -} diff --git a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java index 6811888e54..46b7db15b8 100644 --- a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java @@ -191,7 +191,6 @@ import org.jooq.WindowDefinition; import org.jooq.exception.DataAccessException; import org.jooq.impl.Tools.BooleanDataKey; import org.jooq.impl.Tools.DataKey; -import org.jooq.impl.Transform.Transformer; import org.jooq.tools.JooqLogger; import org.jooq.tools.StringUtils; diff --git a/jOOQ/src/main/java/org/jooq/impl/Tools.java b/jOOQ/src/main/java/org/jooq/impl/Tools.java index ac3fd9d31c..94a037a6a5 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Tools.java +++ b/jOOQ/src/main/java/org/jooq/impl/Tools.java @@ -264,7 +264,6 @@ import org.jooq.exception.MappingException; import org.jooq.exception.NoDataFoundException; import org.jooq.exception.TooManyRowsException; import org.jooq.impl.ResultsImpl.ResultOrRowsImpl; -import org.jooq.impl.Tools.Cache.CachedOperation; import org.jooq.tools.Ints; import org.jooq.tools.JooqLogger; import org.jooq.tools.StringUtils; @@ -858,9 +857,9 @@ final class Tools { /** * Create a new record. */ - static final RecordDelegate newRecord(boolean fetched, RecordFactory factory, Configuration configuration) { + static final RecordDelegate newRecord(boolean fetched, F0 factory, Configuration configuration) { try { - R record = factory.newInstance(); + R record = factory.apply(); // [#3300] Records that were fetched from the database if (record instanceof AbstractRecord) @@ -877,15 +876,15 @@ final class Tools { * Create a new record factory. */ @SuppressWarnings({ "unchecked", "rawtypes" }) - static final RecordFactory recordFactory(final Class type, final Field[] fields) { + static final F0 recordFactory(final Class type, final Field[] fields) { // An ad-hoc type resulting from a JOIN or arbitrary SELECT if (type == RecordImpl.class || type == Record.class) { final RowImpl row = new RowImpl(fields); - return new RecordFactory() { + return new F0() { @Override - public R newInstance() { + public R apply() { return (R) new RecordImpl(row); } }; @@ -898,9 +897,9 @@ final class Tools { // [#919] Allow for accessing non-public constructors final Constructor constructor = Reflect.accessible(type.getDeclaredConstructor()); - return new RecordFactory() { + return new F0() { @Override - public R newInstance() { + public R apply() { try { return constructor.newInstance(); } @@ -3161,29 +3160,17 @@ final class Tools { static class Cache { /** - * A callback wrapping expensive operations. - */ - static interface CachedOperation { - - /** - * An expensive operation. - */ - V call(); - } - - /** - * Run a {@link CachedOperation} in the context of a - * {@link Configuration}. + * Run a cached operation in the context of a {@link Configuration}. * * @param configuration The configuration that may cache the outcome of - * the {@link CachedOperation}. + * the cached operation. * @param operation The expensive operation. * @param type The cache type to be used. * @param keys The cache keys. * @return The cached value or the outcome of the cached operation. */ @SuppressWarnings("unchecked") - static final V run(Configuration configuration, CachedOperation operation, DataCacheKey type, Object key) { + static final V run(Configuration configuration, F0 operation, DataCacheKey type, Object key) { // If no configuration is provided take the default configuration that loads the default Settings if (configuration == null) @@ -3191,7 +3178,7 @@ final class Tools { // Shortcut caching when the relevant Settings flag isn't set. if (!reflectionCaching(configuration.settings())) - return operation.call(); + return operation.apply(); Map cache = (Map) configuration.data(type); if (cache == null) { @@ -3211,7 +3198,7 @@ final class Tools { result = cache.get(key); if (result == null) { - result = operation.call(); + result = operation.apply(); cache.put(key, result == null ? NULL : result); } } @@ -3407,10 +3394,10 @@ final class Tools { * or methods */ static final boolean hasColumnAnnotations(final Configuration configuration, final Class type) { - return Cache.run(configuration, new CachedOperation() { + return Cache.run(configuration, new F0() { @Override - public Boolean call() { + public Boolean apply() { if (!isJPAAvailable()) return false; @@ -3443,10 +3430,10 @@ final class Tools { * Get all members annotated with a given column name */ static final List getAnnotatedMembers(final Configuration configuration, final Class type, final String name) { - return Cache.run(configuration, new CachedOperation>() { + return Cache.run(configuration, new F0>() { @Override - public List call() { + public List apply() { List result = new ArrayList<>(); for (java.lang.reflect.Field member : getInstanceMembers(type)) { @@ -3484,10 +3471,10 @@ final class Tools { * Get all members matching a given column name */ static final List getMatchingMembers(final Configuration configuration, final Class type, final String name) { - return Cache.run(configuration, new CachedOperation>() { + return Cache.run(configuration, new F0>() { @Override - public List call() { + public List apply() { List result = new ArrayList<>(); // [#1942] Caching these values before the field-loop significantly @@ -3510,10 +3497,10 @@ final class Tools { * Get all setter methods annotated with a given column name */ static final List getAnnotatedSetters(final Configuration configuration, final Class type, final String name) { - return Cache.run(configuration, new CachedOperation>() { + return Cache.run(configuration, new F0>() { @Override - public List call() { + public List apply() { Set set = new LinkedHashSet<>(); for (Method method : getInstanceMethods(type)) { @@ -3561,10 +3548,10 @@ final class Tools { * Get the first getter method annotated with a given column name */ static final Method getAnnotatedGetter(final Configuration configuration, final Class type, final String name) { - return Cache.run(configuration, new CachedOperation() { + return Cache.run(configuration, new F0() { @Override - public Method call() { + public Method apply() { for (Method method : getInstanceMethods(type)) { Column column = method.getAnnotation(Column.class); @@ -3612,10 +3599,10 @@ final class Tools { * Get all setter methods matching a given column name */ static final List getMatchingSetters(final Configuration configuration, final Class type, final String name) { - return Cache.run(configuration, new CachedOperation>() { + return Cache.run(configuration, new F0>() { @Override - public List call() { + public List apply() { // [#8460] Prevent duplicate methods in the call hierarchy Set set = new LinkedHashSet<>(); @@ -3650,10 +3637,10 @@ final class Tools { * Get the first getter method matching a given column name */ static final Method getMatchingGetter(final Configuration configuration, final Class type, final String name) { - return Cache.run(configuration, new CachedOperation() { + return Cache.run(configuration, new F0() { @Override - public Method call() { + public Method apply() { // [#1942] Caching these values before the method-loop significantly // accerates POJO mapping String camelCase = StringUtils.toCamelCase(name); diff --git a/jOOQ/src/main/java/org/jooq/impl/Transform.java b/jOOQ/src/main/java/org/jooq/impl/Transform.java index e2c6f43f6b..2a1f291e25 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Transform.java +++ b/jOOQ/src/main/java/org/jooq/impl/Transform.java @@ -61,9 +61,9 @@ import org.jooq.QueryPart; */ final class Transform { - final Transformer> fieldTransformer; + final F1, Field> fieldTransformer; - Transform(Transformer> fieldTransformer) { + Transform(F1, Field> fieldTransformer) { this.fieldTransformer = fieldTransformer; } @@ -73,7 +73,7 @@ final class Transform { else if (condition instanceof CombinedCondition) return CombinedCondition.of(((CombinedCondition) condition).operator, transform(((CombinedCondition) condition).conditions)); else if (condition instanceof CompareCondition) - return new CompareCondition(fieldTransformer.transform(((CompareCondition) condition).field1), fieldTransformer.transform(((CompareCondition) condition).field2), ((CompareCondition) condition).comparator); + return new CompareCondition(fieldTransformer.apply(((CompareCondition) condition).field1), fieldTransformer.apply(((CompareCondition) condition).field2), ((CompareCondition) condition).comparator); else return condition; } @@ -86,8 +86,4 @@ final class Transform { return result; } - - interface Transformer { - Q transform(Q queryPart); - } }