data.dao.SubModelDao.java Source code

Java tutorial

Introduction

Here is the source code for data.dao.SubModelDao.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.SubModel;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hibernate.Criteria;
import org.hibernate.SQLQuery;
import org.springframework.stereotype.Repository;
import support.StringAdapter;

/**
 *
 * @author bezdatiuzer
 */
@Repository("subModel")
public class SubModelDao extends Dao<SubModel> {

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

    public List<SubModel> getAllSubs() {
        Criteria cr = currentSession().createCriteria(getSupportedClass());
        cr.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        return cr.list();
    }

    public HashMap<Long, String> getGenIdUrlMap() {
        HashMap<Long, String> res = new HashMap();
        String sql = "select id,url from car_model_generation";
        SQLQuery query = currentSession().createSQLQuery(sql);
        query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
        List data = query.list();

        for (Object object : data) {
            Map row = (Map) object;
            res.put(Long.valueOf((int) row.get("id")), StringAdapter.getString(row.get("url")));
        }
        return res;
    }

}