SHOW:
|
|
- or go back to the newest paste.
| 1 | - | package com.goijo.desmon.entity; |
| 1 | + | package org.jlego.core.dao; |
| 2 | ||
| 3 | - | import java.io.Serializable; |
| 3 | + | import java.util.List; |
| 4 | ||
| 5 | - | import javax.persistence.Column; |
| 5 | + | import javax.persistence.Query; |
| 6 | - | import javax.persistence.Entity; |
| 6 | + | |
| 7 | - | import javax.persistence.Table; |
| 7 | + | |
| 8 | - | import javax.persistence.GeneratedValue; |
| 8 | + | * Base interface for all DAO classes <br/> |
| 9 | - | import javax.persistence.GenerationType; |
| 9 | + | * Example: |
| 10 | - | import javax.persistence.Id; |
| 10 | + | * |
| 11 | - | import javax.persistence.SequenceGenerator; |
| 11 | + | * <code><br/> |
| 12 | * public class AnotherDao extends BaseDaoImpl <Long, User> implements BaseDao {<br/>
| |
| 13 | * <br/> | |
| 14 | - | import org.jlego.core.entity.BaseEntityMaster; |
| 14 | + | * }<br/> |
| 15 | * </code> | |
| 16 | * | |
| 17 | - | * Entity class for table dmon_account |
| 17 | + | * @author Ali Irawan |
| 18 | - | * @version 1.0.0 |
| 18 | + | * @version 1.0 |
| 19 | * @param <K> | |
| 20 | - | |
| 20 | + | * key type |
| 21 | - | @Entity( name=Account.ENTITY_NAME) |
| 21 | + | * @param <E> |
| 22 | - | @Table( name=Account.TABLE_NAME) |
| 22 | + | * value/entity type |
| 23 | - | public class Account extends BaseEntityMaster implements Serializable{
|
| 23 | + | |
| 24 | - | private static final long serialVersionUID = -1L; |
| 24 | + | public interface BaseDao<K, E> {
|
| 25 | - | public static final String TABLE_NAME = "dmon_account"; |
| 25 | + | |
| 26 | - | public static final String ENTITY_NAME = "com.goijo.desmon.entity.Account"; |
| 26 | + | /** |
| 27 | * insert data to persistence | |
| 28 | - | @Id |
| 28 | + | * |
| 29 | - | @SequenceGenerator(allocationSize=1,name="dmon_account_seq", sequenceName = "dmon_account_seq") |
| 29 | + | * @param entity |
| 30 | - | @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="dmon_account_seq") |
| 30 | + | * object to be inserted |
| 31 | - | @Column(name="account_id") |
| 31 | + | * @throws CoreException |
| 32 | - | private Long id; |
| 32 | + | */ |
| 33 | ||
| 34 | - | @Column(name="tenant_id") |
| 34 | + | public void persist(E entity); |
| 35 | - | private Long tenantId; |
| 35 | + | |
| 36 | /** | |
| 37 | - | @Column(name="site_id") |
| 37 | + | * update data to persistence |
| 38 | - | private Long siteId; |
| 38 | + | * |
| 39 | * @param entity | |
| 40 | - | @Column(name="username", length=50) |
| 40 | + | * object to be updated |
| 41 | - | private String username; |
| 41 | + | * @throws CoreException |
| 42 | */ | |
| 43 | - | @Column(name="password", length=100) |
| 43 | + | |
| 44 | - | private String password; |
| 44 | + | public E merge(K id, E entity); |
| 45 | ||
| 46 | /** | |
| 47 | * delete data from persistence | |
| 48 | - | public Long getId() {
|
| 48 | + | * |
| 49 | - | return id; |
| 49 | + | * @param id |
| 50 | - | } |
| 50 | + | * primary key that uniquely identify the object to be deleted |
| 51 | - | public void setId(Long id) {
|
| 51 | + | * @throws CoreException |
| 52 | - | this.id = id; |
| 52 | + | */ |
| 53 | - | } |
| 53 | + | |
| 54 | public void remove(K id); | |
| 55 | - | public Long getTenantId() {
|
| 55 | + | |
| 56 | - | return tenantId; |
| 56 | + | /** |
| 57 | - | } |
| 57 | + | * Search data from persistence using specified ID |
| 58 | - | public void setTenantId(Long tenantId) {
|
| 58 | + | * |
| 59 | - | this.tenantId = tenantId; |
| 59 | + | * @param id |
| 60 | - | } |
| 60 | + | * primary key that uniquely identify the object |
| 61 | * @return return the object defined by Key, if no data match the method | |
| 62 | - | public Long getSiteId() {
|
| 62 | + | * returns null |
| 63 | - | return siteId; |
| 63 | + | */ |
| 64 | - | } |
| 64 | + | public E findByPk(K id); |
| 65 | - | public void setSiteId(Long siteId) {
|
| 65 | + | |
| 66 | - | this.siteId = siteId; |
| 66 | + | /** |
| 67 | - | } |
| 67 | + | * Query data with specified criteria |
| 68 | * | |
| 69 | - | public String getUsername() {
|
| 69 | + | * @return list of data with specific entity type |
| 70 | - | return username; |
| 70 | + | */ |
| 71 | - | } |
| 71 | + | |
| 72 | - | public void setUsername(String username) {
|
| 72 | + | public E find(Criteria criteria); |
| 73 | - | this.username = username; |
| 73 | + | |
| 74 | - | } |
| 74 | + | /** |
| 75 | * Query all data and return in a List | |
| 76 | - | public String getPassword() {
|
| 76 | + | * |
| 77 | - | return password; |
| 77 | + | * @return list of data with specific entity type |
| 78 | - | } |
| 78 | + | */ |
| 79 | - | public void setPassword(String password) {
|
| 79 | + | |
| 80 | - | this.password = password; |
| 80 | + | public List<E> findAll(); |
| 81 | - | } |
| 81 | + | |
| 82 | /** | |
| 83 | * Query data with specified criteria and return in a List | |
| 84 | * | |
| 85 | * @return list of data with specific entity type | |
| 86 | */ | |
| 87 | public List<E> findAll(Criteria criteria); | |
| 88 | ||
| 89 | /** | |
| 90 | * Return number of data in table | |
| 91 | * @return count value | |
| 92 | */ | |
| 93 | public long count(); | |
| 94 | ||
| 95 | /** | |
| 96 | * Create a query with JPQL language | |
| 97 | * @param query JPQL language | |
| 98 | * @return an instance of javax.persistence.Query | |
| 99 | */ | |
| 100 | public Query createQuery(String query); | |
| 101 | ||
| 102 | /** | |
| 103 | * Create a query with named query | |
| 104 | * @param queryName name of named query (JPQL) | |
| 105 | * @return an instance of javax.persistence.Query | |
| 106 | */ | |
| 107 | public Query createNamedQuery(String queryName); | |
| 108 | ||
| 109 | /** | |
| 110 | * Create a query with using native SQL language. This is database specific. Using it will reduce portability between databases | |
| 111 | * @param sqlString SQL native language based on the database used | |
| 112 | * @return an instance of javax.persistence.Query | |
| 113 | */ | |
| 114 | public Query createNativeQuery(String sqlString); | |
| 115 | ||
| 116 | /** | |
| 117 | * Flush cache | |
| 118 | * | |
| 119 | */ | |
| 120 | public void flush(); | |
| 121 | ||
| 122 | } |