📄 cardlistoperation.java
字号:
package hibernate.iml;
import java.util.List;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Transaction;
import common.HibernateSessionFactory;
public class CardListOperation extends DBOperationParent {
/**
* method update 将计数器加1
* @param key
*/
public boolean update(String key) throws HibernateException{
boolean returnCode = false;
try {
if(!session.isOpen()) session = HibernateSessionFactory.currentSession();
Transaction tx = session.beginTransaction();
String sql = " from CardList where cardnum='"+key+"' and ifuse=0";
Query query = session.createQuery(sql);
query.setMaxResults(5);
List lists = query.list();
if((lists!=null)&&lists.size()>0){
CardList object = (CardList) lists.get(0);
object.setIfuse(1);
session.update(object);
returnCode=true;
}
tx.commit();
HibernateSessionFactory.closeSession();
} catch (HibernateException e) {
e.printStackTrace();
}
return returnCode;
}
/**
* 得到单个记录值
* @param key
* @return boolean
* @throws HibernateException
*/
public boolean getInfo(String key) throws HibernateException{
boolean returnCode = false;
try {
if(!session.isOpen()) session = HibernateSessionFactory.currentSession();
String sql = " from CardList where cardnum='"+key+"' and ifuse=0";
Query query = session.createQuery(sql);
query.setMaxResults(5);
List lists = query.list();
if((lists!=null)&&lists.size()>0) returnCode = true;
} catch (HibernateException e) {
e.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return returnCode;
}
/**
* method update 更新记录
* @param object
* @param key
* @return 是否更新成功
* @throws HibernateException
*/
public boolean update(Object objectTmp, String key) throws HibernateException {
// TODO Auto-generated method stub
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -