Groovy ActiveRecord

ActiveRecord support for Spring boot entity classes.

License

License

Categories

Categories

Groovy Languages Ant Build Tools
GroupId

GroupId

it.nicolasanti
ArtifactId

ArtifactId

groovy-activerecord
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Groovy ActiveRecord
ActiveRecord support for Spring boot entity classes.
Project URL

Project URL

https://github.com/nicolinux72/groovy-activerecord
Source Code Management

Source Code Management

https://github.com/nicolinux72/groovy-activerecord.git

Download groovy-activerecord

How to add to project

<!-- https://jarcasting.com/artifacts/it.nicolasanti/groovy-activerecord/ -->
<dependency>
    <groupId>it.nicolasanti</groupId>
    <artifactId>groovy-activerecord</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/it.nicolasanti/groovy-activerecord/
implementation 'it.nicolasanti:groovy-activerecord:1.0.0'
// https://jarcasting.com/artifacts/it.nicolasanti/groovy-activerecord/
implementation ("it.nicolasanti:groovy-activerecord:1.0.0")
'it.nicolasanti:groovy-activerecord:jar:1.0.0'
<dependency org="it.nicolasanti" name="groovy-activerecord" rev="1.0.0">
  <artifact name="groovy-activerecord" type="jar" />
</dependency>
@Grapes(
@Grab(group='it.nicolasanti', module='groovy-activerecord', version='1.0.0')
)
libraryDependencies += "it.nicolasanti" % "groovy-activerecord" % "1.0.0"
[it.nicolasanti/groovy-activerecord "1.0.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-data-jpa jar 1.3.0.RELEASE
org.codehaus.groovy : groovy-all jar 2.4.3
org.codehaus.groovy : groovy-templates jar 2.4.3

test (2)

Group / Artifact Type Version
hsqldb : hsqldb jar 1.8.0.10
org.springframework.boot : spring-boot-starter-test jar 1.3.0.RELEASE

Project Modules

There are no modules declared in this project.

Groovy ActiveRecord

This library adds ActiveRecord support to your groovy jpa entity inside a Spring Boot application. That's all.

Setup your project

Add grovy active-record library to your Spring Boot project dependencies. For example add these lines to your pom.xml file:

<dependency>
    <groupId>it.nicolasanti</groupId>
    <artifactId>groovy-activerecord</artifactId>
    <version>1.0.0</version>
</dependency>

Or this line to your build.gradle file:

compile 'it.nicolasanti:groovy-activerecord:1.0.0'

Please consider that this library work with early versio of Spring boot also, so you may consider to replace dependency to Spring Boot 1.3.0.RELEASE with the version your are actually use.

The last step is remember to scan for component the groovy-activerecord'jar also, something like this:

@ComponentScan("it.nicolasanti.autoconfigure")

Setup your entity class

Simpliy add the trait ActiveRecordRepository to your entity jpa entity class in this way:

@Entity  
class YourEntity implements ActiveRecordRepository {
  ...
}

Then Spring Boot, starting up your application, will add to your entity class standard Active Record methods like:

/** Perform a SELECT COUNT for this entity on database */
static countEntities() 
	
/** Return all entities store on database: pay attention on high volume tables. */
static findAllEntities() 
	
/** Retreive from database the entity with the passed primary key */
static  findEntity(id) 
	
/** Found all entities then paginate the results */
static findEntries( int firstResult, int maxResults) 
		
/** Persiste this instance */
def persist() 
	
/** Remove from db this instance */
def remove()  

/** Force EntityManager to flush pending changes */
void flush()  

/** Clear EntityManager */
void clear()  

/** Merge this instance with the one inside EntityManager  */
def merge()   

You could found all these methods inside the class [ActiveRecordRepository] (https://github.com/nicolinux72/groovy-activerecord/blob/master/src/main/groovy/it/nicolasanti/autoconfigure/ActiveRecordRepository.groovy)

Working example

If you are interested in see a workging example you could take a look to test classes: you'll find an entity class named Studente (with means student, in italian) with and id, a name and a surname as only properties. The injected ActiveRecord methods are tested in the class ActiveRecordTest.

Versions

Version
1.0.0