List of usage examples for org.hibernate.engine.spi NamedQueryDefinition isCacheable
public boolean isCacheable()
From source file:com.googlecode.hibernate.audit.listener.AuditSessionFactoryObserver.java
License:Open Source License
private void updateMetaModel(Session session) { session.flush();// ww w . j a v a 2s.com 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()); }
From source file:com.googlecode.hibernate.audit.synchronization.work.AbstractAuditWorkUnit.java
License:Open Source License
protected AuditLogicalGroup getAuditLogicalGroup(Session session, AuditConfiguration auditConfiguration, AuditEvent auditEvent) {/*w ww. j av a 2s.com*/ AuditLogicalGroup logicalGroup = auditConfiguration.getExtensionManager().getAuditLogicalGroupProvider() .getAuditLogicalGroup(session, auditEvent); AuditLogicalGroup result = null; if (logicalGroup != null) { AuditType auditType = HibernateAudit.getAuditType(session, logicalGroup.getAuditType().getClassName()); String externalId = logicalGroup.getExternalId(); result = HibernateAudit.getAuditLogicalGroup(session, auditType, externalId); HibernateException createAuditLogicalGroupException = null; if (result == null) { createAuditLogicalGroupException = createAuditLogicalGroup(session, logicalGroup, auditType); // remove the cached query (possibly null) results so that the result after that is not null. NamedQueryDefinition namedQueryDefinition = ((SessionFactoryImplementor) session .getSessionFactory()).getNamedQuery( HibernateAudit.SELECT_AUDIT_LOCAL_GROUP_BY_AUDIT_TYPE_AND_EXTERNAL_ID); if (namedQueryDefinition.isCacheable()) { String cacheRegion = ((SessionFactoryImplementor) session.getSessionFactory()) .getNamedQuery(HibernateAudit.SELECT_AUDIT_LOCAL_GROUP_BY_AUDIT_TYPE_AND_EXTERNAL_ID) .getCacheRegion(); if (cacheRegion != null) { session.getSessionFactory().getCache().evictQueryRegion(cacheRegion); } else { session.getSessionFactory().getCache().evictQueryRegions(); } } result = HibernateAudit.getAuditLogicalGroup(session, auditType, externalId); } if (result == null) { if (createAuditLogicalGroupException != null) { throw createAuditLogicalGroupException; } else { throw new HibernateException("Unable to create and then retrieve AuditLogicalGroup: className=" + logicalGroup.getAuditType().getClassName() + ",externalId=" + logicalGroup.getExternalId()); } } auditLogicalGroups.add(result); } return result; }