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

📄 bitandfunction.java

📁 spring+acegi编写的网上书城
💻 JAVA
字号:
package net.livebookstore.hibernate;

import java.util.List;

import org.hibernate.*;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.engine.*;
import org.hibernate.type.Type;

/**
 * If don't have this 'bitand' function, Hibernate will report 
 * exception: unexpected char: '&' when using "a & b" SQL operation.
 * 
 * @author Xuefeng
 */
public class BitAndFunction implements SQLFunction {

    public Type getReturnType(Type type, Mapping mapping) {
        return Hibernate.INTEGER;
    }

    public boolean hasArguments() {
        return true;
    }

    public boolean hasParenthesesIfNoArguments() {
        return true;
    }

    public String render(List args, SessionFactoryImplementor factory) throws QueryException {
        if (args.size() != 2) {
            throw new IllegalArgumentException("BitAndFunction requires 2 arguments!"); 
        }
        return args.get(0).toString() + " & " + args.get(1).toString();
    }

}

⌨️ 快捷键说明

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