コード例 #1
0
  private static void updateCommand(String[] args) {
    String unitName, filename = null, url, username, password;
    if (args.length < 5)
      System.out.println("Expected unitName jdbcUrl jdbcUsername jdbcPassword [filename]");
    else {
      unitName = args[1];
      url = args[2];
      username = args[3];
      password = args[4];
      if (args.length > 5) filename = args[5];

      Configuration configuration = HibernateDDL.getConfiguration(unitName);
      configuration.buildMappings();
      AuditConfiguration.getFor(configuration);
      Dialect dialect = Dialect.getDialect(configuration.getProperties());

      Connection conn = null;
      DatabaseMetadata meta = null;
      try {
        conn = DriverManager.getConnection(url, username, password);
        meta = new DatabaseMetadata(conn, dialect, configuration, true);

        List<SchemaUpdateScript> updateScriptList =
            configuration.generateSchemaUpdateScriptList(dialect, meta);
        String[] updateSQL = SchemaUpdateScript.toStringArray(updateScriptList);

        HibernateDDL.stringToStream(updateSQL, filename);

      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }
コード例 #2
0
  private static void createDropCommand(String[] args) {
    if (args.length < 3) {
      System.out.println("Expected unitName and filename");
    } else {
      String unitName = args[1];
      String filename = args[2];

      EnversSchemaGenerator esg =
          new EnversSchemaGenerator(HibernateDDL.getConfiguration(unitName));
      org.hibernate.tool.hbm2ddl.SchemaExport se = esg.export();
      se.setOutputFile(filename);
      se.setFormat(true);
      se.setDelimiter(";");
      se.execute(false, false, false, false);
    }
  }