本文整理汇总了Java中org.apache.ibatis.io.ResolverUtil类的典型用法代码示例。如果您正苦于以下问题:Java ResolverUtil类的具体用法?Java ResolverUtil怎么用?Java ResolverUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResolverUtil类属于org.apache.ibatis.io包,在下文中一共展示了ResolverUtil类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMigrations
import org.apache.ibatis.io.ResolverUtil; //导入依赖的package包/类
@Override
public List<Change> getMigrations() {
List<Change> migrations = new ArrayList<Change>();
ResolverUtil<MigrationScript> resolver = getResolver(MigrationScript.class);
resolver.findImplementations(MigrationScript.class, packageNames);
Set<Class<? extends MigrationScript>> classes = resolver.getClasses();
for (Class<? extends MigrationScript> clazz : classes) {
try {
if (!Modifier.isAbstract(clazz.getModifiers())) {
MigrationScript script = clazz.newInstance();
Change change = parseChangeFromMigrationScript(script);
migrations.add(change);
}
} catch (Exception e) {
throw new MigrationException("Could not instanciate MigrationScript: " + clazz.getName(), e);
}
}
return migrations;
}
示例2: getScriptReader
import org.apache.ibatis.io.ResolverUtil; //导入依赖的package包/类
@Override
public Reader getScriptReader(Change change, boolean undo) {
ResolverUtil<MigrationScript> resolver = getResolver(MigrationScript.class);
final String className = change.getFilename();
for (String pkg : packageNames) {
resolver.find(new Test() {
@Override
public boolean matches(Class<?> type) {
return type != null && MigrationScript.class.isAssignableFrom(type) && type.getName().equals(className);
}
}, pkg);
}
Reader reader = null;
Set<Class<? extends MigrationScript>> classes = resolver.getClasses();
for (Class<? extends MigrationScript> clazz : classes) {
try {
MigrationScript script = clazz.newInstance();
reader = new StringReader(undo ? script.getDownScript() : script.getUpScript());
} catch (Exception e) {
throw new MigrationException("Could not instanciate MigrationScript: " + clazz.getName(), e);
}
// There should be only one script.
break;
}
return reader;
}
示例3: getSoleScriptReader
import org.apache.ibatis.io.ResolverUtil; //导入依赖的package包/类
public <T extends SimpleScript> Reader getSoleScriptReader(Class<T> scriptClass) {
ResolverUtil<T> resolver = getResolver(scriptClass);
resolver.findImplementations(scriptClass, packageNames);
Set<Class<? extends T>> classes = resolver.getClasses();
if (classes == null || classes.isEmpty()) {
return null;
}
if (classes.size() > 1) {
throw new MigrationException("There can be only one implementation of " + scriptClass.getName());
}
Class<? extends T> clazz = classes.iterator().next();
try {
T script = clazz.newInstance();
return new StringReader(script.getScript());
} catch (Exception e) {
throw new MigrationException("Could not instanciate script class: " + clazz.getName(), e);
}
}
示例4: setResource
import org.apache.ibatis.io.ResolverUtil; //导入依赖的package包/类
/**
* 查找mybatis配置文件填充至Set集合
*
* @param parent 节点
* @param resources
* @param mapper
* @throws ClassNotFoundException
*/
private void setResource(XNode parent, Set<String> resources, Set<Class<?>> mapper) throws ClassNotFoundException {
for (XNode child : parent.getChildren()) {
if ("package".equals(child.getName())) {
String mapperPackage = child.getStringAttribute("name");
ResolverUtil<Class<?>> resolverUtil = new ResolverUtil<>();
resolverUtil.find(new ResolverUtil.IsA(Object.class), mapperPackage);
Set<Class<? extends Class<?>>> mapperSet = resolverUtil.getClasses();
mapper.addAll(mapperSet);
} else {
String resource = child.getStringAttribute("resource");
String url = child.getStringAttribute("url");
String mapperClass = child.getStringAttribute("class");
if (resource != null && url == null && mapperClass == null) {
resources.add(resource);
} else if (resource == null && url != null && mapperClass == null) {
resources.add(url);
} else if (resource == null && url == null && mapperClass != null) {
Class<?> mapperInterface = Resources.classForName(mapperClass);
mapper.add(mapperInterface);
} else {
throw new BuilderException(
"A mapper element may only specify a url, resource or class, but not more than one.");
}
}
}
}
示例5: addMappers
import org.apache.ibatis.io.ResolverUtil; //导入依赖的package包/类
/**
* @since 3.2.2
*/
public void addMappers(String packageName, Class<?> superType) {
ResolverUtil<Class<?>> resolverUtil = new ResolverUtil<Class<?>>();
resolverUtil.find(new ResolverUtil.IsA(superType), packageName);
Set<Class<? extends Class<?>>> mapperSet = resolverUtil.getClasses();
for (Class<?> mapperClass : mapperSet) {
addMapper(mapperClass);
}
}
示例6: registerAliases
import org.apache.ibatis.io.ResolverUtil; //导入依赖的package包/类
public void registerAliases(String packageName, Class<?> superType){
ResolverUtil<Class<?>> resolverUtil = new ResolverUtil<Class<?>>();
resolverUtil.find(new ResolverUtil.IsA(superType), packageName);
Set<Class<? extends Class<?>>> typeSet = resolverUtil.getClasses();
for(Class<?> type : typeSet){
// Ignore inner classes and interfaces (including package-info.java)
// Skip also inner classes. See issue #6
if (!type.isAnonymousClass() && !type.isInterface() && !type.isMemberClass()) {
registerAlias(type);
}
}
}
示例7: register
import org.apache.ibatis.io.ResolverUtil; //导入依赖的package包/类
public void register(String packageName) {
ResolverUtil<Class<?>> resolverUtil = new ResolverUtil<Class<?>>();
resolverUtil.find(new ResolverUtil.IsA(TypeHandler.class), packageName);
Set<Class<? extends Class<?>>> handlerSet = resolverUtil.getClasses();
for (Class<?> type : handlerSet) {
//Ignore inner classes and interfaces (including package-info.java) and abstract classes
if (!type.isAnonymousClass() && !type.isInterface() && !Modifier.isAbstract(type.getModifiers())) {
register(type);
}
}
}
示例8: addMappers
import org.apache.ibatis.io.ResolverUtil; //导入依赖的package包/类
/**
* @since 3.2.2
*/
public void addMappers(String packageName, Class<?> superType) {
//查找包下所有是superType的类
ResolverUtil<Class<?>> resolverUtil = new ResolverUtil<Class<?>>();
resolverUtil.find(new ResolverUtil.IsA(superType), packageName);
Set<Class<? extends Class<?>>> mapperSet = resolverUtil.getClasses();
for (Class<?> mapperClass : mapperSet) {
addMapper(mapperClass);
}
}
示例9: registerAliases
import org.apache.ibatis.io.ResolverUtil; //导入依赖的package包/类
public void registerAliases(String packageName, Class<?> superType){
//TODO ResolverUtil
ResolverUtil<Class<?>> resolverUtil = new ResolverUtil<Class<?>>();
resolverUtil.find(new ResolverUtil.IsA(superType), packageName);
Set<Class<? extends Class<?>>> typeSet = resolverUtil.getClasses();
for(Class<?> type : typeSet){
// Ignore inner classes and interfaces (including package-info.java)
// Skip also inner classes. See issue #6
if (!type.isAnonymousClass() && !type.isInterface() && !type.isMemberClass()) {
registerAlias(type);
}
}
}
示例10: getResolver
import org.apache.ibatis.io.ResolverUtil; //导入依赖的package包/类
private <T> ResolverUtil<T> getResolver(Class<T> type) {
ResolverUtil<T> resolver = new ResolverUtil<T>();
if (classLoader != null) {
resolver.setClassLoader(classLoader);
}
return resolver;
}
示例11: check
import org.apache.ibatis.io.ResolverUtil; //导入依赖的package包/类
private static void check() {
try {
Class.forName(ResolverUtil.class.getName());
Class.forName(Test.class.getName());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
示例12: find
import org.apache.ibatis.io.ResolverUtil; //导入依赖的package包/类
@Override
public <T> Set<Class<? extends T>> find(Matcher matcher, String packageName,
ClassLoader classloader) {
ResolverUtil<T> util = new ResolverUtil<>();
util.setClassLoader(classloader);
return util.find(new AdaptTest(matcher), packageName).getClasses();
}
示例13: getClasses
import org.apache.ibatis.io.ResolverUtil; //导入依赖的package包/类
/**
* 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.
*/
final Set<Class<?>> getClasses(final String packageName) {
return getClasses(new ResolverUtil.IsA(Object.class), packageName);
}