📄 countryareadao.java
字号:
package tarena.dao;
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.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;
import tarena.entity.Countryarea;
@SuppressWarnings("unchecked")
public class CountryareaDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(CountryareaDAO.class);
// property constants
public static final String AREANAME = "areaname";
public static final String PARENTID = "parentid";
public static final String LEVEL = "level";
public void save(Countryarea transientInstance) {
Session session = getSession();
Transaction t = session.beginTransaction();
try {
session.save(transientInstance);
t.commit();
} catch (RuntimeException re) {
t.rollback();
throw re;
}
}
public void delete(Countryarea persistentInstance) {
Session session = getSession();
Transaction t = session.beginTransaction();
try {
session.delete(persistentInstance);
t.commit();
} catch (RuntimeException re) {
t.rollback();
throw re;
}
}
public Countryarea findById(java.lang.Integer id) {
try {
Countryarea instance = (Countryarea) getSession().get(
"tarena.entity.Countryarea", id);
return instance;
} catch (RuntimeException re) {
throw re;
} finally {
closeSession();
}
}
public Integer getDefaultId(Integer parentid){
String queryString = "from Countryarea as model where model."
+ PARENTID + "= ?";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, parentid);
return ((Countryarea)(queryObject.list().get(0))).getId();
}
public List<Countryarea> findByExample(Countryarea instance) {
try {
List results = getSession().createCriteria(
"tarena.entity.Countryarea").add(Example.create(instance))
.list();
return results;
} catch (RuntimeException re) {
throw re;
}
}
public List<Countryarea> findByProperty(String propertyName, Object value) {
log.debug("finding Countryarea instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Countryarea as model where model."
+ propertyName + "= ?";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List<Countryarea> findByAreaname(Object areaname) {
return findByProperty(AREANAME, areaname);
}
public List<Countryarea> findByParentid(Object parentid) {
return findByProperty(PARENTID, parentid);
}
public List<Countryarea> findByLevel(Object level) {
return findByProperty(LEVEL, level);
}
public List<Countryarea> findAll() {
try {
String queryString = "from Countryarea";
Query queryObject = getSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException re) {
throw re;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -