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

com.arch.util.CachedUtils Maven / Gradle / Ivy

There is a newer version: 18.12.0
Show newest version
package com.arch.util;

import org.hibernate.jpa.QueryHints;

import javax.persistence.Cacheable;
import javax.persistence.TypedQuery;

public final class CachedUtils {

    private CachedUtils() {

    }

    public static  TypedQuery createQueryCache(Class clazz, TypedQuery query) {
        if (!cached(clazz)) {
            return query;
        }

        return query.setHint(QueryHints.HINT_CACHEABLE, true);
    }

    public static  TypedQuery forceCache(TypedQuery query) {
        return query.setHint(QueryHints.HINT_CACHEABLE, true);
    }


    public static boolean cached(Class clazz) {
        Cacheable cacheable = clazz.getAnnotation(Cacheable.class);
        return cacheable != null && cacheable.value();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy