All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.doudou.common.tool.datebase.jpa.JpaInterceptor Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
package top.doudou.common.tool.datebase.jpa;

import org.hibernate.proxy.map.MapProxyFactory;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.stereotype.Component;

/**
 * @author 傻男人<[email protected]>
 * @description  jpa拦截器(格式化sql)
 * @date 2020-07-27
 */
@Component
@ConditionalOnClass(MapProxyFactory.class)
public class JpaInterceptor implements StatementInspector {

    @Override
    public String inspect(String sql) {
        System.out.println("==>  sql sentence          " + replace(sql));
        return sql;
    }

    private String replace(String sql){
        sql = sql.replaceAll("as [\\w]+", "");
        sql = sql.replaceAll("[\\w]+\\d_","");
        sql = sql.replaceAll(", ", ",").replaceAll(" ,", ",");
        return sql.replaceAll("\\.","");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy