Example usage for org.hibernate.engine.spi NamedQueryDefinition getCacheRegion

List of usage examples for org.hibernate.engine.spi NamedQueryDefinition getCacheRegion

Introduction

In this page you can find the example usage for org.hibernate.engine.spi NamedQueryDefinition getCacheRegion.

Prototype

public String getCacheRegion() 

Source Link

Usage

From source file:com.googlecode.hibernate.audit.listener.AuditSessionFactoryObserver.java

License:Open Source License

private void updateMetaModel(Session session) {
    session.flush();// www .j ava2  s. c o m
    NamedQueryDefinition selectAuditTypeNamedQueryDefinition = ((SessionFactoryImplementor) session
            .getSessionFactory()).getNamedQuery(HibernateAudit.SELECT_AUDIT_TYPE_BY_CLASS_NAME);
    NamedQueryDefinition selectAuditTypeFieldNamedQueryDefinition = ((SessionFactoryImplementor) session
            .getSessionFactory())
                    .getNamedQuery(HibernateAudit.SELECT_AUDIT_TYPE_FIELD_BY_CLASS_NAME_AND_PROPERTY_NAME);

    if (selectAuditTypeNamedQueryDefinition.isCacheable()
            && selectAuditTypeNamedQueryDefinition.getCacheRegion() != null) {
        session.getSessionFactory().getCache()
                .evictQueryRegion(selectAuditTypeNamedQueryDefinition.getCacheRegion());
    }

    if (selectAuditTypeFieldNamedQueryDefinition.isCacheable()
            && selectAuditTypeFieldNamedQueryDefinition.getCacheRegion() != null) {
        session.getSessionFactory().getCache()
                .evictQueryRegion(selectAuditTypeFieldNamedQueryDefinition.getCacheRegion());
    }

    session.getSessionFactory().getCache().evictEntityRegion(AuditType.class.getName());
    session.getSessionFactory().getCache().evictEntityRegion(AuditTypeField.class.getName());
}