timonJava 數(shù)據(jù)庫(kù)持久工具
Timon 是基于Java的數(shù)據(jù)庫(kù)持久工具, 提供SQL Maps以及SQL工具
采用XML定義SQL語(yǔ)句
支持?jǐn)?shù)據(jù)庫(kù)與Java對(duì)象之間的映射
支持外部數(shù)據(jù)緩存,支持Ehcache,Memcached和內(nèi)置同步緩存
提供SQL語(yǔ)句解析、格式化工具
安裝方式
<dependency> <groupId>org.pinae</groupId> <artifactId>timon</artifactId> <version>1.1</version> </dependency>
實(shí)例代碼
1. XML配置
<?xml version="1.0" encoding="UTF-8" ?> <global key="table" value="person" /> <mapper namespaces="org.piane.timon"> <sql name="getPerson"> select * from :table where 1=1 <choose when="id"> and id = :id </choose> </sql> </mapper>
2.實(shí)例代碼
public class SQLSessionFactoryDemo {
public static void main(String[] args) {
SQLSessionFactory sessionFactory = null;
SQLBuilder builder = null;
try {
builder = new SQLBuilder()
sessionFactory = new SQLSessionFactory();
SQLSession session = sessionFactory.getSession();
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("id", 1);
Person person = (Person)session.one(
builder.getSQLByNameWithParameters("org.piane.timon.getPerson", parameters),
Person.class);
session.close();
} catch (IOException e) {
}
}
}
評(píng)論
圖片
表情
