-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jed Li
authored and
Jed Li
committed
Dec 5, 2019
0 parents
commit 528677a
Showing
16 changed files
with
677 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>mybatix.learn</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.springframework.ide.eclipse.core.springbuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.springframework.ide.eclipse.core.springnature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
eclipse.preferences.version=1 | ||
encoding//src/main/java=UTF-8 | ||
encoding//src/main/resources=UTF-8 | ||
encoding//src/test/java=UTF-8 | ||
encoding/<project>=UTF-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.source=1.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>ariix</groupId> | ||
<artifactId>mybatix.learn</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>mybatix.learn</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mybatis</groupId> | ||
<artifactId>mybatis</artifactId> | ||
<version>3.2.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.mybatis</groupId> | ||
<artifactId>mybatis-spring</artifactId> | ||
<version>1.1.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.oracle</groupId> | ||
<artifactId>ojdbc6</artifactId> | ||
<version>11.2.0.1.0</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
46 changes: 46 additions & 0 deletions
46
mybatix.learn/src/main/java/ariix/mybatix/learn/db/DatabaseUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package ariix.mybatix.learn.db; | ||
|
||
import java.io.IOException; | ||
import java.io.Reader; | ||
|
||
import org.apache.ibatis.io.Resources; | ||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.apache.ibatis.session.SqlSessionFactoryBuilder; | ||
|
||
public class DatabaseUtils { | ||
|
||
// Life Scope is the application life cycle | ||
private static SqlSessionFactory sqlSessionFactory; | ||
|
||
static { | ||
|
||
if (sqlSessionFactory == null) { | ||
|
||
synchronized (DatabaseUtils.class) { | ||
|
||
if (sqlSessionFactory == null) { | ||
|
||
try { | ||
String resource = "config/MyBatisConfiguration.xml"; | ||
Reader reader = Resources.getResourceAsReader(resource); | ||
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader, "oracle"); | ||
// SqlSessionFactoryBuilder instance should be a local instance | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
System.exit(1); // terminate JVM | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
public static SqlSessionFactory getSqlSessionFactory() { | ||
return sqlSessionFactory; | ||
} | ||
|
||
public static void main(String[] args) { | ||
System.out.println(sqlSessionFactory); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
mybatix.learn/src/main/java/ariix/mybatix/learn/db/dw/SqlSessionGoodPractice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package ariix.mybatix.learn.db.dw; | ||
|
||
import org.apache.ibatis.session.SqlSession; | ||
|
||
import ariix.mybatix.learn.db.DatabaseUtils; | ||
|
||
public class SqlSessionGoodPractice { | ||
|
||
public static void main(String[] args) { | ||
SqlSessionGoodPractice instance = new SqlSessionGoodPractice(); | ||
instance.goodPracticeSinceJDK7(); | ||
instance.goodPracticeBeforeJDK7(); | ||
} | ||
|
||
|
||
/** | ||
* remember to release Session finally | ||
*/ | ||
public void goodPracticeSinceJDK7() { | ||
//SqlSession is closeable, use try with | ||
|
||
// Since JDK7 | ||
try (SqlSession sqlSession = DatabaseUtils.getSqlSessionFactory().openSession()) { | ||
|
||
String phone = sqlSession.selectOne("ariix.mybatix.learn.db.mapper.DwMapper.distPhone", 26166); | ||
System.out.println(phone); | ||
|
||
} finally { | ||
|
||
} | ||
} | ||
|
||
|
||
/** | ||
* remember to release Session finally | ||
*/ | ||
public void goodPracticeBeforeJDK7() { | ||
//SqlSession is closeable, use try with | ||
|
||
// Since JDK7 | ||
SqlSession sqlSession = DatabaseUtils.getSqlSessionFactory().openSession(); | ||
try { | ||
|
||
String phone = sqlSession.selectOne("ariix.mybatix.learn.db.mapper.DwMapper.distPhone", 26166); | ||
System.out.println(phone); | ||
|
||
} finally { | ||
if (sqlSession != null) { | ||
sqlSession.close(); | ||
} | ||
} | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
mybatix.learn/src/main/java/ariix/mybatix/learn/db/mapper/DwMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ariix.mybatix.learn.db.mapper; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
public interface DwMapper { | ||
String distPhone(String distId); | ||
|
||
int saveWebCategory(WebCategory web); | ||
|
||
WebCategory getWebCategory(WebCategory web); | ||
|
||
void updateWebCategory(WebCategory web); | ||
|
||
int deleteWebCategory(WebCategory web); | ||
|
||
List<WebCategory> findWebCategoryList(Date startDate,Date endDate); | ||
} |
85 changes: 85 additions & 0 deletions
85
mybatix.learn/src/main/java/ariix/mybatix/learn/db/mapper/WebCategory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package ariix.mybatix.learn.db.mapper; | ||
|
||
import java.io.Serializable; | ||
import java.util.Date; | ||
|
||
public class WebCategory implements Serializable{ | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private String itemCode; | ||
private String categoryKey; | ||
private Integer displayOrder; | ||
private Integer disclaimer; | ||
private Date startDate; | ||
private Date endDate; | ||
|
||
public String getItemCode() { | ||
return itemCode; | ||
} | ||
public void setItemCode(String itemCode) { | ||
this.itemCode = itemCode; | ||
} | ||
public String getCategoryKey() { | ||
return categoryKey; | ||
} | ||
public void setCategoryKey(String categoryKey) { | ||
this.categoryKey = categoryKey; | ||
} | ||
public Integer getDisplayOrder() { | ||
return displayOrder; | ||
} | ||
public void setDisplayOrder(Integer displayOrder) { | ||
this.displayOrder = displayOrder; | ||
} | ||
public Integer getDisclaimer() { | ||
return disclaimer; | ||
} | ||
public void setDisclaimer(Integer disclaimer) { | ||
this.disclaimer = disclaimer; | ||
} | ||
public Date getStartDate() { | ||
return startDate; | ||
} | ||
public void setStartDate(Date startdate) { | ||
this.startDate = startdate; | ||
} | ||
public Date getEndDate() { | ||
return endDate; | ||
} | ||
public void setEndDate(Date endDate) { | ||
this.endDate = endDate; | ||
} | ||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result | ||
+ ((categoryKey == null) ? 0 : categoryKey.hashCode()); | ||
result = prime * result | ||
+ ((itemCode == null) ? 0 : itemCode.hashCode()); | ||
return result; | ||
} | ||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
WebCategory other = (WebCategory) obj; | ||
if (categoryKey == null) { | ||
if (other.categoryKey != null) | ||
return false; | ||
} else if (!categoryKey.equals(other.categoryKey)) | ||
return false; | ||
if (itemCode == null) { | ||
if (other.itemCode != null) | ||
return false; | ||
} else if (!itemCode.equals(other.itemCode)) | ||
return false; | ||
return true; | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
mybatix.learn/src/main/java/ariix/mybatix/learn/db/typehandler/ExampleTypeHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package ariix.mybatix.learn.db.typehandler; | ||
|
||
import java.sql.CallableStatement; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
import org.apache.ibatis.type.BaseTypeHandler; | ||
import org.apache.ibatis.type.JdbcType; | ||
import org.apache.ibatis.type.MappedJdbcTypes; | ||
|
||
//Besides implement a self-defined Type handler, | ||
//you need to enable it in Mybatis Configuration File | ||
|
||
@MappedJdbcTypes(JdbcType.VARCHAR) | ||
public class ExampleTypeHandler extends BaseTypeHandler<String> { | ||
|
||
@Override | ||
public void setNonNullParameter(PreparedStatement ps, int i, | ||
String parameter, JdbcType jdbcType) throws SQLException { | ||
ps.setString(i, parameter); | ||
} | ||
|
||
@Override | ||
public String getNullableResult(ResultSet rs, String columnName) | ||
throws SQLException { | ||
return rs.getString(columnName); | ||
} | ||
|
||
@Override | ||
public String getNullableResult(ResultSet rs, int columnIndex) | ||
throws SQLException { | ||
return rs.getString(columnIndex); | ||
} | ||
|
||
@Override | ||
public String getNullableResult(CallableStatement cs, int columnIndex) | ||
throws SQLException { | ||
return cs.getString(columnIndex); | ||
} | ||
|
||
} |
Oops, something went wrong.