You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package com.fanruan.api.data;
|
|
|
|
|
|
|
|
import com.fanruan.api.util.TypeKit;
|
|
|
|
import com.fr.data.impl.Connection;
|
|
|
|
import com.fr.file.ConnectionConfig;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 数据连接相关工具类
|
|
|
|
*/
|
|
|
|
public class ConnectionKit {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取指定名字的数据连接
|
|
|
|
*
|
|
|
|
* @param name 名字
|
|
|
|
* @return 数据连接
|
|
|
|
*/
|
|
|
|
public @Nullable Connection getConnection(@NotNull String name) {
|
|
|
|
return ConnectionConfig.getInstance().getConnection(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取指定名字和指定类型的数据连接
|
|
|
|
*
|
|
|
|
* @param name 数据连接的名字
|
|
|
|
* @param type 类型
|
|
|
|
* @return 数据连接
|
|
|
|
*/
|
|
|
|
public <T extends Connection> @Nullable T getConnection(@NotNull String name, Class<? extends Connection> type) {
|
|
|
|
Connection connection = getConnection(name);
|
|
|
|
if (TypeKit.objectInstanceOf(connection, type)) {
|
|
|
|
return (T) connection;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|