Skip to content

Commit 6a828aa

Browse files
Updated for rewrite changes.
1 parent 7924e18 commit 6a828aa

File tree

36 files changed

+204
-132
lines changed

36 files changed

+204
-132
lines changed

chapter01/src/main/java/com/mybatis3/util/MyBatisSqlSessionFactory.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,21 @@ public static SqlSessionFactory getSqlSessionFactory()
3636
{
3737
if(sqlSessionFactory==null)
3838
{
39-
InputStream inputStream;
39+
InputStream inputStream = null;
4040
try
4141
{
4242
inputStream = Resources.getResourceAsStream("mybatis-config.xml");
4343
sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
4444
}catch (IOException e)
4545
{
4646
throw new RuntimeException(e.getCause());
47+
}finally {
48+
if(inputStream != null){
49+
try {
50+
inputStream.close();
51+
} catch (IOException e) {
52+
}
53+
}
4754
}
4855
}
4956
return sqlSessionFactory;

chapter02/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This module, chapter02, is a maven based java project to demonstrate the followi
44
. Configuration using XML
55
. Configuration using Java API.
66

7-
Note: You can create MySQL Database tables using scripts in src/main/resources/sql folder of chapter01 module.
7+
Note: You can create MySQL Database tables using scripts in src/main/resources/sql folder.
88

99
How to Run:
1010
1. Configure Database Connection properties like hostname, username and password in src/main/resources/application.properties file.

chapter02/src/main/java/com/mybatis3/services/StudentService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public List<Student> findAllStudents()
2828
{
2929
SqlSession sqlSession = openSqlSession();
3030
try {
31+
//sqlSession.selectList("com.mybatis3.mappers.StudentMapper.findAllStudents");
3132
StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
3233
return studentMapper.findAllStudents();
3334
} finally {

chapter02/src/main/resources/full-mybatis-config.xml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"http://mybatis.org/dtd/mybatis-3-config.dtd">
55
<configuration>
66

7+
<!-- This file is for a reference purpose for various configuration options -->
78
<properties resource="application.properties">
89
<property name="username" value="db_user"/>
910
<property name="password" value="verysecurepwd"/>
@@ -26,13 +27,13 @@
2627
</settings>
2728

2829
<typeAliases>
29-
<typeAlias alias="Tutor" type="chapter03.domain.Tutor"/>
30-
<package name="chapter03.domain"/>
30+
<typeAlias alias="Tutor" type="com.mybatis3.domain.Tutor"/>
31+
<package name="com.mybatis3.domain"/>
3132
</typeAliases>
3233

3334
<typeHandlers>
34-
<typeHandler handler="chapter03.PhoneTypeHandler"/>
35-
<package name="chapter03"/>
35+
<typeHandler handler="com.mybatis3.typehandlers.PhoneTypeHandler"/>
36+
<package name="com.mybatis3.typehandlers"/>
3637
</typeHandlers>
3738

3839
<environments default="development">
@@ -56,9 +57,9 @@
5657
</environments>
5758

5859
<mappers>
59-
<mapper resource="chapter03/StudentMapper.xml"/>
60-
<mapper url="file:///var/mappers/PostMapper.xml"/>
61-
<mapper class="chapter03.TutorMapper"/>
60+
<mapper resource="com/mybatis3/mappers/StudentMapper.xml"/>
61+
<mapper url="file:///var/mappers/StudentMapper.xml"/>
62+
<mapper class="com.mybatis3.mappers.TutorMapper"/>
6263
</mappers>
6364

6465

chapter03/src/main/java/com/mybatis3/domain/Address.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package com.mybatis3.domain;
22

3+
import java.io.Serializable;
4+
35
/**
46
* @author Siva
57
*
68
*/
7-
public class Address
9+
public class Address implements Serializable
810
{
11+
private static final long serialVersionUID = 1L;
12+
913
private Integer addrId;
1014
private String street;
1115
private String city;

chapter03/src/main/java/com/mybatis3/domain/Course.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mybatis3.domain;
22

3+
import java.io.Serializable;
34
import java.util.ArrayList;
45
import java.util.Date;
56
import java.util.List;
@@ -8,8 +9,10 @@
89
* @author Siva
910
*
1011
*/
11-
public class Course
12+
public class Course implements Serializable
1213
{
14+
private static final long serialVersionUID = 1L;
15+
1316
private Integer courseId;
1417
private String name;
1518
private String description;

chapter03/src/main/java/com/mybatis3/domain/PhoneNumber.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
*/
44
package com.mybatis3.domain;
55

6+
import java.io.Serializable;
7+
68

79
/**
810
* @author Siva
911
*
1012
*/
11-
public class PhoneNumber
13+
public class PhoneNumber implements Serializable
1214
{
15+
private static final long serialVersionUID = 1L;
16+
1317
private String countryCode;
1418
private String stateCode;
1519
private String number;

chapter03/src/main/java/com/mybatis3/domain/Student.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package com.mybatis3.domain;
22

3+
import java.io.Serializable;
4+
35

46
/**
57
* @author Siva
68
*
79
*/
8-
public class Student
10+
public class Student implements Serializable
911
{
12+
private static final long serialVersionUID = 1L;
1013
private Integer studId;
1114
private String name;
1215
private String email;

chapter03/src/main/java/com/mybatis3/domain/Tutor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package com.mybatis3.domain;
22

3+
import java.io.Serializable;
34
import java.util.List;
45

56
/**
67
* @author Siva
78
*
89
*/
9-
public class Tutor
10+
public class Tutor implements Serializable
1011
{
12+
private static final long serialVersionUID = 1L;
13+
1114
private Integer tutorId;
1215
private String name;
1316
private String email;

chapter03/src/main/java/com/mybatis3/services/StudentService.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import java.util.Map;
55

66
import org.apache.ibatis.session.SqlSession;
7-
import org.slf4j.Logger;
8-
import org.slf4j.LoggerFactory;
97

108
import com.mybatis3.domain.Student;
119
import com.mybatis3.mappers.StudentMapper;
@@ -14,14 +12,12 @@
1412

1513
public class StudentService
1614
{
17-
private Logger logger = LoggerFactory.getLogger(getClass());
1815

1916
public List<Student> findAllStudents()
2017
{
2118
SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
2219
try {
2320
StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
24-
logger.debug("StudentMapper-DEBUG :"+studentMapper);
2521
return studentMapper.findAllStudents();
2622
} finally {
2723
sqlSession.close();
@@ -33,7 +29,6 @@ public Student findStudentById(Integer id)
3329
SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
3430
try {
3531
StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
36-
logger.debug("StudentMapper-DEBUG :"+studentMapper);
3732
return studentMapper.findStudentById(id);
3833
} finally {
3934
sqlSession.close();
@@ -72,7 +67,6 @@ public void createStudentWithMap(Map<String, Object> studentDataMap) {
7267
SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
7368
try {
7469
StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
75-
System.err.println("with map");
7670
mapper.insertStudentWithMap(studentDataMap);
7771
sqlSession.commit();
7872
}

0 commit comments

Comments
 (0)