📄 sortdao.java
字号:
package org.openblog.hibernate;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.apache.commons.beanutils.BeanUtils;
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 org.openblog.hibernate.HibernateSessionFactory;
import org.openblog.hibernate.Sort;
import org.openblog.hibernate.SortView;
import java.util.*;
/**
* A data access object (DAO) providing persistence and search support for Sort
* 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 org.openblog.hibernate.Sort
* @author MyEclipse Persistence Tools
*/
public class SortDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(SortDAO.class);
// property constants
public static final String SORT_NAME = "sortName";
public static final String SORT_PARENT = "sortParent";
List sortlist = new ArrayList();
List sortcount = new ArrayList();
public List showSortId(int id)
{
sortlist.add(new Integer(id));
this.subshowSortId(id);
return sortlist;
}
public List subshowSortId(int id)
{
List list = new ArrayList();
Session session = HibernateSessionFactory.getSession();
String hql = "from Sort where sortParent =" + id;
list = session.createQuery(hql).list();
for(int i=0 ; i<list.size();i++)
{
Sort sort = (Sort)list.get(i);
sortcount.add(sort.getSortId());
this.showSortId(sort.getSortId().intValue());
}
return sortcount;
}
public List getSubSortPic(int id, int level)
{
int count = 0;
String blank = "";
List list = new ArrayList();
Vector v = new Vector();
Session session = HibernateSessionFactory.getSession();
String hql = "from Sort where sortParent =" + id;
list = session.createQuery(hql).list();
//Sort sort2=(Sort)list.get(0);
//System.out.println(sort2.getSortName()+"!!!!!!");
for(int i=0 ; i<list.size();i++)
{
blank = "";
for(int j= 0 ; j<level;j++)
{
if(j!= level-1)
{
blank = blank + " <img src='../Image/tree2.gif' width='15' height='15' valign='abvmiddle'>";
}
else
{
blank = blank + " <img src='../Image/tree1.gif' width='15' height='15' valign='abvmiddle'>";
}
}
count = level;
count = count +1;
Sort sort = (Sort)list.get(i);
SortView SortView = new SortView();
try {
BeanUtils.copyProperties(SortView, sort);
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SortView.setSortName(blank+" "+SortView.getSortName());
//System.out.println(SortView.getSortName()+"!!!!!");
sortlist.add(SortView);
this.getSubSortPic(SortView.getSortId().intValue(), count);
}
return sortlist;
}
public List getSubSort(int id, int level)
{
int count = 0;
String blank = "";
List list = new ArrayList();
Session session = HibernateSessionFactory.getSession();
String hql = "from Sort where sortParent =" + id;
list = session.createQuery(hql).list();
for(int i=0 ; i<list.size();i++)
{
blank = "";
for(int j= 0 ; j<level;j++)
{
if(j!= level-1)
{
blank = blank + " │";
}
else
{
blank = blank + " ├";
}
}
count = level;
count = count +1;
Sort sort = (Sort)list.get(i);
SortView SortView = new SortView();
try {
BeanUtils.copyProperties(SortView, sort);
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SortView.setSortName(blank+SortView.getSortName());
sortlist.add(SortView);
this.getSubSort(SortView.getSortId().intValue(), count);
}
return sortlist;
}
public List showSort(int id,String showpage)
{
List list = new ArrayList();
Session session = HibernateSessionFactory.getSession();
String hql = "from Sort where sortParent =" + id;
list = session.createQuery(hql).list();
for(int i=0 ; i<list.size();i++)
{
Sort sort = (Sort)list.get(i);
SortView SortView = new SortView();
try {
BeanUtils.copyProperties(SortView, sort);
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SortView.setSortName("<div class=\"item_category\"><a href=\""+showpage+"?classid="+String.valueOf(sort.getSortId())+"\">"+SortView.getSortName()+"</a></div>");
sortlist.add(SortView);
this.showSort(SortView.getSortId().intValue(),showpage);
}
return sortlist;
}
public void save(Sort transientInstance) {
Transaction trans = null;
log.debug("saving Sort instance");
try {
trans=getSession().beginTransaction();
getSession().save(transientInstance);
getSession().flush();
trans.commit();
log.debug("save successful");
} catch (RuntimeException re) {
if(trans!=null) trans.rollback();
log.error("save failed", re);
throw re;
}
}
public void delete(Sort persistentInstance) {
Transaction trans =null;
log.debug("deleting Sort instance");
try {
trans= getSession().beginTransaction();
getSession().delete(persistentInstance);
getSession().flush();
trans.commit();
log.debug("delete successful");
} catch (RuntimeException re) {
if(trans!=null) trans.rollback();
log.error("delete failed", re);
throw re;
}
}
public void ModifySort(Sort Sort)
{
Session session = HibernateSessionFactory.getSession();
org.hibernate.Transaction ts = null;
try
{
ts= session.beginTransaction();
session.update(Sort);
ts.commit();
}
catch(Exception ex)
{
if(ts!=null) ts.rollback();
System.out.println("
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -