[jOOQ/jOOQ#10472] Supplier must be serializable
This commit is contained in:
parent
c1a4986a39
commit
d6d904c943
@ -38,7 +38,6 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.jooq.Catalog;
|
||||
@ -59,21 +58,21 @@ public final class LazyCatalog extends AbstractNamed implements Catalog {
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = -2260128711891951254L;
|
||||
private static final long serialVersionUID = -2260128711891951254L;
|
||||
|
||||
final Callable<Catalog> callable;
|
||||
transient Catalog catalog;
|
||||
final LazySupplier<Catalog> supplier;
|
||||
transient Catalog catalog;
|
||||
|
||||
public LazyCatalog(Name name, Callable<Catalog> callable) {
|
||||
public LazyCatalog(Name name, LazySupplier<Catalog> supplier) {
|
||||
super(name, CommentImpl.NO_COMMENT);
|
||||
|
||||
this.callable = callable;
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
private final Catalog catalog() {
|
||||
if (catalog == null) {
|
||||
try {
|
||||
catalog = callable.call();
|
||||
catalog = supplier.get();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@ -38,7 +38,6 @@
|
||||
package org.jooq.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.jooq.Catalog;
|
||||
@ -66,19 +65,19 @@ public final class LazySchema extends AbstractNamed implements Schema {
|
||||
*/
|
||||
private static final long serialVersionUID = -2260128711891951254L;
|
||||
|
||||
final Callable<Schema> callable;
|
||||
transient Schema schema;
|
||||
final LazySupplier<Schema> supplier;
|
||||
transient Schema schema;
|
||||
|
||||
public LazySchema(Name name, Comment comment, Callable<Schema> callable) {
|
||||
public LazySchema(Name name, Comment comment, LazySupplier<Schema> supplier) {
|
||||
super(name, comment);
|
||||
|
||||
this.callable = callable;
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
private final Schema schema() {
|
||||
if (schema == null) {
|
||||
try {
|
||||
schema = callable.call();
|
||||
schema = supplier.get();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
61
jOOQ/src/main/java/org/jooq/impl/LazySupplier.java
Normal file
61
jOOQ/src/main/java/org/jooq/impl/LazySupplier.java
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 java.io.Serializable;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.jooq.Internal;
|
||||
|
||||
/**
|
||||
* A lazy supplier
|
||||
*/
|
||||
@Internal
|
||||
@FunctionalInterface
|
||||
public interface LazySupplier<T> extends Serializable, Supplier<T> {
|
||||
|
||||
/**
|
||||
* Gets a result.
|
||||
*
|
||||
* @return a result
|
||||
*/
|
||||
|
||||
@Override
|
||||
|
||||
T get();
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user