Пример #1
0
  /**
   * Create DDL Generator for specified database engine with given global and specific
   * configurations.
   *
   * @param engine Database engine.
   * @param globalConf Global configuration file.
   * @param specificConf Specific configuration file for database engine.
   * @return DDL generator for database engine.
   * @throws GeneratorException If database engine has not been specified or no generator is
   *     available for the database engine.
   */
  public static Generator createDDLGenerator(
      final String engine, final String globalConf, final String specificConf)
      throws GeneratorException {
    DDLGenConfiguration config = new DDLGenConfiguration();

    // load default global configuration
    config.addProperties(Generator.GLOBAL_CONFIG_PATH + Generator.GLOBAL_CONFIG_NAME);
    // overload with global configuration given on commandline
    if (globalConf != null) {
      config.addProperties(globalConf);
    }

    GeneratorRegistry registry = new GeneratorRegistry(config);

    String eng = config.getStringValue(DDLGenConfiguration.DEFAULT_ENGINE_KEY, "");
    if (engine != null) {
      eng = engine;
    }
    Generator gen = registry.getGenerator(eng.toLowerCase());

    // load default configuration for specific database engine
    config.addProperties(gen.getEngineConfigPath() + gen.getEngineConfigName());
    // overload with specific configuration given on commandline
    if (specificConf != null) {
      config.addProperties(specificConf);
    }

    // create key generator registry  to be used by the generator
    gen.setKeyGenRegistry(new KeyGeneratorRegistry(config));

    // initialize generator
    gen.initialize();

    return gen;
  }
 @Override
 public void initialize(Configuration config) {
   super.initialize(config);
   rand = new Random();
 }