Java tutorial
/* * Copyright 2005-2013 shopxx.net. All rights reserved. * Support: http://www.shopxx.net * License: http://www.shopxx.net/license */ package net.groupbuy.dao.impl; import javax.persistence.FlushModeType; import javax.persistence.NoResultException; import net.groupbuy.dao.PluginConfigDao; import net.groupbuy.entity.PluginConfig; import org.springframework.stereotype.Repository; /** * Dao - ?? * * @author SHOP++ Team * @version 3.0 */ @Repository("pluginConfigDaoImpl") public class PluginConfigDaoImpl extends BaseDaoImpl<PluginConfig, Long> implements PluginConfigDao { public boolean pluginIdExists(String pluginId) { if (pluginId == null) { return false; } String jpql = "select count(*) from PluginConfig pluginConfig where pluginConfig.pluginId = :pluginId"; Long count = entityManager.createQuery(jpql, Long.class).setFlushMode(FlushModeType.COMMIT) .setParameter("pluginId", pluginId).getSingleResult(); return count > 0; } public PluginConfig findByPluginId(String pluginId) { if (pluginId == null) { return null; } try { String jpql = "select pluginConfig from PluginConfig pluginConfig where pluginConfig.pluginId = :pluginId"; return entityManager.createQuery(jpql, PluginConfig.class).setFlushMode(FlushModeType.COMMIT) .setParameter("pluginId", pluginId).getSingleResult(); } catch (NoResultException e) { return null; } } }