
org.ow2.bonita.util.DbTool Maven / Gradle / Ivy
/**
* Copyright (C) 2007 Bull S. A. S.
* Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.ow2.bonita.util;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.ow2.bonita.env.EnvConstants;
import org.ow2.bonita.env.EnvironmentFactory;
import org.ow2.bonita.env.GlobalEnvironmentFactory;
/**
* @author Guillaume Porcher
* Helper class to initialize DB tables from the environment.
*/
public final class DbTool {
private DbTool() { }
private static SchemaExport getSchemaExport(String configurationName) {
EnvironmentFactory envFactory = GlobalEnvironmentFactory.getEnvironmentFactory();
if (envFactory == null) {
String message = ExceptionManager.getInstance().getFullMessage("bh_DBT_1");
throw new BonitaRuntimeException(message);
}
Configuration config = (Configuration) envFactory.get(configurationName);
if (config == null) {
String message = ExceptionManager.getInstance().getFullMessage(
"bh_DBT_2", configurationName);
throw new BonitaRuntimeException(message);
}
return new SchemaExport(config, config.buildSettings());
}
/**
* Export DB schema to the database defined in the environment.
*/
public static void recreateDb(String configurationName) {
SchemaExport schemaExport = getSchemaExport(configurationName);
schemaExport.create(false, true);
}
public static void dropDb(String configurationName) {
SchemaExport schemaExport = getSchemaExport(configurationName);
schemaExport.drop(false, true);
}
public static void main(String[] args) {
if (args == null || args.length < 1) {
String message = ExceptionManager.getInstance().getFullMessage(
"bh_DBT_3", EnvConstants.CORE_HB_CONF_NAME, EnvConstants.HISTORY_HB_CONF_NAME);
throw new IllegalArgumentException(message);
}
for (String conf : args) {
recreateDb(conf);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy