⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hxttdialect.java

📁 hibernate连接access数据库,以及一些其他的hibernate介绍
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package com.hxtt.support.hibernate;

import org.hibernate.Hibernate;
import org.hibernate.dialect.Dialect;
//@author Gavin King, David Channon steve.ebersole@jboss.com
//http://viewvc.jboss.org/cgi-bin/viewvc.cgi/hibernate/core/trunk/core/src/main/java/org/hibernate/dialect/
//http://viewvc.jboss.org/cgi-bin/viewvc.cgi/hibernate/core/trunk/core/src/main/java/org/hibernate/dialect/Dialect.java?view=markup
import org.hibernate.dialect.function.VarArgsSQLFunction;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.function.NoArgSQLFunction;
import org.hibernate.dialect.function.StandardSQLFunction;

/**
 * An common SQL  dialect for HXTT JDBC drivers.
 * Written according to Jboss' dialect samples.
 */
public abstract class HxttDialect extends Dialect {
    
    static final String DEFAULT_BATCH_SIZE = "15";
    static final String NO_BATCH = "0";
    
    
    public HxttDialect() {
        super();
        //Mathematical Functions
        registerFunction("abs", new StandardSQLFunction("abs") );
        registerFunction("ceiling", new StandardSQLFunction("ceiling", Hibernate.INTEGER) );
        registerFunction("ceil", new StandardSQLFunction("ceil", Hibernate.INTEGER) );		registerFunction("sign", new StandardSQLFunction("sign", Hibernate.INTEGER) );
        registerFunction("degrees", new StandardSQLFunction("degrees", Hibernate.DOUBLE) );
        registerFunction("exp", new StandardSQLFunction("exp", Hibernate.DOUBLE) );
        registerFunction("floor", new StandardSQLFunction("floor", Hibernate.INTEGER) );
        registerFunction("int", new StandardSQLFunction("int", Hibernate.INTEGER) );
        registerFunction("log", new StandardSQLFunction("log", Hibernate.DOUBLE) );
        registerFunction("log10", new StandardSQLFunction("log10", Hibernate.DOUBLE) );
        registerFunction("log2", new StandardSQLFunction("log2", Hibernate.DOUBLE) );
        registerFunction("ln", new StandardSQLFunction("ln", Hibernate.DOUBLE) );
        registerFunction("mod", new StandardSQLFunction("mod", Hibernate.INTEGER) );
        registerFunction("pi", new NoArgSQLFunction("pi", Hibernate.DOUBLE) );
        registerFunction("pow", new StandardSQLFunction("pow", Hibernate.DOUBLE) );
        registerFunction("power", new StandardSQLFunction("power", Hibernate.DOUBLE) );
        registerFunction("padians", new StandardSQLFunction("padians", Hibernate.DOUBLE) );
        registerFunction("radians", new StandardSQLFunction("radians", Hibernate.DOUBLE) );
        registerFunction("rand", new NoArgSQLFunction("rand", Hibernate.DOUBLE) );
        registerFunction("round", new StandardSQLFunction("round", Hibernate.INTEGER) );
        registerFunction("sign", new StandardSQLFunction("sign", Hibernate.INTEGER) );
        registerFunction("sqrt", new StandardSQLFunction("sqrt", Hibernate.DOUBLE) );
        registerFunction("trunc", new StandardSQLFunction("trunc", Hibernate.DOUBLE) );
        registerFunction("truncate", new StandardSQLFunction("truncate", Hibernate.DOUBLE) );
        //Trigonometric Functions
        registerFunction("acos", new StandardSQLFunction("acos", Hibernate.DOUBLE) );
        registerFunction("asin", new StandardSQLFunction("asin", Hibernate.DOUBLE) );
        registerFunction("atan", new StandardSQLFunction("atan", Hibernate.DOUBLE) );
        registerFunction("atan2", new StandardSQLFunction("atan2", Hibernate.DOUBLE) );
        registerFunction("cos", new StandardSQLFunction("cos", Hibernate.DOUBLE) );
        registerFunction("cot", new StandardSQLFunction("cot", Hibernate.DOUBLE) );
        registerFunction("crc32", new StandardSQLFunction("crc32", Hibernate.LONG) );
        registerFunction("sin", new StandardSQLFunction("sin", Hibernate.DOUBLE) );
        registerFunction("tan", new StandardSQLFunction("tan", Hibernate.DOUBLE) );
        
//String Functions
        registerFunction("alltrim", new StandardSQLFunction("alltrim") );
        registerFunction("asc", new StandardSQLFunction("asc", Hibernate.INTEGER) );
        registerFunction("ascii", new StandardSQLFunction("ascii", Hibernate.INTEGER) );
        registerFunction("at", new StandardSQLFunction("at", Hibernate.INTEGER) );
        registerFunction("bin", new StandardSQLFunction("bin", Hibernate.STRING) );
        registerFunction("bit_length", new StandardSQLFunction("bit_length", Hibernate.LONG) );
        registerFunction("char_length", new StandardSQLFunction("char_length", Hibernate.LONG) );
        registerFunction("character_length", new StandardSQLFunction("character_length", Hibernate.LONG) );
        registerFunction("char", new StandardSQLFunction("char", Hibernate.STRING) );
        registerFunction("chr", new StandardSQLFunction("char", Hibernate.STRING) );
        registerFunction("chrtran", new StandardSQLFunction("chrtran", Hibernate.STRING) );
        registerFunction( "concat", new VarArgsSQLFunction(Hibernate.STRING, "", "||", "") );
        registerFunction( "concat_ws", new VarArgsSQLFunction(Hibernate.STRING, "", "||", "") );
        registerFunction( "conv", new StandardSQLFunction("conv", Hibernate.STRING) );
        registerFunction( "difference", new StandardSQLFunction("difference", Hibernate.STRING) );
        registerFunction("hex", new StandardSQLFunction("hex", Hibernate.STRING) );
        registerFunction("initcap", new StandardSQLFunction("initcap") );
//	registerFunction("insert", new StandardSQLFunction("insert") );
        registerFunction("instr", new StandardSQLFunction("instr", Hibernate.INTEGER) );
        registerFunction("lcase", new StandardSQLFunction("lcase") );
        registerFunction("left", new StandardSQLFunction("left", Hibernate.INTEGER) );
        registerFunction("len", new StandardSQLFunction("len", Hibernate.LONG) );
        registerFunction("length", new StandardSQLFunction("length", Hibernate.LONG) );
        registerFunction("locate", new StandardSQLFunction("locate", Hibernate.LONG) );
        registerFunction("lower", new StandardSQLFunction("lower") );
        registerFunction("lpad", new StandardSQLFunction("lpad", Hibernate.STRING) );
        registerFunction("ltrim", new StandardSQLFunction("ltrim") );
        registerFunction("mid", new StandardSQLFunction("mid", Hibernate.STRING) );
        registerFunction("oct", new StandardSQLFunction("oct", Hibernate.STRING) );
        registerFunction("octet_length", new StandardSQLFunction("octet_length", Hibernate.LONG) );
        registerFunction("padc", new StandardSQLFunction("padc", Hibernate.STRING) );
        registerFunction("padl", new StandardSQLFunction("padl", Hibernate.STRING) );
        registerFunction("padr", new StandardSQLFunction("padr", Hibernate.STRING) );
        registerFunction("position", new StandardSQLFunction("position", Hibernate.INTEGER) );
        registerFunction("proper", new StandardSQLFunction("proper") )	;
        registerFunction("repeat", new StandardSQLFunction("repeat", Hibernate.STRING) );
        registerFunction("replicate", new StandardSQLFunction("replicate", Hibernate.STRING) );
        registerFunction("replace", new StandardSQLFunction("replace", Hibernate.STRING) );
        registerFunction("right", new StandardSQLFunction("right", Hibernate.INTEGER) );
        registerFunction("rpad", new StandardSQLFunction("rpad", Hibernate.STRING) );
        registerFunction("rtrim", new StandardSQLFunction("rtrim") );
        registerFunction("soundex", new StandardSQLFunction("soundex") );
        registerFunction("space", new StandardSQLFunction("space", Hibernate.STRING) );
        registerFunction( "strcat", new VarArgsSQLFunction(Hibernate.STRING, "", "||", "") );
        registerFunction("strcmp", new StandardSQLFunction("strcmp", Hibernate.INTEGER) );
        registerFunction("strconv", new StandardSQLFunction("strconv", Hibernate.STRING) );
        registerFunction("strtran", new StandardSQLFunction("strtran", Hibernate.STRING) );
        registerFunction("stuff", new StandardSQLFunction("stuff", Hibernate.STRING) );
        registerFunction("substr", new StandardSQLFunction("stuff", Hibernate.STRING) );
        registerFunction("substring", new StandardSQLFunction("substring", Hibernate.STRING) );
        registerFunction("translate", new StandardSQLFunction("translate", Hibernate.STRING) );
        registerFunction("trim", new StandardSQLFunction("trim") );
        registerFunction("ucase", new StandardSQLFunction("ucase") );
        registerFunction("upper", new StandardSQLFunction("upper") );
        registerFunction("charmirr", new StandardSQLFunction("charmirr") );
        registerFunction("reverse", new StandardSQLFunction("reverse") );
        
        //Date/Time Functions
        registerFunction("addtime",new StandardSQLFunction("addtime",Hibernate.TIMESTAMP));
        registerFunction("cdow",new StandardSQLFunction("cdow",Hibernate.STRING));
        registerFunction("cmonth",new StandardSQLFunction("cmonth",Hibernate.STRING));
        registerFunction("curdate", new NoArgSQLFunction("curdate", Hibernate.DATE) );
        registerFunction("curtime", new NoArgSQLFunction("curtime", Hibernate.TIME) );
        registerFunction("date", new StandardSQLFunction("date", Hibernate.DATE) );
        registerFunction("datediff", new StandardSQLFunction("datediff", Hibernate.INTEGER) );
        registerFunction("datetime",new  NoArgSQLFunction("datetime",Hibernate.TIMESTAMP));
        registerFunction("date_add",new  StandardSQLFunction("date_add",Hibernate.DATE));
        registerFunction("date_sub",new  StandardSQLFunction("date_sub",Hibernate.DATE));
        registerFunction("adddate",new  StandardSQLFunction("adddate",Hibernate.DATE));
        registerFunction("subdate",new  StandardSQLFunction("subdate",Hibernate.DATE));
        registerFunction("day", new StandardSQLFunction("day", Hibernate.INTEGER) );
        registerFunction("dayofmonth", new StandardSQLFunction("dayofmonth", Hibernate.INTEGER) );
        registerFunction("dayname", new StandardSQLFunction("dayname", Hibernate.STRING) );
        registerFunction("dayofweek", new StandardSQLFunction("dayofweek", Hibernate.INTEGER) );
        registerFunction("dayofyear", new StandardSQLFunction("dayofyear", Hibernate.INTEGER) );
        registerFunction("extract",new  StandardSQLFunction("extract",Hibernate.INTEGER));
        registerFunction("dow",new StandardSQLFunction("dow",Hibernate.STRING));
        registerFunction("from_days", new StandardSQLFunction("from_days", Hibernate.DATE) );
        registerFunction("gomonth", new StandardSQLFunction("gomonth", Hibernate.DATE) );
        registerFunction("hour", new StandardSQLFunction("hour", Hibernate.INTEGER) );
        registerFunction("last_day", new StandardSQLFunction("last_day", Hibernate.DATE) );
        registerFunction("minute",new  StandardSQLFunction("minute",Hibernate.INTEGER));
        registerFunction("millisecond",new  StandardSQLFunction("millisecond",Hibernate.INTEGER));
        registerFunction("microsecond",new  StandardSQLFunction("microsecond",Hibernate.INTEGER));
        registerFunction("month",new  StandardSQLFunction("month",Hibernate.INTEGER));
        registerFunction("monthname",new StandardSQLFunction("monthname",Hibernate.STRING));
        registerFunction("now", new NoArgSQLFunction("now", Hibernate.TIMESTAMP) );
        registerFunction("quarter", new StandardSQLFunction("quarter", Hibernate.INTEGER) );
        registerFunction("second", new StandardSQLFunction("second", Hibernate.INTEGER) );
        registerFunction("sub_time", new NoArgSQLFunction("sub_time", Hibernate.TIMESTAMP) );
        registerFunction("sysdate", new NoArgSQLFunction("sysdate", Hibernate.TIMESTAMP) );
        registerFunction("time", new StandardSQLFunction("time", Hibernate.TIME) );
        registerFunction("timediff", new StandardSQLFunction("timediff", Hibernate.TIME) );
        registerFunction("timestamp", new StandardSQLFunction("timestamp", Hibernate.TIMESTAMP) );
        registerFunction("timestampadd", new StandardSQLFunction("timestampadd", Hibernate.TIMESTAMP) );
        registerFunction("timestampdiff", new StandardSQLFunction("timestampdiff", Hibernate.INTEGER) );
        registerFunction("to_days", new StandardSQLFunction("to_days", Hibernate.INTEGER) );
        registerFunction("week", new StandardSQLFunction("week", Hibernate.INTEGER) );
        registerFunction("weekofyear", new StandardSQLFunction("weekofyear", Hibernate.INTEGER) );
        registerFunction("year", new StandardSQLFunction("year", Hibernate.INTEGER) );
        //boolean functions
        registerFunction("empty", new StandardSQLFunction("empty", Hibernate.BOOLEAN) );
        registerFunction("isblank", new StandardSQLFunction("isblank", Hibernate.BOOLEAN) );
        registerFunction("isalpha", new StandardSQLFunction("isalpha", Hibernate.BOOLEAN) );
        registerFunction("isdigit", new StandardSQLFunction("isdigit", Hibernate.BOOLEAN) );
        registerFunction("isnull", new StandardSQLFunction("isnull", Hibernate.BOOLEAN) );
        //Conversion Functions
        registerFunction("cbool", new StandardSQLFunction("cbool", Hibernate.BOOLEAN) );
        registerFunction("cbyte", new StandardSQLFunction("cbyte", Hibernate.BYTE) );
        registerFunction("cdate", new StandardSQLFunction("cdate", Hibernate.DATE) );
        registerFunction("cdbl", new StandardSQLFunction("cdbl", Hibernate.DOUBLE) );
        registerFunction("cint", new StandardSQLFunction("cint", Hibernate.INTEGER) );
        registerFunction("clng", new StandardSQLFunction("clng", Hibernate.LONG) );
        registerFunction("csng", new StandardSQLFunction("csng", Hibernate.FLOAT) );
        registerFunction("cstr", new StandardSQLFunction("cstr", Hibernate.STRING) );
        registerFunction("ctod", new StandardSQLFunction("ctod", Hibernate.DATE) );
        registerFunction("ctot", new StandardSQLFunction("ctot", Hibernate.TIMESTAMP) );
        registerFunction("dtoc", new StandardSQLFunction("dtoc", Hibernate.STRING) );
        registerFunction("dtot", new StandardSQLFunction("dtot", Hibernate.TIMESTAMP) );
        registerFunction("ttoc", new StandardSQLFunction("ttoc", Hibernate.STRING) );
        registerFunction("ttod", new StandardSQLFunction("ttod", Hibernate.DATE) );
        //Security Functions
        registerFunction("compress", new StandardSQLFunction("compress", Hibernate.STRING) );
        registerFunction("uncompress", new StandardSQLFunction("uncompress", Hibernate.STRING) );
        registerFunction("encrypt", new StandardSQLFunction("encrypt", Hibernate.STRING) );
        registerFunction("decrypt", new StandardSQLFunction("decrypt", Hibernate.STRING) );
        registerFunction("encode", new StandardSQLFunction("encode", Hibernate.STRING) );
        registerFunction("decode", new StandardSQLFunction("decode", Hibernate.STRING) );
        registerFunction("md5", new StandardSQLFunction("md5", Hibernate.STRING) );
        registerFunction("crypt3", new StandardSQLFunction("crypt3", Hibernate.STRING) );
        //System Functions
        registerFunction( "database", new NoArgSQLFunction("database", Hibernate.STRING, false) );
        registerFunction( "user", new NoArgSQLFunction("user", Hibernate.STRING, false) );
        registerFunction( "deleted", new NoArgSQLFunction("deleted", Hibernate.BOOLEAN, false) );
        registerFunction( "reccount", new NoArgSQLFunction("reccount", Hibernate.LONG, false) );
        registerFunction( "recno", new NoArgSQLFunction("recno", Hibernate.LONG, false) );
        registerFunction( "rowlocked", new NoArgSQLFunction("rowlocked", Hibernate.BOOLEAN, false) );
        //Miscellaneous Functions
        registerFunction( "nvl", new StandardSQLFunction("nvl") );
        registerFunction( "ifnull", new StandardSQLFunction("ifnull") );
        
        
        getDefaultProperties().setProperty(Environment.MAX_FETCH_DEPTH, "2");
        getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE);
    }
    
    // SEQUENCE support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    /**
     * Does this dialect support sequences?
     *
     * @return True if sequences supported; false otherwise.
     */
    public final boolean supportsSequences() {
        return true;//false;
    }
    
    /**
     * Does this dialect support "pooled" sequences.  Not aware of a better
     * name for this.  Essentially can we specify the initial and increment values?
     *
     * @return True if such "pooled" sequences are supported; false otherwise.
     * @see #getCreateSequenceStrings(String, int, int)
     * @see #getCreateSequenceString(String, int, int)
     */
    public boolean supportsPooledSequences() {
        return true;//false;
    }
    
    /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -