package com.atlassian.stash.internal.hibernate.dialect;

import org.hibernate.dialect.SQLServer2005Dialect;

import java.sql.Types;

/**
 * Overrides the types for {@code CHAR}, {@code CLOB}, {@code LONGVARCHAR} and {@code VARCHAR} to use Unicode-ready
 * SQL types.
 *
 * @since 2.1
 */
public class CustomSqlServer2005Dialect extends SQLServer2005Dialect {

    public CustomSqlServer2005Dialect() {
        registerColumnType(Types.CHAR, "nchar($l)");
        //Note: SQL Server Management Studio for SQL Server 2005 reports the column types as nvarchar(MAX), which is
        //      what the Liquibase MSSQLTypeConverter creates them as. However, Microsoft's SQL Server JDBC driver
        //      reports the columns as ntext for 2005 (where it correctly reports them as nvarchar(MAX) for 2008 and
        //      2012). This dialect reflects what Microsoft's driver returns, and may not work with jTDS
        registerColumnType(Types.CLOB, "ntext");
        registerColumnType(Types.LONGVARCHAR, "ntext");
        registerColumnType(Types.VARCHAR, "ntext");
        registerColumnType(Types.VARCHAR, 4000, "nvarchar($l)");
    }
}
