ActiveJPA 针对 JPA 的活动记录模式开源项目

我要开发同款
匿名用户2014年04月10日
107阅读

技术信息

开源地址
https://github.com/ActiveJpa/activejpa
授权协议
Apache

作品详情

ActiveJPA基于JPA,提供了MartiFowler所提出的活动记录模式(ActiveRecordpatter)的Java实现。借助于ActiveJPA,模型本身会作为DAO并与数据库交互,这样就不需要额外的代码作为数据访问层了。

ActiveJPA使用到了JPA规范,因此所有JPA的ORM实现(Hiberate、EclipseLik、OpeJPA等)都可以与ActiveJPA协同使用。

示例代码:

// Get order by idOrder order = Order.fidById(12345L);// Get all orders for a customer that are shippedList<Order> orders = Order.where("customer_email", "dummyemail@dummy.com", "status", "shipped");// Get all orders for the product category 'books' ad pagiate itFilter filter = ew Filter();filter.setPageNo(1);filter.setPerPage(25);filter.addCoditio(ew Coditio("orderItems.product.category", Operator.eq, "books");List<Order> orders = Order.where(filter);// Cout of orders matchig the filterLog cout = Order.cout(filter);// Get the first order matchig the filterLog cout = Order.first("customer_email", "dummyemail@dummy.com", "status", "shipped");// Get the uique order matchig the coditiosLog cout = Order.oe("customer_email", "dummyemail@dummy.com", "status", "shipped");// Dump everythigList<Order> orders = Order.all();// Delete all orders matchig the filterLog cout = Order.deleteAll(filter);// Check if order exists with the give idetifierboolea exists = Order.exists(1234L);// Save orderorder.setBilligAmout(1000.0);order.persist();// Delete orderorder.delete();// Update attributesMap<Strig, Object> attributes = ew HashMap<Strig, Object>();attributes.put("billigAmout", 1000.0);order.updateAttributes(attributes);// Fid order item by id withi a orderorder.collectios("order_items").fidById(123L);// Search order items by filter with a orderorder.collectios("order_items").fidById(filter);........

功能介绍

ActiveJPA基于JPA,提供了Martin Fowler所提出的活动记录模式(Active Record pattern)的Java实现。借助于ActiveJPA,模型本身会作为DAO并与...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论