📄 paymentcarddaoimpl.java
字号:
package org.bestteam.dao.impl;
import java.util.List;
import org.bestteam.dao.PaymentCardDao;
import org.bestteam.domain.PaymentCard;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class PaymentCardDaoImpl extends HibernateDaoSupport implements
PaymentCardDao {
/**
*
* @param ApplicationContext 一个ApplicationContext的对象
* @return PaymentCard的对象
* 在类加载时通过AplicationContext对象得到PaymentCard的对象
*/
public static PaymentCard getFromApplicationContext(ApplicationContext ctx) {
return (PaymentCard) ctx.getBean("paymentCardDao");
}
public boolean attachClean(PaymentCard instance) {
try{
getHibernateTemplate().lock(instance, LockMode.NONE);
}catch(RuntimeException re) {
re.printStackTrace();
return false;
}
return true;
}
/**
* @param PaymentCard 一个PaymentCard的对象
* @return boolean
* 对传进来的PaymentCard对象保存或更新
* 当该对象为一个托管对象时,该方法会执行更新动作
* 当对象为一个瞬时对象时,该方法会执行保存动作
*/
public boolean attachDirty(PaymentCard instance) {
try{
getHibernateTemplate().saveOrUpdate(instance);
}catch(RuntimeException re) {
re.printStackTrace();
return false;
}
return true;
}
public boolean dalete(PaymentCard persistentInstance) {
try{
getHibernateTemplate().delete(persistentInstance);
}catch(RuntimeException re) {
re.printStackTrace();
return false;
}
return true;
}
public List findPaymentCardByExample(PaymentCard instance) {
List paymentCardList = null;
try{
paymentCardList = getHibernateTemplate().findByExample(instance);
}catch(RuntimeException re) {
re.printStackTrace();
}
return paymentCardList;
}
/**
* @param String 该类对象的一个属性的名称
* Object 该属性名所对应的对象的值
* @return List列表
* 根据类对象的一个属性的名称和其对应的值,查找该类对象的实例,
* 因为输入的属性不保证能唯一标识该对象,所以返回的对象将是一个由该类对象组成的List列表
*/
public List findPaymentCardByProperty(String propertyName, Object value) {
List paymentCardList = null;
try{
String queryString = "from PaymentCard as paymentCard where paymentCard."
+ propertyName + "=?";
paymentCardList = getHibernateTemplate().find(queryString, value);
}catch(RuntimeException re) {
re.printStackTrace();
}
return paymentCardList;
}
/**
* @param Integer 用户的ID
* @return PaymentCard的对象
* 根据该用户的用户ID(主键),查找该用户的支付宝信息
* 如果用户ID不存在,则返回空值
*/
public PaymentCard findPaymentCardByUserId(Integer userID) {
PaymentCard paymentCard = null;
try{
paymentCard = (PaymentCard) getHibernateTemplate().get(PaymentCard.class, userID);
}catch(RuntimeException re) {
re.printStackTrace();
}
return paymentCard;
}
public PaymentCard merge(PaymentCard detachedInstance) {
PaymentCard paymentCard = null;
try{
paymentCard = (PaymentCard) getHibernateTemplate().merge(detachedInstance);
}catch(RuntimeException re) {
re.printStackTrace();
}
return paymentCard;
}
/**
* @param PaymentCard PaymentCard的对象
* @return boolean
* 将传入的PaymentCard对象持久化
* 应注意传入的对象的id(在对象中应该保持该属性为Null)不能重复
*/
public boolean save(PaymentCard transientInstance) {
try{
getHibernateTemplate().save(transientInstance);
}catch(RuntimeException re) {
re.printStackTrace();
return false;
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -