Open Source Repository

Home /hibernate/hibernate-3.2.7.ga | Repository Home



org/hibernate/dialect/MckoiDialect.java
//$Id: MckoiDialect.java 9328 2006-02-23 17:32:47Z steveebersole $
package org.hibernate.dialect;

import java.sql.Types;

import org.hibernate.Hibernate;
import org.hibernate.LockMode;
import org.hibernate.persister.entity.Lockable;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.dialect.lock.LockingStrategy;
import org.hibernate.dialect.lock.UpdateLockingStrategy;
import org.hibernate.dialect.lock.SelectLockingStrategy;
import org.hibernate.sql.CaseFragment;
import org.hibernate.sql.MckoiCaseFragment;

/**
 * An SQL dialect compatible with McKoi SQL
 @author Doug Currie, Gabe Hicks
 */
public class MckoiDialect extends Dialect {
  public MckoiDialect() {
    super();
    registerColumnTypeTypes.BIT, "bit" );
    registerColumnTypeTypes.BIGINT, "bigint" );
    registerColumnTypeTypes.SMALLINT, "smallint" );
    registerColumnTypeTypes.TINYINT, "tinyint" );
    registerColumnTypeTypes.INTEGER, "integer" );
    registerColumnTypeTypes.CHAR, "char(1)" );
    registerColumnTypeTypes.VARCHAR, "varchar($l)" );
    registerColumnTypeTypes.FLOAT, "float" );
    registerColumnTypeTypes.DOUBLE, "double" );
    registerColumnTypeTypes.DATE, "date" );
    registerColumnTypeTypes.TIME, "time" );
    registerColumnTypeTypes.TIMESTAMP, "timestamp" );
    registerColumnTypeTypes.VARBINARY, "varbinary" );
    registerColumnTypeTypes.NUMERIC, "numeric" );
    registerColumnTypeTypes.BLOB, "blob" );
    registerColumnTypeTypes.CLOB, "clob" );

    registerFunction"upper"new StandardSQLFunction("upper") );
    registerFunction"lower"new StandardSQLFunction("lower") );
    registerFunction"sqrt"new StandardSQLFunction("sqrt", Hibernate.DOUBLE) );
    registerFunction"abs"new StandardSQLFunction("abs") );
    registerFunction"sign"new StandardSQLFunction"sign", Hibernate.INTEGER ) );
    registerFunction"length"new StandardSQLFunction"length", Hibernate.INTEGER ) );
    registerFunction"round"new StandardSQLFunction"round", Hibernate.INTEGER ) );
    registerFunction"mod"new StandardSQLFunction"mod", Hibernate.INTEGER ) );
    registerFunction"least"new StandardSQLFunction("least") );
    registerFunction"greatest"new StandardSQLFunction("greatest") );
    registerFunction"user"new StandardSQLFunction"user", Hibernate.STRING ) );
    registerFunction"concat"new StandardSQLFunction"concat", Hibernate.STRING ) );

    getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH);
  }

  public String getAddColumnString() {
    return "add column";
  }

  public String getSequenceNextValString(String sequenceName) {
    return "select " + getSelectSequenceNextValStringsequenceName );
  }

  public String getSelectSequenceNextValString(String sequenceName) {
    return "nextval('" + sequenceName + "')";
  }

  public String getCreateSequenceString(String sequenceName) {
    return "create sequence " + sequenceName;
  }

  public String getDropSequenceString(String sequenceName) {
    return "drop sequence " + sequenceName;
  }

  public String getForUpdateString() {
    return "";
  }

  public boolean supportsSequences() {
    return true;
  }

  public CaseFragment createCaseFragment() {
    return new MckoiCaseFragment();
  }

  public LockingStrategy getLockingStrategy(Lockable lockable, LockMode lockMode) {
    // Mckoi has no known variation of a "SELECT ... FOR UPDATE" syntax...
    if lockMode.greaterThanLockMode.READ ) ) {
      return new UpdateLockingStrategylockable, lockMode );
    }
    else {
      return new SelectLockingStrategylockable, lockMode );
    }
  }
}