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

play.db.helper.JpaHelper Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
package play.db.helper;

import java.util.List;
import javax.persistence.Query;
import play.db.jpa.JPA;

public class JpaHelper {

    private JpaHelper() {
    }

    public static Query execute(String sql, Object ... params) {
        Query query = JPA.em().createQuery(sql);
        int index = 0;
        for (Object param : params) {
            query.setParameter(++index, param);
        }
        return query;
    }

    public static Query executeList(String sql, List params) {
        Query query = JPA.em().createQuery(sql);
        int index = 0;
        for (Object param : params) {
            query.setParameter(++index, param);
        }
        return query;
    }

    public static Query execute(SqlQuery query) {
        return executeList(query.toString(), query.getParams());
    }

}