introduced IdentifiableEntity
This commit is contained in:
@ -87,6 +87,18 @@ public abstract class CommonAbstractController {
|
|||||||
return audit;
|
return audit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TransactionAttribute(TransactionAttributeType.REQUIRED)
|
||||||
|
@Transactional
|
||||||
|
@Lock(LockType.WRITE)
|
||||||
|
public <T extends IdentifiableEntity> T createOrUpdate(T entity, String createdBy) throws ControllerException {
|
||||||
|
if (entity.getId() == null) {
|
||||||
|
create(entity, createdBy);
|
||||||
|
return entity;
|
||||||
|
} else {
|
||||||
|
return update(entity, createdBy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TransactionAttribute(TransactionAttributeType.REQUIRED)
|
@TransactionAttribute(TransactionAttributeType.REQUIRED)
|
||||||
@Transactional
|
@Transactional
|
||||||
@Lock(LockType.WRITE)
|
@Lock(LockType.WRITE)
|
||||||
@ -137,7 +149,7 @@ public abstract class CommonAbstractController {
|
|||||||
@Transactional
|
@Transactional
|
||||||
@Lock(LockType.WRITE)
|
@Lock(LockType.WRITE)
|
||||||
public <T extends Serializable> T update(T entity, String updatedBy) throws ControllerException {
|
public <T extends Serializable> T update(T entity, String updatedBy) throws ControllerException {
|
||||||
T currentEntity = executeUpdate(entity, updatedBy);
|
T currentEntity = executeUpdate(entity, updatedBy);
|
||||||
if (EndDateable.class.isAssignableFrom(entity.getClass())) {
|
if (EndDateable.class.isAssignableFrom(entity.getClass())) {
|
||||||
T newEntity = EntityUtil.cloneToNewEntity(currentEntity);
|
T newEntity = EntityUtil.cloneToNewEntity(currentEntity);
|
||||||
em.merge(currentEntity);
|
em.merge(currentEntity);
|
||||||
@ -173,10 +185,22 @@ public abstract class CommonAbstractController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected <T extends Serializable> Predicate getFilterCondition(CriteriaBuilder cb, Root<T> root, Map<String, Object> filters, Map<String, Object> excludeFilters) {
|
protected <T extends Serializable> Predicate getFilterCondition(CriteriaBuilder cb, Root<T> root, Map<String, Object> filters, Map<String, Object> excludeFilters) {
|
||||||
Predicate filterCondition = null;
|
// Predicate filterCondition = null;
|
||||||
filterCondition = getFilterCondition(filterCondition, cb, root, filters, true);
|
// filterCondition = getFilterCondition(filterCondition, cb, root, filters, true);
|
||||||
filterCondition = getFilterCondition(filterCondition, cb, root, excludeFilters, false);
|
// filterCondition = getFilterCondition(filterCondition, cb, root, excludeFilters, false);
|
||||||
return filterCondition;
|
// return filterCondition;
|
||||||
|
Predicate includeFilterCondition = getFilterCondition(null, cb, root, filters, true);
|
||||||
|
Predicate excludeFilterCondition = getFilterCondition(null, cb, root, excludeFilters, false);
|
||||||
|
|
||||||
|
if ((includeFilterCondition == null) && (excludeFilterCondition == null)) {
|
||||||
|
return null;
|
||||||
|
} else if (includeFilterCondition == null) {
|
||||||
|
return excludeFilterCondition;
|
||||||
|
} else if (excludeFilterCondition == null) {
|
||||||
|
return includeFilterCondition;
|
||||||
|
} else {
|
||||||
|
return cb.and(includeFilterCondition, excludeFilterCondition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -186,8 +210,7 @@ public abstract class CommonAbstractController {
|
|||||||
* @param cb the criteria builder to use
|
* @param cb the criteria builder to use
|
||||||
* @param root the root of the object to search for
|
* @param root the root of the object to search for
|
||||||
* @param filters the filters to apply
|
* @param filters the filters to apply
|
||||||
* @param include if set to true, the filter is used as include filter (equals, in). If set to false, the filter is
|
* @param include if set to true, the filter is used as include filter (equals, in). If set to false, the filter is inverted and used as exclude filter (not equals, not in etc)
|
||||||
* inverted and used as exclude filter (not equals, not in etc)
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected <T extends Serializable> Predicate getFilterCondition(Predicate filterCondition, CriteriaBuilder cb, Root<T> root, Map<String, Object> filters, boolean include) {
|
protected <T extends Serializable> Predicate getFilterCondition(Predicate filterCondition, CriteriaBuilder cb, Root<T> root, Map<String, Object> filters, boolean include) {
|
||||||
@ -300,8 +323,7 @@ public abstract class CommonAbstractController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns null, if the list is empty or null itself. Returns the one element if there is exactly one element in the
|
* returns null, if the list is empty or null itself. Returns the one element if there is exactly one element in the list. Otherwise an exception is thrown
|
||||||
* list. Otherwise an exception is thrown
|
|
||||||
*
|
*
|
||||||
* @param resultList
|
* @param resultList
|
||||||
* @return
|
* @return
|
||||||
|
|||||||
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 joern.muehlencord.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package de.muehlencord.shared.db;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author joern.muehlencord
|
||||||
|
*/
|
||||||
|
public interface IdentifiableEntity extends Serializable{
|
||||||
|
|
||||||
|
Object getId();
|
||||||
|
|
||||||
|
String getIdString();
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user