Skip to content

Instantly share code, notes, and snippets.

@azizkhani
Last active June 2, 2020 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azizkhani/221e8bec9a2d70f4783b19eb7e1bf95d to your computer and use it in GitHub Desktop.
Save azizkhani/221e8bec9a2d70f4783b19eb7e1bf95d to your computer and use it in GitHub Desktop.
GenericRepositoryServicePattern
public interface IAbstarctRepository<T,PK extends Serializable> {
List<T> getAll();
T loadByEntityId(PK entityId);
boolean delete(T entity);
boolean deleteByEntityId(PK entityId);
void update(T entity);
PK saveOrUpdate(T entity);
boolean save(List<T> entities);
}
public class AbstarctRepository<T, PK extends Serializable> implements IAbstarctRepository<T, PK> {
T loadByEntityId(PK entityId){
// write code
}
}
public interface IAbstarctService<T,PK extends Serializable> {
List<T> getAll();
T loadByEntityId(PK entityId);
boolean delete(T entity);
boolean deleteByEntityId(PK entityId);
void update(T entity);
PK saveOrUpdate(T entity);
boolean save(List<T> entities);
}
public abstract class AbstarctService<T, PK extends Serializable> implements IAbstarctService<T, PK> {
protected abstract IAbstractRepository<T, PK> getGenericRepo();
T loadByEntityId(PK entityId){
getGenericRepo.loadByEntityId(entityId);
}
}
public interface IPartyRepository extends IAbstarctRepository<Party,Long> {
List<Party> findByPartyName(String partyName)
}
public interface PartyRepository extends AbstarctRepository<Party,Long> implement IPartyRepository{
List<Party> findByPartyName(String partyName){
// write codes
}
}
public interface IPartyService extends IAbstarctService<Party,Long> {
List<Party> findByPartyName(String partyName)
}
public interface PartyService extends AbstarctService<Party,Long> implement IPartyService{
List<Party> findByPartyName(String partyName){
// write codes
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment