All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.dialect.SQLServer2008DialectCustom Maven / Gradle / Ivy

The newest version!
package org.hibernate.dialect;

import java.sql.Types;

import org.hibernate.dialect.function.SQLFunctionTemplate;
import org.hibernate.type.StandardBasicTypes;

/**
 * 
  public static void appendListeners(SessionFactory sessionFactory, PostInsertEventListener... postInsertEventListeners) {
    if (SessionFactoryImpl.class.isInstance(sessionFactory)) {
      getEventListenerRegistry((SessionFactoryImpl) sessionFactory).appendListeners(EventType.POST_INSERT, postInsertEventListeners);
    }
  }

  public static void appendListeners(SessionFactory sessionFactory, PostLoadEventListener... postLoadEventListeners) {
    if (SessionFactoryImpl.class.isInstance(sessionFactory)) {
      getEventListenerRegistry((SessionFactoryImpl) sessionFactory).appendListeners(EventType.POST_LOAD, postLoadEventListeners);
    }
  }

  public static void appendListeners(SessionFactory sessionFactory, PostUpdateEventListener... postUpdateEventListeners) {
    if (SessionFactoryImpl.class.isInstance(sessionFactory)) {
      getEventListenerRegistry((SessionFactoryImpl) sessionFactory).appendListeners(EventType.POST_UPDATE, postUpdateEventListeners);
    }
  }

  public static void appendListeners(SessionFactory sessionFactory, PostDeleteEventListener... postDeleteEventListeners) {
    if (SessionFactoryImpl.class.isInstance(sessionFactory)) {
      getEventListenerRegistry((SessionFactoryImpl) sessionFactory).appendListeners(EventType.POST_DELETE, postDeleteEventListeners);
    }
  }

  private static EventListenerRegistry getEventListenerRegistry(SessionFactoryImpl sessionFactoryImpl) {
    return sessionFactoryImpl.getServiceRegistry().getService(EventListenerRegistry.class);
  }
 *  SQL SERVER 2008 기준 varchar > nvarchar 변경
 * 
 * @see org.hibernate.dialect.function.StandardSQLFunction
 */
public class SQLServer2008DialectCustom extends SQLServer2008Dialect {
  private static final int NVARCHAR_MAX_LENGTH = 4000;

  public SQLServer2008DialectCustom() {
    super();
    registerColumnType(Types.NCLOB, "nvarchar(MAX)");
    registerColumnType(Types.CLOB, "nvarchar(MAX)");
    registerColumnType(Types.LONGVARCHAR, "nvarchar(MAX)");
    registerColumnType(Types.VARCHAR, "nvarchar(MAX)");
    registerColumnType(Types.VARCHAR, NVARCHAR_MAX_LENGTH, "nvarchar($l)");

    registerHibernateType(Types.NCHAR, StandardBasicTypes.CHARACTER.getName());
    registerHibernateType(Types.NCHAR, 1, StandardBasicTypes.CHARACTER.getName());
    registerHibernateType(Types.NCHAR, 255, StandardBasicTypes.STRING.getName());
    registerHibernateType(Types.NVARCHAR, StandardBasicTypes.STRING.getName());
    registerHibernateType(Types.LONGNVARCHAR, StandardBasicTypes.STRING.getName());
    // registerHibernateType(Types.LONGNVARCHAR, StandardBasicTypes.TEXT.getName());
    // registerHibernateType(Types.NCLOB, StandardBasicTypes.CLOB.getName());

    // registerFunction("", new SQLFunctionTemplate(IntegerType.INSTANCE, "(?1 & ?2)"));
    registerFunction("STR", new SQLFunctionTemplate(StandardBasicTypes.STRING, "CAST(?1 AS nvarchar(MAX))"));
    registerFunction("CONTAINS", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "CONTAINS(?1, ?2) AND 1"));
    registerFunction("BITOR", new SQLFunctionTemplate(StandardBasicTypes.LONG, "(?1 | ?2)"));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy