All Projects → ActiveJpa → Activejpa

ActiveJpa / Activejpa

Licence: apache-2.0
A simple active record pattern library in java that makes programming DAL easier

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Activejpa

active-persistence
Active Persistence is a implementation of Active Record Query Interface for JPA that makes it easy and fun.
Stars: ✭ 14 (-91.86%)
Mutual labels:  activerecord, jpa
SimpleCurd
2个类,实现类ActiveRecord,无需写Mapper, mybatis增强
Stars: ✭ 14 (-91.86%)
Mutual labels:  activerecord, jpa
With model
Dynamically build an Active Record model (with table) within a test context
Stars: ✭ 119 (-30.81%)
Mutual labels:  activerecord
Ldaprecord
A fully-featured LDAP framework.
Stars: ✭ 159 (-7.56%)
Mutual labels:  activerecord
Identity cache
IdentityCache is a blob level caching solution to plug into Active Record. Don't #find, #fetch!
Stars: ✭ 1,733 (+907.56%)
Mutual labels:  activerecord
Closure tree
Easily and efficiently make your ActiveRecord models support hierarchies
Stars: ✭ 1,665 (+868.02%)
Mutual labels:  activerecord
Querybuilder
SQL query builder, written in c#, helps you build complex queries easily, supports SqlServer, MySql, PostgreSql, Oracle, Sqlite and Firebird
Stars: ✭ 2,111 (+1127.33%)
Mutual labels:  activerecord
Online Learning Cloud Platform
👀在线学习平台,前端主要技术:Angular,后端主要技术:springboot (项目包含前台,后台上传失误,可能丢失代码......分为前台展示系统及后台管理系统。前台系统包含首页门户、多级菜单、问题页面、免费课程、练习页面等模块。 后台管理系统包含课程管理、用户管理、管理员管理、评论管理等模块。系统介绍及详细功能点、技术点见项目内文档描述)
Stars: ✭ 117 (-31.98%)
Mutual labels:  jpa
Hibernate Reactive
A reactive API for Hibernate ORM, supporting non-blocking database drivers and a reactive style of interaction with the database.
Stars: ✭ 167 (-2.91%)
Mutual labels:  jpa
Torque Postgresql
Add support to complex resources of PostgreSQL, like data types, array associations, and auxiliary statements (CTE)
Stars: ✭ 130 (-24.42%)
Mutual labels:  activerecord
Graphql Jpa
JPA Implementation of GraphQL (builds on graphql-java)
Stars: ✭ 156 (-9.3%)
Mutual labels:  jpa
Jersey Jwt
Example of REST API with JWT authentication using Jersey, Jackson, Undertow, Weld, Hibernate and Arquillian.
Stars: ✭ 131 (-23.84%)
Mutual labels:  jpa
Awesome Python Models
A curated list of awesome Python libraries, which implement models, schemas, serializers/deserializers, ODM's/ORM's, Active Records or similar patterns.
Stars: ✭ 124 (-27.91%)
Mutual labels:  activerecord
Coloquent
Javascript/Typescript library mapping objects and their interrelations to JSON API, with a clean, fluent ActiveRecord-like (e.g. similar to Laravel's Eloquent) syntax for creating, retrieving, updating and deleting model objects.
Stars: ✭ 149 (-13.37%)
Mutual labels:  activerecord
X Admin
致力于快速开发中小型后台管理系统项目模板(更新中......)
Stars: ✭ 123 (-28.49%)
Mutual labels:  jpa
Spring Boot Leaning
Spring Boot 2.X 最全课程代码
Stars: ✭ 2,008 (+1067.44%)
Mutual labels:  jpa
Calculate All
calculate_all method for aggregate functions in Active Record
Stars: ✭ 118 (-31.4%)
Mutual labels:  activerecord
Enumerize
Enumerated attributes with I18n and ActiveRecord/Mongoid support
Stars: ✭ 1,637 (+851.74%)
Mutual labels:  activerecord
Graphql Query Resolver
Minimize N+1 queries generated by GraphQL and ActiveRecord
Stars: ✭ 148 (-13.95%)
Mutual labels:  activerecord
Spring Data Jpa
Simplifies the development of creating a JPA-based data access layer.
Stars: ✭ 2,238 (+1201.16%)
Mutual labels:  jpa

ActiveJpa Build Status Coverage Status

ActiveJpa is a java library that attempts to implement the active record pattern on top of JPA. The goal of this library is to eliminate the need to create DAO or Repository classes and make programming DAL a lot more simpler.

What can you do with ActiveJpa?

AcitveJpa abstracts out some of the most common functionalities you might need in your DAL. You should be able to do,

	// 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", "[email protected]", "status", "shipped");
	
	// Get all orders for the product category 'books' and paginate it
	Filter filter = new Filter()
			.page(1, 25)
			.condition("orderItems.product.category", Operator.eq, "books")
			.sortBy("status", true);
	List<Order> orders = Order.where(filter);
	
	// Or rather use filter on the model itself
	List<Order> orders = Order.filter().page(1, 25).condition("orderItems.product.category", Operator.eq, "books").sortBy("status", true).list();
	
	// Count of orders matching the filter
	Long count = Order.count(filter);
	
	// Get the first order matching the filter
	Long count = Order.first("customer_email", "[email protected]", "status", "shipped");
	
	// Get the unique order matching the conditions
	Long count = Order.one("customer_email", "[email protected]", "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").where(filter);
	order.collections("order_items").filter().page(1, 25).sortBy("status", "true");
	
	....
	....
	

Getting Started

Setting Up Maven

ActiveJpa is available as a Maven artifact and should be fairly simpler to integrate with your application. Just add the below maven dependency to your pom.xml file,

   <dependencies>
     <dependency>
       <groupId>org.activejpa</groupId>
       <artifactId>activejpa-core</artifactId>
       <version>1.1.0</version>
     </dependency>
   </dependencies>
   
   <repositories>
     <repository>
       <id>jcenter</id>
       <url>https://jcenter.bintray.com</url>
       <snapshots>
         <enabled>false</enabled>
       </snapshots>
     </repository>
   </repositories>

Hooking into your application

ActiveJPA does some runtime bytecode enhancement to simplify development and madates you to hook it before your models are loaded by the classloader. There are two ways you can hook it to your application,

  • Run your applicaiton with the activejpa java agent by the below jvm option "-javaagent:activejpa-core.jar"
  • At the bootstrap of your application, before your classes are loaded, manually load the java agent using the following code. This will require you to add tools.jar to your dependency list.
	ActiveJpaAgentLoader.instance().loadAgent();

Setup EntityManagerFactory

You have to feed in the persistence unit to ActiveJpa to do the magic. There are multiple ways you can do this,

	// Add the persistence unit defined by persistence.xml identified by the name 'order'. The persistence.xml should be available in the classpath
	JPA.addPersistenceUnit("order");
	
	// If you have entity manager factory already created, you can attach the same to ActiveJpa
	JPA.addPersistenceUnit("order", entityManagerFactory);

Enhancing your Entities

ActiveJpa enhances all the classes that is a subclass of org.activejpa.entity.Model and has java.persistence.Entity annotation. So ensure all your JPA entities extend org.activejpa.entity.Model class

	@java.persistence.Entity
	public class Order extends org.activejpa.entity.Model {
		
		private Long id;
		
		@javax.persistence.Id
		@javax.persistence.GeneratedValue(strategy=javax.persistence.GenerationType.AUTO)
		public Long getId() {
			return id;
		}
	}

Managing transactions

All the update operations in the model class will open up a transaction if one is not found in the current context. Below code demonstrates wrapping a unit of work under a transaction,

	JPAContext context = JPA.instance.getDefaultConfig().getContext();
	context.beginTxn();
	boolean failed = true;
	try {
		// Your unit of work here
		failed = false;
	} finally {
		// Commit or rollback the transaction
		context.closeTxn(failed);
	}
	

Testing your models

The setup done for taking care of byte code instrumentation applies for your test cases. But most of the IDE's support running individual test cases and adding the -javaagent option to every such run is a pain.

ActiveJpa provides an abstract model test class for tesng that enables instrumentation for all your modles without specifying -javaagent option to your test runs. To use this you will have to extend org.activejpa.entity.testng.BaseModelTest class,

	public class OrderTest extends BaseModelTest {
		
		@Test
		public void testCreateOrder() {
			Order order = new Order();
			order.setCustomerEmail("[email protected]");
			...
			...
			order.persist();
			Assert.assertEquals(Order.where("customer_email", "[email protected]").get(0), order);
		}
	}

Examples

Vanilla application

Checkout the vanilla application using ActiveJpa

Spring integration

There's a sample application that demonstrates the Spring-ActiveJpa integration

How to ask for help?

Create an issue explaining your issue as detail as possible.

License

ActiveJPA is offered under Apache License, Version 2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].