本文整理汇总了Java中org.apache.ibatis.session.SqlSessionFactoryBuilder类的典型用法代码示例。如果您正苦于以下问题:Java SqlSessionFactoryBuilder类的具体用法?Java SqlSessionFactoryBuilder怎么用?Java SqlSessionFactoryBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SqlSessionFactoryBuilder类属于org.apache.ibatis.session包,在下文中一共展示了SqlSessionFactoryBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
//mybatis的配置文件
String resource = "mybatis-conf.xml";
//使用类加载器加载mybatis的配置文件(它也加载关联的映射文件)
InputStream is = Desensitization.class.getClassLoader().getResourceAsStream(resource);
//构建sqlSession的工厂
SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is);
//使用MyBatis提供的Resources类加载mybatis的配置文件(它也加载关联的映射文件)
//Reader reader = Resources.getResourceAsReader(resource);
//构建sqlSession的工厂
//SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader);
//创建能执行映射文件中sql的sqlSession
SqlSession session = sessionFactory.openSession();
/**
* 映射sql的标识字符串,
* me.gacl.mapping.userMapper是userMapper.xml文件中mapper标签的namespace属性的值,
* getUser是select标签的id属性值,通过select标签的id属性值就可以找到要执行的SQL
*/
String statement = "com.creditease.dbus.ws.mapper.DesensitizationMapper.getDesensitizationInformation";//映射sql的标识字符串
//执行查询返回一个唯一user对象的sql
List<DesensitizationInformation> informations = session.selectList(statement,26);
for (DesensitizationInformation information: informations
) {
System.out.println(information);
}
}
示例2: BaseDao
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //导入依赖的package包/类
BaseDao() {
//判断SessionFactory是否初始化过,初始化过后就不重复初始化,保证系统的运行效率。
if (!isInit) {
try {
//读入Mybatis配置文件
inputStream = Resources.getResourceAsStream(resource);
//通过配置文件构建sql数据工厂
sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
System.out.println("getConnectionSuccful");
isInit = true;
} catch (IOException e) {
e.printStackTrace();
}
} else {
System.out.println("already init");
}
}
示例3: createSqlSessionManager
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //导入依赖的package包/类
/**
* This method creates the sqlSessionManager of myBatis. It integrates all the SQL mappers
*
* @return a {@link SqlSessionFactory}
*/
private SqlSessionManager createSqlSessionManager() {
Environment environment = new Environment(DEFAULT, this.transactionFactory,
taskanaEngineConfiguration.getDatasource());
Configuration configuration = new Configuration(environment);
// add mappers
configuration.addMapper(TaskMapper.class);
configuration.addMapper(TaskMonitorMapper.class);
configuration.addMapper(WorkbasketMapper.class);
configuration.addMapper(DistributionTargetMapper.class);
configuration.addMapper(ClassificationMapper.class);
configuration.addMapper(WorkbasketAccessMapper.class);
configuration.addMapper(ObjectReferenceMapper.class);
configuration.addMapper(QueryMapper.class);
configuration.addMapper(AttachmentMapper.class);
configuration.getTypeHandlerRegistry().register(MapTypeHandler.class);
SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(configuration);
SqlSessionManager sessionManager = SqlSessionManager.newInstance(sessionFactory);
return sessionManager;
}
示例4: getSqlSession
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //导入依赖的package包/类
/**
* 获取SqlSession
* @return
* @throws IOException
*/
public SqlSession getSqlSession() throws IOException, ClassNotFoundException {
org.apache.ibatis.session.Configuration config = new org.apache.ibatis.session.Configuration();
config.setCallSettersOnNulls(true); // 设计null调用setter方法
config.setMapUnderscoreToCamelCase(true); // 驼峰命名支持
// 设置mapper
config.addMappers(targetPackage);
// 设置数据源,事务
PooledDataSourceFactory dataSourceFactory = new PooledDataSourceFactory();
dataSourceFactory.setProperties(DBHelper.properties);
DataSource dataSource = dataSourceFactory.getDataSource();
JdbcTransactionFactory transactionFactory = new JdbcTransactionFactory();
Environment environment = new Environment("test", transactionFactory, dataSource);
config.setEnvironment(environment);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
return sqlSessionFactory.openSession(true);
}
示例5: setUp
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
System.out.println("Starting up CmsCmProcessor tests");
String resource = "mybatis-config.xml";
Reader reader = Resources.getResourceAsReader( resource );
SqlSessionFactory sf = new SqlSessionFactoryBuilder().build(reader);
session = sf.openSession();
clazzMapper = session.getMapper(ClazzMapper.class);
ciMapper = session.getMapper(CIMapper.class);
mdValidator = new CmsMdValidator();
cmValidator = new CmsCmValidator();
mdProcessor = new CmsMdProcessor();
mdProcessor.setClazzMapper( clazzMapper );
mdProcessor.setMdValidator(mdValidator);
cmProcessor = new CmsCmProcessor();
cmProcessor.setCiMapper(ciMapper);
cmProcessor.setMdProcessor(mdProcessor);
cmProcessor.setCmValidator(cmValidator);
RelationMapper relationMapper=session.getMapper(RelationMapper.class);
mdProcessor.setRelationMapper(relationMapper);
}
示例6: DBManager
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //导入依赖的package包/类
public DBManager(AppConfiguration appConfig) {
this.appConfig = appConfig;
boolean isDev = appConfig.getBool(CONFIG_KEY_APP_DEV_MODE, true);
String dbHost = appConfig.get(CONFIG_KEY_MYSQL_HOST, DEFAULT_MYSQL_HOST);
int dbPort = appConfig.getInt(CONFIG_KEY_MYSQL_PORT, DEFAULT_MYSQL_PORT);
String dbName = appConfig.get(CONFIG_KEY_MYSQL_DBNAME, DEFAULT_MEYSQL_DBNAME);
String dbUser = appConfig.get(CONFIG_KEY_MYSQL_USER, "");
String dbPass = appConfig.get(CONFIG_KEY_MYSQL_PASS, "");
String dbDriver = "com.mysql.cj.jdbc.Driver";
String connString = "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName + "?autoReconnect=true&useSSL=false&useUnicode=true";
DataSource dataSource = new PooledDataSource(dbDriver, connString, dbUser, dbPass);
TransactionFactory transactionFactory = new JdbcTransactionFactory();
Environment environment = new Environment(isDev ? "development" : "production", transactionFactory, dataSource);
configuration = new Configuration(environment);
configuration.addMappers("com.elune.dao");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
示例7: build
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //导入依赖的package包/类
/**
* Create an instance of MyBatis.
*
* @param environment The dropwizard environment
* @param config A Mybatis config object
* @param dataSource
* @param name The name of this mybatis factory used for metrics
* @return An instance of MyBatis.
*/
public final SqlSessionFactory build(Environment environment,
MyBatisConfiguration config,
ManagedDataSource dataSource,
String name) {
SqlSessionFactory sessionFactory = null;
// Try to use the mybatis configuration file if it is specified and exists.
try (InputStream inputStream = Resources.getResourceAsStream(config.getConfigFile())) {
sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
} catch (IOException ioe) {
// Build session factory from configuration values given in the dropwizard config.
TransactionFactory transactionFactory = new JdbcTransactionFactory();
org.apache.ibatis.mapping.Environment myBatisEnvironment =
new org.apache.ibatis.mapping.Environment(ENV_NAME, transactionFactory, dataSource);
Configuration mybatisConfiguration = new Configuration(myBatisEnvironment);
sessionFactory = new SqlSessionFactoryBuilder().build(mybatisConfiguration);
}
environment.lifecycle().manage(dataSource);
environment.healthChecks().register(name,
new MyBatisHealthCheck(sessionFactory, config.getConfig().getValidationQuery()));
return sessionFactory;
}
示例8: init
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //导入依赖的package包/类
@Override
public void init(DbConnection connection) throws Exception {
JdbcConnectionPool pool = JdbcConnectionPool.create(connection.uri, connection.username, connection.password);
TransactionFactory transactionFactory = new JdbcTransactionFactory();
Environment environment = new Environment("jdblender", transactionFactory, pool);
Configuration cfg = new Configuration(environment);
cfg.setMapUnderscoreToCamelCase(true);
cfg.addMapper(BrandsMapper.class);
cfg.addMapper(SeriesMapper.class);
cfg.addMapper(ModelsMapper.class);
cfg.addMapper(SparesMapper.class);
//Create session
sqlSessionFactory = new SqlSessionFactoryBuilder().build(cfg);
}
示例9: setUp
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
// create an SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/ancestor_ref/mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
// populate in-memory database
SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/ancestor_ref/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例10: setUp
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
// create an SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/include_property/mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
// populate in-memory database
SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/include_property/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例11: setUp
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
// create a SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/associationtest/mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
// populate in-memory database
SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/associationtest/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例12: setUp
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
// create a SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/column_forwarding/mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
// populate in-memory database
SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/column_forwarding/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例13: before
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //导入依赖的package包/类
@Before
public void before() throws Exception {
// create a SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/lazyload_proxyfactory_comparison/mybatis-config-" + getConfiguration() + ".xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
// populate in-memory database
SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/lazyload_proxyfactory_comparison/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
sqlSession = sqlSessionFactory.openSession();
mapper = sqlSession.getMapper(Mapper.class);
}
示例14: setUp
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
// create a SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/foreach/mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
// populate in-memory database
SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/foreach/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例15: setUp
import org.apache.ibatis.session.SqlSessionFactoryBuilder; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
// create a SqlSessionFactory
Reader reader = Resources
.getResourceAsReader("org/apache/ibatis/submitted/call_setters_on_nulls/mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
// populate in-memory database
SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
reader = Resources
.getResourceAsReader("org/apache/ibatis/submitted/call_setters_on_nulls/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}