Java tutorial
/* * Copyright 2005-2015 shopxx.net. All rights reserved. * Support: http://3936242.01p.com/ * License: http://3936242.01p.com/license */ package net.shopxx.dao.impl; import javax.persistence.NoResultException; import net.shopxx.dao.PluginConfigDao; import net.shopxx.entity.PluginConfig; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Repository; @Repository("pluginConfigDaoImpl") public class PluginConfigDaoImpl extends BaseDaoImpl<PluginConfig, Long> implements PluginConfigDao { public boolean pluginIdExists(String pluginId) { if (StringUtils.isEmpty(pluginId)) { return false; } String jpql = "select count(*) from PluginConfig pluginConfig where pluginConfig.pluginId = :pluginId"; Long count = entityManager.createQuery(jpql, Long.class).setParameter("pluginId", pluginId) .getSingleResult(); return count > 0; } public PluginConfig findByPluginId(String pluginId) { if (StringUtils.isEmpty(pluginId)) { return null; } try { String jpql = "select pluginConfig from PluginConfig pluginConfig where pluginConfig.pluginId = :pluginId"; return entityManager.createQuery(jpql, PluginConfig.class).setParameter("pluginId", pluginId) .getSingleResult(); } catch (NoResultException e) { return null; } } }