📄 storageindodaohibernate.java
字号:
package com.strong.ims.dao.sysmanage.hibernate;
import java.util.Date;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.strong.ims.comutil.IConstants;
import com.strong.ims.comutil.PageBean;
import com.strong.ims.comutil.dao.Hibernate;
import com.strong.ims.comutil.exception.BaseException;
import com.strong.ims.dao.sysmanage.StorageInfoDao;
import com.strong.ims.domain.sysmanage.StorageInfo;
/**
* 仓库DAO 实现类
* @author jiang
*
*/
public class StorageIndoDaoHibernate implements StorageInfoDao {
public StorageIndoDaoHibernate() {
super();
// TODO Auto-generated constructor stub
}
/**
* 根据 主键查询
*/
public StorageInfo loadStorageInfo(String id)
throws BaseException{
// TODO Auto-generated method stub
Session session = Hibernate.currentSession( );
StorageInfo storageInfo = null;
try {
storageInfo = (StorageInfo)session.get(StorageInfo.class,id);
}
catch(HibernateException ex) {
ex.printStackTrace();
throw new BaseException(ex,"",IConstants.ERROR_DAOPROCESS);
//throw new ;
}
catch(Exception e) {
e.printStackTrace();
throw new BaseException(e,"",IConstants.ERROR_UNKOWN);
//throw new Exception();
}
finally {
session.close();
}
return storageInfo;
}
/**
* create 仓库信息,持久化
*/
public void createStorageInfo(StorageInfo storageInfo)
throws BaseException {
Session session = Hibernate.currentSession();
Transaction tx = session.beginTransaction();
try {
session.save(storageInfo);
tx.commit();
}
catch(HibernateException e) {
e.printStackTrace();
tx.rollback();
throw new BaseException(e,"",IConstants.ERROR_DAOPROCESS);
}
catch(Exception e) {
e.printStackTrace();
tx.rollback();
throw new BaseException(e,"",IConstants.ERROR_UNKOWN);
}
finally {
session.close();
}
}
/**
* delete 仓库信息
* @param StorageInfo
*/
public void deleteStorageInfo(StorageInfo storageInfo)
throws BaseException{
Session session = Hibernate.currentSession();
Transaction tx = session.beginTransaction();
try {
session.delete(storageInfo);
tx.commit();
}
catch(HibernateException e) {
e.printStackTrace( );
tx.rollback();
throw new BaseException(e,"",IConstants.ERROR_DAOPROCESS);
}
catch(Exception e ) {
e.printStackTrace( );
tx.rollback();
throw new BaseException(e,"",IConstants.ERROR_UNKOWN);
}
finally {
session.close();
}
}
/**
* update 仓库信息
* @param StorageInfo
*/
public void updateStorageInfo(StorageInfo storageInfo)
throws BaseException{
// TODO Auto-generated method stub
Session session = Hibernate.currentSession();
Transaction tx = session.beginTransaction();
try {
session.update(storageInfo);
tx.commit();
}
catch(HibernateException e) {
e.printStackTrace();
tx.rollback();
throw new BaseException(e,"",IConstants.ERROR_DAOPROCESS);
}
catch(Exception e ) {
e.printStackTrace();
tx.rollback();
throw new BaseException(e,"",IConstants.ERROR_UNKOWN);
}
finally {
session.close();
}
}
/**
* 查询全部
*
*/
public List loadStorageInfoAll( )
throws BaseException{
List list = null;
Session session = Hibernate.currentSession();
try{
list = session.createQuery("from StorageInfo as s").list();
}
catch(HibernateException e) {
e.printStackTrace();
throw new BaseException(e,"",IConstants.ERROR_DAOPROCESS);
}
catch(Exception e ) {
e.printStackTrace();
throw new BaseException(e,"",IConstants.ERROR_UNKOWN);
}
finally{
session.close();
}
return list;
}
/**
* 查询全部
* 支持分页
*/
public List loadStorageInfoAll(PageBean pageBean )
throws BaseException{
List list = null;
Session session = Hibernate.currentSession();
try{
list = session.createQuery("from StorageInfo as s").list();
}
catch(HibernateException e) {
e.printStackTrace();
throw new BaseException(e,"",IConstants.ERROR_DAOPROCESS);
}
catch(Exception e ) {
e.printStackTrace();
throw new BaseException(e,"",IConstants.ERROR_UNKOWN);
}
finally{
session.close();
}
return list;
}
/**
* 查询 根据仓库名,状态,模糊查询
* @param Hql
*/
public List loadStorageInfoByHQL(String HQL )
throws BaseException{
List list = null;
Session session = Hibernate.currentSession();
try{
list = session.createQuery( HQL ).list();
}
catch(HibernateException e) {
e.printStackTrace();
throw new BaseException(e,"",IConstants.ERROR_DAOPROCESS);
}
catch(Exception e ) {
e.printStackTrace();
throw new BaseException(e,"",IConstants.ERROR_UNKOWN);
}
finally{
session.close();
}
return list;
}
/**
* 查询 根据仓库名,状态,模糊查询
* 支持分页
* @param Hql
*
* ???????????????????????
*/
public List loadStorageInfoByHQL(String HQL ,PageBean pageBean)
throws BaseException{
List list = null;
Session session = Hibernate.currentSession();
try{
list = session.createQuery( HQL ).list();
}
catch(HibernateException e) {
e.printStackTrace();
throw new BaseException(e,"",IConstants.ERROR_DAOPROCESS);
}
catch(Exception e ) {
e.printStackTrace();
throw new BaseException(e,"",IConstants.ERROR_UNKOWN);
}
finally{
session.close();
}
return list;
}
/**
* 简单测试
* @param args
*/
public static void main(String args[] ) {
StorageInfo Info = new StorageInfo( );
Info.setF_sid("00000002");
Info.setF_isdelete("0");
Info.setF_memo("你好");
Info.setF_storagename("我呀");
Info.setF_deldatatime(new Date());
//DaoFactory.getStorageInfoDao().createStorageInfo(Info);
//DaoFactory.getStorageInfoDao().updateStorageInfo(new StorageInfo());
//StorageInfo storageInfo = DaoFactory.getStorageInfoDao().loadStorageInfo("00000002");
//System.out.println(storageInfo.toString());
//DaoFactory.getStorageInfoDao().deleteStorageInfo(new StorageInfo());
//System.out.println( DaoFactory.getStorageInfoDao().loadStorageInfoAll().size() );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -