net.shopxx.dao.impl.ShippingDaoImpl.java Source code

Java tutorial

Introduction

Here is the source code for net.shopxx.dao.impl.ShippingDaoImpl.java

Source

/*
 * 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.ShippingDao;
import net.shopxx.entity.Shipping;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

@Repository("shippingDaoImpl")
public class ShippingDaoImpl extends BaseDaoImpl<Shipping, Long> implements ShippingDao {

    public Shipping findBySn(String sn) {
        if (StringUtils.isEmpty(sn)) {
            return null;
        }
        String jpql = "select shipping from Shipping shipping where lower(shipping.sn) = lower(:sn)";
        try {
            return entityManager.createQuery(jpql, Shipping.class).setParameter("sn", sn).getSingleResult();
        } catch (NoResultException e) {
            return null;
        }
    }

}