use of org.jessma.util.PackageHelper.ClassFilter in project JessMA by ldcsaa.
the class MyBatisSessionMgr method buildSessionFactory.
/** 创建 {@link SqlSessionFactory} */
private void buildSessionFactory() {
synchronized (this) {
if (sessionFactory == null) {
try {
Reader reader = Resources.getResourceAsReader(configFile);
sessionFactory = new SqlSessionFactoryBuilder().build(reader, environment);
if (GeneralHelper.isStrNotEmpty(pattern)) {
Set<String> packages = PackageHelper.getPackages(pattern);
for (String pkg : packages) {
Set<Class<?>> entities = PackageHelper.getClasses(pkg, false, new ClassFilter() {
@Override
public boolean accept(Class<?> clazz) {
if (!BeanHelper.isPublicInterface(clazz))
return false;
return true;
}
});
Configuration cfg = sessionFactory.getConfiguration();
for (Class<?> clazz : entities) {
if (!cfg.hasMapper(clazz))
cfg.addMapper(clazz);
}
}
}
} catch (IOException e) {
throw new SqlSessionException(e);
}
}
}
}
Aggregations