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

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

Introduction

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

Prototype

int delete(String statement);

Source Link

Document

Execute a delete statement.

Usage

From source file:com.baidu.oped.apm.plugin.mybatis.SqlSessionTestBase.java

License:Apache License

protected final void testAndVerifyDelete() throws Exception {
    // Given/*from   w w w  .ja  v  a2  s.  com*/
    final String deleteId = "deleteId";
    SqlSession sqlSession = getSqlSession();
    // When
    sqlSession.delete(deleteId);
    sqlSession.delete(deleteId, new Object());
    // Then
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    Method delete1 = sqlSession.getClass().getDeclaredMethod("delete", String.class);
    Method delete2 = sqlSession.getClass().getDeclaredMethod("delete", String.class, Object.class);
    verifier.verifyTrace(event("MYBATIS", delete1, Expectations.cachedArgs(deleteId)));
    verifier.verifyTrace(event("MYBATIS", delete2, Expectations.cachedArgs(deleteId)));
}

From source file:com.baomidou.mybatisplus.test.oracle.TestUserMapperTest.java

License:Apache License

/**
 *
 * RUN   MySql  //from  w  w w .  j  a va2s  .c o m
 *
 */
public static void main(String[] args) {

    //?
    InputStream in = TestUserMapperTest.class.getClassLoader().getResourceAsStream("oracle-config.xml");

    /*
       *  MybatisSessionFactoryBuilder 
     * SqlSessionFactoryBaseMapper
     */
    MybatisSessionFactoryBuilder mf = new MybatisSessionFactoryBuilder();

    /** ? oracle */
    GlobalConfiguration gc = new GlobalConfiguration();
    gc.setDbType("oracle");
    mf.setGlobalConfig(gc);

    /*
     * 1??????
     * 2?????
     * 3?????
     *    ?? @TableId(value = "test_id") 
     */
    //mf.setDbColumnUnderline(true);

    SqlSessionFactory sessionFactory = mf.build(in);
    SqlSession session = sessionFactory.openSession();
    TestUserMapper testUserMapper = session.getMapper(TestUserMapper.class);
    System.err.println(" debug run  test_user ??? ");
    session.delete("deleteAll");

    /**
     * ?
     */
    int rlt = testUserMapper.insert(new TestUser("10", "abc", 18, 1));
    System.err.println("\n--------------insert-------" + rlt);
    sleep();

    /**
     * ??
     */
    List<TestUser> ul = new ArrayList<>();
    ul.add(new TestUser("11", "1a", 11, 1));
    ul.add(new TestUser("12", "2a", 12, 2));
    ul.add(new TestUser("a", 1, 1));
    ul.add(new TestUser("b", 2, 2));
    ul.add(new TestUser("c", 3, 1));
    for (TestUser u : ul) {
        rlt = testUserMapper.insert(u);
    }
    System.err.println("\n--------------insertBatch-------" + rlt);
    sleep();

    /**
     * ?
     */
    List<TestUser> ul1 = new ArrayList<>();
    ul1.add(new TestUser("10", "update-0a", 11, 1));
    ul1.add(new TestUser("11", "update-1a", 11, 1));
    ul1.add(new TestUser("12", "update-2a", 12, 2));
    for (TestUser u : ul1) {
        rlt = testUserMapper.updateById(u);
    }
    System.err.println("\n--------------updateBatchById-------" + rlt);
    sleep();

    System.err.println(
            "\n------------------list  ---- testType = 1 ?--id--DESC--?--------");
    Page<TestUser> page = new Page<>(1, 2);
    EntityWrapper<TestUser> ew = new EntityWrapper<>(new TestUser(1), "TEST_ID DESC");
    List<TestUser> paginList = testUserMapper.selectPage(page, ew);
    page.setRecords(paginList);
    for (int i = 0; i < page.getRecords().size(); i++) {
        print(page.getRecords().get(i));
    }
    System.err.println(" " + page.toString());

    /* ?  */
    rlt = session.delete("deleteAll");
    System.err.println("?? rlt=" + rlt);

    /**
     * ??
     */
    session.commit();
}

From source file:com.mybatisX.test.oracle.TestUserMapperTest.java

License:Apache License

/**
 * //  ww w . j av  a 2 s.c om
 * RUN   MySql  
 * 
 */
public static void main(String[] args) {

    //?
    InputStream in = TestUserMapperTest.class.getClassLoader().getResourceAsStream("oracle-config.xml");

    /*
     *  MybatisSessionFactoryBuilder 
     * SqlSessionFactoryBaseMapper
     */
    MybatisSessionFactoryBuilder mf = new MybatisSessionFactoryBuilder();

    /** ? oracle */
    mf.setDbType("oracle");

    /*
     * 1??????
     * 2?????
     * 3?????
     *    ?? @TableId(value = "test_id") 
     */
    //mf.setDbColumnUnderline(true);

    SqlSessionFactory sessionFactory = mf.build(in);
    SqlSession session = sessionFactory.openSession();
    TestUserMapper testUserMapper = session.getMapper(TestUserMapper.class);
    System.err.println(" debug run  test_user ??? ");
    session.delete("deleteAll");

    /**
     * ?
     */
    int rlt = testUserMapper.insert(new TestUser("10", "abc", 18, 1));
    System.err.println("\n--------------insert-------" + rlt);
    sleep();

    /**
     * ??
     */
    List<TestUser> ul = new ArrayList<TestUser>();
    ul.add(new TestUser("11", "1a", 11, 1));
    ul.add(new TestUser("12", "2a", 12, 2));
    ul.add(new TestUser("a", 1, 1));
    ul.add(new TestUser("b", 2, 2));
    ul.add(new TestUser("c", 3, 1));
    for (TestUser u : ul) {
        rlt = testUserMapper.insert(u);
    }
    System.err.println("\n--------------insertBatch-------" + rlt);
    sleep();

    /**
     * ?
     */
    List<TestUser> ul1 = new ArrayList<TestUser>();
    ul1.add(new TestUser("10", "update-0a", 11, 1));
    ul1.add(new TestUser("11", "update-1a", 11, 1));
    ul1.add(new TestUser("12", "update-2a", 12, 2));
    for (TestUser u : ul1) {
        rlt = testUserMapper.updateById(u);
    }
    System.err.println("\n--------------updateBatchById-------" + rlt);
    sleep();

    System.err.println(
            "\n------------------list  ---- testType = 1 ?--id--DESC--?--------");
    Page<TestUser> page = new Page<TestUser>(1, 2);
    EntityWrapper<TestUser> ew = new EntityWrapper<TestUser>(new TestUser(1), "TEST_ID DESC");
    List<TestUser> paginList = testUserMapper.selectPage(page, ew);
    page.setRecords(paginList);
    for (int i = 0; i < page.getRecords().size(); i++) {
        print(page.getRecords().get(i));
    }
    System.err.println(" " + page.toString());

    /* ?  */
    rlt = session.delete("deleteAll");
    System.err.println("?? rlt=" + rlt);

    /**
     * ??
     */
    session.commit();
}

From source file:com.onnurimotors.wm.service.WmService.java

public String regenerateDB() {
    SqlSession session = sqlSession();

    session.delete("watchman.mybatis.dropManagementTable");
    session.commit();//from   w w  w .ja  v a2  s.  c o m
    session.delete("watchman.mybatis.dropHistoryManagementTable");
    session.commit();
    session.delete("watchman.mybatis.dropVehicleTable");
    session.commit();
    session.delete("watchman.mybatis.dropHistoryTable");
    session.commit();

    session.insert("watchman.mybatis.createManagementTable");
    session.commit();
    session.insert("watchman.mybatis.createHistoryManagementTable");
    session.commit();
    session.insert("watchman.mybatis.createVehicleTable");
    session.commit();
    session.insert("watchman.mybatis.createHistoryTable");
    session.commit();

    session.close();

    return "Success";
}

From source file:com.onnurimotors.wm.service.WmService.java

public String modifyDB() {
    SqlSession session = sqlSession();

    //session.update("watchman.mybatis.modifyEmployeeTable");
    //session.commit();

    session.delete("watchman.mybatis.dropEmployeeTable");
    session.commit();/*from   w w  w  . ja va  2 s.  co m*/

    session.insert("watchman.mybatis.createEmployeeTable");
    session.commit();

    session.close();

    return "Success";
}

From source file:net.hasor.db.orm.mybatis3.SqlExecutorTemplate.java

License:Apache License

public int delete(final String statement) throws SQLException {
    return this.execute(new SqlSessionCallback<Integer>() {
        public Integer doSqlSession(SqlSession sqlSession) {
            return sqlSession.delete(statement);
        }//w  w w  . j ava2 s .c  om
    });
}

From source file:webim.dao.ibatis.WebimHistoryDao.java

License:Apache License

/**
 * with?MySQL:<br>/*from www  . ja v  a  2s  .co  m*/
 * 
 * "UPDATE webim_histories SET fromdel = 1 Where from = @0 and to = @1 and type = 'chat'"
 * <br>
 * "UPDATE webim_histories SET todel = 1 Where to = @0 and from = @1 and type = 'chat'"
 * <br>
 * "DELETE FROM webim_histories WHERE fromdel = 1 AND todel = 1"
 * 
 * @param uid
 *            uid
 * @param with
 *            id,????long
 */
public void clearHistories(String uid, String with) {
    Map<String, String> params = new HashMap<String, String>();
    params.put("uid", uid);
    params.put("with", with);
    SqlSession session = sessionFactory.openSession();
    try {
        session.update("HistoryMapper.clearFromHistory", params);
        session.update("HistoryMapper.clearToHistory", params);
        session.delete("HistoryMapper.deleteHistory");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        session.close();
    }
}

From source file:webim.dao.ibatis.WebimHistoryDao.java

License:Apache License

public void clearAll() {
    SqlSession session = sessionFactory.openSession();
    try {/*  w ww  .  j  av  a 2 s.c om*/
        session.delete("HistoryMapper.clearAll");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        session.close();
    }
}

From source file:webim.dao.ibatis.WebimRoomDao.java

License:Apache License

public void clearAll() {
    SqlSession session = sessionFactory.openSession();
    try {/*w w w .  j ava2s  . c om*/
        session.delete("RoomMapper.deleteMembers");
        session.delete("RoomMapper.deleteRooms");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        session.close();
    }
}