コード例 #1
0
ファイル: DataDiff.java プロジェクト: digoal/metl
  protected void createDatabase() {
    if (databasePlatform == null) {
      ResettableBasicDataSource ds = new ResettableBasicDataSource();
      ds.setDriverClassName(Driver.class.getName());
      ds.setMaxActive(1);
      ds.setInitialSize(1);
      ds.setMinIdle(1);
      ds.setMaxIdle(1);
      databaseName = UUID.randomUUID().toString();
      if (inMemoryCompare) {
        ds.setUrl("jdbc:h2:mem:" + databaseName);
      } else {
        ds.setUrl("jdbc:h2:file:./" + databaseName);
      }
      databasePlatform =
          JdbcDatabasePlatformFactory.createNewPlatformInstance(
              ds, new SqlTemplateSettings(), true, false);

      Model inputModel = context.getFlowStep().getComponent().getInputModel();
      List<ModelEntity> entities = inputModel.getModelEntities();
      for (ModelEntity entity : entities) {
        Table table = new Table();
        table.setName(entity.getName() + "_1");
        List<ModelAttribute> attributes = entity.getModelAttributes();
        for (ModelAttribute attribute : attributes) {
          DataType dataType = attribute.getDataType();
          Column column = new Column(attribute.getName());
          if (dataType.isNumeric()) {
            column.setTypeCode(Types.DECIMAL);
          } else if (dataType.isBoolean()) {
            column.setTypeCode(Types.BOOLEAN);
          } else if (dataType.isTimestamp()) {
            column.setTypeCode(Types.TIMESTAMP);
          } else if (dataType.isBinary()) {
            column.setTypeCode(Types.BLOB);
          } else {
            column.setTypeCode(Types.LONGVARCHAR);
          }

          column.setPrimaryKey(attribute.isPk());
          table.addColumn(column);
        }
        alterCaseToMatchLogicalCase(table);
        databasePlatform.createTables(false, false, table);

        table.setName(entity.getName().toUpperCase() + "_2");
        databasePlatform.createTables(false, false, table);
      }

      log(LogLevel.INFO, "Creating databasePlatform with the following url: %s", ds.getUrl());
    }
  }