/*
 * Copyright (C) 2016 LibreCCM Foundation.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 */
package com.arsdigita.toolbox.ui;

import org.libreccm.cdi.utils.CdiUtil;

import javax.persistence.criteria.CriteriaQuery;

/**
 *
 * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
 * @param <T> Type of entity retrieved by the query.
 */
public abstract class AbstractDataQueryBuilder<T> implements DataQueryBuilder<T> {

    /**
     * Retrieves the {@link DataTableController} can creates a new
     * {@code CriteriaQuery} using
     * {@link DataTableController#createQuery(java.lang.Class)}.
     *
     * @param entityClass
     *
     * @return A new {@link CriteriaQuery} which can be further customised.
     */
    protected CriteriaQuery<T> createBaseQuery(final Class<T> entityClass) {
        final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
        final DataTableController controller = cdiUtil.findBean(
            DataTableController.class);

        return controller.createQuery(entityClass);
    }

}
