|
| 1 | +package com.baeldung.liquibase.utility; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | + |
| 5 | +import liquibase.database.AbstractJdbcDatabase; |
| 6 | +import liquibase.database.Database; |
| 7 | +import liquibase.database.core.DB2Database; |
| 8 | +import liquibase.database.core.DerbyDatabase; |
| 9 | +import liquibase.database.core.FirebirdDatabase; |
| 10 | +import liquibase.database.core.H2Database; |
| 11 | +import liquibase.database.core.HsqlDatabase; |
| 12 | +import liquibase.database.core.InformixDatabase; |
| 13 | +import liquibase.database.core.MSSQLDatabase; |
| 14 | +import liquibase.database.core.MySQLDatabase; |
| 15 | +import liquibase.database.core.OracleDatabase; |
| 16 | +import liquibase.database.core.PostgresDatabase; |
| 17 | +import liquibase.database.core.SQLiteDatabase; |
| 18 | +import liquibase.database.core.SybaseASADatabase; |
| 19 | +import liquibase.database.core.SybaseDatabase; |
| 20 | +import liquibase.database.core.UnsupportedDatabase; |
| 21 | +import liquibase.datatype.LiquibaseDataType; |
| 22 | +import liquibase.datatype.core.BigIntType; |
| 23 | +import liquibase.datatype.core.BlobType; |
| 24 | +import liquibase.datatype.core.BooleanType; |
| 25 | +import liquibase.datatype.core.CharType; |
| 26 | +import liquibase.datatype.core.ClobType; |
| 27 | +import liquibase.datatype.core.CurrencyType; |
| 28 | +import liquibase.datatype.core.DateTimeType; |
| 29 | +import liquibase.datatype.core.DateType; |
| 30 | +import liquibase.datatype.core.DecimalType; |
| 31 | +import liquibase.datatype.core.DoubleType; |
| 32 | +import liquibase.datatype.core.FloatType; |
| 33 | +import liquibase.datatype.core.IntType; |
| 34 | +import liquibase.datatype.core.MediumIntType; |
| 35 | +import liquibase.datatype.core.NCharType; |
| 36 | +import liquibase.datatype.core.NVarcharType; |
| 37 | +import liquibase.datatype.core.NumberType; |
| 38 | +import liquibase.datatype.core.TimeType; |
| 39 | +import liquibase.datatype.core.TimestampType; |
| 40 | +import liquibase.datatype.core.TinyIntType; |
| 41 | +import liquibase.datatype.core.UUIDType; |
| 42 | +import liquibase.datatype.core.VarcharType; |
| 43 | + |
| 44 | +public class LiquibaseDatatypes { |
| 45 | + public static void main(String[] args) { |
| 46 | + List<LiquibaseDataType> dataTypes = getDataTypes(); |
| 47 | + List<AbstractJdbcDatabase> databases = getDatabases(); |
| 48 | + |
| 49 | + for (LiquibaseDataType dataTypeInstance : dataTypes) { |
| 50 | + try { |
| 51 | + LiquibaseDataType dataType = dataTypeInstance; |
| 52 | + dataType.finishInitialization(""); |
| 53 | + System.out.println(dataType.getName()); |
| 54 | + |
| 55 | + for (AbstractJdbcDatabase databaseInstance : databases) { |
| 56 | + try { |
| 57 | + Database database = databaseInstance; |
| 58 | + String databaseType = dataType.toDatabaseDataType(database) |
| 59 | + .toString(); |
| 60 | + System.out.println(databaseInstance.getName() + ": " + databaseType); |
| 61 | + } catch (Exception e) { |
| 62 | + System.err.println("Error initializing database class " + databaseInstance.getName() + ": " + e.getMessage()); |
| 63 | + } |
| 64 | + } |
| 65 | + System.out.println(); |
| 66 | + } catch (Exception e) { |
| 67 | + System.err.println("Error initializing data type class " + dataTypeInstance.getName() + ": " + e.getMessage()); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + private static List<LiquibaseDataType> getDataTypes() { |
| 73 | + return List.of( |
| 74 | + new BooleanType(), |
| 75 | + new TinyIntType(), |
| 76 | + new IntType(), |
| 77 | + new MediumIntType(), |
| 78 | + new BigIntType(), |
| 79 | + new FloatType(), |
| 80 | + new DoubleType(), |
| 81 | + new DecimalType(), |
| 82 | + new NumberType(), |
| 83 | + new BlobType(), |
| 84 | + new DateTimeType(), |
| 85 | + new TimeType(), |
| 86 | + new TimestampType(), |
| 87 | + new DateType(), |
| 88 | + new CharType(), |
| 89 | + new VarcharType(), |
| 90 | + new NCharType(), |
| 91 | + new NVarcharType(), |
| 92 | + new ClobType(), |
| 93 | + new CurrencyType(), |
| 94 | + new UUIDType()); |
| 95 | + } |
| 96 | + |
| 97 | + private static List<AbstractJdbcDatabase> getDatabases() { |
| 98 | + return List.of( |
| 99 | + new MySQLDatabase(), |
| 100 | + new SQLiteDatabase(), |
| 101 | + new H2Database(), |
| 102 | + new PostgresDatabase(), |
| 103 | + new DB2Database(), |
| 104 | + new MSSQLDatabase(), |
| 105 | + new OracleDatabase(), |
| 106 | + new HsqlDatabase(), |
| 107 | + new FirebirdDatabase(), |
| 108 | + new DerbyDatabase(), |
| 109 | + new InformixDatabase(), |
| 110 | + new SybaseDatabase(), |
| 111 | + new SybaseASADatabase()); |
| 112 | + } |
| 113 | +} |
| 114 | + |
0 commit comments