|
Hibernate example source code file (HibernateStatsImpl.java)
The Hibernate HibernateStatsImpl.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.ArrayList; import java.util.List; import javax.management.MBeanNotificationInfo; import javax.management.NotCompliantMBeanException; import javax.management.Notification; import javax.management.openmbean.CompositeData; import javax.management.openmbean.TabularData; import net.sf.ehcache.hibernate.management.api.HibernateStats; import org.hibernate.SessionFactory; import org.hibernate.stat.Statistics; /** * Implementation of {@link HibernateStats} * <p/> * <p/> * * @author <a href="mailto:asanoujam@terracottatech.com">Abhishek Sanoujam */ public class HibernateStatsImpl extends BaseEmitterBean implements HibernateStats { private static final double MILLIS_PER_SECOND = 1000; private static final MBeanNotificationInfo NOTIFICATION_INFO; private final SessionFactory sessionFactory; static { final String[] notifTypes = new String[] { }; final String name = Notification.class.getName(); final String description = "Hibernate Statistics Event"; NOTIFICATION_INFO = new MBeanNotificationInfo( notifTypes, name, description ); } /** * Constructor accepting the backing {@link SessionFactory} * * @param sessionFactory * * @throws javax.management.NotCompliantMBeanException */ public HibernateStatsImpl(SessionFactory sessionFactory) throws NotCompliantMBeanException { super( HibernateStats.class ); this.sessionFactory = sessionFactory; } /** * @return statistics */ private Statistics getStatistics() { return sessionFactory.getStatistics(); } /** * {@inheritDoc} * * @see HibernateStats#clearStats() */ public void clearStats() { getStatistics().clear(); sendNotification( CACHE_STATISTICS_RESET ); } /** * {@inheritDoc} * * @see HibernateStats#disableStats() */ public void disableStats() { setStatisticsEnabled( false ); } /** * {@inheritDoc} * * @see HibernateStats#enableStats() */ public void enableStats() { setStatisticsEnabled( true ); } /** * {@inheritDoc} * * @see HibernateStats#getCloseStatementCount() */ public long getCloseStatementCount() { return getStatistics().getCloseStatementCount(); } /** * {@inheritDoc} * * @see HibernateStats#getConnectCount() */ public long getConnectCount() { return getStatistics().getConnectCount(); } /** * Not supported right now */ public long getDBSQLExecutionSample() { throw new UnsupportedOperationException( "Use getQueryExecutionCount() instead" ); } /** * {@inheritDoc} * * @see HibernateStats#getFlushCount() */ public long getFlushCount() { return getStatistics().getFlushCount(); } /** * {@inheritDoc} * * @see HibernateStats#getOptimisticFailureCount() */ public long getOptimisticFailureCount() { return getStatistics().getOptimisticFailureCount(); } /** * {@inheritDoc} * * @see HibernateStats#getPrepareStatementCount() */ public long getPrepareStatementCount() { return getStatistics().getPrepareStatementCount(); } /** * {@inheritDoc} * * @see HibernateStats#getQueryExecutionCount() */ public long getQueryExecutionCount() { return getStatistics().getQueryExecutionCount(); } /** * {@inheritDoc} * * @see HibernateStats#getQueryExecutionRate() */ public double getQueryExecutionRate() { long startTime = getStatistics().getStartTime(); long now = System.currentTimeMillis(); double deltaSecs = ( now - startTime ) / MILLIS_PER_SECOND; return getQueryExecutionCount() / deltaSecs; } /** * {@inheritDoc} * * @see HibernateStats#getQueryExecutionSample() */ public long getQueryExecutionSample() { throw new UnsupportedOperationException( "TODO: need to impl. rates for query execution" ); } /** * {@inheritDoc} * * @see HibernateStats#getSessionCloseCount() */ public long getSessionCloseCount() { return getStatistics().getSessionCloseCount(); } /** * {@inheritDoc} * * @see HibernateStats#getSessionOpenCount() */ public long getSessionOpenCount() { return getStatistics().getSessionOpenCount(); } /** * {@inheritDoc} * * @see HibernateStats#getSuccessfulTransactionCount() */ public long getSuccessfulTransactionCount() { return getStatistics().getSuccessfulTransactionCount(); } /** * {@inheritDoc} * * @see HibernateStats#getTransactionCount() */ public long getTransactionCount() { return getStatistics().getTransactionCount(); } /** * {@inheritDoc} * * @see HibernateStats#isStatisticsEnabled() */ public boolean isStatisticsEnabled() { return getStatistics().isStatisticsEnabled(); } /** * {@inheritDoc} * * @see HibernateStats#setStatisticsEnabled(boolean) */ public void setStatisticsEnabled(boolean flag) { getStatistics().setStatisticsEnabled( flag ); sendNotification( CACHE_STATISTICS_ENABLED, flag ); } /** * {@inheritDoc} * * @see HibernateStats#getEntityStats() */ public TabularData getEntityStats() { List<CompositeData> result = new ArrayList Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate HibernateStatsImpl.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.