Last active
June 2, 2020 09:50
-
-
Save azizkhani/221e8bec9a2d70f4783b19eb7e1bf95d to your computer and use it in GitHub Desktop.
GenericRepositoryServicePattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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