org.hibernate.boot.model.source.internal.hbm.AuxiliaryDatabaseObjectBinder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-core Show documentation
Show all versions of hibernate-core Show documentation
Hibernate's core ORM functionality
/*
* 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.boot.model.source.internal.hbm;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmAuxiliaryDatabaseObjectType;
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmDialectScopeType;
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
import org.hibernate.boot.model.relational.SimpleAuxiliaryDatabaseObject;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
/**
* @author Steve Ebersole
*/
public class AuxiliaryDatabaseObjectBinder {
/**
* Handling for a {@code } declaration.
*
* @param context Access to information relative to the mapping document containing this binding
* @param auxDbObjectMapping The {@code } binding
*/
public static void processAuxiliaryDatabaseObject(
HbmLocalMetadataBuildingContext context,
JaxbHbmAuxiliaryDatabaseObjectType auxDbObjectMapping) {
final AuxiliaryDatabaseObject auxDbObject;
if ( auxDbObjectMapping.getDefinition() != null ) {
final String auxDbObjectImplClass = auxDbObjectMapping.getDefinition().getClazz();
try {
auxDbObject = (AuxiliaryDatabaseObject) context.getBuildingOptions()
.getServiceRegistry()
.getService( ClassLoaderService.class )
.classForName( auxDbObjectImplClass )
.newInstance();
}
catch (ClassLoadingException cle) {
throw cle;
}
catch (Exception e) {
throw new org.hibernate.boot.MappingException(
String.format(
"Unable to instantiate custom AuxiliaryDatabaseObject class [%s]",
auxDbObjectImplClass
),
context.getOrigin()
);
}
}
else {
auxDbObject = new SimpleAuxiliaryDatabaseObject(
context.getMetadataCollector().getDatabase().getDefaultNamespace(),
auxDbObjectMapping.getCreate(),
auxDbObjectMapping.getDrop(),
null
);
}
if ( !auxDbObjectMapping.getDialectScope().isEmpty() ) {
if ( AuxiliaryDatabaseObject.Expandable.class.isInstance( auxDbObject ) ) {
final AuxiliaryDatabaseObject.Expandable expandable
= (AuxiliaryDatabaseObject.Expandable) auxDbObject;
for ( JaxbHbmDialectScopeType dialectScopeBinding : auxDbObjectMapping.getDialectScope() ) {
expandable.addDialectScope( dialectScopeBinding.getName() );
}
}
else {
// error? warn?
}
}
context.getMetadataCollector().getDatabase().addAuxiliaryDatabaseObject( auxDbObject );
}
}