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