Ujorm 1.22 发布,改进内容:
- The UjoProperty interface extends the CriterionMaker now for a simpler Criterion building.
- A new annotation parameter called converter can be assigned for a special reading data from/to ResultSet.
- A new method UjoComparator.sort() is implemented, as well as a better type safe using Java generics.
- Solid database names of foreign columns name constraints are implemented.
- The right parameter of Criterion can be an indirect property.
- The default implementation toString() of the AbstractUjo object is improved
Ujorm是一个新的开源Java版ORM框架,Ujorm的作 者目标是开发一个足够敏捷的ORM框架作为Java应用的持久层,以适合快速迭代开发的敏捷团队。Ujorm的第一个优势是性能上的优势,从一个简单的 SELECT来时,Ujorm的性能要远远高于同类框架。当然Ujorm还包括有:类型安全的查询参数,更小的性能开销,和最简化的实体解决方案。
[代码] 保存数据
- OrmHandler.getInstance().loadDatabase(Database.class);
- Order order = new Order();
- order.setDate(new Date());
- order.setDescr("John's order");
- Item item1 = new Item();
- item1.setOrder(order);
- item1.setDescr("Yellow table");
- Item item2 = new Item();
- item2.setOrder(order);
- item2.setDescr("Green window");
- Session session = OrmHandler.getInstance()
- .createSession();
- session.save(order);
- session.save(item1);
- session.save(item2);
- session.commit();
- session.close();
[代码] 查询数据
- Criterion<Item> cn1, cn2, criterion;
- cn1 = Criterion.where( Item.ID, Operator.GE, 1L );
- cn2 = Criterion.where( Item.ORDER.add(Order.DESCR)
- , "John's order" ); // Equals to
- criterion = cn1.and(cn2);
- Session session = OrmHandler.getInstance()
- .createSession();
- Query<Item> items = session.createQuery(criterion)
- .orderBy ( Item.ORDER.add(Order.CREATED)
- , Item.ID.descending() );
- System.out.println( "Row count: " + items.getCount());
- for (Item item : items) {
- String descr = item.getDescr();
- Date created = item.getOrder().getDate();
- System.out.println( created + " : " + descr );
- }
- session.close();
[代码] 排序
- OrmHandler hr = OrmHandler.getInstance();
- MetaColumn col = (MetaColumn)
- hr.findColumnModel(Order.DESCR);
- StringBuilder msg = new StringBuilder()
- .append("Length : " + col.getMaxLength() + '\n')
- .append("NotNull: " + col.isMandatory() + '\n')
- .append("PrimKey: " + col.isPrimaryKey() + '\n')
- .append("DB name: " + col.getFullName() + '\n')
- ;
- System.out.println(msg);
原文链接:http://www.oschina.net/news/25177/ujorm-1-2-2-java-orm-framework
【编辑推荐】