hjg
2024-02-05 301115d5e96b56cd093eee3fcff2d60a15184162
提交 | 用户 | 时间
58d006 1 package com.mandi.common;
A 2
3 import java.util.List;
4
5 import org.hibernate.QueryException;
6 import org.hibernate.dialect.MySQLDialect;
7 import org.hibernate.dialect.function.SQLFunction;
8 import org.hibernate.dialect.function.StandardSQLFunction;
9 import org.hibernate.engine.spi.Mapping;
10 import org.hibernate.engine.spi.SessionFactoryImplementor;
11 import org.hibernate.type.StandardBasicTypes;
12 import org.hibernate.type.Type;
13
14
15 public class Custommysqldialect extends MySQLDialect{
16     protected void registerVarcharTypes(){
17         registerFunction("group_concat", new StandardSQLFunction("group_concat"));
18         registerFunction("bitand", new SQLFunction() {
19             
20             @Override
21             public String render(Type arg0, List arg1, SessionFactoryImplementor arg2)
22                     throws QueryException {
23                 if(arg1.size()>1)
24                 {
25                     return arg1.get(0).toString()+"&"+arg1.get(1).toString();
26                 }
27                 return "";
28             }
29             
30             @Override
31             public boolean hasParenthesesIfNoArguments() {
32                 return true;
33             }
34             
35             @Override
36             public boolean hasArguments() {
37                 return true;
38             }
39             
40             @Override
41             public Type getReturnType(Type arg0, Mapping arg1) throws QueryException {
42                 return StandardBasicTypes.INTEGER;
43             }
44         });
45     }
46 }