-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reintroduce delete(id) method with better JPA implementation
- Loading branch information
1 parent
eaab5a2
commit 405bd3e
Showing
10 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,20 +14,20 @@ | |
|
||
import javax.inject.Inject; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.EntityNotFoundException; | ||
|
||
|
||
/** | ||
* This class serves as inheritance base for the JPA repositories. | ||
* | ||
* @param <A> JPA Entity Type (DDD: Aggregate) | ||
* @param <K> key type | ||
* | ||
* @author [email protected] | ||
* @author [email protected] | ||
*/ | ||
public abstract class BaseJpaRepository<A extends AggregateRoot<K>, K> extends BaseRepository<A, K> { | ||
|
||
@Inject | ||
@Inject | ||
protected EntityManager entityManager; | ||
|
||
/** | ||
|
@@ -41,24 +41,33 @@ protected BaseJpaRepository(Class<A> aggregateRootClass, Class<K> kClass) { | |
} | ||
|
||
@Override | ||
protected A doLoad(K id) { | ||
protected A doLoad(K id) { | ||
return entityManager.find(getAggregateRootClass(), id); | ||
} | ||
|
||
@Override | ||
protected void doDelete(K id) { | ||
A aggregate = load(id); | ||
if (aggregate == null) { | ||
throw new EntityNotFoundException("Attempt to delete non-existent aggregate with id " + id + " of class " + getAggregateRootClass().getCanonicalName()); | ||
} | ||
entityManager.remove(aggregate); | ||
} | ||
|
||
@Override | ||
protected void doDelete(A aggregate) { | ||
entityManager.remove(aggregate); | ||
} | ||
|
||
@Override | ||
protected void doPersist(A aggregate) { | ||
entityManager.persist(aggregate); | ||
entityManager.persist(aggregate); | ||
} | ||
|
||
@Override | ||
protected A doSave(A aggregate) { | ||
return entityManager.merge(aggregate); | ||
} | ||
|
||
|
||
} |
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
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
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