// 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.ber;

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

privileged aspect Ber_Roo_Jpa_ActiveRecord {
    
    @PersistenceContext
    transient EntityManager Ber.entityManager;
    
    public static final EntityManager Ber.entityManager() {
        EntityManager em = new Ber().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 Ber.countBers() {
        return entityManager().createQuery("SELECT COUNT(o) FROM Ber o", Long.class).getSingleResult();
    }
    
    public static List<Ber> Ber.findAllBers() {
        return entityManager().createQuery("SELECT o FROM Ber o", Ber.class).getResultList();
    }
    
    public static Ber Ber.findBer(Long id) {
        if (id == null) return null;
        return entityManager().find(Ber.class, id);
    }
    
    public static List<Ber> Ber.findBerEntries(int firstResult, int maxResults) {
        return entityManager().createQuery("SELECT o FROM Ber o", Ber.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
    }
    
    @Transactional
    public void Ber.persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.persist(this);
    }
    
    @Transactional
    public void Ber.remove() {
        if (this.entityManager == null) this.entityManager = entityManager();
        if (this.entityManager.contains(this)) {
            this.entityManager.remove(this);
        } else {
            Ber attached = Ber.findBer(this.id);
            this.entityManager.remove(attached);
        }
    }
    
    @Transactional
    public void Ber.flush() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.flush();
    }
    
    @Transactional
    public void Ber.clear() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.clear();
    }
    
    @Transactional
    public Ber Ber.merge() {
        if (this.entityManager == null) this.entityManager = entityManager();
        Ber merged = this.entityManager.merge(this);
        this.entityManager.flush();
        return merged;
    }
    
}
