Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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;

Author(s):
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) {
      throw new BonitaRuntimeException("Unable to find EnvironmentFactory.");
    }
    Configuration config = (ConfigurationenvFactory.get(configurationName);
    if (config == null) {
      throw new BonitaRuntimeException("Unable to find a hibernate configuration '" 
          + configurationName + "' in the EnvironmentFactory.");
    }
    return new SchemaExport(configconfig.buildSettings());
  }
  
  
Export DB schema to the database defined in the environment.
  public static void recreateDb(String configurationName) {
    SchemaExport schemaExport = getSchemaExport(configurationName);
    schemaExport.create(falsetrue);
  }
  
  public static void dropDb(String configurationName) {
    SchemaExport schemaExport = getSchemaExport(configurationName);
    schemaExport.drop(falsetrue);
  }
  
  public static void main(String[] args) {
    if (args == null || args.length < 1) {
      String message = "\n";
      message += "This tool helps you (re)creating a database. The database is splited in two : \n";
      message += "- core database (required)\n";
      message += "- history database (optionnal)\n";
      message += "When initializing the core database,  you need to specify the two following hibernate configuration :\n";
      message += "- core configuration : " + . + "\n";
      message += "When initializing the history database,  you need to specify the two following hibernate configuration :\n";
      message += "- history configuration : " + . + "\n";
      message += "If you specify the two configurations, both core and history databases will be (re)created.\n";
      throw new IllegalArgumentException(message);
    }
    for (String conf : args) {
      recreateDb(conf);
    }
  }
New to GrepCode? Check out our FAQ X