Ejemplo n.º 1
0
  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;
  }
Ejemplo n.º 2
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.get(Columns.TABLE_SCHEMA));

      String comment = record.get(Columns.COLUMN_COMMENT);
      String table = record.get(Columns.TABLE_NAME);
      String column = record.get(Columns.COLUMN_NAME);
      String name = table + "_" + column;
      String columnType = record.get(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, columnDefinition.getType()) == null) {
            DefaultEnumDefinition definition = new DefaultEnumDefinition(schema, name, comment);

            CSVReader reader =
                new CSVReader(
                    new StringReader(columnType.replaceAll("(^enum\\()|(\\)$)", "")),
                    ',' // Separator
                    ,
                    '\'' // Quote character
                    ,
                    true // Strict quotes
                    );

            for (String string : reader.next()) {
              definition.addLiteral(string);
            }

            result.add(definition);
          }
        }
      }
    }

    return result;
  }