Search in sources :

Example 1 with JaxbHbmDialectScopeType

use of org.hibernate.boot.jaxb.hbm.spi.JaxbHbmDialectScopeType in project hibernate-orm by hibernate.

the class AuxiliaryDatabaseObjectBinder method processAuxiliaryDatabaseObject.

/**
	 * Handling for a {@code <database-object/>} declaration.
	 *
	 * @param context Access to information relative to the mapping document containing this binding
	 * @param auxDbObjectMapping The {@code <database-object/>} 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);
}
Also used : JaxbHbmDialectScopeType(org.hibernate.boot.jaxb.hbm.spi.JaxbHbmDialectScopeType) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) SimpleAuxiliaryDatabaseObject(org.hibernate.boot.model.relational.SimpleAuxiliaryDatabaseObject) AuxiliaryDatabaseObject(org.hibernate.boot.model.relational.AuxiliaryDatabaseObject) SimpleAuxiliaryDatabaseObject(org.hibernate.boot.model.relational.SimpleAuxiliaryDatabaseObject) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException)

Aggregations

JaxbHbmDialectScopeType (org.hibernate.boot.jaxb.hbm.spi.JaxbHbmDialectScopeType)1 AuxiliaryDatabaseObject (org.hibernate.boot.model.relational.AuxiliaryDatabaseObject)1 SimpleAuxiliaryDatabaseObject (org.hibernate.boot.model.relational.SimpleAuxiliaryDatabaseObject)1 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)1