ActiveJPA针对 JPA 的活动记录模式
ActiveJPA基于JPA,提供了Martin Fowler所提出的活动记录模式(Active Record pattern)的Java实现。借助于ActiveJPA,模型本身会作为DAO并与数据库交互,这样就不需要额外的代码作为数据访问层了。
ActiveJPA使用到了JPA规范,因此所有JPA的ORM实现(Hibernate、EclipseLink、OpenJPA等)都可以与ActiveJPA协同使用。
示例代码:
// Get order by id Order order = Order.findById(12345L); // Get all orders for a customer that are shipped List<Order> orders = Order.where("customer_email", "dummyemail@dummy.com", "status", "shipped"); // Get all orders for the product category 'books' and paginate it Filter 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 filter Long count = Order.count(filter); // Get the first order matching the filter Long count = Order.first("customer_email", "dummyemail@dummy.com", "status", "shipped"); // Get the unique order matching the conditions Long count = Order.one("customer_email", "dummyemail@dummy.com", "status", "shipped"); // Dump everything List<Order> orders = Order.all(); // Delete all orders matching the filter Long count = Order.deleteAll(filter); // Check if order exists with the given identifier boolean exists = Order.exists(1234L); // Save order order.setBillingAmount(1000.0); order.persist(); // Delete order order.delete(); // Update attributes Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("billingAmount", 1000.0); order.updateAttributes(attributes); // Find order item by id within an order order.collections("order_items").findById(123L); // Search order items by filter with an order order.collections("order_items").findById(filter); .... ....
评论
SimpleSteps记录程序活动步骤
SimpleSteps是WindowsPhone8.1上使用StepCounterAPI的应用实例。用户可以通过此程序查看到最近七天内使用应用程序的步骤。
SimpleSteps记录程序活动步骤
0
SimpleActivity记录应用程序活动情况
SimpleActivity是一个在WindowsPhone8.1上使用ActivityMonitorAPI的应用实例。通过使用这个工具,用户可以看到在过去的七天内,使用程序的情况。
SimpleActivity记录应用程序活动情况
0
Spring Data JPA轻松实现基于 JPA 的库
SpringDataJPA的目标是通过让一些必须的工作变得更简单,来显著提高数据访问层的实现。作为一个开发者,你写你的仓库界面,包括自定义查询方法,而Spring给你提供自动实现。特性对建立基于Spr
Spring Data JPA轻松实现基于 JPA 的库
0
Spring Data JPA轻松实现基于 JPA 的库
Spring Data JPA 的目标是通过让一些必须的工作变得更简单,来显著提高数据访问层的实现。
Spring Data JPA轻松实现基于 JPA 的库
0
myjpa实现 JPA 的插件
使用mybatis来实现jpa的部分功能,可以与spring-data-jpa进行结合操作。1.与spring-data-jpa结合1.1定义mapper 定义mapper时,继承自JpaReposi
myjpa实现 JPA 的插件
0