/**
   * Creates the platform for the configured database.
   *
   * @return The platform
   */
  public Platform getPlatform() throws BuildException {
    Platform platform = null;

    if (_databaseType == null) {
      if (_dataSource == null) {
        throw new BuildException("No database specified.");
      }
      if (_databaseType == null) {
        _databaseType =
            new PlatformUtils()
                .determineDatabaseType(_dataSource.getDriverClassName(), _dataSource.getUrl());
      }
      if (_databaseType == null) {
        _databaseType = new PlatformUtils().determineDatabaseType(_dataSource);
      }
    }
    try {
      platform = PlatformFactory.createNewPlatformInstance(_databaseType);
    } catch (Exception ex) {
      throw new BuildException("Database type " + _databaseType + " is not supported.", ex);
    }
    if (platform == null) {
      throw new BuildException("Database type " + _databaseType + " is not supported.");
    }
    platform.setDataSource(_dataSource);
    platform.setDelimitedIdentifierModeOn(isUseDelimitedSqlIdentifiers());
    platform.setForeignKeysSorted(isSortForeignKeys());

    return platform;
  }
  public void contextInitialized(ServletContextEvent event) {
    springContext = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
    dataSource = (DataSource) springContext.getBean("dataSource");

    Platform platform = PlatformFactory.createNewPlatformInstance(dataSource);

    Database database =
        new DatabaseIO().read(new InputStreamReader(getClass().getResourceAsStream("/ddl.xml")));

    platform.alterTables(database, false);
  }
예제 #3
0
파일: DB.java 프로젝트: slavianp/webscrap
  void ddlUtilsExport() throws Exception {
    Platform platform = PlatformFactory.createNewPlatformInstance(ds);
    Connection conn = ds.getConnection();
    Database db = platform.readModelFromDatabase(conn, "MyDbTest");
    DatabaseIO dbio = new DatabaseIO();

    StringPrintStream out;

    out = new StringPrintStream();
    Writer wr = new OutputStreamWriter(out, "UTF-8");
    dbio.write(db, wr);
    wr.flush();
    String exportDDL = out.toString();
    System.out.println(exportDDL);
    /*		out = new StringPrintStream();
    		DatabaseDataIO dataIO = new DatabaseDataIO();
    		dataIO.writeDataToXML(platform, db, out, "utf-8");
    		String exportDML = out.toString();
    */
    conn.close();
  }