(empty log message)
@@ -1,36 +0,0 @@ | ||
1 | -package sample.logiic; | |
2 | -import java.util.List; | |
3 | - | |
4 | -import org.apache.ibatis.session.RowBounds; | |
5 | - | |
6 | -import test.oracle.CountriesEntity; | |
7 | -import test.oracle.CountriesExample; | |
8 | -import test.oracle.CountriesMapper; | |
9 | - | |
10 | -public class SampleLogic extends AbstractLogic { | |
11 | - | |
12 | - @Override | |
13 | - protected int doExcecute() throws Exception { | |
14 | - { | |
15 | - SampleMapper mapper = DB.getMapper(SampleMapper.class); | |
16 | - int r = mapper.selectCountCountries(); | |
17 | - System.out.println("r = " + r); | |
18 | - } | |
19 | - { | |
20 | - SampleMapper mapper = DB.getMapper(SampleMapper.class); | |
21 | - RowBounds bounds = new RowBounds(0, 3); | |
22 | - List<CountriesEntity> list = mapper.selectCountriesList("1", bounds); | |
23 | - for (CountriesEntity dto : list) { | |
24 | - System.out.println(dto); | |
25 | - } | |
26 | - } | |
27 | - { | |
28 | - CountriesMapper mapper = DB.getMapper(CountriesMapper.class); | |
29 | - List<CountriesEntity> list = mapper.selectByExample(new CountriesExample()); | |
30 | - for (CountriesEntity dto : list) { | |
31 | - System.out.println(dto); | |
32 | - } | |
33 | - } | |
34 | - return OK; | |
35 | - } | |
36 | -} |
@@ -1,24 +0,0 @@ | ||
1 | -package sample.logiic; | |
2 | - | |
3 | -public abstract class AbstractLogic { | |
4 | - | |
5 | - final static int OK = 0; | |
6 | - final static int ERROR = 1; | |
7 | - final static int FALT = -1; | |
8 | - | |
9 | - abstract protected int doExcecute() throws Exception; | |
10 | - | |
11 | - final public int execute() { | |
12 | - try { | |
13 | - int r = doExcecute(); | |
14 | - DB.commit(); | |
15 | - return r; | |
16 | - } catch (Exception e) { | |
17 | - e.printStackTrace(); | |
18 | - DB.rollback(); | |
19 | - return FALT; | |
20 | - } finally { | |
21 | - DB.close(); | |
22 | - } | |
23 | - } | |
24 | -} |
@@ -1,8 +0,0 @@ | ||
1 | -package sample.logiic; | |
2 | - | |
3 | -public class SampleBatch { | |
4 | - | |
5 | - public static void main(String[] args) throws Exception { | |
6 | - new SampleLogic().execute(); | |
7 | - } | |
8 | -} |
@@ -1,57 +0,0 @@ | ||
1 | -package sample.logiic; | |
2 | -import java.io.InputStream; | |
3 | -import java.util.HashMap; | |
4 | - | |
5 | -import org.apache.ibatis.io.Resources; | |
6 | -import org.apache.ibatis.session.SqlSession; | |
7 | -import org.apache.ibatis.session.SqlSessionFactory; | |
8 | -import org.apache.ibatis.session.SqlSessionFactoryBuilder; | |
9 | - | |
10 | -public class DB { | |
11 | - | |
12 | - private static HashMap<String, SqlSession> sessionMap = new HashMap<>(); | |
13 | - private static SqlSessionFactory sqlSessionFactory; | |
14 | - static { | |
15 | - try { | |
16 | - InputStream inputStream = Resources.getResourceAsStream("mybatis-config_oracle.xml"); | |
17 | - sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); | |
18 | - } catch (Exception e) { | |
19 | - e.printStackTrace(); | |
20 | - } | |
21 | - } | |
22 | - | |
23 | - private static String getThreadName() { | |
24 | - return Thread.currentThread().getName(); | |
25 | - } | |
26 | - | |
27 | - private static SqlSession get() { | |
28 | - return sessionMap.get(getThreadName()); | |
29 | - } | |
30 | - | |
31 | - public static <T> T getMapper(Class<T> arg0) { | |
32 | - SqlSession sqlSession = get(); | |
33 | - if (sqlSession == null) { | |
34 | - sqlSession = sqlSessionFactory.openSession(); | |
35 | - sessionMap.put(getThreadName(), sqlSession); | |
36 | - } | |
37 | - return sqlSession.getMapper(arg0); | |
38 | - } | |
39 | - | |
40 | - public static void close() { | |
41 | - SqlSession sqlSession = get(); | |
42 | - if (sqlSession != null) { | |
43 | - sqlSession.close(); | |
44 | - sessionMap.remove(getThreadName()); | |
45 | - } | |
46 | - } | |
47 | - | |
48 | - public static void commit() { | |
49 | - SqlSession sqlSession = get(); | |
50 | - if (sqlSession != null) sqlSession.commit(); | |
51 | - } | |
52 | - | |
53 | - public static void rollback() { | |
54 | - SqlSession sqlSession = get(); | |
55 | - if (sqlSession != null) sqlSession.rollback(); | |
56 | - } | |
57 | -} |
@@ -1,24 +0,0 @@ | ||
1 | -package sample.logiic; | |
2 | -import java.util.List; | |
3 | - | |
4 | -import org.apache.ibatis.annotations.Param; | |
5 | -import org.apache.ibatis.annotations.Result; | |
6 | -import org.apache.ibatis.annotations.Results; | |
7 | -import org.apache.ibatis.annotations.Select; | |
8 | -import org.apache.ibatis.session.RowBounds; | |
9 | - | |
10 | -import test.oracle.CountriesEntity; | |
11 | - | |
12 | -public interface SampleMapper { | |
13 | - | |
14 | - @Select("SELECT count(*) FROM Countries") | |
15 | - int selectCountCountries(); | |
16 | - | |
17 | - @Select("SELECT * FROM Countries where region_id = #{region_id}") | |
18 | - @Results(value = { | |
19 | - @Result(property="countryId", column="country_id"), | |
20 | - @Result(property="countryName", column="country_name") | |
21 | - }) | |
22 | - List<CountriesEntity> selectCountriesList(@Param("region_id") String regionId, RowBounds bounds); | |
23 | - | |
24 | -} |
@@ -0,0 +1,24 @@ | ||
1 | +package sample.logic; | |
2 | + | |
3 | +public abstract class AbstractLogic { | |
4 | + | |
5 | + final static int OK = 0; | |
6 | + final static int ERROR = 1; | |
7 | + final static int FALT = -1; | |
8 | + | |
9 | + abstract protected int doExcecute() throws Exception; | |
10 | + | |
11 | + final public int execute() { | |
12 | + try { | |
13 | + int r = doExcecute(); | |
14 | + DB.commit(); | |
15 | + return r; | |
16 | + } catch (Exception e) { | |
17 | + e.printStackTrace(); | |
18 | + DB.rollback(); | |
19 | + return FALT; | |
20 | + } finally { | |
21 | + DB.close(); | |
22 | + } | |
23 | + } | |
24 | +} |
@@ -0,0 +1,57 @@ | ||
1 | +package sample.logic; | |
2 | +import java.io.InputStream; | |
3 | +import java.util.HashMap; | |
4 | + | |
5 | +import org.apache.ibatis.io.Resources; | |
6 | +import org.apache.ibatis.session.SqlSession; | |
7 | +import org.apache.ibatis.session.SqlSessionFactory; | |
8 | +import org.apache.ibatis.session.SqlSessionFactoryBuilder; | |
9 | + | |
10 | +public class DB { | |
11 | + | |
12 | + private static HashMap<String, SqlSession> sessionMap = new HashMap<>(); | |
13 | + private static SqlSessionFactory sqlSessionFactory; | |
14 | + static { | |
15 | + try { | |
16 | + InputStream inputStream = Resources.getResourceAsStream("mybatis-config_oracle.xml"); | |
17 | + sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); | |
18 | + } catch (Exception e) { | |
19 | + e.printStackTrace(); | |
20 | + } | |
21 | + } | |
22 | + | |
23 | + private static String getThreadName() { | |
24 | + return Thread.currentThread().getName(); | |
25 | + } | |
26 | + | |
27 | + private static SqlSession get() { | |
28 | + return sessionMap.get(getThreadName()); | |
29 | + } | |
30 | + | |
31 | + public static <T> T getMapper(Class<T> arg0) { | |
32 | + SqlSession sqlSession = get(); | |
33 | + if (sqlSession == null) { | |
34 | + sqlSession = sqlSessionFactory.openSession(); | |
35 | + sessionMap.put(getThreadName(), sqlSession); | |
36 | + } | |
37 | + return sqlSession.getMapper(arg0); | |
38 | + } | |
39 | + | |
40 | + public static void close() { | |
41 | + SqlSession sqlSession = get(); | |
42 | + if (sqlSession != null) { | |
43 | + sqlSession.close(); | |
44 | + sessionMap.remove(getThreadName()); | |
45 | + } | |
46 | + } | |
47 | + | |
48 | + public static void commit() { | |
49 | + SqlSession sqlSession = get(); | |
50 | + if (sqlSession != null) sqlSession.commit(); | |
51 | + } | |
52 | + | |
53 | + public static void rollback() { | |
54 | + SqlSession sqlSession = get(); | |
55 | + if (sqlSession != null) sqlSession.rollback(); | |
56 | + } | |
57 | +} |
@@ -0,0 +1,8 @@ | ||
1 | +package sample.logic; | |
2 | + | |
3 | +public class SampleBatch { | |
4 | + | |
5 | + public static void main(String[] args) throws Exception { | |
6 | + new SampleLogic().execute(); | |
7 | + } | |
8 | +} |
@@ -0,0 +1,36 @@ | ||
1 | +package sample.logic; | |
2 | +import java.util.List; | |
3 | + | |
4 | +import org.apache.ibatis.session.RowBounds; | |
5 | + | |
6 | +import test.oracle.CountriesEntity; | |
7 | +import test.oracle.CountriesExample; | |
8 | +import test.oracle.CountriesMapper; | |
9 | + | |
10 | +public class SampleLogic extends AbstractLogic { | |
11 | + | |
12 | + @Override | |
13 | + protected int doExcecute() throws Exception { | |
14 | + { | |
15 | + SampleMapper mapper = DB.getMapper(SampleMapper.class); | |
16 | + int r = mapper.selectCountCountries(); | |
17 | + System.out.println("r = " + r); | |
18 | + } | |
19 | + { | |
20 | + SampleMapper mapper = DB.getMapper(SampleMapper.class); | |
21 | + RowBounds bounds = new RowBounds(0, 3); | |
22 | + List<CountriesEntity> list = mapper.selectCountriesList("1", bounds); | |
23 | + for (CountriesEntity dto : list) { | |
24 | + System.out.println(dto); | |
25 | + } | |
26 | + } | |
27 | + { | |
28 | + CountriesMapper mapper = DB.getMapper(CountriesMapper.class); | |
29 | + List<CountriesEntity> list = mapper.selectByExample(new CountriesExample()); | |
30 | + for (CountriesEntity dto : list) { | |
31 | + System.out.println(dto); | |
32 | + } | |
33 | + } | |
34 | + return OK; | |
35 | + } | |
36 | +} |
@@ -0,0 +1,24 @@ | ||
1 | +package sample.logic; | |
2 | +import java.util.List; | |
3 | + | |
4 | +import org.apache.ibatis.annotations.Param; | |
5 | +import org.apache.ibatis.annotations.Result; | |
6 | +import org.apache.ibatis.annotations.Results; | |
7 | +import org.apache.ibatis.annotations.Select; | |
8 | +import org.apache.ibatis.session.RowBounds; | |
9 | + | |
10 | +import test.oracle.CountriesEntity; | |
11 | + | |
12 | +public interface SampleMapper { | |
13 | + | |
14 | + @Select("SELECT count(*) FROM Countries") | |
15 | + int selectCountCountries(); | |
16 | + | |
17 | + @Select("SELECT * FROM Countries where region_id = #{region_id}") | |
18 | + @Results(value = { | |
19 | + @Result(property="countryId", column="country_id"), | |
20 | + @Result(property="countryName", column="country_name") | |
21 | + }) | |
22 | + List<CountriesEntity> selectCountriesList(@Param("region_id") String regionId, RowBounds bounds); | |
23 | + | |
24 | +} |