Example usage for org.hibernate.dialect Dialect supportsUnique

List of usage examples for org.hibernate.dialect Dialect supportsUnique

Introduction

In this page you can find the example usage for org.hibernate.dialect Dialect supportsUnique.

Prototype

@Deprecated
public boolean supportsUnique() 

Source Link

Document

Does this dialect support the UNIQUE column syntax?

Usage

From source file:corner.migration.services.impl.fragment.AbstractMigrateFragment.java

License:Apache License

/**
 * ?SQL//  ww w  . j  a  va 2 s . c om
 * @param col 
 * @return SQL 
 * @see Table#sqlCreateString(Dialect, Mapping, String, String)
 */
protected String getSQLType(Column col) {
    //      boolean identityColumn = idValue != null && idValue.isIdentityColumn( dialect );
    boolean identityColumn = false;
    StringBuffer buf = new StringBuffer();
    Dialect dialect = getDialect();
    Mapping p = this.getSessionFactory();
    buf.append(col.getQuotedName(dialect)).append(' ');

    String pkname = "id";
    if (identityColumn && col.getQuotedName(dialect).equals(pkname)) {
        // to support dialects that have their own identity data type
        if (dialect.hasDataTypeInIdentityColumn()) {
            buf.append(col.getSqlType(dialect, p));
        }
        buf.append(' ').append(dialect.getIdentityColumnString(col.getSqlTypeCode(p)));
    } else {

        buf.append(col.getSqlType(dialect, p));

        String defaultValue = col.getDefaultValue();
        if (defaultValue != null) {
            buf.append(" default ").append(defaultValue);
        }

        if (col.isNullable()) {
            buf.append(dialect.getNullColumnString());
        } else {
            buf.append(" not null");
        }

    }

    boolean useUniqueConstraint = col.isUnique() && (!col.isNullable() || dialect.supportsNotNullUnique());
    if (useUniqueConstraint) {
        if (dialect.supportsUnique()) {
            buf.append(" unique");
        } else {
            //               UniqueKey uk = getOrCreateUniqueKey( col.getQuotedName( dialect ) + '_' );
            //               uk.addColumn( col );
        }
    }

    if (col.hasCheckConstraint() && dialect.supportsColumnCheck()) {
        buf.append(" check (").append(col.getCheckConstraint()).append(")");
    }

    String columnComment = col.getComment();
    if (columnComment != null) {
        buf.append(dialect.getColumnComment(columnComment));
    }
    return buf.toString();
}