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

org.jlot.hibernate.orm.JlotImplicitNamingStrategy Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
package org.jlot.hibernate.orm;

import java.lang.reflect.Field;

import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.ImplicitBasicColumnNameSource;
import org.hibernate.boot.model.naming.ImplicitJoinColumnNameSource;
import org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl;
import org.hibernate.cfg.Ejb3Column;

public class JlotImplicitNamingStrategy extends ImplicitNamingStrategyComponentPathImpl
{
	@Override
	public Identifier determineJoinColumnName ( ImplicitJoinColumnNameSource source )
	{
		String name = source.getReferencedColumnName().toString();
		Identifier identifier = toIdentifier(name, source.getBuildingContext());
		return identifier;
	}

	@Override
	public Identifier determineBasicColumnName ( ImplicitBasicColumnNameSource source )
	{
		try
		{
			Field ejb3ColumnField = source.getClass().getDeclaredField("this$0");
			ejb3ColumnField.setAccessible(true);
			Ejb3Column ejb3Column = (Ejb3Column) ejb3ColumnField.get(source);

			// explicit naming oder implicit
			String tableName = ejb3Column.getPropertyHolder().getTable().getName();
			final Identifier basicColumnName = super.determineBasicColumnName(source);
			String columnName = tableName + "_" + basicColumnName.toString();
			return Identifier.toIdentifier(columnName);
		}
		catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e)
		{
			throw new RuntimeException(e);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy