Example usage for org.apache.ibatis.session Configuration hasStatement

List of usage examples for org.apache.ibatis.session Configuration hasStatement

Introduction

In this page you can find the example usage for org.apache.ibatis.session Configuration hasStatement.

Prototype

public boolean hasStatement(String statementName) 

Source Link

Usage

From source file:org.workspace7.osgi.mybatis.itests.MyBatisExtenderIT.java

License:Apache License

@Test
public void testExtender() throws SQLException {

    try {/*from w ww.j  av a 2 s. co  m*/
        createAndDropH2Table(demodbDS);
        ServiceReference[] mybatisConfigRefs = bundleContext.getServiceReferences(Configuration.class.getName(),
                "(dataSourceName=demodbDS)");
        assertNotNull(mybatisConfigRefs);
        assertEquals(1, mybatisConfigRefs.length);
        Configuration mybatisConfig = (Configuration) bundleContext.getService(mybatisConfigRefs[0]);
        assertNotNull(mybatisConfig);
        boolean hasStatement = mybatisConfig.hasStatement("selectAllPersons");
        assertTrue(hasStatement);
    } catch (InvalidSyntaxException e) {
        fail(e.getMessage());
    } catch (Exception e) {
        fail(e.getMessage());
    }
}

From source file:org.workspace7.osgi.mybatis.itests.MyBatisExtenderIT.java

License:Apache License

@Test
public void testSqlSessionQuery() throws SQLException {
    try {// www .j a va 2 s  . co m
        createAndDropH2Table(demodbDS);
        ServiceReference[] mybatisConfigRefs = bundleContext.getServiceReferences(Configuration.class.getName(),
                "(dataSourceName=demodbDS)");
        assertNotNull(mybatisConfigRefs);
        assertEquals(1, mybatisConfigRefs.length);
        Configuration mybatisConfig = (Configuration) bundleContext.getService(mybatisConfigRefs[0]);
        assertNotNull(mybatisConfig);
        boolean hasStatement = mybatisConfig.hasStatement("selectAllPersons");
        assertTrue(hasStatement);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(mybatisConfig);
        List<Object> listOfPersons = sqlSessionFactory.openSession().selectList("selectAllPersons");
        assertFalse(listOfPersons.isEmpty());
        assertEquals(4, listOfPersons.size());

    } catch (InvalidSyntaxException e) {
        fail(e.getMessage());
    } catch (Exception e) {
        fail(e.getMessage());
    }
}