Git Product home page Git Product logo

common-db's Introduction

common-db

数据库、SQL查询一些方法的提取.

使用方式

下载本项目,gradle clean build得到的jar包引入工程即可。本项目依赖于utils

version:1.8.0

1.直接导入

compile 'top.jfunc.common:common-db:${version}'

2.其中的 Pagination和PageConverter是针对spring和hibernate环境的,不需要的话可以排除

compile ('top.jfunc.common:common-db:${version}'){ exclude group:'org.springframework.data' exclude group:'org.hibernate' }

1.QueryHelper

一个巨好用的SQL拼写器,让你从SQL拼写的泥沼中解脱出来,不用管空格,顺序,参数处理。还支持方法连缀。

2.SQLFormatter

可以对SQL语句进行美化。

4.QueryWithFilter

查询表数据,复杂的过滤在Java应用层做,SQL中只写很容易过滤的条件,基于一个事实:数据库过滤复杂条件效率不高。方法接受一个RecordFilter,实现对Record的过滤。

@FunctionalInterface
public interface Filter<T> extends Predicate<T>{
    /**
     * 看一条记录是否满足条件
     * @param record 一条记录
     * @return 是否满足
     */
    @Override
    boolean test(T record);
    /**
     * 过滤记录
     * @param records 源记录,同时也是过滤后的
     * @return 满足条件的记录条数
     */
    default List<T> filter(List<T> records){
        Objects.requireNonNull(records);
        return records.parallelStream().filter(this::test).collect(Collectors.toList());

        /*Iterator<Record> iterator = records.iterator();
        while (iterator.hasNext()) {
            Record record = iterator.next();
            boolean acc = test(record);
            if(!acc){
                //不满足的删除
                iterator.remove();
            }
        }*/
    }
}

4.Pagination

处理JPA环境下的复杂SQL查询,配合QueryHelper有着奇妙的化学反应

common-db's People

Contributors

xiongshiyan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.