package com.tcs.hrr.dao;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.tcs.hrr.domain.Datadictionary;
/**
* A data access object (DAO) providing persistence and search support for
* Datadictionary entities. Transaction control of the save(), update() and
* delete() operations can directly support Spring container-managed
* transactions or they can be augmented to handle user-managed Spring
* transactions. Each of these methods provides additional information for how
* to configure it for the desired type of transaction control.
*
* @see com.tcs.hrr.domain.Datadictionary
* @author MyEclipse Persistence Tools
*/
public class DatadictionaryDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(DatadictionaryDAO.class);
// property constants
public static final String DATA_TYPE = "dataType";
public static final String DATA_VALUE = "dataValue";
public static final String DATA_SUB_VALUE1 = "dataSubValue1";
public static final String DATA_SUB_VALUE2 = "dataSubValue2";
public static final String CREATE_BY = "createBy";
public static final String UPDATE_BY = "updateBy";
protected void initDao() {
// do nothing
}
public void save(Datadictionary transientInstance) {
log.debug("saving Datadictionary instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Datadictionary persistentInstance) {
log.debug("deleting Datadictionary instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Datadictionary findById(java.lang.Integer id) {
log.debug("getting Datadictionary instance with id: " + id);
try {
Datadictionary instance = (Datadictionary) getHibernateTemplate()
.get("com.tcs.hrr.domain.Datadictionary", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Datadictionary instance) {
log.debug("finding Datadictionary instance by example");
try {
List results = getHibernateTemplate().findByExample(instance);
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding Datadictionary instance with property: "
+ propertyName + ", value: " + value);
try {
String queryString = "from Datadictionary as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findByDataType(Object dataType) {
return findByProperty(DATA_TYPE, dataType);
}
public List findByDataValue(Object dataValue) {
return findByProperty(DATA_VALUE, dataValue);
}
public List findByDataSubValue1(Object dataSubValue1) {
return findByProperty(DATA_SUB_VALUE1, dataSubValue1);
}
public List findByDataSubValue2(Object dataSubValue2) {
return findByProperty(DATA_SUB_VALUE2, dataSubValue2);
}
public List findByCreateBy(Object createBy) {
return findByProperty(CREATE_BY, createBy);
}
public List findByUpdateBy(Object updateBy) {
return findByProperty(UPDATE_BY, updateBy);
}
public List findAll() {
log.debug("finding all Datadictionary instances");
try {
String queryString = "from Datadictionary";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Datadictionary merge(Datadictionary detachedInstance) {
log.debug("merging Datadictionary instance");
try {
Datadictionary result = (Datadictionary) getHibernateTemplate()
.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Datadictionary instance) {
log.debug("attaching dirty Datadictionary instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Datadictionary instance) {
log.debug("attaching clean Datadictionary instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public List findAllByType(String type) {
log.debug("Get all datadictionary record by data type");
List list;
String queryString = "select distinct dataValue,dataType from Datadictionary where dataType='"
+ type + "'";
Query query = this.getSession().createQuery(queryString);
list = query.list();
return list;
}
public List findBySQL(String queryString) {
log.debug("find datadictionary instance by sql ");
Query query = this.getSession().createQuery(queryString);
List list = query.list();
System.out.println(list);
return list;
}
public static DatadictionaryDAO getFromApplicationContext(
ApplicationContext ctx) {
return (DatadictionaryDAO) ctx.getBean("DatadictionaryDAO");
}
public List findAllByCityByParam(String sql, String param) {
System.out.println("param*********"+param);
Query query = this.getSession().createQuery("from Datadictionary where dataValue='" + param + "'");
List list = query.list();
System.out.println(list.size());
return list;
}
}