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

org.hibernate.cache.ehcache.management.impl.CacheRegionUtils Maven / Gradle / Ivy

Go to download

Integration for using Ehcache 2.x as a Hibernate second-level-cache provider

There is a newer version: 6.0.0.Alpha7
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.cache.ehcache.management.impl;

/**
 * CacheRegionUtils
 *
 * @author gkeim
 */
@SuppressWarnings("UnusedDeclaration")
public abstract class CacheRegionUtils {
	/**
	 * Determine a short name from the full name
	 *
	 * @param fullName The full name
	 *
	 * @return The short name
	 */
	public static String determineShortName(String fullName) {
		String result = fullName;

		if ( fullName != null ) {
			final String[] comps = fullName.split( "\\." );
			if ( comps.length == 1 ) {
				return fullName;
			}
			boolean truncate = true;
			for ( int i = 0; i < comps.length; i++ ) {
				final String comp = comps[i];
				final char c = comp.charAt( 0 );
				if ( truncate && Character.isUpperCase( c ) ) {
					truncate = false;
				}
				if ( truncate ) {
					comps[i] = Character.toString( c );
				}
			}
			result = join( comps, '.' );
		}

		return result;
	}

	/**
	 * Same as Hibernate internal {@link org.hibernate.internal.util.StringHelper#join} methods
	 *
	 * @param elements The things to join
	 * @param c The separator between elements
	 *
	 * @return The joined string
	 */
	private static String join(String[] elements, char c) {
		if ( elements == null ) {
			return null;
		}
		final StringBuilder sb = new StringBuilder();
		for ( String s : elements ) {
			sb.append( s ).append( c );
		}
		return sb.length() > 0 ? sb.substring( 0, sb.length() - 1 ) : "";
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy