net.groupbuy.dao.impl.NavigationDaoImpl.java Source code

Java tutorial

Introduction

Here is the source code for net.groupbuy.dao.impl.NavigationDaoImpl.java

Source

/*
 * 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 java.util.List;

import javax.persistence.FlushModeType;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import net.groupbuy.dao.NavigationDao;
import net.groupbuy.entity.Navigation;
import net.groupbuy.entity.Navigation.Position;

import org.springframework.stereotype.Repository;

/**
 * Dao - 
 * 
 * @author SHOP++ Team
 * @version 3.0
 */
@Repository("navigationDaoImpl")
public class NavigationDaoImpl extends BaseDaoImpl<Navigation, Long> implements NavigationDao {

    public List<Navigation> findList(Position position) {
        CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
        CriteriaQuery<Navigation> criteriaQuery = criteriaBuilder.createQuery(Navigation.class);
        Root<Navigation> root = criteriaQuery.from(Navigation.class);
        criteriaQuery.select(root);
        if (position != null) {
            criteriaQuery.where(criteriaBuilder.equal(root.get("position"), position));
        }
        criteriaQuery.orderBy(criteriaBuilder.asc(root.get("order")));
        return entityManager.createQuery(criteriaQuery).setFlushMode(FlushModeType.COMMIT).getResultList();
    }

}