![JAR search and dependency download from the Maven repository](/logo.png)
net.e6tech.elements.common.resources.Transactional Maven / Gradle / Ivy
/*
* Copyright 2017 Futeh Kao
*
* 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.
*/
package net.e6tech.elements.common.resources;
import net.e6tech.elements.common.util.function.*;
import java.util.concurrent.Callable;
/**
* Created by futeh.
*/
@FunctionalInterface
@SuppressWarnings({"squid:S00112", "squid:S1602"})
public interface Transactional {
T open();
default R apply(Callable callable) {
return commit(callable);
}
default R call(Callable callable) {
return commit(callable);
}
default R commit(Callable callable) {
Resources resources = open();
resources.submit(r -> {
return callable.call();
});
return resources.commit();
}
default void run(RunnableWithException runnable) {
commit(runnable);
}
default void accept(RunnableWithException runnable) {
commit(runnable);
}
default void commit(RunnableWithException runnable) {
Resources resources = open();
resources.submit(r -> {
runnable.run();
});
resources.commit();
}
default R apply(Class cls, FunctionWithException function) {
return commit(cls, function);
}
default R commit(Class cls, FunctionWithException function) {
Resources resources = open();
resources.submit(r -> {
return function.apply(r.getInstance(cls));
});
return resources.commit();
}
default void accept(Class cls, ConsumerWithException consumer) {
commit(cls, consumer);
}
default void commit(Class cls, ConsumerWithException consumer) {
Resources resources = open();
resources.submit(r -> {
consumer.accept(r.getInstance(cls));
});
resources.commit();
}
default R apply(Class cls, Class cls2, BiFunctionWithException function) {
return commit(cls, cls2, function);
}
default R commit(Class cls, Class cls2, BiFunctionWithException function) {
Resources resources = open();
resources.submit(r -> {
return function.apply(r.getInstance(cls), r.getInstance(cls2));
});
return resources.commit();
}
default void accept(Class cls, Class cls2, BiConsumerWithException consumer) {
commit(cls, cls2, consumer);
}
default void commit(Class cls, Class cls2, BiConsumerWithException consumer) {
Resources resources = open();
resources.submit(r -> {
consumer.accept(r.getInstance(cls), r.getInstance(cls2));
});
resources.commit();
}
default R apply(Class cls, Class cls2, Class cls3, TriFunctionWithException function) {
return commit(cls, cls2, cls3, function);
}
default R commit(Class cls, Class cls2, Class cls3, TriFunctionWithException function) {
Resources resources = open();
resources.submit(r -> {
return function.apply(r.getInstance(cls), r.getInstance(cls2), r.getInstance(cls3));
});
return resources.commit();
}
default void accept(Class cls, Class cls2, Class cls3, TriConsumerWithException consumer) {
commit(cls, cls2, cls3, consumer);
}
default void commit(Class cls, Class cls2, Class cls3, TriConsumerWithException consumer) {
Resources resources = open();
resources.submit(r -> {
consumer.accept(r.getInstance(cls), r.getInstance(cls2), r.getInstance(cls3));
});
resources.commit();
}
default void accept(Class[] classes, ConsumerWithException
© 2015 - 2025 Weber Informatics LLC | Privacy Policy