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

com.foreach.across.modules.hibernate.strategy.AbstractTableAliasNamingStrategy Maven / Gradle / Ivy

There is a newer version: 4.5.1
Show newest version
package com.foreach.across.modules.hibernate.strategy;

import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;

import java.util.HashMap;
import java.util.Map;

public abstract class AbstractTableAliasNamingStrategy extends PhysicalNamingStrategyStandardImpl
{
	private final static Map> REGISTERED_ALIAS_MAPS = new HashMap<>();

	private final Map aliasMap;

	protected AbstractTableAliasNamingStrategy() {
		aliasMap = REGISTERED_ALIAS_MAPS.get( getClass() );
	}

	@Override
	public Identifier toPhysicalTableName( Identifier name, JdbcEnvironment context ) {
		return new Identifier( alias( name.getText() ), name.isQuoted() );
	}

	private String alias( String tableName ) {
		if ( aliasMap.containsKey( tableName ) ) {
			return aliasMap.get( tableName );
		}

		return tableName;
	}

	public static void registerTableAliases( Class strategyClass, Map tableAliases ) {
		REGISTERED_ALIAS_MAPS.put( strategyClass, tableAliases );
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy