[hibernate-commits] Hibernate SVN: r14127 - in core/branches/Branch_3_2/src/org/hibernate: engine and 4 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Oct 19 20:06:51 EDT 2007


Author: scottmarlownovell
Date: 2007-10-19 20:06:51 -0400 (Fri, 19 Oct 2007)
New Revision: 14127

Modified:
   core/branches/Branch_3_2/src/org/hibernate/action/CollectionRecreateAction.java
   core/branches/Branch_3_2/src/org/hibernate/action/CollectionRemoveAction.java
   core/branches/Branch_3_2/src/org/hibernate/action/CollectionUpdateAction.java
   core/branches/Branch_3_2/src/org/hibernate/action/EntityDeleteAction.java
   core/branches/Branch_3_2/src/org/hibernate/action/EntityIdentityInsertAction.java
   core/branches/Branch_3_2/src/org/hibernate/action/EntityInsertAction.java
   core/branches/Branch_3_2/src/org/hibernate/action/EntityUpdateAction.java
   core/branches/Branch_3_2/src/org/hibernate/engine/TwoPhaseLoad.java
   core/branches/Branch_3_2/src/org/hibernate/engine/loading/CollectionLoadContext.java
   core/branches/Branch_3_2/src/org/hibernate/event/def/DefaultInitializeCollectionEventListener.java
   core/branches/Branch_3_2/src/org/hibernate/event/def/DefaultLoadEventListener.java
   core/branches/Branch_3_2/src/org/hibernate/jmx/StatisticsService.java
   core/branches/Branch_3_2/src/org/hibernate/stat/Statistics.java
   core/branches/Branch_3_2/src/org/hibernate/stat/StatisticsImpl.java
   core/branches/Branch_3_2/src/org/hibernate/stat/StatisticsImplementor.java
Log:
Additional statistics added.  Operations that take over OperationThreshold milliseconds will be logged.

Modified: core/branches/Branch_3_2/src/org/hibernate/action/CollectionRecreateAction.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/action/CollectionRecreateAction.java	2007-10-19 22:27:20 UTC (rev 14126)
+++ core/branches/Branch_3_2/src/org/hibernate/action/CollectionRecreateAction.java	2007-10-20 00:06:51 UTC (rev 14127)
@@ -21,7 +21,11 @@
 	}
 
 	public void execute() throws HibernateException {
-		final PersistentCollection collection = getCollection();
+        final boolean stats = getSession().getFactory().getStatistics().isStatisticsEnabled();
+        long startTime = 0;
+        if ( stats ) startTime = System.currentTimeMillis();
+
+        final PersistentCollection collection = getCollection();
 		
 		getPersister().recreate( collection, getKey(), getSession() );
 		
@@ -31,9 +35,9 @@
 		
 		evict();
 
-		if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
+		if ( stats ) {
 			getSession().getFactory().getStatisticsImplementor()
-					.recreateCollection( getPersister().getRole() );
+					.recreateCollection( getPersister().getRole(), System.currentTimeMillis() - startTime);
 		}
 	}
 

Modified: core/branches/Branch_3_2/src/org/hibernate/action/CollectionRemoveAction.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/action/CollectionRemoveAction.java	2007-10-19 22:27:20 UTC (rev 14126)
+++ core/branches/Branch_3_2/src/org/hibernate/action/CollectionRemoveAction.java	2007-10-20 00:06:51 UTC (rev 14127)
@@ -25,7 +25,11 @@
 	}
 
 	public void execute() throws HibernateException {
-		if ( !emptySnapshot ) getPersister().remove( getKey(), getSession() );
+        final boolean stats = getSession().getFactory().getStatistics().isStatisticsEnabled();
+        long startTime = 0;
+        if ( stats ) startTime = System.currentTimeMillis();
+
+        if ( !emptySnapshot ) getPersister().remove( getKey(), getSession() );
 		
 		final PersistentCollection collection = getCollection();
 		if (collection!=null) {
@@ -36,9 +40,9 @@
 		
 		evict();
 
-		if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
+		if ( stats ) {
 			getSession().getFactory().getStatisticsImplementor()
-					.removeCollection( getPersister().getRole() );
+					.removeCollection( getPersister().getRole(), System.currentTimeMillis() - startTime);
 		}
 	}
 

Modified: core/branches/Branch_3_2/src/org/hibernate/action/CollectionUpdateAction.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/action/CollectionUpdateAction.java	2007-10-19 22:27:20 UTC (rev 14126)
+++ core/branches/Branch_3_2/src/org/hibernate/action/CollectionUpdateAction.java	2007-10-20 00:06:51 UTC (rev 14127)
@@ -32,6 +32,9 @@
 		final CollectionPersister persister = getPersister();
 		final PersistentCollection collection = getCollection();
 		boolean affectedByFilters = persister.isAffectedByEnabledFilters(session);
+        final boolean stats = session.getFactory().getStatistics().isStatisticsEnabled();
+        long startTime = 0;
+        if ( stats ) startTime = System.currentTimeMillis();
 
 		if ( !collection.wasInitialized() ) {
 			if ( !collection.hasQueuedOperations() ) throw new AssertionFailure( "no queued adds" );
@@ -62,9 +65,9 @@
 
 		evict();
 
-		if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
+		if ( stats ) {
 			getSession().getFactory().getStatisticsImplementor().
-					updateCollection( getPersister().getRole() );
+					updateCollection( getPersister().getRole(), System.currentTimeMillis() - startTime);
 		}
 	}
 

Modified: core/branches/Branch_3_2/src/org/hibernate/action/EntityDeleteAction.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/action/EntityDeleteAction.java	2007-10-19 22:27:20 UTC (rev 14126)
+++ core/branches/Branch_3_2/src/org/hibernate/action/EntityDeleteAction.java	2007-10-20 00:06:51 UTC (rev 14127)
@@ -44,6 +44,9 @@
 		EntityPersister persister = getPersister();
 		SessionImplementor session = getSession();
 		Object instance = getInstance();
+        final boolean stats = session.getFactory().getStatistics().isStatisticsEnabled();
+        long startTime = 0;
+        if ( stats ) startTime = System.currentTimeMillis();
 
 		boolean veto = preDelete();
 
@@ -93,9 +96,9 @@
 
 		postDelete();
 
-		if ( getSession().getFactory().getStatistics().isStatisticsEnabled() && !veto ) {
+		if ( stats && !veto ) {
 			getSession().getFactory().getStatisticsImplementor()
-					.deleteEntity( getPersister().getEntityName() );
+					.deleteEntity( getPersister().getEntityName(), System.currentTimeMillis() - startTime);
 		}
 	}
 

Modified: core/branches/Branch_3_2/src/org/hibernate/action/EntityIdentityInsertAction.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/action/EntityIdentityInsertAction.java	2007-10-19 22:27:20 UTC (rev 14126)
+++ core/branches/Branch_3_2/src/org/hibernate/action/EntityIdentityInsertAction.java	2007-10-20 00:06:51 UTC (rev 14127)
@@ -38,7 +38,10 @@
 		final EntityPersister persister = getPersister();
 		final SessionImplementor session = getSession();
 		final Object instance = getInstance();
-		
+        final boolean stats = session.getFactory().getStatistics().isStatisticsEnabled();
+        long startTime = 0;
+        if ( stats ) startTime = System.currentTimeMillis();
+
 		boolean veto = preInsert();
 
 		// Don't need to lock the cache here, since if someone
@@ -65,9 +68,9 @@
 		
 		postInsert();
 
-		if ( session.getFactory().getStatistics().isStatisticsEnabled() && !veto ) {
+		if ( stats && !veto ) {
 			session.getFactory().getStatisticsImplementor()
-					.insertEntity( getPersister().getEntityName() );
+					.insertEntity( getPersister().getEntityName(), System.currentTimeMillis() - startTime);
 		}
 
 	}

Modified: core/branches/Branch_3_2/src/org/hibernate/action/EntityInsertAction.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/action/EntityInsertAction.java	2007-10-19 22:27:20 UTC (rev 14126)
+++ core/branches/Branch_3_2/src/org/hibernate/action/EntityInsertAction.java	2007-10-20 00:06:51 UTC (rev 14127)
@@ -46,6 +46,10 @@
 		Object instance = getInstance();
 		Serializable id = getId();
 
+        final boolean stats = session.getFactory().getStatistics().isStatisticsEnabled();
+        long startTime = 0;
+        if ( stats ) startTime = System.currentTimeMillis();
+
 		boolean veto = preInsert();
 
 		// Don't need to lock the cache here, since if someone
@@ -96,7 +100,7 @@
 //			boolean put = persister.getCache().insert(ck, cacheEntry);
 			boolean put = persister.getCache().insert( ck, cacheEntry, version );
 			
-			if ( put && factory.getStatistics().isStatisticsEnabled() ) {
+			if ( put && stats ) {
 				factory.getStatisticsImplementor()
 						.secondLevelCachePut( getPersister().getCache().getRegionName() );
 			}
@@ -105,9 +109,9 @@
 
 		postInsert();
 
-		if ( factory.getStatistics().isStatisticsEnabled() && !veto ) {
+		if ( stats && !veto ) {
 			factory.getStatisticsImplementor()
-					.insertEntity( getPersister().getEntityName() );
+					.insertEntity( getPersister().getEntityName(), System.currentTimeMillis() - startTime);
 		}
 
 	}

Modified: core/branches/Branch_3_2/src/org/hibernate/action/EntityUpdateAction.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/action/EntityUpdateAction.java	2007-10-19 22:27:20 UTC (rev 14126)
+++ core/branches/Branch_3_2/src/org/hibernate/action/EntityUpdateAction.java	2007-10-20 00:06:51 UTC (rev 14127)
@@ -65,7 +65,11 @@
 		boolean veto = preUpdate();
 
 		final SessionFactoryImplementor factory = getSession().getFactory();
-		Object previousVersion = this.previousVersion;
+        final boolean stats = factory.getStatistics().isStatisticsEnabled();
+        long startTime = 0;
+        if ( stats ) startTime = System.currentTimeMillis();
+
+        Object previousVersion = this.previousVersion;
 		if ( persister.isVersionPropertyGenerated() ) {
 			// we need to grab the version value from the entity, otherwise
 			// we have issues with generated-version entities that may have
@@ -158,9 +162,9 @@
 
 		postUpdate();
 
-		if ( factory.getStatistics().isStatisticsEnabled() && !veto ) {
+		if ( stats && !veto ) {
 			factory.getStatisticsImplementor()
-					.updateEntity( getPersister().getEntityName() );
+					.updateEntity( getPersister().getEntityName(), System.currentTimeMillis() - startTime);
 		}
 	}
 

Modified: core/branches/Branch_3_2/src/org/hibernate/engine/TwoPhaseLoad.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/engine/TwoPhaseLoad.java	2007-10-19 22:27:20 UTC (rev 14126)
+++ core/branches/Branch_3_2/src/org/hibernate/engine/TwoPhaseLoad.java	2007-10-20 00:06:51 UTC (rev 14127)
@@ -93,7 +93,11 @@
 			final PostLoadEvent postLoadEvent) throws HibernateException {
 		
 		//TODO: Should this be an InitializeEntityEventListener??? (watch out for performance!)
-	
+        final SessionFactoryImplementor factory = session.getFactory();
+        final boolean stats = factory.getStatistics().isStatisticsEnabled();
+        long startTime = 0;
+        if ( stats ) startTime = System.currentTimeMillis();
+
 		final PersistenceContext persistenceContext = session.getPersistenceContext();
 		EntityEntry entityEntry = persistenceContext.getEntry(entity);
 		if ( entityEntry == null ) {
@@ -128,7 +132,6 @@
 	
 		persister.setPropertyValues( entity, hydratedState, session.getEntityMode() );
 	
-		final SessionFactoryImplementor factory = session.getFactory();
 		if ( persister.hasCache() && session.getCacheMode().isPutEnabled() ) {
 			
 			if ( log.isDebugEnabled() )
@@ -208,8 +211,8 @@
 					MessageHelper.infoString( persister, id, session.getFactory() )
 				);
 		
-		if ( factory.getStatistics().isStatisticsEnabled() ) {
-			factory.getStatisticsImplementor().loadEntity( persister.getEntityName() );
+		if ( stats) {
+			factory.getStatisticsImplementor().loadEntity( persister.getEntityName(), System.currentTimeMillis() - startTime);
 		}
 	
 	}

Modified: core/branches/Branch_3_2/src/org/hibernate/engine/loading/CollectionLoadContext.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/engine/loading/CollectionLoadContext.java	2007-10-19 22:27:20 UTC (rev 14126)
+++ core/branches/Branch_3_2/src/org/hibernate/engine/loading/CollectionLoadContext.java	2007-10-20 00:06:51 UTC (rev 14127)
@@ -233,6 +233,9 @@
 		}
 		final SessionImplementor session = getLoadContext().getPersistenceContext().getSession();
 		final EntityMode em = session.getEntityMode();
+        final boolean stats = session.getFactory().getStatistics().isStatisticsEnabled();
+        long startTime = 0;
+        if ( stats ) startTime = System.currentTimeMillis();
 
 		boolean hasNoQueuedAdds = lce.getCollection().endRead(); // warning: can cause a recursive calls! (proxy initialization)
 
@@ -260,8 +263,8 @@
 			log.debug( "collection fully initialized: " + MessageHelper.collectionInfoString(persister, lce.getKey(), session.getFactory() ) );
 		}
 
-		if ( session.getFactory().getStatistics().isStatisticsEnabled() ) {
-			session.getFactory().getStatisticsImplementor().loadCollection( persister.getRole() );
+		if ( stats ) {
+			session.getFactory().getStatisticsImplementor().loadCollection( persister.getRole(), System.currentTimeMillis() - startTime);
 		}
 	}
 

Modified: core/branches/Branch_3_2/src/org/hibernate/event/def/DefaultInitializeCollectionEventListener.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/def/DefaultInitializeCollectionEventListener.java	2007-10-19 22:27:20 UTC (rev 14126)
+++ core/branches/Branch_3_2/src/org/hibernate/event/def/DefaultInitializeCollectionEventListener.java	2007-10-20 00:06:51 UTC (rev 14127)
@@ -33,6 +33,9 @@
 
 		PersistentCollection collection = event.getCollection();
 		SessionImplementor source = event.getSession();
+        final boolean stats = source.getFactory().getStatistics().isStatisticsEnabled();
+        long startTime = 0;
+        if ( stats ) startTime = System.currentTimeMillis();
 
 		CollectionEntry ce = source.getPersistenceContext().getCollectionEntry(collection);
 		if (ce==null) throw new HibernateException("collection was evicted");
@@ -60,10 +63,10 @@
 				ce.getLoadedPersister().initialize( ce.getLoadedKey(), source );
 				log.trace("collection initialized");
 
-				if ( source.getFactory().getStatistics().isStatisticsEnabled() ) {
+				if ( stats ) {
 					source.getFactory().getStatisticsImplementor().fetchCollection( 
-							ce.getLoadedPersister().getRole() 
-						);
+							ce.getLoadedPersister().getRole(),
+                            System.currentTimeMillis() - startTime);
 				}
 			}
 		}

Modified: core/branches/Branch_3_2/src/org/hibernate/event/def/DefaultLoadEventListener.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/event/def/DefaultLoadEventListener.java	2007-10-19 22:27:20 UTC (rev 14126)
+++ core/branches/Branch_3_2/src/org/hibernate/event/def/DefaultLoadEventListener.java	2007-10-20 00:06:51 UTC (rev 14127)
@@ -392,15 +392,19 @@
 			final EntityKey keyToLoad,
 			final LoadEventListener.LoadType options) throws HibernateException {
 		final SessionImplementor source = event.getSession();
-		Object entity = persister.load(
+        final boolean stats = source.getFactory().getStatistics().isStatisticsEnabled();
+        long startTime = 0;
+        if ( stats ) startTime = System.currentTimeMillis();
+
+        Object entity = persister.load(
 				event.getEntityId(),
 				event.getInstanceToLoad(),
 				event.getLockMode(),
 				source
 		);
 
-		if ( event.isAssociationFetch() && source.getFactory().getStatistics().isStatisticsEnabled() ) {
-			source.getFactory().getStatisticsImplementor().fetchEntity( event.getEntityClassName() );
+		if ( event.isAssociationFetch() && stats) {
+			source.getFactory().getStatisticsImplementor().fetchEntity( event.getEntityClassName(), System.currentTimeMillis() - startTime);
 		}
 
 		return entity;

Modified: core/branches/Branch_3_2/src/org/hibernate/jmx/StatisticsService.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/jmx/StatisticsService.java	2007-10-19 22:27:20 UTC (rev 14126)
+++ core/branches/Branch_3_2/src/org/hibernate/jmx/StatisticsService.java	2007-10-20 00:06:51 UTC (rev 14127)
@@ -314,4 +314,14 @@
 	public String getQueryExecutionMaxTimeQueryString() {
 		return stats.getQueryExecutionMaxTimeQueryString();
 	}
+
+    public void setOperationThreshold(long threshold) {
+        stats.setOperationThreshold(threshold);
+    }
+
+    public long getOperationThreshold() {
+        return stats.getOperationThreshold();
+    }
+
+
 }

Modified: core/branches/Branch_3_2/src/org/hibernate/stat/Statistics.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/stat/Statistics.java	2007-10-19 22:27:20 UTC (rev 14126)
+++ core/branches/Branch_3_2/src/org/hibernate/stat/Statistics.java	2007-10-20 00:06:51 UTC (rev 14127)
@@ -208,4 +208,17 @@
 	 * that occurred
 	 */
 	public long getOptimisticFailureCount();
+
+    /**
+     * Set the operationThreshold to a value greater than zero to enable logging of long running operations.
+     * @param threshold (milliseconds)
+     */
+    public void setOperationThreshold(long threshold);
+
+    /**
+     *
+     * @return Operationthreshold, if greater than zero, operations that exceed the level will be logged. 
+     */
+    public long getOperationThreshold();
+
 }
\ No newline at end of file

Modified: core/branches/Branch_3_2/src/org/hibernate/stat/StatisticsImpl.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/stat/StatisticsImpl.java	2007-10-19 22:27:20 UTC (rev 14126)
+++ core/branches/Branch_3_2/src/org/hibernate/stat/StatisticsImpl.java	2007-10-20 00:06:51 UTC (rev 14127)
@@ -46,8 +46,11 @@
 	private long secondLevelCacheHitCount;
 	private long secondLevelCacheMissCount;
 	private long secondLevelCachePutCount;
-	
-	private long queryExecutionCount;
+
+    private long operationThreshold = 0;    // log operations that take longer than this value (in milliseconds)
+                                            // We don't log anything if operationThreshold == 0 
+
+    private long queryExecutionCount;
 	private long queryExecutionMaxTime;
 	private String queryExecutionMaxTimeQueryString;
 	private long queryCacheHitCount;
@@ -68,7 +71,20 @@
 	/** entity statistics per query string (HQL or SQL) */
 	private final Map queryStatistics = new HashMap();
 
-	public StatisticsImpl() {
+    static final String OPERATION_LOAD = "load ";
+    static final String OPERATION_FETCH = "fetch ";
+    static final String OPERATION_UPDATE = "update ";
+    static final String OPERATION_INSERT = "insert ";
+    static final String OPERATION_DELETE = "delete ";
+    static final String OPERATION_LOADCOLLECTION = "loadCollection ";
+    static final String OPERATION_FETCHCOLLECTION = "fetchCollection ";
+    static final String OPERATION_UPDATECOLLECTION = "updateCollection ";
+    static final String OPERATION_RECREATECOLLECTION = "recreateCollection ";
+    static final String OPERATION_REMOVECOLLECTION = "removeCollection ";
+    static final String OPERATION_EXECUTEQUERY = "executeQuery ";
+    static final String OPERATION_ENDTRANSACTION = "endTransaction ";
+
+    public StatisticsImpl() {
 		clear();
 	}
 
@@ -140,17 +156,44 @@
 	public synchronized void connect() {
 		connectCount++;
 	}
-	
-	public synchronized void loadEntity(String entityName) {
-		entityLoadCount++;
-		getEntityStatistics(entityName).loadCount++;
-	}
 
-	public synchronized void fetchEntity(String entityName) {
-		entityFetchCount++;
-		getEntityStatistics(entityName).fetchCount++;
-	}
+    public synchronized void setOperationThreshold(long threshold) {
+        operationThreshold = threshold;
+    }
 
+    public synchronized long getOperationThreshold() {
+        return operationThreshold;
+    }
+
+    private void logOperation(String operation, String entityName, long time) {
+        if(entityName != null)
+            log.info(operation+entityName + " " + time + "ms");
+        else
+            log.info(operation);  // just log that the event occurred
+
+    }
+
+
+    public void loadEntity(String entityName, long time) {
+        synchronized(this) {
+            entityLoadCount++;
+		    getEntityStatistics(entityName).loadCount++;
+        }
+        if(operationThreshold > 0 && operationThreshold < time) {
+            logOperation(OPERATION_LOAD,entityName, time);
+        }
+    }
+
+    public void fetchEntity(String entityName, long time) {
+        synchronized(this) {
+            entityFetchCount++;
+    		getEntityStatistics(entityName).fetchCount++;
+        }    
+        if(operationThreshold > 0 && operationThreshold < time) {
+            logOperation(OPERATION_FETCH,entityName, time);
+        }
+    }
+
 	/**
 	 * find entity statistics per name
 	 * 
@@ -165,26 +208,41 @@
 		}
 		return es;
 	}
-	
-	public synchronized void updateEntity(String entityName) {
-		entityUpdateCount++;
-		EntityStatistics es = getEntityStatistics(entityName);
-		es.updateCount++;
-	}
 
-	public synchronized void insertEntity(String entityName) {
-		entityInsertCount++;
-		EntityStatistics es = getEntityStatistics(entityName);
-		es.insertCount++;
-	}
+    public void updateEntity(String entityName, long time) {
+        synchronized(this) {
+            entityUpdateCount++;
+    		EntityStatistics es = getEntityStatistics(entityName);
+    		es.updateCount++;
+        }
+        if(operationThreshold > 0 && operationThreshold < time) {
+            logOperation(OPERATION_UPDATE,entityName, time);
+        }
+    }
 
-	public synchronized void deleteEntity(String entityName) {
-		entityDeleteCount++;
-		EntityStatistics es = getEntityStatistics(entityName);
-		es.deleteCount++;
-	}
+	public void insertEntity(String entityName, long time) {
+        synchronized(this) {
+            entityInsertCount++;
+            EntityStatistics es = getEntityStatistics(entityName);
+            es.insertCount++;
+        }
+        if(operationThreshold > 0 && operationThreshold < time) {
+            logOperation(OPERATION_INSERT,entityName, time);
+        }
+    }
 
-	/**
+	public void deleteEntity(String entityName, long time) {
+        synchronized(this) {
+            entityDeleteCount++;
+    		EntityStatistics es = getEntityStatistics(entityName);
+    		es.deleteCount++;
+        }
+        if(operationThreshold > 0 && operationThreshold < time) {
+            logOperation(OPERATION_DELETE,entityName, time);
+        }
+    }
+
+    /**
 	 * Get collection statistics per role
 	 * 
 	 * @param role collection role
@@ -199,30 +257,55 @@
 		return cs;
 	}
 	
-	public synchronized void loadCollection(String role) {
-		collectionLoadCount++;
-		getCollectionStatistics(role).loadCount++;
-	}
+	public void loadCollection(String role, long time) {
+        synchronized(this) {
+            collectionLoadCount++;
+		    getCollectionStatistics(role).loadCount++;
+        }
+        if(operationThreshold > 0 && operationThreshold < time) {
+            logOperation(OPERATION_LOADCOLLECTION,role, time);
+        }
+    }
 
-	public synchronized void fetchCollection(String role) {
-		collectionFetchCount++;
-		getCollectionStatistics(role).fetchCount++;
-	}
+    public void fetchCollection(String role, long time) {
+        synchronized(this) {
+            collectionFetchCount++;
+    		getCollectionStatistics(role).fetchCount++;
+        }
+        if(operationThreshold > 0 && operationThreshold < time) {
+            logOperation(OPERATION_FETCHCOLLECTION,role, time);
+        }
+    }
 
-	public synchronized void updateCollection(String role) {
-		collectionUpdateCount++;
-		getCollectionStatistics(role).updateCount++;
-	}
+	public void updateCollection(String role, long time) {
+        synchronized(this) {
+            collectionUpdateCount++;
+    		getCollectionStatistics(role).updateCount++;
+        }
+        if(operationThreshold > 0 && operationThreshold < time) {
+            logOperation(OPERATION_UPDATECOLLECTION,role, time);
+        }
+    }
 
-	public synchronized void recreateCollection(String role) {
-		collectionRecreateCount++;
-		getCollectionStatistics(role).recreateCount++;
-	}
+	public void recreateCollection(String role, long time) {
+        synchronized(this) {
+            collectionRecreateCount++;
+	    	getCollectionStatistics(role).recreateCount++;
+        }
+        if(operationThreshold > 0 && operationThreshold < time) {
+            logOperation(OPERATION_RECREATECOLLECTION,role, time);
+        }
+    }
 
-	public synchronized void removeCollection(String role) {
-		collectionRemoveCount++;
-		getCollectionStatistics(role).removeCount++;
-	}
+	public void removeCollection(String role, long time) {
+        synchronized(this) {
+            collectionRemoveCount++;
+    		getCollectionStatistics(role).removeCount++;
+        }
+        if(operationThreshold > 0 && operationThreshold < time) {
+            logOperation(OPERATION_REMOVECOLLECTION,role, time);
+        }
+    }
 	
 	/**
 	 * Second level cache statistics per region
@@ -257,17 +340,23 @@
 		getSecondLevelCacheStatistics(regionName).missCount++;
 	}
 
-	public synchronized void queryExecuted(String hql, int rows, long time) {
-		queryExecutionCount++;
-		if (queryExecutionMaxTime<time) {
-			queryExecutionMaxTime=time;
-			queryExecutionMaxTimeQueryString = hql;
-		}
-		if (hql!=null) {
-			QueryStatistics qs = getQueryStatistics(hql);
-			qs.executed(rows, time);
-		}
-	}
+
+    public void queryExecuted(String hql, int rows, long time) {
+        synchronized(this) {
+            queryExecutionCount++;
+            if (queryExecutionMaxTime<time) {
+                queryExecutionMaxTime=time;
+                queryExecutionMaxTimeQueryString = hql;
+            }
+            if (hql!=null) {
+                QueryStatistics qs = getQueryStatistics(hql);
+                qs.executed(rows, time);
+            }
+        }
+        if(operationThreshold > 0 && operationThreshold < time) {
+            logOperation(OPERATION_EXECUTEQUERY,hql, time);
+        }
+    }
 	
 	public synchronized void queryCacheHit(String hql, String regionName) {
 		queryCacheHitCount++;
@@ -556,10 +645,17 @@
 		}
 	}
 
-	public void endTransaction(boolean success) {
-		transactionCount++;
-		if (success) commitedTransactionCount++;
-	}
+    public void endTransaction(boolean success) {
+        synchronized(this) {
+            transactionCount++;
+		    if (success) commitedTransactionCount++;
+        }
+        // The end transaction message can get too verbose (output log fills up with just end tx messages)
+        //if(operationThreshold > 0) {    // show endTransaction operations if we are logging operations that exceed a threshold.
+        //    logOperation(OPERATION_ENDTRANSACTION,null, 0);
+        //}
+
+    }
 	
 	public long getSuccessfulTransactionCount() {
 		return commitedTransactionCount;

Modified: core/branches/Branch_3_2/src/org/hibernate/stat/StatisticsImplementor.java
===================================================================
--- core/branches/Branch_3_2/src/org/hibernate/stat/StatisticsImplementor.java	2007-10-19 22:27:20 UTC (rev 14126)
+++ core/branches/Branch_3_2/src/org/hibernate/stat/StatisticsImplementor.java	2007-10-20 00:06:51 UTC (rev 14127)
@@ -11,16 +11,16 @@
 	public void closeSession();
 	public void flush();
 	public void connect();
-	public void loadEntity(String entityName);
-	public void fetchEntity(String entityName);
-	public void updateEntity(String entityName);
-	public void insertEntity(String entityName);
-	public void deleteEntity(String entityName);
-	public void loadCollection(String role);
-	public void fetchCollection(String role);
-	public void updateCollection(String role);
-	public void recreateCollection(String role);
-	public void removeCollection(String role);
+	public void loadEntity(String entityName, long time);
+	public void fetchEntity(String entityName, long time);
+	public void updateEntity(String entityName, long time);
+	public void insertEntity(String entityName, long time);
+	public void deleteEntity(String entityName, long time);
+	public void loadCollection(String role, long time);
+	public void fetchCollection(String role, long time);
+	public void updateCollection(String role, long time);
+	public void recreateCollection(String role, long time);
+	public void removeCollection(String role, long time);
 	public void secondLevelCachePut(String regionName);
 	public void secondLevelCacheHit(String regionName);
 	public void secondLevelCacheMiss(String regionName);
@@ -28,7 +28,7 @@
 	public void queryCacheHit(String hql, String regionName);
 	public void queryCacheMiss(String hql, String regionName);
 	public void queryCachePut(String hql, String regionName);
-	public void endTransaction(boolean success);
+	public void endTransaction(boolean success);  // TODO:  add beginTransaction method
 	public void closeStatement();
 	public void prepareStatement();
 	public void optimisticFailure(String entityName);




More information about the hibernate-commits mailing list