use of com.alibaba.druid.spring.User in project druid by alibaba.
the class SpringMybatisFilterTest method test_spring.
public void test_spring() throws Exception {
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("com/alibaba/druid/pool/mybatis/spring-config-mybatis.xml");
DataSource dataSource = (DataSource) context.getBean("dataSource");
{
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("CREATE TABLE sequence_seed (value INTEGER, name VARCHAR(50))");
stmt.close();
conn.close();
}
{
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("CREATE TABLE t_User (id BIGINT, name VARCHAR(50))");
stmt.close();
conn.close();
}
{
Connection conn = dataSource.getConnection();
conn.setAutoCommit(false);
Statement stmt = conn.createStatement();
stmt.execute("insert into sequence_seed (value ,name) values (0, 'druid-spring-test')");
stmt.close();
conn.commit();
conn.close();
}
UserMapper userMapper = (UserMapper) context.getBean("userMapper");
{
User user = new User();
user.setName("xx");
userMapper.addUser(user);
}
{
userMapper.errorSelect(1);
}
{
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("DROP TABLE sequence_seed");
stmt.close();
conn.close();
}
{
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("DROP TABLE t_User");
stmt.close();
conn.close();
}
context.close();
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
}
use of com.alibaba.druid.spring.User in project druid by alibaba.
the class SqlMapClientWrapperTest method test_wrap.
public void test_wrap() throws Exception {
SqlMapClientImpl client = (SqlMapClientImpl) context.getBean("master-sqlMapClient");
Assert.assertNotNull(client);
SqlMapClientWrapper wrapper = new SqlMapClientWrapper(client);
wrapper.insert("User.insert", new User(12345678, "aaa"));
{
Exception error = null;
try {
wrapper.insert("User.insert");
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
wrapper.update("User.update", new User(12345678, "bbb"));
{
Exception error = null;
try {
wrapper.update("User.update");
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
Assert.assertNotNull((User) wrapper.queryForObject("User.select"));
Assert.assertNotNull((User) wrapper.queryForObject("User.select", Collections.emptyMap()));
Assert.assertNotNull((User) wrapper.queryForObject("User.select", Collections.emptyMap(), new User()));
Assert.assertEquals(1, wrapper.queryForList("User.select").size());
Assert.assertEquals(1, wrapper.queryForList("User.select", Collections.emptyMap()).size());
Assert.assertEquals(1, wrapper.queryForList("User.select", Collections.emptyMap(), 0, 2).size());
wrapper.queryWithRowHandler("User.select", new RowHandler() {
@Override
public void handleRow(Object valueObject) {
}
});
wrapper.queryWithRowHandler("User.select", Collections.emptyMap(), new RowHandler() {
@Override
public void handleRow(Object valueObject) {
}
});
Assert.assertEquals(1, wrapper.queryForPaginatedList("User.select", 10).size());
Assert.assertEquals(1, wrapper.queryForPaginatedList("User.select", Collections.emptyMap(), 10).size());
Assert.assertNotNull(wrapper.queryForMap("User.select", Collections.emptyMap(), "id"));
Assert.assertNotNull(wrapper.queryForMap("User.select", Collections.emptyMap(), "id", "name"));
wrapper.delete("User.delete", 12345678L);
{
Exception error = null;
try {
wrapper.delete("User.delete");
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
wrapper.startBatch();
wrapper.executeBatch();
wrapper.executeBatchDetailed();
}
use of com.alibaba.druid.spring.User in project druid by alibaba.
the class SpringIbatisFilterTest method test_spring.
public void test_spring() throws Exception {
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("com/alibaba/druid/pool/ibatis/spring-config-ibatis.xml");
DataSource dataSource = (DataSource) context.getBean("dataSource");
{
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("CREATE TABLE sequence_seed (value INTEGER, name VARCHAR(50) PRIMARY KEY)");
stmt.close();
conn.close();
}
{
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("CREATE TABLE t_User (id BIGINT PRIMARY KEY, name VARCHAR(50))");
stmt.close();
conn.close();
}
{
Connection conn = dataSource.getConnection();
conn.setAutoCommit(false);
Statement stmt = conn.createStatement();
stmt.execute("insert into sequence_seed (value ,name) values (0, 'druid-spring-test')");
stmt.close();
conn.commit();
conn.close();
}
// user-service
IUserService service = (IUserService) context.getBean("user-service");
User user = new User();
user.setName("xx");
service.addUser(user);
TestFilter filter = (TestFilter) context.getBean("test-filter");
Assert.assertEquals(2, filter.getConnectCount());
{
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("DROP TABLE sequence_seed");
stmt.close();
conn.close();
}
{
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
stmt.execute("DROP TABLE t_User");
stmt.close();
conn.close();
}
Assert.assertEquals(1, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
Map<String, Object> wallStats = DruidStatService.getInstance().getWallStatMap(Collections.<String, String>emptyMap());
System.out.println("wall-stats : " + JSONUtils.toJSONString(wallStats));
context.close();
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
}
use of com.alibaba.druid.spring.User in project druid by alibaba.
the class SqlMapExecutorWrapperTest_2 method test_wrap.
public void test_wrap() throws Exception {
SqlMapClientImpl client = (SqlMapClientImpl) context.getBean("master-sqlMapClient");
Assert.assertNotNull(client);
SqlMapExecutorWrapper wrapper = new SqlMapExecutorWrapper(client, client);
wrapper.insert("User.insert", new User(12345678, "aaa"));
{
Exception error = null;
try {
wrapper.insert("User.insert");
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
wrapper.update("User.update", new User(12345678, "bbb"));
{
Exception error = null;
try {
wrapper.update("User.update");
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
Assert.assertNotNull((User) wrapper.queryForObject("User.select"));
Assert.assertNotNull((User) wrapper.queryForObject("User.select", Collections.emptyMap()));
Assert.assertNotNull((User) wrapper.queryForObject("User.select", Collections.emptyMap(), new User()));
Assert.assertEquals(1, wrapper.queryForList("User.select").size());
Assert.assertEquals(1, wrapper.queryForList("User.select", Collections.emptyMap()).size());
Assert.assertEquals(1, wrapper.queryForList("User.select", Collections.emptyMap(), 0, 2).size());
wrapper.queryWithRowHandler("User.select", new RowHandler() {
@Override
public void handleRow(Object valueObject) {
}
});
wrapper.queryWithRowHandler("User.select", Collections.emptyMap(), new RowHandler() {
@Override
public void handleRow(Object valueObject) {
}
});
Assert.assertEquals(1, wrapper.queryForPaginatedList("User.select", 10).size());
Assert.assertEquals(1, wrapper.queryForPaginatedList("User.select", Collections.emptyMap(), 10).size());
Assert.assertNotNull(wrapper.queryForMap("User.select", Collections.emptyMap(), "id"));
Assert.assertNotNull(wrapper.queryForMap("User.select", Collections.emptyMap(), "id", "name"));
wrapper.delete("User.delete", 12345678L);
{
Exception error = null;
try {
wrapper.delete("User.delete");
} catch (Exception ex) {
error = ex;
}
Assert.assertNotNull(error);
}
wrapper.startBatch();
wrapper.executeBatch();
wrapper.executeBatchDetailed();
}
Aggregations