Example usage for org.hibernate.dialect.function SQLFunctionTemplate SQLFunctionTemplate

List of usage examples for org.hibernate.dialect.function SQLFunctionTemplate SQLFunctionTemplate

Introduction

In this page you can find the example usage for org.hibernate.dialect.function SQLFunctionTemplate SQLFunctionTemplate.

Prototype

public SQLFunctionTemplate(Type type, String template) 

Source Link

Document

Constructs a SQLFunctionTemplate

Usage

From source file:com.agroservices.hibernate.Dialect.java

public Dialect() {
    super();/* w ww . j  ava 2s.c  o m*/
    registerFunction("date_add_interval",
            new SQLFunctionTemplate(StandardBasicTypes.DATE, "DATE_ADD(?1, INTERVAL ?2 ?3)"));
    registerFunction("date_diff", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "DATEDIFF(?1, ?2)"));
    registerFunction("cast_new", new SQLFunctionTemplate(StandardBasicTypes.FLOAT, "CAST(?1 as DECIMAL)"));
}

From source file:com.allinfinance.hibernate.dialect.OracleDialect.java

License:Open Source License

public OracleDialect() {
    super();/*from   w  w  w  .  j  a va  2 s .  c  o  m*/
    registerColumnType(Types.BIT, "number(1,0)");
    registerColumnType(Types.BIGINT, "number(19,0)");
    registerColumnType(Types.SMALLINT, "number(5,0)");
    registerColumnType(Types.TINYINT, "number(3,0)");
    registerColumnType(Types.INTEGER, "number(10,0)");
    registerColumnType(Types.CHAR, "char(1 char)");
    registerColumnType(Types.VARCHAR, 4000, "varchar2($l char)");
    registerColumnType(Types.VARCHAR, "long");
    registerColumnType(Types.FLOAT, "float");
    registerColumnType(Types.DOUBLE, "double precision");
    registerColumnType(Types.DATE, "date");
    registerColumnType(Types.TIME, "date");
    registerColumnType(Types.TIMESTAMP, "timestamp");
    registerColumnType(Types.VARBINARY, 2000, "raw($l)");
    registerColumnType(Types.VARBINARY, "long raw");
    registerColumnType(Types.NUMERIC, "number($p,$s)");
    registerColumnType(Types.BLOB, "blob");
    registerColumnType(Types.CLOB, "clob");
    /** shen_antonio. */
    registerHibernateType(Types.CHAR, Hibernate.STRING.getName());

    getDefaultProperties().setProperty(Environment.USE_STREAMS_FOR_BINARY, "true");
    getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE);

    registerFunction("abs", new StandardSQLFunction("abs"));
    registerFunction("sign", new StandardSQLFunction("sign", Hibernate.INTEGER));

    registerFunction("acos", new StandardSQLFunction("acos", Hibernate.DOUBLE));
    registerFunction("asin", new StandardSQLFunction("asin", Hibernate.DOUBLE));
    registerFunction("atan", new StandardSQLFunction("atan", Hibernate.DOUBLE));
    registerFunction("cos", new StandardSQLFunction("cos", Hibernate.DOUBLE));
    registerFunction("cosh", new StandardSQLFunction("cosh", Hibernate.DOUBLE));
    registerFunction("exp", new StandardSQLFunction("exp", Hibernate.DOUBLE));
    registerFunction("ln", new StandardSQLFunction("ln", Hibernate.DOUBLE));
    registerFunction("sin", new StandardSQLFunction("sin", Hibernate.DOUBLE));
    registerFunction("sinh", new StandardSQLFunction("sinh", Hibernate.DOUBLE));
    registerFunction("stddev", new StandardSQLFunction("stddev", Hibernate.DOUBLE));
    registerFunction("sqrt", new StandardSQLFunction("sqrt", Hibernate.DOUBLE));
    registerFunction("tan", new StandardSQLFunction("tan", Hibernate.DOUBLE));
    registerFunction("tanh", new StandardSQLFunction("tanh", Hibernate.DOUBLE));
    registerFunction("variance", new StandardSQLFunction("variance", Hibernate.DOUBLE));

    registerFunction("round", new StandardSQLFunction("round"));
    registerFunction("trunc", new StandardSQLFunction("trunc"));
    registerFunction("ceil", new StandardSQLFunction("ceil"));
    registerFunction("floor", new StandardSQLFunction("floor"));

    /** shen_antoni. */
    registerFunction("chr", new StandardSQLFunction("chr", Hibernate.CHARACTER));
    registerFunction("initcap", new StandardSQLFunction("initcap"));
    registerFunction("lower", new StandardSQLFunction("lower"));
    registerFunction("ltrim", new StandardSQLFunction("ltrim"));
    registerFunction("rtrim", new StandardSQLFunction("rtrim"));
    registerFunction("soundex", new StandardSQLFunction("soundex"));
    registerFunction("upper", new StandardSQLFunction("upper"));
    registerFunction("ascii", new StandardSQLFunction("ascii", Hibernate.INTEGER));
    registerFunction("length", new StandardSQLFunction("length", Hibernate.LONG));

    registerFunction("to_char", new StandardSQLFunction("to_char", Hibernate.STRING));
    registerFunction("to_date", new StandardSQLFunction("to_date", Hibernate.TIMESTAMP));

    registerFunction("current_date", new NoArgSQLFunction("current_date", Hibernate.DATE, false));
    registerFunction("current_time", new NoArgSQLFunction("current_timestamp", Hibernate.TIME, false));
    registerFunction("current_timestamp",
            new NoArgSQLFunction("current_timestamp", Hibernate.TIMESTAMP, false));

    registerFunction("lastday", new StandardSQLFunction("lastday", Hibernate.DATE));
    registerFunction("sysdate", new NoArgSQLFunction("sysdate", Hibernate.DATE, false));
    registerFunction("systimestamp", new NoArgSQLFunction("systimestamp", Hibernate.TIMESTAMP, false));
    registerFunction("uid", new NoArgSQLFunction("uid", Hibernate.INTEGER, false));
    registerFunction("user", new NoArgSQLFunction("user", Hibernate.STRING, false));

    registerFunction("rowid", new NoArgSQLFunction("rowid", Hibernate.LONG, false));
    registerFunction("rownum", new NoArgSQLFunction("rownum", Hibernate.LONG, false));

    // Multi-param string dialect functions...
    registerFunction("concat", new VarArgsSQLFunction(Hibernate.STRING, "", "||", ""));
    registerFunction("instr", new StandardSQLFunction("instr", Hibernate.INTEGER));
    registerFunction("instrb", new StandardSQLFunction("instrb", Hibernate.INTEGER));
    registerFunction("lpad", new StandardSQLFunction("lpad", Hibernate.STRING));
    registerFunction("replace", new StandardSQLFunction("replace", Hibernate.STRING));
    registerFunction("rpad", new StandardSQLFunction("rpad", Hibernate.STRING));
    registerFunction("substr", new StandardSQLFunction("substr", Hibernate.STRING));
    registerFunction("substrb", new StandardSQLFunction("substrb", Hibernate.STRING));
    registerFunction("translate", new StandardSQLFunction("translate", Hibernate.STRING));

    registerFunction("substring", new StandardSQLFunction("substr", Hibernate.STRING));
    registerFunction("locate", new StandardSQLFunction("instr", Hibernate.INTEGER));
    registerFunction("bit_length", new SQLFunctionTemplate(Hibernate.INTEGER, "vsize(?1)*8"));
    registerFunction("coalesce", new NvlFunction());

    // Multi-param numeric dialect functions...
    registerFunction("atan2", new StandardSQLFunction("atan2", Hibernate.FLOAT));
    registerFunction("log", new StandardSQLFunction("log", Hibernate.INTEGER));
    registerFunction("mod", new StandardSQLFunction("mod", Hibernate.INTEGER));
    registerFunction("nvl", new StandardSQLFunction("nvl"));
    registerFunction("nvl2", new StandardSQLFunction("nvl2"));
    registerFunction("power", new StandardSQLFunction("power", Hibernate.FLOAT));

    // Multi-param date dialect functions...
    registerFunction("add_months", new StandardSQLFunction("add_months", Hibernate.DATE));
    registerFunction("months_between", new StandardSQLFunction("months_between", Hibernate.FLOAT));
    registerFunction("next_day", new StandardSQLFunction("next_day", Hibernate.DATE));

    registerFunction("str", new StandardSQLFunction("to_char", Hibernate.STRING));
}

From source file:com.enigmabridge.hibernate.dialect.SQLiteDialect.java

License:unlicense.org

public SQLiteDialect() {
    registerColumnType(Types.BIT, "boolean");
    registerColumnType(Types.TINYINT, "tinyint");
    registerColumnType(Types.SMALLINT, "smallint");
    registerColumnType(Types.INTEGER, "integer");
    registerColumnType(Types.BIGINT, "bigint");
    registerColumnType(Types.FLOAT, "float");
    registerColumnType(Types.REAL, "real");
    registerColumnType(Types.DOUBLE, "double");
    registerColumnType(Types.NUMERIC, "numeric($p, $s)");
    registerColumnType(Types.DECIMAL, "decimal");
    registerColumnType(Types.CHAR, "char");
    registerColumnType(Types.VARCHAR, "varchar($l)");
    registerColumnType(Types.LONGVARCHAR, "longvarchar");
    registerColumnType(Types.DATE, "date");
    registerColumnType(Types.TIME, "time");
    registerColumnType(Types.TIMESTAMP, "datetime");
    registerColumnType(Types.BINARY, "blob");
    registerColumnType(Types.VARBINARY, "blob");
    registerColumnType(Types.LONGVARBINARY, "blob");
    registerColumnType(Types.BLOB, "blob");
    registerColumnType(Types.CLOB, "clob");
    registerColumnType(Types.BOOLEAN, "boolean");

    registerFunction("concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "", "||", ""));
    registerFunction("mod", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "?1 % ?2"));
    registerFunction("quote", new StandardSQLFunction("quote", StandardBasicTypes.STRING));
    registerFunction("random", new NoArgSQLFunction("random", StandardBasicTypes.INTEGER));
    registerFunction("round", new StandardSQLFunction("round"));
    registerFunction("substr", new StandardSQLFunction("substr", StandardBasicTypes.STRING));
    registerFunction("trim", new AbstractAnsiTrimEmulationFunction() {
        protected SQLFunction resolveBothSpaceTrimFunction() {
            return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1)");
        }/* w  w w  .  j  ava2  s  .  co  m*/

        protected SQLFunction resolveBothSpaceTrimFromFunction() {
            return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?2)");
        }

        protected SQLFunction resolveLeadingSpaceTrimFunction() {
            return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1)");
        }

        protected SQLFunction resolveTrailingSpaceTrimFunction() {
            return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1)");
        }

        protected SQLFunction resolveBothTrimFunction() {
            return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1, ?2)");
        }

        protected SQLFunction resolveLeadingTrimFunction() {
            return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1, ?2)");
        }

        protected SQLFunction resolveTrailingTrimFunction() {
            return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1, ?2)");
        }
    });
    uniqueDelegate = new SQLiteUniqueDelegate(this);
}

From source file:com.gramercysoftware.hibernate.SQLiteDialect.java

License:Open Source License

public SQLiteDialect() {
    registerColumnType(Types.BIT, "integer");
    registerColumnType(Types.TINYINT, "tinyint");
    registerColumnType(Types.SMALLINT, "smallint");
    registerColumnType(Types.INTEGER, "integer");
    registerColumnType(Types.BIGINT, "bigint");
    registerColumnType(Types.FLOAT, "float");
    registerColumnType(Types.REAL, "real");
    registerColumnType(Types.DOUBLE, "double");
    registerColumnType(Types.NUMERIC, "numeric");
    registerColumnType(Types.DECIMAL, "decimal");
    registerColumnType(Types.CHAR, "char");
    registerColumnType(Types.VARCHAR, "varchar");
    registerColumnType(Types.LONGVARCHAR, "longvarchar");
    registerColumnType(Types.DATE, "date");
    registerColumnType(Types.TIME, "time");
    registerColumnType(Types.TIMESTAMP, "timestamp");
    registerColumnType(Types.BINARY, "blob");
    registerColumnType(Types.VARBINARY, "blob");
    registerColumnType(Types.LONGVARBINARY, "blob");
    registerColumnType(Types.NULL, "null");
    registerColumnType(Types.BLOB, "blob");
    registerColumnType(Types.CLOB, "clob");
    registerColumnType(Types.BOOLEAN, "integer");

    registerFunction("concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "", "||", ""));
    registerFunction("mod", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "?1 % ?2"));
    registerFunction("substr", new StandardSQLFunction("substr", StandardBasicTypes.STRING));
    registerFunction("substring", new StandardSQLFunction("substr", StandardBasicTypes.STRING));
}

From source file:com.jada.jpa.connection.CustomMySQLDialect.java

License:Open Source License

public CustomMySQLDialect() {
    super();/*from w  ww . j a v a  2  s.  c  o  m*/
    registerFunction("date_add_interval",
            new SQLFunctionTemplate(Hibernate.DATE, "date_add(?1, INTERVAL ?2 ?3)"));
    registerFunction("to_date", new SQLFunctionTemplate(Hibernate.DATE, "str_to_date(?1, ?2)"));
}

From source file:com.manager.config.SQLiteDialect.java

public SQLiteDialect() {
    registerColumnType(Types.BIT, "integer");
    registerColumnType(Types.TINYINT, "tinyint");
    registerColumnType(Types.SMALLINT, "smallint");
    registerColumnType(Types.INTEGER, "integer");
    registerColumnType(Types.BIGINT, "bigint");
    registerColumnType(Types.FLOAT, "float");
    registerColumnType(Types.REAL, "real");
    registerColumnType(Types.DOUBLE, "double");
    registerColumnType(Types.NUMERIC, "numeric");
    registerColumnType(Types.DECIMAL, "decimal");
    registerColumnType(Types.CHAR, "char");
    registerColumnType(Types.VARCHAR, "varchar");
    registerColumnType(Types.LONGVARCHAR, "longvarchar");
    registerColumnType(Types.DATE, "date");
    registerColumnType(Types.TIME, "time");
    registerColumnType(Types.TIMESTAMP, "timestamp");
    registerColumnType(Types.BINARY, "blob");
    registerColumnType(Types.VARBINARY, "blob");
    registerColumnType(Types.LONGVARBINARY, "blob");
    // registerColumnType(Types.NULL, "null");
    registerColumnType(Types.BLOB, "blob");
    registerColumnType(Types.CLOB, "clob");
    registerColumnType(Types.BOOLEAN, "integer");

    registerFunction("concat", new VarArgsSQLFunction(StringType.INSTANCE, "", "||", ""));
    registerFunction("mod", new SQLFunctionTemplate(StringType.INSTANCE, "?1 % ?2"));
    registerFunction("substr", new StandardSQLFunction("substr", StringType.INSTANCE));
    registerFunction("substring", new StandardSQLFunction("substr", StringType.INSTANCE));
}

From source file:com.marvinformatics.hibernate.json.PostgreSQL93Dialect.java

License:Apache License

public PostgreSQL93Dialect() {
    super();/* w  w w.  j  a va 2 s .c o  m*/
    registerColumnType(Types.JAVA_OBJECT, "json");

    registerFunction("json_text", new SQLFunctionTemplate(StringType.INSTANCE, "?1 ->> ?2"));
}

From source file:com.mysema.query.jpa.support.ExtendedHSQLDialect.java

License:Apache License

public ExtendedHSQLDialect() {
    registerFunction("trim", new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(both from ?1)"));
}

From source file:com.mysema.query.jpa.support.TeradataDialect.java

License:Open Source License

/**
 * Constructor//  w  w w .  j  a v  a 2  s  . c  o m
 */
public TeradataDialect() {
    super();
    // registerColumnType data types
    registerColumnType(Types.NUMERIC, "NUMERIC($p,$s)");
    registerColumnType(Types.DOUBLE, "DOUBLE PRECISION");
    registerColumnType(Types.BIGINT, "NUMERIC(18,0)");
    registerColumnType(Types.BIT, "BYTEINT");
    registerColumnType(Types.TINYINT, "BYTEINT");
    registerColumnType(Types.VARBINARY, "VARBYTE($l)");
    registerColumnType(Types.BINARY, "BYTEINT");
    registerColumnType(Types.LONGVARCHAR, "LONG VARCHAR");
    registerColumnType(Types.CHAR, "CHAR(1)");
    registerColumnType(Types.DECIMAL, "DECIMAL");
    registerColumnType(Types.INTEGER, "INTEGER");
    registerColumnType(Types.SMALLINT, "SMALLINT");
    registerColumnType(Types.FLOAT, "FLOAT");
    registerColumnType(Types.VARCHAR, "VARCHAR($l)");
    registerColumnType(Types.DATE, "DATE");
    registerColumnType(Types.TIME, "TIME");
    registerColumnType(Types.TIMESTAMP, "TIMESTAMP");
    registerColumnType(Types.BOOLEAN, "BYTEINT"); // hibernate seems to
                                                  // ignore this type...
    registerColumnType(Types.BLOB, "BLOB");
    registerColumnType(Types.CLOB, "CLOB");

    registerFunction("year", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "extract(year from ?1)"));
    registerFunction("length", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "character_length(?1)"));
    registerFunction("concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "(", "||", ")"));
    registerFunction("substring",
            new SQLFunctionTemplate(StandardBasicTypes.STRING, "substring(?1 from ?2 for ?3)"));
    registerFunction("locate", new SQLFunctionTemplate(StandardBasicTypes.STRING, "position(?1 in ?2)"));
    registerFunction("mod", new SQLFunctionTemplate(StandardBasicTypes.STRING, "?1 mod ?2"));
    registerFunction("str", new SQLFunctionTemplate(StandardBasicTypes.STRING, "cast(?1 as varchar(255))"));

    // bit_length feels a bit broken to me. We have to cast to char in order
    // to
    // pass when a numeric value is supplied. But of course the answers
    // given will
    // be wildly different for these two datatypes. 1234.5678 will be 9
    // bytes as
    // a char string but will be 8 or 16 bytes as a true numeric.
    // Jay Nance 2006-09-22
    registerFunction("bit_length",
            new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "octet_length(cast(?1 as char))*4"));

    // The preference here would be
    // SQLFunctionTemplate( Hibernate.TIMESTAMP, "current_timestamp(?1)",
    // false)
    // but this appears not to work.
    // Jay Nance 2006-09-22
    registerFunction("current_timestamp",
            new SQLFunctionTemplate(StandardBasicTypes.TIMESTAMP, "current_timestamp"));
    registerFunction("current_time", new SQLFunctionTemplate(StandardBasicTypes.TIME, "current_time"));
    registerFunction("current_date", new SQLFunctionTemplate(StandardBasicTypes.DATE, "current_date"));
    // IBID for current_time and current_date

    registerKeyword("account");
    registerKeyword("alias");
    registerKeyword("class");
    registerKeyword("column");
    registerKeyword("first");
    registerKeyword("map");
    registerKeyword("month");
    registerKeyword("password");
    registerKeyword("role");
    registerKeyword("summary");
    registerKeyword("title");
    registerKeyword("type");
    registerKeyword("value");
    registerKeyword("year");

    // Tell hibernate to use getBytes instead of getBinaryStream
    getDefaultProperties().setProperty(Environment.USE_STREAMS_FOR_BINARY, "false");
    // No batch statements
    getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH);
}

From source file:com.querydsl.jpa.support.DialectSupport.java

License:Apache License

public static SQLFunction createFunction(SQLTemplates templates, Operator operator) {
    Template template = templates.getTemplate(operator);
    Type type = HibernateUtil.getType(operator.getType());
    return new SQLFunctionTemplate(type, convert(template));
}