Skip to content

Commit

Permalink
new project
Browse files Browse the repository at this point in the history
  • Loading branch information
Jed Li authored and Jed Li committed Dec 5, 2019
0 parents commit 528677a
Show file tree
Hide file tree
Showing 16 changed files with 677 additions and 0 deletions.
31 changes: 31 additions & 0 deletions mybatix.learn/.classpath
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>
1 change: 1 addition & 0 deletions mybatix.learn/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
29 changes: 29 additions & 0 deletions mybatix.learn/.project
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>
5 changes: 5 additions & 0 deletions mybatix.learn/.settings/org.eclipse.core.resources.prefs
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
13 changes: 13 additions & 0 deletions mybatix.learn/.settings/org.eclipse.jdt.core.prefs
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
4 changes: 4 additions & 0 deletions mybatix.learn/.settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
42 changes: 42 additions & 0 deletions mybatix.learn/pom.xml
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>
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);
}

}
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();
}
}
}

}
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);
}
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;
}

}
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);
}

}
Loading

0 comments on commit 528677a

Please sign in to comment.