Exemple #1
0
  @Override
  protected List<EnumDefinition> getEnums0() throws SQLException {
    List<EnumDefinition> result = new ArrayList<EnumDefinition>();

    Result<Record5<String, String, String, String, String>> records =
        create()
            .select(
                Columns.TABLE_SCHEMA,
                Columns.COLUMN_COMMENT,
                Columns.TABLE_NAME,
                Columns.COLUMN_NAME,
                Columns.COLUMN_TYPE)
            .from(COLUMNS)
            .where(
                Columns.COLUMN_TYPE
                    .like("enum(%)")
                    .and(Columns.TABLE_SCHEMA.in(getInputSchemata())))
            .orderBy(
                Columns.TABLE_SCHEMA.asc(), Columns.TABLE_NAME.asc(), Columns.COLUMN_NAME.asc())
            .fetch();

    for (Record record : records) {
      SchemaDefinition schema = getSchema(record.getValue(Columns.TABLE_SCHEMA));

      String comment = record.getValue(Columns.COLUMN_COMMENT);
      String table = record.getValue(Columns.TABLE_NAME);
      String column = record.getValue(Columns.COLUMN_NAME);
      String name = table + "_" + column;
      String columnType = record.getValue(Columns.COLUMN_TYPE);

      // [#1237] Don't generate enum classes for columns in MySQL tables
      // that are excluded from code generation
      TableDefinition tableDefinition = getTable(schema, table);
      if (tableDefinition != null) {
        ColumnDefinition columnDefinition = tableDefinition.getColumn(column);

        if (columnDefinition != null) {

          // [#1137] Avoid generating enum classes for enum types that
          // are explicitly forced to another type
          if (getConfiguredForcedType(columnDefinition) == null) {
            DefaultEnumDefinition definition = new DefaultEnumDefinition(schema, name, comment);
            for (String string : columnType.replaceAll("enum\\(|\\)", "").split(",")) {
              definition.addLiteral(string.trim().replaceAll("'", ""));
            }

            result.add(definition);
          }
        }
      }
    }

    return result;
  }
  private final List<EnumDefinition> getConfiguredEnums() {
    List<EnumDefinition> result = new ArrayList<EnumDefinition>();

    for (EnumType enumType : configuredEnumTypes) {
      String name = enumType.getName();
      DefaultEnumDefinition e = new DefaultEnumDefinition(getSchemata().get(0), name, null, true);

      String literals = enumType.getLiterals();

      try {
        @SuppressWarnings("resource")
        CSVReader reader = new CSVReader(new StringReader(literals));
        e.addLiterals(reader.readNext());
      } catch (IOException ignore) {
      }

      result.add(e);
    }

    return result;
  }