Skip to content

kg6zvp/sudden-dao

Repository files navigation

Sudden DAO

Quick and easy use of JPA with a DAO so instant it will shock you.

License Maven Central pipeline status

A DAO (Data Access Object) is almost always needed in a java project. Extend the eisiges.sudden_dao.GenericPersistenceManager class and that's it.

Use Cases

  1. Query a database for a list of all objects whose values match an object's non-null object member variables
Rock keyRock = new Rock();
keyRock.setColor(Color.BLUE);
List<Rock> blueRocks = rockManager.getMatching(keyRock);
  1. Retrieve an object's primary key
rockManager.getId(myObject);

Getting started

  1. Add sudden-dao to your project

Maven:

		<dependency>
			<groupId>es.eisig</groupId>
			<artifactId>sudden-dao</artifactId>
			<version>1.0.0</version>
		</dependency>

Gradle:

repositories {
	mavenCentral()
}

dependencies {
	implementation 'es.eisig:sudden-dao:1.0.0'
}
  1. Create a class extending eisiges.sudden_dao.GenericPersistenceManager

  2. Create an empty constructor which calls super(Class<T> entityClass)

  3. (optional) add additional methods

@Local // javax.ejb.Local
public class UserBean extends GenericPersistenceManager<MyUser, Long> { // MyUser: entity being managed, Long: type of primary key
	public UserBean(){
		super(MyUser.class);
	}

	public TypedQuery<MyUser> getByBirthdateAsc() {
		return this.find().sortBy(MyUser_.birthdate).ascending().build();
	}
}

The following functions are exposed by GenericPersistenceManager:

boolean containsKey(K)

T persist(T)

K getId(T)

T save(T)

T get(K)

void remove(T)

void saveAll(Collection<T>)

void removeAll(Collection<T>)

List<T> getAll()

boolean isTableEmpty()

List<T> getMatching(T)

About

Quick and easy use of JPA with a DAO so instant it will shock you.

Resources

License

Stars

Watchers

Forks

Packages

No packages published