/**
* This file is part of Faktotum.
*
*
* Faktotum 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 3 of
* the License, or (at your option) any later version.
*
* Faktotum 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 Faktotum.
*
* If not, see <http://www.gnu.org/licenses/>.
*/
package de.romankreisel.faktotum.dao;
import java.util.logging.Level;
import javax.ejb.Stateless;
import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import de.romankreisel.faktotum.datamodel.SettingEntity;
import de.romankreisel.faktotum.datamodel.SettingEntity_;
/**
* The Data Access Object for the SettingEntity
*
* @author Roman Kreisel <mail@romankreisel.de>
*/
@SuppressWarnings("rawtypes")
@Stateless
public class SettingDao extends JpaDao<SettingEntity> {
/**
* Returns the setting from the DB or null if not found.
*
* @param identifier
* @return
*/
public SettingEntity getSetting(String identifier) {
CriteriaBuilder criteriaBuilder = this.getCriteriaBuilder();
CriteriaQuery<SettingEntity> criteriaQuery = criteriaBuilder.createQuery(SettingEntity.class);
Root<SettingEntity> entityRoot = criteriaQuery.from(SettingEntity.class);
criteriaQuery.where(criteriaBuilder.equal(entityRoot.get(SettingEntity_.identifier), identifier));
TypedQuery<SettingEntity> typedQuery = this.createQuery(criteriaQuery);
try {
SettingEntity searchResult = typedQuery.getSingleResult();
return searchResult;
} catch (NoResultException e) {
this.getLogger().log(Level.FINE, "Setting " + identifier + " not in DB", e);
}
return null;
}
}