
org.mybatis.guice.AbstractMyBatisModule Maven / Gradle / Ivy
/*
* Copyright 2009-2023 the original author or authors.
*
* 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
*
* https://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.mybatis.guice;
import static com.google.inject.matcher.Matchers.annotatedWith;
import static com.google.inject.matcher.Matchers.any;
import static com.google.inject.matcher.Matchers.not;
import static com.google.inject.name.Names.named;
import static com.google.inject.util.Providers.guicify;
import static org.mybatis.guice.Preconditions.checkArgument;
import com.google.inject.AbstractModule;
import com.google.inject.Binder;
import com.google.inject.Scopes;
import com.google.inject.matcher.AbstractMatcher;
import java.lang.reflect.Method;
import java.util.Set;
import org.apache.ibatis.io.ResolverUtil;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionManager;
import org.mybatis.guice.mappers.MapperProvider;
import org.mybatis.guice.session.SqlSessionManagerProvider;
import org.mybatis.guice.transactional.Transactional;
import org.mybatis.guice.transactional.TransactionalMethodInterceptor;
abstract class AbstractMyBatisModule extends AbstractModule {
protected static final AbstractMatcher DECLARED_BY_OBJECT = new AbstractMatcher() {
@Override
public boolean matches(Method method) {
return method.getDeclaringClass() == Object.class;
}
};
protected static final AbstractMatcher SYNTHETIC = new AbstractMatcher() {
@Override
public boolean matches(Method method) {
return method.isSynthetic();
}
};
private ClassLoader resourcesClassLoader = getDefaultClassLoader();
private ClassLoader driverClassLoader = getDefaultClassLoader();
/**
* Return a set of all classes contained in the given package.
*
* @param packageName
* the package has to be analyzed.
*
* @return a set of all classes contained in the given package.
*/
protected static Set> getClasses(String packageName) {
return AbstractMyBatisModule.getClasses(new ResolverUtil.IsA(Object.class), packageName);
}
/**
* Return a set of all classes contained in the given package that match with the given test requirement.
*
* @param test
* the class filter on the given package.
* @param packageName
* the package has to be analyzed.
*
* @return a set of all classes contained in the given package.
*/
protected static Set> getClasses(ResolverUtil.Test test, String packageName) {
checkArgument(test != null, "Parameter 'test' must not be null");
checkArgument(packageName != null, "Parameter 'packageName' must not be null");
return new ResolverUtil
© 2015 - 2025 Weber Informatics LLC | Privacy Policy