All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.stat.internal.CollectionStatisticsImpl Maven / Gradle / Ivy

There is a newer version: 7.0.0.Alpha1
Show newest version
/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or .
 */
package org.hibernate.stat.internal;

import java.io.Serializable;
import java.util.concurrent.atomic.LongAdder;

import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.stat.CollectionStatistics;

/**
 * Collection related statistics
 *
 * @author Alex Snaps
 */
public class CollectionStatisticsImpl extends AbstractCacheableDataStatistics implements CollectionStatistics, Serializable {

	private final String collectionRole;
	private final LongAdder loadCount = new LongAdder();
	private final LongAdder fetchCount = new LongAdder();
	private final LongAdder updateCount = new LongAdder();
	private final LongAdder removeCount = new LongAdder();
	private final LongAdder recreateCount = new LongAdder();

	CollectionStatisticsImpl(CollectionPersister persister) {
		super(
				() -> persister.getCacheAccessStrategy() != null
						? persister.getCacheAccessStrategy().getRegion()
						: null
		);

		this.collectionRole = persister.getRole();
	}

	public long getLoadCount() {
		return loadCount.sum();
	}

	public long getFetchCount() {
		return fetchCount.sum();
	}

	public long getRecreateCount() {
		return recreateCount.sum();
	}

	public long getRemoveCount() {
		return removeCount.sum();
	}

	public long getUpdateCount() {
		return updateCount.sum();
	}

	void incrementLoadCount() {
		loadCount.increment();
	}

	void incrementFetchCount() {
		fetchCount.increment();
	}

	void incrementUpdateCount() {
		updateCount.increment();
	}

	void incrementRecreateCount() {
		recreateCount.increment();
	}

	void incrementRemoveCount() {
		removeCount.increment();
	}

	public String toString() {
		final StringBuilder buffer = new StringBuilder()
				.append( "CollectionStatistics" )
				.append( "[collectionRole=" ).append( collectionRole )
				.append( ",loadCount=" ).append( this.loadCount )
				.append( ",fetchCount=" ).append( this.fetchCount )
				.append( ",recreateCount=" ).append( this.recreateCount )
				.append( ",removeCount=" ).append( this.removeCount )
				.append( ",updateCount=" ).append( this.updateCount );
		appendCacheStats( buffer );
		return buffer.append(']').toString();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy