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

com.github.aqiu202.starters.jpa.sql.HqlQuery Maven / Gradle / Ivy

There is a newer version: 1.2.1
Show newest version
package com.github.aqiu202.starters.jpa.sql;

import javax.persistence.EntityManager;
import javax.persistence.Query;

public final class HqlQuery extends AbstractQuery {

    private HqlQuery(EntityManager entityManager) {
        super(entityManager);
    }

    public static  HqlQuery of(EntityManager entityManager) {
        return new HqlQuery<>(entityManager);
    }

    @Override
    public Query createQuery(String hql) {
        return this.entityManager.createQuery(hql);
    }

    @Override
    protected String getCountSql(String sql) {
        int i = sql.toLowerCase().indexOf("from");
        if (i == -1) {
            return null;
        }
        StringBuilder sb = new StringBuilder(sql);
        return "select count(*) " + sb.substring(i);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy