Skip to content

ztbsuper/yaz

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Yet Another Zeratul Build Status

Yet Another Zeratul(YAZ) is a new version of Zeratul.

YAZ provides a fundamental BaseDao, with convenient method for querying.

##Usage

Maven dependency:

<dependency>
    <groupId>com.exmertec.yaz</groupId>
    <artifactId>yaz</artifactId>
    <version>0.06</version>
    <type>jar</type>
    <scope>compile</scope>
</dependency>

To use it just:

public class UserDao extends BaseDao<User> {
    public UserDao() {
        super(User.class);
    }
    
    @PersistenceContext
    public void injectEntityManager(EntityManager entityManager) {
        super.setEntityManager(entityManager);
    }
    
    public List<User> findUserByName(String key) {
        return where(field("name").like(key), field("status").ne(DISABLED)).queryList();
    }
}

To make it easier, it's recommended to add a BaseDaoWrapper in your project:

public abstract class BaseDaoWrapper<T> extends BaseDao<T> {
    protected BaseDaoWrapper(Class<T> prototype) {
        super(prototype);
    }

    @PersistenceContext
    public void injectEntityManager(EntityManager entityManager) {
        super.setEntityManager(entityManager);
    }
}

public class UserDao extends BaseDaoWrapper<User> {
    public UserDao() {
        super(User.class);
    }
    
    public List<User> findUserByName(String key) {
        return where(field("name").like(key), field("status").ne(DISABLED)).queryList();
    }
}

Or if you're trying to use DDD repository pattern:

public class UserDao extends BaseDaoWrapper<User> {
    public UserDao() {
        super(User.class);
    }
}

public class UserRepository extends BaseRepository<User> {
    private UserDao userDao;

    public User find(String userId) {
        return userDao.idEquals(userId).querySingle();
    }
}

Please refer to the test source code, which shows how to use different query methods provided by YAZ.

About

Yet Another Zeratul, a JPA wrapper for easier data accessing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%