GithubHelp home page GithubHelp logo

everwar2017 / mosheh Goto Github PK

View Code? Open in Web Editor NEW

This project forked from geektcp/mosheh

0.0 0.0 0.0 451 KB

common libray for Java

Home Page: http://mosheh.okfar.cn

License: Apache License 2.0

Java 100.00%

mosheh's Introduction

mosheh

Actions Status Security Score Maven Central OpenSSF Best Practices Java Doc

describe

mosheh is a common library for Java, which release in maven repository:
https://mvnrepository.com/artifact/com.geektcp.common/mosheh

this is a tiny project. we can use it to develop big project.

Furthermore, mosheh offers a convenient API for build many cache, collection, executor.

maven dependency

<!-- https://mvnrepository.com/artifact/com.geektcp.common/mosheh -->
<dependency>
    <groupId>com.geektcp.common</groupId>
    <artifactId>mosheh</artifactId>
    <version>1.0.3</version>
</dependency>

example

package xxx;

/**
 * @author Geektcp 2021/9/23 14:30
 */
@Slf4j
@Service
public class RoomInfoServerImpl extends JpaBase implements RoomInfoServer {

    private LoadingCache<Object, List<RoomInfoVo>> tinyCache = CacheBuilder.newBuilder()
            .refreshAfterWrite(7, TimeUnit.SECONDS)
            .expireAfterWrite(5, TimeUnit.SECONDS)
            .build(new TinyLoader<Object, List<RoomInfoVo>>() {
                @Override
                public List<RoomInfoVo> load(Object key) {
                    return null;
                }
            });

    public List<RoomInfoVo> queryRoomInfo(RoomInfoQo qo) {
        log.info("qo: {}", JSON.toJSONString(qo));
        
        // get result from tiny cache
        List<RoomInfoVo> cacheResult =  roomCache.get(qo);
        if(Objects.nonNull(cacheResult)){
            return cacheResult;
        }

        // here is your code, for example: select mysql with JPA or Mybatis
        String title = qo.getTitle();
        String id = qo.getId();
        String author = qo.getAuthor();

        QRoomInfoPo qRoomInfoPo = QRoomInfoPo.roomInfoPo;
        JPQLQuery<RoomInfoPo> jpqlQuery = jpa.select(qRoomInfoPo).from(qRoomInfoPo);
        if(StringUtils.isNotEmpty(title)){
            jpqlQuery.where(qRoomInfoPo.title.like(JQL.likeWrap(title)));
        }
        if(StringUtils.isNotEmpty(id)){
            jpqlQuery.where(qRoomInfoPo.id.eq(id));
        }
        if(StringUtils.isNotEmpty(author)){
            jpqlQuery.where(qRoomInfoPo.author.like(JQL.likeWrap(author)));
        }
        List<RoomInfoPo> poList = jpqlQuery.orderBy(qRoomInfoPo.updateBy.asc()).fetch();

        if (CollectionUtils.isEmpty(poList)) {
            return null;
        }
        List<RoomInfoVo> voList = poList.stream().map((RoomInfoPo po) -> {
            RoomInfoVo vo = new RoomInfoVo();
            BeanMapper.map(po, vo);
            return vo;
        }).collect(Collectors.toList());

        // add result to tiny cache
        roomCache.put(qo, voList);
        
        return voList;
    }

}

mosheh's People

Contributors

geektcp avatar snyk-bot 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.