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

我要开发同款
匿名用户2014年04月10日
29阅读
开发技术Java
所属分类程序开发、ORM/持久层框架
授权协议Apache

作品详情

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

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

示例代码:

// Get order by idOrder order = Order.findById(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' and paginate itFilter filter = new Filter();filter.setPageNo(1);filter.setPerPage(25);filter.addCondition(new Condition("orderItems.product.category", Operator.eq, "books");List<Order> orders = Order.where(filter);// Count of orders matching the filterLong count = Order.count(filter);// Get the first order matching the filterLong count = Order.first("customer_email", "dummyemail@dummy.com", "status", "shipped");// Get the unique order matching the conditionsLong count = Order.one("customer_email", "dummyemail@dummy.com", "status", "shipped");// Dump everythingList<Order> orders = Order.all();// Delete all orders matching the filterLong count = Order.deleteAll(filter);// Check if order exists with the given identifierboolean exists = Order.exists(1234L);// Save orderorder.setBillingAmount(1000.0);order.persist();// Delete orderorder.delete();// Update attributesMap<String, Object> attributes = new HashMap<String, Object>();attributes.put("billingAmount", 1000.0);order.updateAttributes(attributes);// Find order item by id within an orderorder.collections("order_items").findById(123L);// Search order items by filter with an orderorder.collections("order_items").findById(filter);........
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论