org.jdbi.v3.sqlobject.Handlers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jdbi3-sqlobject Show documentation
Show all versions of jdbi3-sqlobject Show documentation
jdbi SqlObject transforms simple annotated interfaces into
full-featured DAO implementations.
/*
* 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 org.jdbi.v3.sqlobject;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CopyOnWriteArrayList;
import org.jdbi.v3.core.config.ConfigRegistry;
import org.jdbi.v3.core.config.JdbiConfig;
import org.jdbi.v3.core.extension.ExtensionHandlerFactory;
import org.jdbi.v3.core.internal.JdbiOptionals;
/**
* Registry for {@link HandlerFactory handler factories}, which produce {@link Handler handlers} for SQL object methods.
* By default, a factory is registered for methods annotated
* with SQL annotations such as {@code @SqlUpdate} or {@code SqlQuery}. Clients may register additional factories to provide
* support for other use cases. In the case that two or more registered factories would support a particular SQL object
* method, the last-registered factory takes precedence.
*
* @deprecated Use {@link ExtensionHandlerFactory} instances that are returned
* from the {@link org.jdbi.v3.core.extension.ExtensionFactory#getExtensionHandlerFactories(ConfigRegistry)} method.
*/
@Deprecated
public class Handlers implements JdbiConfig {
private final List factories;
public Handlers() {
factories = new CopyOnWriteArrayList<>();
}
private Handlers(Handlers that) {
factories = new CopyOnWriteArrayList<>(that.factories);
}
List getFactories() {
return factories;
}
/**
* Registers the given handler factory with the registry.
* @param factory the factory to register
* @return this
*/
public Handlers register(HandlerFactory factory) {
factories.add(0, factory);
return this;
}
public Optional findFor(Class> sqlObjectType, Method method) {
return factories.stream()
.flatMap(factory -> JdbiOptionals.stream(factory.buildHandler(sqlObjectType, method)))
.findFirst();
}
@Override
public Handlers createCopy() {
return new Handlers(this);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy