/*
* Copyright 2010 Semafor Informatik & Energie AG, Basel, Switzerland
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.semafor.gendas.dao;
import java.util.List;
import javax.persistence.Query;
import org.springframework.stereotype.Repository;
import ch.semafor.gendas.model.CoreException;
import ch.semafor.gendas.model.PropertyType;
@Repository("propertyTypeDao")
public class PropertyTypeDaoImpl extends GenericDaoJpa<PropertyType,Long>
implements PropertyTypeDao {
PropertyTypeDaoImpl(){
super(PropertyType.class);
}
@SuppressWarnings("unchecked")
public PropertyType findByName(final String name) throws CoreException {
List<PropertyType> l = null; // NOPMD by wim on 9/20/10 9:14 AM
final Query q = getEntityManager().createQuery( "from PropertyType where name = :name"); // NOPMD by wim on 9/20/10 9:14 AM
q.setParameter( "name", name );
l = q.getResultList();
if( l == null || l.isEmpty() ){
throw new CoreException("PropertyType '" + name + "' not found");
}
return l.get(0);
}
@SuppressWarnings("unchecked")
public boolean exists(final String name) {
List<PropertyType> l = getEntityManager() // NOPMD by wim on 9/20/10 9:14 AM
.createQuery( "from PropertyType where name = :name")
. setParameter("name", name)
.getResultList();
if( l == null || l.isEmpty() ){
return false; // NOPMD by wim on 9/20/10 9:14 AM
}
return true;
}
}