Search in sources :

Example 6 with BaseEntity

use of com.netsteadfast.greenstep.base.model.BaseEntity in project bamboobsc by billchen198318.

the class BaseService method deleteObject.

@SuppressWarnings({ "unchecked", "rawtypes" })
@ServiceMethodAuthority(type = { ServiceMethodType.DELETE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
public DefaultResult<Boolean> deleteObject(T object) throws ServiceException, Exception {
    if (object == null || !(object instanceof BaseValueObj)) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.OBJ_NULL));
    }
    DefaultResult<Boolean> result = new DefaultResult<Boolean>();
    Class<E> entityObjectClass = GenericsUtils.getSuperClassGenricType(getClass(), 1);
    E entityObject = entityObjectClass.newInstance();
    ((BaseEntity) entityObject).setOid(((BaseValueObj) object).getOid());
    boolean status = false;
    if (this.countByOid(entityObject) > 0) {
        this.delete(entityObject);
        status = true;
    }
    result.setValue(status);
    if (status) {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.DELETE_SUCCESS)));
    } else {
        result.setSystemMessage(new SystemMessage(SysMessageUtil.get(GreenStepSysMsgConstants.DELETE_FAIL)));
    }
    return result;
}
Also used : SystemMessage(com.netsteadfast.greenstep.base.model.SystemMessage) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) BaseEntity(com.netsteadfast.greenstep.base.model.BaseEntity) BaseValueObj(com.netsteadfast.greenstep.base.model.BaseValueObj) DefaultResult(com.netsteadfast.greenstep.base.model.DefaultResult) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)6 BaseEntity (com.netsteadfast.greenstep.base.model.BaseEntity)6 DefaultResult (com.netsteadfast.greenstep.base.model.DefaultResult)6 ServiceMethodAuthority (com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)6 SystemMessage (com.netsteadfast.greenstep.base.model.SystemMessage)6 Transactional (org.springframework.transaction.annotation.Transactional)6 IOException (java.io.IOException)4 BaseValueObj (com.netsteadfast.greenstep.base.model.BaseValueObj)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2