📄 companyintrohibernatedao.java~530~
字号:
package org.lenovoAC.hibernateDao;
import java.util.*;
import org.lenovoAC.pojo.CompanyIntro;
import org.lenovoAC.dao.CompanyIntroDAO;
import org.lenovoAC.tools.Tools;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.orm.hibernate.LocalSessionFactoryBean;
import net.sf.hibernate.Hibernate;
import net.sf.hibernate.Session;
import net.sf.hibernate.Query;
import javax.servlet.http.HttpServletRequest;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.LockMode;
import oracle.sql.CLOB;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
* 安诚概况
* 公司简介表:company_intro
*/
public class CompanyIntroHibernateDao
extends BaseDao
{
/**
* 添加公司简介
* @param comIntro CompanyIntro
*/
public void insertCompanyIntro(CompanyIntro com)
throws Exception
{
/*CompanyIntro com=new CompanyIntro();
com.setTitle(request.getParameter("title"));
com.setTime(new java.util.Date());
this.getHibernateTemplate().save(com);
Connection con= null;
ResultSet rs=null;
Session session=this.getSession();
con=session.connection();
con.setAutoCommit(false);
String sql="select * from company_intro_chang where id='"+com.getId()+"' for update";
PreparedStatement ps = con.prepareStatement(sql);
rs=ps.executeQuery();
if(rs.next())
{
oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("context");
java.io.Writer out=clob.getCharacterOutputStream();
out.write(Tools.toIsoAndNotNull(request.getParameter("context")));
out.close();
con.commit();
con.close();
}*/
//this.getHibernateTemplate().save(com);
Session session=this.getSession();
Transaction tx=session.beginTransaction();
session.save(com);
tx.commit();
session.close();
}
/**
* 修改公司简介信息
* @param comIntroId String
*/
public void updateCompanyIntro(CompanyIntro comIntro)
{
net.sf.hibernate.Session session =null;
java.sql.Connection con=null;
java.sql.PreparedStatement ps=null;
try
{
String sql="update COMPANY_INTRO set title=?,context=?,Type_state=?,Time=sysdate,display_state=? where id=?";
session=this.getSession();
con=session.connection();
ps=con.prepareStatement(sql);
ps.setString(1,comIntro.getTitle());
// ps.setString(2,comIntro.getContext());
//ps.setString(2,comIntro.getContext());
ps.setString(3,comIntro.getTypeState());
ps.setString(4,comIntro.getDisplayState());
ps.setString(5,comIntro.getId());
ps.executeUpdate();
ps.close();
con.close();
session.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
/**
* 修改
* @param comIn CompanyIntro
*/
public void updateCompanyIntroTwo(String id,CompanyIntro comIn)
{
CompanyIntro newCom=this.getCompanyIntro(id);
newCom.setTitle(comIn.getTitle());
newCom.setContext(comIn.getContext());
newCom.setTime(comIn.getTime());
newCom.setTypeState(comIn.getTypeState());
newCom.setDisplayState(comIn.getTypeState());
this.getHibernateTemplate().update(comIn);
this.getHibernateTemplate().flush();
}
/**
* 删除公司简介信息
* @param comIntroId String
*/
public void delCompanyIntro(String comIntroId)
{
CompanyIntro comIntro=(CompanyIntro)this.getHibernateTemplate().get(CompanyIntro.class,comIntroId);
this.getHibernateTemplate().delete(comIntro);
this.getHibernateTemplate().flush();
}
/**
* 取得指定ID的简介对象
* @param comIntroId String
* @return CompanyIntro
*/
public CompanyIntro getCompanyIntro(String comIntroId)
{
return (CompanyIntro)this.getHibernateTemplate().load(CompanyIntro.class,comIntroId);
}
/**
* 取得数据库中所有记录
* @return List
*/
public List getAllCompanyIntro()
{
String hql="from CompanyIntro com order by com.time desc";
try
{
Query query=this.getHibernateTemplate().createQuery(this.getSession(),hql);
return query.list();
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
//return this.getHibernateTemplate().find(hql);
}
/**
* 取得指定记录的标志
* @param companyIntroId String
* @return String
*/
public String getState(String companyIntroId)
{
String hql="select com.state from CompanyIntro as com where com.id=?";
return (String)this.getHibernateTemplate().find(hql,companyIntroId,Hibernate.STRING).get(0);
}
/**
* 得到限制的记录数
* @param maxSize int
* @return List
*/
public List getCompanyLimit(int maxSize)
{
List list=null;
String hql="from CompanyIntro as c order by c.time desc";
try
{
Query query=this.getHibernateTemplate().createQuery(this.getSession(),hql);
query.setFirstResult(0);
query.setMaxResults(maxSize);
list=query.list();
}
catch(Exception e)
{
e.printStackTrace();
}
return list;
}
public List getCompanyTT(String typeState)
{
String hql="from CompanyIntro as c where c.typeState=? and c.displayState=? order by c.time desc";
String[] arr={typeState,"01"};
return this.getHibernateTemplate().find(hql,arr);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -