br.com.jhonsapp.bootstrap.object.service.generic.AbstractService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bootstrap-object Show documentation
Show all versions of bootstrap-object Show documentation
A complete architecture for creating and managing users.
package br.com.jhonsapp.bootstrap.object.service.generic;
import br.com.jhonsapp.bootstrap.object.domain.generic.DomainObject;
import br.com.jhonsapp.bootstrap.object.persistence.generic.GenericDAO;
public abstract class AbstractService implements Service {
private static final long serialVersionUID = 3583603527173873467L;
@Override
public boolean saveOrUpdate(T object) {
if (isStateInvalid(object))
throw new IllegalStateException("The object state is illegal.");
if (!isUnique(object))
throw new IllegalArgumentException("The object already exists.");
preSaveOrUpdate(object);
boolean result = false;
if (object.getId() == 0L)
result = getDAO().persist(object);
else
result = getDAO().update(object) != null;
postSaveOrUpdate(object, result);
return result;
}
protected void preSaveOrUpdate(T object) {
}
protected void postSaveOrUpdate(T object, boolean result) {
}
protected abstract GenericDAO getDAO();
public abstract boolean isStateInvalid(T object);
public abstract boolean isUnique(T object);
public abstract boolean hasObject(T object);
@Override
public boolean remove(T object) {
preRemove(object);
boolean result = getDAO().remove(object);
postRemove(object, result);
return result;
}
protected void preRemove(T object) {
}
protected void postRemove(T object, boolean result) {
}
}