3 * Copyright (C) 2009-2019 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.platform.db.migration.charset;
22 import java.sql.ResultSet;
23 import java.sql.SQLException;
24 import java.util.Locale;
25 import javax.annotation.concurrent.Immutable;
26 import org.sonar.db.version.SqTables;
29 * Result of standard SQL command "select * from INFORMATION_SCHEMA" (columns listed in {@link #SELECT_COLUMNS}).
32 public class ColumnDef {
34 public static final String SELECT_COLUMNS = "select table_name, column_name, character_set_name, collation_name, data_type, character_maximum_length, is_nullable ";
36 private final String table;
37 private final String column;
38 private final String charset;
39 private final String collation;
40 private final String dataType;
41 private final long size;
42 private final boolean nullable;
44 public ColumnDef(String table, String column, String charset, String collation, String dataType, long size, boolean nullable) {
47 this.charset = charset;
48 this.collation = collation;
49 this.dataType = dataType;
51 this.nullable = nullable;
54 public String getTable() {
58 public String getColumn() {
62 public String getCharset() {
66 public String getCollation() {
70 public String getDataType() {
74 public long getSize() {
78 public boolean isNullable() {
82 public boolean isInSonarQubeTable() {
83 String tableName = table.toLowerCase(Locale.ENGLISH);
84 return SqTables.TABLES.contains(tableName) || SqTables.OLD_DROPPED_TABLES.contains(tableName);
87 public enum ColumnDefRowConverter implements SqlExecutor.RowConverter<ColumnDef> {
91 public ColumnDef convert(ResultSet rs) throws SQLException {
92 String nullableText = rs.getString(7);
93 boolean nullable = "YES".equalsIgnoreCase(nullableText);
96 rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getLong(6), nullable);