|
Hibernate example source code file (EhcacheHibernate.java)
The Hibernate EhcacheHibernate.java source code/* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are * distributed under license by Red Hat Inc. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.cache.ehcache.management.impl; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import javax.management.MBeanNotificationInfo; import javax.management.NotCompliantMBeanException; import javax.management.Notification; import javax.management.openmbean.TabularData; import net.sf.ehcache.CacheManager; import net.sf.ehcache.hibernate.management.api.EhcacheHibernateMBean; import net.sf.ehcache.hibernate.management.api.EhcacheStats; import net.sf.ehcache.hibernate.management.api.HibernateStats; import org.hibernate.SessionFactory; /** * Implementation of the {@link EhcacheHibernateMBean} * <p/> * <p/> * * @author <a href="mailto:asanoujam@terracottatech.com">Abhishek Sanoujam */ public class EhcacheHibernate extends BaseEmitterBean implements EhcacheHibernateMBean { private static final MBeanNotificationInfo NOTIFICATION_INFO; private final AtomicBoolean statsEnabled = new AtomicBoolean( true ); private EhcacheStats ehcacheStats; private volatile HibernateStats hibernateStats = NullHibernateStats.INSTANCE; static { final String[] notifTypes = new String[] { }; final String name = Notification.class.getName(); final String description = "Ehcache Hibernate Statistics Event"; NOTIFICATION_INFO = new MBeanNotificationInfo( notifTypes, name, description ); } /** * Constructor accepting the backing {@link CacheManager} * * @param manager the backing {@link CacheManager} * * @throws NotCompliantMBeanException */ public EhcacheHibernate(CacheManager manager) throws NotCompliantMBeanException { super( EhcacheHibernateMBean.class ); ehcacheStats = new EhcacheStatsImpl( manager ); } /** * Enable hibernate statistics with the input session factory */ public void enableHibernateStatistics(SessionFactory sessionFactory) { try { hibernateStats = new HibernateStatsImpl( sessionFactory ); } catch ( Exception e ) { throw new RuntimeException( e ); } } /** * {@inheritDoc} */ public boolean isHibernateStatisticsSupported() { return hibernateStats instanceof HibernateStatsImpl; } /** * {@inheritDoc} */ public void setStatisticsEnabled(boolean flag) { if ( flag ) { ehcacheStats.enableStats(); hibernateStats.enableStats(); } else { ehcacheStats.disableStats(); hibernateStats.disableStats(); } statsEnabled.set( flag ); sendNotification( HibernateStats.CACHE_STATISTICS_ENABLED, flag ); } /** * {@inheritDoc} */ public boolean isStatisticsEnabled() { return statsEnabled.get(); } /** * {@inheritDoc} */ public void clearStats() { ehcacheStats.clearStats(); hibernateStats.clearStats(); } /** * {@inheritDoc} */ public void disableStats() { setStatisticsEnabled( false ); } /** * {@inheritDoc} */ public void enableStats() { setStatisticsEnabled( true ); } /** * {@inheritDoc} */ public void flushRegionCache(String region) { ehcacheStats.flushRegionCache( region ); sendNotification( HibernateStats.CACHE_REGION_FLUSHED, region ); } /** * {@inheritDoc} */ public void flushRegionCaches() { ehcacheStats.flushRegionCaches(); sendNotification( HibernateStats.CACHE_FLUSHED ); } /** * {@inheritDoc} */ public String generateActiveConfigDeclaration() { return ehcacheStats.generateActiveConfigDeclaration(); } /** * {@inheritDoc} */ public String generateActiveConfigDeclaration(String region) { return ehcacheStats.generateActiveConfigDeclaration( region ); } /** * {@inheritDoc} */ public long getCacheHitCount() { return ehcacheStats.getCacheHitCount(); } /** * {@inheritDoc} */ public double getCacheHitRate() { return ehcacheStats.getCacheHitRate(); } /** * {@inheritDoc} */ public long getCacheHitSample() { return ehcacheStats.getCacheHitSample(); } /** * {@inheritDoc} */ public long getCacheMissCount() { return ehcacheStats.getCacheMissCount(); } /** * {@inheritDoc} */ public double getCacheMissRate() { return ehcacheStats.getCacheMissRate(); } /** * {@inheritDoc} */ public long getCacheMissSample() { return ehcacheStats.getCacheMissSample(); } /** * {@inheritDoc} */ public long getCachePutCount() { return ehcacheStats.getCachePutCount(); } /** * {@inheritDoc} */ public double getCachePutRate() { return ehcacheStats.getCachePutRate(); } /** * {@inheritDoc} */ public long getCachePutSample() { return ehcacheStats.getCachePutSample(); } /** * {@inheritDoc} */ public TabularData getCacheRegionStats() { return hibernateStats.getCacheRegionStats(); } /** * {@inheritDoc} */ public long getCloseStatementCount() { return hibernateStats.getCloseStatementCount(); } /** * {@inheritDoc} */ public TabularData getCollectionStats() { return hibernateStats.getCollectionStats(); } /** * {@inheritDoc} */ public long getConnectCount() { return hibernateStats.getConnectCount(); } /** * {@inheritDoc} */ public TabularData getEntityStats() { return hibernateStats.getEntityStats(); } /** * {@inheritDoc} */ public long getFlushCount() { return hibernateStats.getFlushCount(); } /** * {@inheritDoc} */ public long getOptimisticFailureCount() { return hibernateStats.getOptimisticFailureCount(); } /** * {@inheritDoc} */ public String getOriginalConfigDeclaration() { return ehcacheStats.getOriginalConfigDeclaration(); } /** * {@inheritDoc} */ public String getOriginalConfigDeclaration(String region) { return ehcacheStats.getOriginalConfigDeclaration( region ); } /** * {@inheritDoc} */ public long getPrepareStatementCount() { return hibernateStats.getPrepareStatementCount(); } /** * {@inheritDoc} */ public long getQueryExecutionCount() { return hibernateStats.getQueryExecutionCount(); } /** * {@inheritDoc} */ public double getQueryExecutionRate() { return hibernateStats.getQueryExecutionRate(); } /** * {@inheritDoc} */ public long getQueryExecutionSample() { return hibernateStats.getQueryExecutionSample(); } /** * {@inheritDoc} */ public TabularData getQueryStats() { return hibernateStats.getQueryStats(); } /** * {@inheritDoc} */ public Map<String, Map Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate EhcacheHibernate.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.