package no.dusken.aranea.service;
import no.dusken.aranea.model.Page;
import no.dusken.aranea.model.SectionPage;
import no.dusken.common.service.GenericService;
import no.dusken.common.service.impl.GenericServiceImpl;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.inject.Inject;
import java.util.List;
/**
* @author Marvin B. Lillehaug <lillehau@underdusken.no>
*/
public abstract class AbstractPageServiceImpl<P extends Page> extends GenericServiceImpl<P> implements GenericService<P> {
@Inject
private SectionPageService sectionPageService;
public AbstractPageServiceImpl(Class<P> type) {
super(type);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, readOnly = false)
public boolean remove(P entity) {
List<SectionPage> sectionPagesByPage = sectionPageService.getSectionPagesByPage(entity);
boolean successfullDelete = true;
for (SectionPage sectionPage : sectionPagesByPage) {
successfullDelete &= sectionPageService.remove(sectionPage);
}
return successfullDelete && super.remove(entity);
}
}