本文整理汇总了Java中org.apache.ibatis.session.Configuration.addInterceptor方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.addInterceptor方法的具体用法?Java Configuration.addInterceptor怎么用?Java Configuration.addInterceptor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ibatis.session.Configuration
的用法示例。
在下文中一共展示了Configuration.addInterceptor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTest
import org.apache.ibatis.session.Configuration; //导入方法依赖的package包/类
@Test
public void doTest() {
HikariDataSource dataSource = new HikariDataSource();// DataSource
// H2 is a memory database
dataSource.setDriverClassName("org.h2.Driver");
dataSource.setJdbcUrl("jdbc:h2:mem:DBName;MODE=MYSQL;DB_CLOSE_DELAY=-1;TRACE_LEVEL_SYSTEM_OUT=0");
dataSource.setUsername("sa");
dataSource.setPassword("");
// MySQL
// dataSource.setDriverClassName("com.mysql.jdbc.Driver");
// dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test?rewriteBatchedStatements=true&useSSL=false");
// dataSource.setUsername("root");
// dataSource.setPassword("root888");
// MS-SqlServer
// dataSource.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// dataSource.setJdbcUrl("jdbc:sqlserver://localhost:1433;databaseName=test");
// dataSource.setUsername("sa");
// dataSource.setPassword("root888");
// ORACLE
// dataSource.setDriverClassName("oracle.jdbc.OracleDriver");
// dataSource.setJdbcUrl("jdbc:oracle:thin:@127.0.0.1:1521:XE");
// dataSource.setUsername("root");
// dataSource.setPassword("root888");
SqlBoxContext ctx = new SqlBoxContext(dataSource);
SqlBoxContext.setDefaultContext(ctx);
ctx.setAllowShowSQL(true);
String[] ddlArray = ctx.toDropAndCreateDDL(User.class);
for (String ddl : ddlArray)
ctx.quiteExecute(ddl);
for (int i = 1; i <= 100; i++)
new User().put("firstName", "Foo" + i, "lastName", "Bar" + i, "age", i).insert();
TransactionFactory transactionFactory = new JdbcTransactionFactory();
Environment environment = new Environment("demo", transactionFactory, dataSource);
Configuration configuration = new Configuration(environment);
configuration.addMapper(UserMapper.class);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
configuration.addInterceptor(new JDialectsPlugin());
SqlSession session = null;
try {
session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
Assert.assertEquals(100, ctx.nQueryForLongValue(conn, "select count(*) from users"));
List<Map<String, Object>> users;
try {
paginInfo.set(new Object[] { ctx.getDialect(), 3, 10 });
users = session.getMapper(UserMapper.class).getOlderThan(50);
} finally {
paginInfo.remove();
}
Assert.assertEquals(10, users.size());
for (Map<String, Object> map : users)
System.out.println("UserName=" + map.get("USERNAME") + ", age=" + map.get("AGE"));
} finally {
session.close();
}
dataSource.close();
}