CCM NG: Reload Methode in AbstractEntityRepository erstellen (#2807) and getIdOfEntity method including implementation in all repositories

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5256 8810af33-2d31-482b-a856-94f89814c4df
ccm-docs
jensp 2018-02-07 15:49:10 +00:00
parent b8cbeefd48
commit 60cbb627c1
36 changed files with 209 additions and 17 deletions

View File

@ -104,6 +104,11 @@ public class AssetRepository
return "objectId";
}
@Override
public Long getIdOfEntity(final Asset entity) {
return entity.getObjectId();
}
@Override
public boolean isNew(final Asset asset) {
return asset.getObjectId() == 0;

View File

@ -115,12 +115,17 @@ public class ContentItemRepository
public Class<ContentItem> getEntityClass() {
return ContentItem.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public Long getIdOfEntity(final ContentItem entity) {
return entity.getObjectId();
}
@Override
public boolean isNew(final ContentItem item) {
return ccmObjectRepo.isNew(item);

View File

@ -54,7 +54,7 @@ public class ContentSectionRepository
try {
return Optional.of(query.getSingleResult());
} catch(NoResultException ex) {
} catch (NoResultException ex) {
return Optional.empty();
}
}
@ -63,12 +63,17 @@ public class ContentSectionRepository
public Class<ContentSection> getEntityClass() {
return ContentSection.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public Long getIdOfEntity(final ContentSection entity) {
return entity.getObjectId();
}
@Override
public boolean isNew(final ContentSection section) {
return section.getObjectId() == 0;

View File

@ -54,12 +54,17 @@ public class ContentTypeRepository
public Class<ContentType> getEntityClass() {
return ContentType.class;
}
@Override
public String getIdAttributeName() {
return "objectId";
}
@Override
public Long getIdOfEntity(final ContentType entity) {
return entity.getObjectId();
}
@Override
public boolean isNew(final ContentType type) {
return type.getObjectId() == 0;

View File

@ -61,6 +61,11 @@ public class FolderRepository extends AbstractEntityRepository<Long, Folder> {
return "objectId";
}
@Override
public Long getIdOfEntity(final Folder entity) {
return entity.getObjectId();
}
@Override
public boolean isNew(final Folder folder) {
return folder.getObjectId() == 0;

View File

@ -46,7 +46,12 @@ public class MultiPartArticleSectionRepository
public String getIdAttributeName() {
return "sectionId";
}
@Override
public Long getIdOfEntity(final MultiPartArticleSection entity) {
return entity.getSectionId();
}
@Override
public Class<MultiPartArticleSection> getEntityClass() {
return MultiPartArticleSection.class;
@ -78,10 +83,10 @@ public class MultiPartArticleSectionRepository
final MultiPartArticleSection section) {
final TypedQuery<MultiPartArticle> query = getEntityManager()
.createNamedQuery("MultiPartArticleSection.findArticleOfSection",
MultiPartArticle.class);
.createNamedQuery("MultiPartArticleSection.findArticleOfSection",
MultiPartArticle.class);
query.setParameter("section", section);
return query.getSingleResult();
}

View File

@ -42,6 +42,11 @@ public class LifecycleDefinitionRepository
return "definitionId";
}
@Override
public Long getIdOfEntity(final LifecycleDefinition entity) {
return entity.getDefinitionId();
}
@Override
public boolean isNew(final LifecycleDefinition lifecycleDefinition) {
return lifecycleDefinition.getDefinitionId() == 0;

View File

@ -27,23 +27,27 @@ import javax.enterprise.context.RequestScoped;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class LifecycleRepository extends AbstractEntityRepository<Long, Lifecycle> {
public class LifecycleRepository
extends AbstractEntityRepository<Long, Lifecycle> {
@Override
public Class<Lifecycle> getEntityClass() {
return Lifecycle.class;
}
@Override
public String getIdAttributeName() {
return "lifecycleId";
}
@Override
public Long getIdOfEntity(final Lifecycle entity) {
return entity.getLifecycleId();
}
@Override
public boolean isNew(final Lifecycle lifecycle) {
return lifecycle.getLifecycleId() == 0;
}
}

View File

@ -27,7 +27,7 @@ import javax.enterprise.context.RequestScoped;
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class PhaseDefinititionRepository
public class PhaseDefinititionRepository
extends AbstractEntityRepository<Long, PhaseDefinition> {
@Override
@ -39,12 +39,15 @@ public class PhaseDefinititionRepository
public String getIdAttributeName() {
return "definitionId";
}
@Override
public Long getIdOfEntity(final PhaseDefinition entity) {
return entity.getDefinitionId();
}
@Override
public boolean isNew(final PhaseDefinition phaseDefinition) {
return phaseDefinition.getDefinitionId() == 0;
}
}

View File

@ -41,6 +41,11 @@ public class PhaseRepository extends AbstractEntityRepository<Long, Phase> {
return "phaseId";
}
@Override
public Long getIdOfEntity(final Phase entity) {
return entity.getPhaseId();
}
@Override
public boolean isNew(final Phase phase) {
return phase.getPhaseId() == 0;

View File

@ -101,4 +101,9 @@ public class PageRepository extends AbstractEntityRepository<Long, Page> {
return page.getObjectId() == 0;
}
@Override
public Long getIdOfEntity(final Page entity) {
return entity.getObjectId();
}
}

View File

@ -87,6 +87,11 @@ public class PagesRepository extends AbstractEntityRepository<Long, Pages> {
return "objectId";
}
@Override
public Long getIdOfEntity(final Pages entity) {
return entity.getObjectId();
}
@Override
public boolean isNew(final Pages pages) {
return pages.getObjectId() == 0;

View File

@ -71,6 +71,11 @@ public class CategoryRepository extends AbstractEntityRepository<Long, Category>
return "objectId";
}
@Override
public Long getIdOfEntity(final Category entity) {
return entity.getObjectId();
}
@Override
public boolean isNew(final Category entity) {
return entity.getObjectId() == 0;

View File

@ -55,6 +55,11 @@ public class DomainRepository extends AbstractEntityRepository<Long, Domain> {
public String getIdAttributeName() {
return "objectId";
}
@Override
public Long getIdOfEntity(final Domain entity) {
return entity.getObjectId();
}
@Override
public boolean isNew(final Domain entity) {

View File

@ -133,6 +133,14 @@ public abstract class AbstractEntityRepository<K, E> implements Serializable {
*/
public abstract String getIdAttributeName();
/**
* Get the primary key/id of a entity.
*
* @param entity The entity
* @return The ID of the provided {@code entity}.
*/
public abstract K getIdOfEntity(E entity);
/**
* Finds an entity by it ID.
*
@ -215,6 +223,16 @@ public abstract class AbstractEntityRepository<K, E> implements Serializable {
return Optional.empty();
}
}
@Transactional(Transactional.TxType.REQUIRED)
public E reload(final E entity, final String... fetchJoins) {
return findById(getIdOfEntity(entity), fetchJoins)
.orElseThrow(() -> new IllegalArgumentException(String
.format("No Entity of type \"%s\" with ID %s in the database.",
getEntityClass().getName(),
Objects.toString(getIdOfEntity(entity)))));
}
/**
* Finds all instances of the entity of the type this repository is

View File

@ -55,6 +55,11 @@ public class CcmObjectRepository extends AbstractEntityRepository<Long, CcmObjec
public String getIdAttributeName() {
return "objectId";
}
@Override
public Long getIdOfEntity(final CcmObject entity) {
return entity.getObjectId();
}
@Override
public boolean isNew(final CcmObject entity) {

View File

@ -49,6 +49,11 @@ public class ResourceRepository extends AbstractEntityRepository<Long,
public String getIdAttributeName() {
return "objectId";
}
@Override
public Long getIdOfEntity(final Resource entity) {
return entity.getObjectId();
}
@Override
public boolean isNew(final Resource entity) {

View File

@ -48,6 +48,11 @@ public class ResourceTypeRepository
public String getIdAttributeName() {
return "resourceTypeId";
}
@Override
public Long getIdOfEntity(final ResourceType entity) {
return entity.getResourceTypeId();
}
@Override
public boolean isNew(final ResourceType entity) {

View File

@ -47,6 +47,11 @@ public class ComponentModelRepository
public String getIdAttributeName() {
return "componentModelId";
}
@Override
public Long getIdOfEntity(final ComponentModel entity) {
return entity.getComponentModelId();
}
@Override
public boolean isNew(final ComponentModel componentModel) {

View File

@ -53,6 +53,11 @@ public class PageModelRepository extends AbstractEntityRepository<Long, PageMode
return "pageModelId";
}
@Override
public Long getIdOfEntity(final PageModel entity) {
return entity.getPageModelId();
}
@Override
public boolean isNew(final PageModel pageModel) {

View File

@ -41,12 +41,17 @@ public class GroupRepository extends AbstractEntityRepository<Long, Group> {
public Class<Group> getEntityClass() {
return Group.class;
}
@Override
public String getIdAttributeName() {
return "partyId";
}
@Override
public Long getIdOfEntity(final Group entity) {
return entity.getPartyId();
}
@Override
public boolean isNew(final Group entity) {
if (entity == null) {

View File

@ -47,6 +47,11 @@ public class PartyRepository extends AbstractEntityRepository<Long, Party> {
return "partyId";
}
@Override
public Long getIdOfEntity(final Party entity) {
return entity.getPartyId();
}
@Override
public boolean isNew(final Party entity) {
if (entity == null) {

View File

@ -47,6 +47,11 @@ public class PermissionRepository
return "permissionId";
}
@Override
public Long getIdOfEntity(final Permission entity) {
return entity.getPermissionId();
}
@Override
public boolean isNew(Permission entity) {
if (entity == null) {

View File

@ -49,6 +49,11 @@ public class RoleRepository extends AbstractEntityRepository<Long, Role> {
return "roleId";
}
@Override
public Long getIdOfEntity(final Role entity) {
return entity.getRoleId();
}
@Override
public boolean isNew(final Role entity) {
if (entity == null) {

View File

@ -47,6 +47,11 @@ public class UserRepository extends AbstractEntityRepository<Long, User> {
public String getIdAttributeName() {
return "partyId";
}
@Override
public Long getIdOfEntity(final User entity) {
return entity.getPartyId();
}
@Override
public boolean isNew(final User user) {

View File

@ -127,6 +127,11 @@ public class SiteRepository extends AbstractEntityRepository<Long, Site> {
public String getIdAttributeName() {
return "objectId";
}
@Override
public Long getIdOfEntity(final Site entity) {
return entity.getObjectId();
}
@Override
public boolean isNew(final Site site) {

View File

@ -51,6 +51,11 @@ public class ApplicationRepository
public String getIdAttributeName() {
return "objectId";
}
@Override
public Long getIdOfEntity(final CcmApplication entity) {
return entity.getObjectId();
}
@Override
public boolean isNew(final CcmApplication application) {

View File

@ -50,6 +50,11 @@ public class AssignableTaskRepository
public String getIdAttributeName() {
return "taskId";
}
@Override
public Long getIdOfEntity(final AssignableTask entity) {
return entity.getTaskId();
}
@Override
public boolean isNew(final AssignableTask task) {

View File

@ -44,6 +44,11 @@ public class TaskCommentRepository
public String getIdAttributeName() {
return "commentId";
}
@Override
public Long getIdOfEntity(final TaskComment entity) {
return entity.getCommentId();
}
@Override
public boolean isNew(TaskComment entity) {

View File

@ -46,6 +46,11 @@ public class TaskRepository extends AbstractEntityRepository<Long, Task> {
public String getIdAttributeName() {
return "taskId";
}
@Override
public Long getIdOfEntity(final Task entity) {
return entity.getTaskId();
}
@Override
public boolean isNew(final Task task) {

View File

@ -47,6 +47,11 @@ public class WorkflowRepository extends AbstractEntityRepository<Long, Workflow>
return "workflowId";
}
@Override
public Long getIdOfEntity(final Workflow entity) {
return entity.getWorkflowId();
}
@Override
public boolean isNew(final Workflow workflow) {
return workflow.getWorkflowId() == 0;

View File

@ -34,6 +34,8 @@ import javax.persistence.EntityManager;
public class BlobObjectRepository extends
AbstractAuditedEntityRepository<Long, BlobObject> {
private static final long serialVersionUID = 35679591875538616L;
@Inject
private EntityManager entityManager;
@ -47,6 +49,11 @@ public class BlobObjectRepository extends
return "blobObjectId";
}
@Override
public Long getIdOfEntity(final BlobObject entity) {
return entity.getBlobObjectId();
}
@Override
public Class<BlobObject> getEntityClass() {
return BlobObject.class;

View File

@ -39,6 +39,11 @@ public class FileRepository extends AbstractResourceRepository<File> {
return "objectId";
}
@Override
public Long getIdOfEntity(final File entity) {
return entity.getObjectId();
}
@Override
public TypedQuery<File> getFindByNameQuery() {
return entityManager.createNamedQuery(

View File

@ -38,6 +38,11 @@ public class FolderRepository extends AbstractResourceRepository<Folder> {
public String getIdAttributeName() {
return "objectId";
}
@Override
public Long getIdOfEntity(final Folder entity) {
return entity.getObjectId();
}
@Override
public TypedQuery<Folder> getFindByNameQuery() {

View File

@ -47,6 +47,11 @@ public class RepositoryRepository
return entity.getObjectId();
}
@Override
public Long getIdOfEntity(final Repository entity) {
return entity.getObjectId();
}
@Override
public String getIdAttributeName() {
return "objectId";

View File

@ -53,6 +53,11 @@ public class ShortcutRepository extends AbstractEntityRepository<Long, Shortcut>
return "shortcutId";
}
@Override
public Long getIdOfEntity(final Shortcut entity) {
return entity.getShortcutId();
}
@Override
public boolean isNew(final Shortcut entity) {
return entity.getShortcutId() == 0;