data.dao.CarDao.java Source code

Java tutorial

Introduction

Here is the source code for data.dao.CarDao.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package data.dao;

import data.dao.parent.Dao;
import data.entity.Car;
import java.math.BigDecimal;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import support.StringAdapter;

/**
 *
 * @author bezdatiuzer
 */
@Repository("carDao")
public class CarDao extends Dao<Car> {

    @Override
    public Class getSupportedClass() {
        return Car.class;
    }

    public List<Car> getCarLesserPrice(BigDecimal price) {

        Criteria cr = currentSession().createCriteria(getSupportedClass());
        cr.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        cr.add(Restrictions.le("cmPrice", price.doubleValue()));
        cr.add(Restrictions.gt("cmPrice", Double.valueOf("0.0")));
        return cr.list();
    }

    public List<Car> findById(Long oldId) {
        Criteria cr = currentSession().createCriteria(getSupportedClass());
        cr.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        cr.add(Restrictions.eq("cmqId", oldId));
        return cr.list();
    }
}