// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
// You may push code into the target .java compilation unit if you wish to edit any member(s).

package nl.bzk.brp.model.data.kern;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import nl.bzk.brp.model.data.kern.HisDoc;
import org.springframework.transaction.annotation.Transactional;

privileged aspect HisDoc_Roo_Jpa_ActiveRecord {
    
    @PersistenceContext
    transient EntityManager HisDoc.entityManager;
    
    public static final EntityManager HisDoc.entityManager() {
        EntityManager em = new HisDoc().entityManager;
        if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
        return em;
    }
    
    public static long HisDoc.countHisDocs() {
        return entityManager().createQuery("SELECT COUNT(o) FROM HisDoc o", Long.class).getSingleResult();
    }
    
    public static List<HisDoc> HisDoc.findAllHisDocs() {
        return entityManager().createQuery("SELECT o FROM HisDoc o", HisDoc.class).getResultList();
    }
    
    public static HisDoc HisDoc.findHisDoc(Long id) {
        if (id == null) return null;
        return entityManager().find(HisDoc.class, id);
    }
    
    public static List<HisDoc> HisDoc.findHisDocEntries(int firstResult, int maxResults) {
        return entityManager().createQuery("SELECT o FROM HisDoc o", HisDoc.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
    }
    
    @Transactional
    public void HisDoc.persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.persist(this);
    }
    
    @Transactional
    public void HisDoc.remove() {
        if (this.entityManager == null) this.entityManager = entityManager();
        if (this.entityManager.contains(this)) {
            this.entityManager.remove(this);
        } else {
            HisDoc attached = HisDoc.findHisDoc(this.id);
            this.entityManager.remove(attached);
        }
    }
    
    @Transactional
    public void HisDoc.flush() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.flush();
    }
    
    @Transactional
    public void HisDoc.clear() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.clear();
    }
    
    @Transactional
    public HisDoc HisDoc.merge() {
        if (this.entityManager == null) this.entityManager = entityManager();
        HisDoc merged = this.entityManager.merge(this);
        this.entityManager.flush();
        return merged;
    }
    
}
