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

grails.orm.hibernate.HibernateEntity.groovy Maven / Gradle / Ivy

There is a newer version: 2023.2.0-RC1
Show newest version
package grails.gorm.hibernate

import groovy.transform.CompileStatic

import org.grails.datastore.gorm.GormEnhancer
import org.grails.datastore.gorm.GormEntity
import org.grails.orm.hibernate.AbstractHibernateGormStaticApi

/**
 * Extends the {@link GormEntity} trait adding additional Hibernate specific methods
 *
 * @author Graeme Rocher
 * @since 6.1
 */
@CompileStatic
trait HibernateEntity extends GormEntity {

    /**
     * Finds all objects for the given string-based query
     *
     * @param sql The query
     *
     * @return The object
     */
    static List findAllWithSql(CharSequence sql) {
        currentHibernateStaticApi().findAllWithSql sql, Collections.emptyMap()
    }

    /**
     * Finds an entity for the given SQL query
     *
     * @param sql The sql query
     * @return The entity
     */
    static D findWithSql(CharSequence sql) {
        currentHibernateStaticApi().findWithSql(sql, Collections.emptyMap())
    }

    /**
     * Finds all objects for the given string-based query
     *
     * @param sql The query
     *
     * @return The object
     */
    static List findAllWithSql(CharSequence sql, Map args) {
        currentHibernateStaticApi().findAllWithSql sql, args
    }

    /**
     * Finds an entity for the given SQL query
     *
     * @param sql The sql query
     * @return The entity
     */
    static D findWithSql(CharSequence sql, Map args) {
        currentHibernateStaticApi().findWithSql(sql, args)
    }

    private static AbstractHibernateGormStaticApi currentHibernateStaticApi() {
        (AbstractHibernateGormStaticApi) GormEnhancer.findStaticApi(this)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy