org.hibernate.testing.schema.SchemaDropHelper Maven / Gradle / Ivy
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.testing.schema;
import java.sql.Connection;
import java.util.Map;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.schema.Action;
import org.hibernate.tool.schema.spi.DelayedDropRegistryNotAvailableImpl;
import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator;
/**
* @author Steve Ebersole
*/
public class SchemaDropHelper {
public static void drop(Metadata metadata) {
drop(
metadata,
( (MetadataImplementor) metadata ).getMetadataBuildingOptions().getServiceRegistry()
);
}
public static void drop(Metadata metadata, ServiceRegistry serviceRegistry) {
final Map settings = serviceRegistry.getService( ConfigurationService.class ).getSettings();
settings.put( AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION, Action.DROP );
SchemaManagementToolCoordinator.process(
metadata,
serviceRegistry,
settings,
DelayedDropRegistryNotAvailableImpl.INSTANCE
);
}
public static void drop(
MetadataImplementor metadata,
StandardServiceRegistry serviceRegistry,
Connection connection) {
final Map settings = serviceRegistry.getService( ConfigurationService.class ).getSettings();
settings.put( AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION, Action.DROP );
settings.put( AvailableSettings.JAKARTA_HBM2DDL_CONNECTION, connection );
SchemaManagementToolCoordinator.process(
metadata,
serviceRegistry,
settings,
DelayedDropRegistryNotAvailableImpl.INSTANCE
);
}
}