没有任何数据可供显示
开源项目社区 | 当前位置 : |
|
www.trustie.net/open_source_projects | 主页 > 开源项目社区 > nanorm |
nanorm
|
0 | 0 | 247 |
贡献者 | 讨论 | 代码提交 |
nanorm is a simple and lightweight data mapper framework inspired by the Apache iBatis. It is not meant to be an full ORM solution.
The main features are:
Strict typing where possible Easy to use Easy to mock in unit tests Low performance overhead compared to hand-written JDBC mapper Latest Changes0.4.3, released 2009-07-16Added ability to enable/disable auto-session support. Note that auto-session is disabled by default starting from this version (so you should open session
explicitly or turn it on via call NanormConfiguration#setAutoSessionEnabled(boolean)).
Fixed issue #18 Minor code style impromevents and JavaDoc updates 0.4.2, released 2008-11-08Moved TypeHandler from the internal package to the API package Added support for mapping result set to result object directly via TypeHandler (@Scalar annotation) Configuration validation improved. Several minor issues fixed 0.4.1, released 2008-10-19Added two new type handlers, for byte and java.util.Locale. Some methods were renamed in public interface DataSink Fixed issue with wrong caching of setters used for setting pre-generated keys Fixed issue with incorrect getters/setters lookup (didn't searched in inherited methods) Fixed issue with handling arrays of primitive types Using with Maven2Add this repository entry to repositories section of Maven POM:
nanorm-releases-repo
Repository on code.google.com
http://nanorm.googlecode.com/svn/maven2/releases/
false
Then add this dependency entry to your Maven POM to include nanorm in your project:
com.google.code.nanorm
nanorm
0.4.3
Sample codeDeclare an interface:
public interface CarMapper {
/**
* Get car by id.
* Declare a mapping. In this case it is automatic, meaning that properties
* not explicitly mapped will be mapped to the columns with same name.
* Explicitly map owner column to ownerName property.
*/
@ResultMap(id = "car", auto = true, mappings = {
@Mapping(value = "ownerName", column = "owner")
})
@Select("SELECT id, model, owner, year FROM cars WHERE ID = ${1}")
Car getCarById(int id);
}Car is a POJO with id, model, year and ownerName properties.
Using the mapper:
NanormFactory factory = ... // Create factory
Connection conn = ... // JDBC connection
CarMapper mapper = factory.createMapper(CarMapper.class);
// Make factory to use this connection for current thread
Session sess = factory.openSession(conn);
try {
Car car = mapper.getCarById(1);
// Use it
...
sess.commit();
} finally {
sess.end();
}