package com.ifish.daoImpl;

import org.hibernate.SQLQuery;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

import com.ifish.dao.VersionDao;
import com.ifish.entity.Version;
import com.ifish.hibernate.HibernateBaseDao;

/** 
 * @ClassName: UserDaoImpl 
 * @Description: TODO 
 * @author ggw 
 *  
 */

@Repository
public class VersionDaoImpl extends HibernateBaseDao<Version, Integer> implements VersionDao {


	@Override
	protected Class<Version> getEntityClass() {
		return Version.class;
	}

	@Override
	public Version getNewestVersion(String phoneType) {
		String sql = "select version_id as versionId,version_code as versionCode,phone_type as phoneType,upload_content as uploadContent,app_address as appAddress,is_must_update as isMustUpdate,create_time as createTime from tbl_version where phone_type=? order by versionId desc";
		SQLQuery query = this.getSession().createSQLQuery(sql);
		query.setString(0, phoneType);
		query.addScalar("versionId")
			.addScalar("versionCode")
			.addScalar("phoneType")
			.addScalar("uploadContent")
			.addScalar("appAddress")
			.addScalar("isMustUpdate")
			.addScalar("createTime")
			.setResultTransformer(Transformers.aliasToBean(Version.class));
		return (Version) query.list().get(0);
	}


}
