Example usage for org.apache.ibatis.session SqlSession getMapper

List of usage examples for org.apache.ibatis.session SqlSession getMapper

Introduction

In this page you can find the example usage for org.apache.ibatis.session SqlSession getMapper.

Prototype

<T> T getMapper(Class<T> type);

Source Link

Document

Retrieves a mapper.

Usage

From source file:com.oneops.cms.test.CmsTest.java

License:Apache License

@SuppressWarnings("unused")
private static void testState(SqlSessionFactory sqlsf) {
    SqlSession session = sqlsf.openSession();
    DJMapper djMapper = session.getMapper(DJMapper.class);

    try {/*from  ww w  . j a va 2s . c om*/
        Integer stateId = djMapper.getReleaseStateId("qqqq");
    } finally {
        session.close();
    }

}

From source file:com.oneops.cms.test.DJTests.java

License:Apache License

/**
 * @param args// ww  w  .  ja v  a2  s  . c o m
 * @throws IOException 
 * @throws SQLException 
 */
public static void main(String[] args) throws IOException, SQLException {
    String resource = "mybatis-config.xml";
    Reader reader = Resources.getResourceAsReader(resource);
    SqlSessionFactory sqlsf = new SqlSessionFactoryBuilder().build(reader);

    SqlSession session = sqlsf.openSession();
    CIMapper ciMapper = session.getMapper(CIMapper.class);
    ClazzMapper clMapper = session.getMapper(ClazzMapper.class);
    NSMapper nsMapper = session.getMapper(NSMapper.class);
    RelationMapper rlMapper = session.getMapper(RelationMapper.class);
    DJMapper djMapper = session.getMapper(DJMapper.class);
    CmsRfcProcessor rfcProcessor = new CmsRfcProcessor();
    CmsCmProcessor cmProcessor = new CmsCmProcessor();

    //cmMan.setCiMapper(ciMapper);
    //cmMan.setCmValidator(cmValidator);
    //cmMan.setNsManager(nsProc);

    cmProcessor.setCiMapper(ciMapper);
    cmProcessor.setCmValidator(cmValidator);
    cmProcessor.setCmsNsProcessor(nsProc);

    cmValidator.setCmsMdProcessor(mdProc);
    cmValidator.setCmsNsProcessor(nsProc);

    djValidator.setCmsMdProcessor(mdProc);
    djValidator.setCmsNsProcessor(nsProc);

    nsProc.setNsMapper(nsMapper);

    CmsMdProcessor mdProcessor = new CmsMdProcessor();
    mdProcessor.setClazzMapper(clMapper);
    mdProcessor.setRelationMapper(rlMapper);

    rfcProcessor.setDjMapper(djMapper);
    rfcProcessor.setCmsNsProcessor(nsProc);
    rfcProcessor.setDjValidator(djValidator);
    rfcProcessor.setCiMapper(ciMapper);

    djMan.setRfcProcessor(rfcProcessor);

    CmsCmRfcMrgProcessor cmrfcProcessor = new CmsCmRfcMrgProcessor();
    cmrfcProcessor.setCmProcessor(cmProcessor);
    cmrfcProcessor.setRfcProcessor(rfcProcessor);
    cmrfcProcessor.setDjValidator(djValidator);

    cmdjMan.setCmRfcMrgProcessor(cmrfcProcessor);

    try {
        //testCreateRelease();
        //testUpdateRelease();
        //testCreateRrfcCi();
        //testUpdateRrfcCi();
        //testRmRrfcCi();
        //testGetRfcCi();
        //testCreateRrfcRelation();
        //testUpdateRrfcRelation();
        testGetRfcCI();
        session.commit();
    } finally {
        session.close();
    }
}

From source file:com.oneops.cms.transmitter.BaseEventReader.java

License:Apache License

public List<CMSEvent> getEvents() {

    SqlSession session = null;
    List<CMSEvent> cmsEvents = new ArrayList<>();

    try {//from  www .j  a  v  a 2 s.c  om

        session = sqlsf.openSession();
        EventMapper eventMapper = session.getMapper(EventMapper.class);

        if (!eventMapper.good2run(getLockName(), processId, PROCESS_TIMEOUT_SECONDS)) {
            if (iamActiveProcess == null || iamActiveProcess) {
                logger.info(">>>>>>>>>Other process has a lock " + getLockName() + ", will wait");
                iamActiveProcess = false;
            }
            session.commit(true);
            return cmsEvents;
        } else {
            if (iamActiveProcess == null || !iamActiveProcess) {
                logger.info(">>>>>>>>>Acquired lock " + getLockName() + ", I'm the active process now");
                iamActiveProcess = true;
            }
            session.commit(true);
        }

        if (isCmsPubActive()) {
            for (CMSEventRecord record : getEvents(eventMapper)) {
                CMSEvent event = populateEvent(record);
                if (event != null) {
                    cmsEvents.add(event);
                }
            }
        }
    } catch (Exception e) {
        if (e instanceof PersistenceException) {
            logger.error("Problem connecting to the postgres db, I will try reconnect...");
            logger.error(e.getMessage());
        } else {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    } finally {
        if (session != null) {
            session.close();
        }
    }

    return cmsEvents;

}

From source file:com.osc.edu.chapter2.Starter.java

License:Open Source License

/**
 * <pre>/* www .  ja v  a2  s .co  m*/
 *  ?  samples/commons/db_configuration/build.xml ?? test-db-start, initializeData Task  .
 * </pre>
 * @param args
 */
public static void main(String[] args) {
    SqlSession session = SqlSessionFactoryManager.getSqlSession();

    List<CustomersDto> customersList = null;
    List<EmployeesDto> employeesList = null;

    logger.debug("Invoke query using Mapper XML.");

    // (xml) mapper ?? namespace, id ?  
    customersList = session.selectList("com.osc.edu.commons.customers.mapper.CustomersMapper.getCustomersList");
    employeesList = session.selectList("com.osc.edu.commons.employees.mapper.EmployeesMapper.getEmployeesList");

    logger.debug("customersList's size : {}", customersList.size());
    logger.debug("employeesList's size : {}", employeesList.size());

    // Mapper ?? ?  
    CustomersMapper customersMapper = session.getMapper(CustomersMapper.class);
    EmployeesMapper employeesMapper = session.getMapper(EmployeesMapper.class);

    //  ? ? ?  ?? .
    customersMapper.deleteCustomers(103);
    employeesMapper.deleteEmployees(1002);

    customersList = customersMapper.getCustomersList();
    employeesList = employeesMapper.getEmployeesList();

    logger.debug("customersList's size : {}", customersList.size());
    logger.debug("employeesList's size : {}", employeesList.size());

    session.close();
}

From source file:com.qs.validation.ValidationCheck.java

public static List<User> getAllUser() {

    ValidationCheck vc = new ValidationCheck();
    SqlSession session = vc.getSqlSession();
    List<User> list = null;
    try {/*from ww  w .j a v  a  2  s  .  c om*/
        UserDao userDao = session.getMapper(UserDao.class);
        list = userDao.getAllUser();
        System.out.println(list.size());

    } finally {
        session.close();
    }

    return list;
}

From source file:com.qs.validation.ValidationCheck.java

public static List<String> getPasswordByName(String userName) {

    List<String> list = null;
    ValidationCheck vc = new ValidationCheck();
    SqlSession session = vc.getSqlSession();

    try {/*from  ww  w  .  ja va  2  s .  co m*/
        UserDao userDao = session.getMapper(UserDao.class);
        list = userDao.getPasswordByName(userName);
        if (!list.isEmpty()) {
            System.out.println(list.size() + list.get(0));
        }

    } finally {
        session.close();
    }

    return list;
}

From source file:com.qs.validation.ValidationCheck.java

public boolean checkUserNameExist(String userName) {

    List<String> list = null;
    ValidationCheck vc = new ValidationCheck();
    SqlSession session = vc.getSqlSession();
    try {//from   w w  w  .j a v  a2s. c  o m

        UserDao userDao = session.getMapper(UserDao.class);
        //User test=userDao.getUserByUserName("admin");
        //System.out.println(test.getPassword()+"test ");
        list = userDao.getPasswordByName(userName);
        if (!list.isEmpty()) {
            System.out.println(list.size() + list.get(0));
            return false;
        } else {
            return true;
        }

    } catch (Exception e) {
        System.out.println(e);
        return false;
    } finally {
        session.close();
    }

}

From source file:com.qs.validation.ValidationCheck.java

public static void main(String[] args) {
    //getAllUser();
    //getPasswordByName("admin");
    ValidationCheck vc = new ValidationCheck();
    //System.out.println(vc.checkUserNameExist("admin")+"jieguojieguo");
    //ValidationCheck  vc=new ValidationCheck();
    SqlSession session = vc.getSqlSession();

    try {/*from  ww w.jav  a 2  s  .co m*/
        //UserDao userDao=session.getMapper(UserDao.class);
        PostDao postDao = session.getMapper(PostDao.class);
        List<Post> list = postDao.getAllPost();
        System.out.println(list.size());

    } catch (Exception e) {
        System.out.println(e);
    }

}

From source file:com.qs.validation.ValidationCheckAll.java

public static void main(String[] args) {

    ValidationCheck vc = new ValidationCheck();
    //System.out.println(vc.checkUserNameExist("admin")+"jieguojieguo");
    //ValidationCheck  vc=new ValidationCheck();
    SqlSession session = vc.getSqlSession();

    try {//from  w w w.  j av  a 2 s .  c o  m
        //UserDao userDao=session.getMapper(UserDao.class);
        PostDao postDao = session.getMapper(PostDao.class);
        List<Post> list = postDao.getAllPost();
        System.out.println(list.size());

    } catch (Exception e) {
        System.out.println(e);
    }

}

From source file:com.quancheng.mybatis.mapper.test.able.TestBasicAble.java

License:Open Source License

/**
 * /*from w  w  w.j  ava2  s . com*/
 */
@Test
public void testInsert() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        UserInfoAbleMapper mapper = sqlSession.getMapper(UserInfoAbleMapper.class);
        UserInfoAble userInfo = new UserInfoAble();
        userInfo.setUsername("abel533");
        userInfo.setPassword("123456");
        userInfo.setUsertype("2");
        userInfo.setEmail("abel533@gmail.com");//insert=false

        Assert.assertEquals(1, mapper.insert(userInfo));

        Assert.assertNotNull(userInfo.getId());
        Assert.assertEquals(6, (int) userInfo.getId());

        userInfo = mapper.selectByPrimaryKey(userInfo.getId());
        //email?
        Assert.assertNull(userInfo.getEmail());
    } finally {
        sqlSession.rollback();
        sqlSession.close();
    }
}