baseImpl

@Repository
@Transactional
public class BaseDaoImpl<T, ID extends Serializable, DaoImpl extends BaseDaoImpl<T, String, DaoImpl>>
extends HibernateDaoSupport implements IBaseDAO<T, String> {

@SuppressWarnings("unchecked")
private static final Class T = null;


public List<T> findObject(String querySql, Object[] values)
throws DataAccessException, SQLException {

return lReturnSure(super.getHibernateTemplate().find(querySql, values));

}


public List<T> findObject(String querySql, Object value)
throws DataAccessException, SQLException {

return lReturnSure(super.getHibernateTemplate().find(querySql, value));

}


public List<T> findObject(String querySql) throws DataAccessException,
SQLException {

return lReturnSure(super.getHibernateTemplate().find(querySql));

}

public List<T> lReturnSure(List<T> l) {
if (!l.isEmpty() && l.size() > 0)
return l;
else
return null;
}

public T oReturnSure(T t) {
if (t != null)
return t;
else
return null;
}


public T findObject(Integer objectId) throws DataAccessException,
SQLException {

return (T) this.getHibernateTemplate().load(T, objectId);

}


public T loadObject(String objectId) throws DataAccessException,
SQLException {

return oReturnSure((T) super.getHibernateTemplate().get(T, objectId));

}

/**===================================================
* T loadObject(Integer objectId) throws DataAccessException, SQLException
* ===================================================
*/
@SuppressWarnings("unchecked")
public T loadObject(Integer objectId) throws DataAccessException,
SQLException {

return oReturnSure((T) super.getHibernateTemplate().get(T, objectId));

}


@SuppressWarnings("unchecked")
public List<T> findObjectByLimit(Map<String, String> condition,
final int firstResult,final int maxResult,Map<String, String> orderByMap) throws DataAccessException,
SQLException {

StringBuffer sb = new StringBuffer(" from " + T + " as model ");

if (condition != null)
{
Set keySet = condition.keySet();
for (Iterator iterator = keySet.iterator(); iterator.hasNext();)
{
Object object = (Object) iterator.next();
sb.append(" and model." + object + "=" + condition.get(object));
}
}
if (orderByMap != null)
{
Set keySet = orderByMap.keySet();
for (Iterator iterator = keySet.iterator(); iterator.hasNext();)
{
String str = (String) iterator.next();
sb.append(" order by model." + str + " " + orderByMap.get(str));
}
}
return getResult(sb.toString(), firstResult, maxResult);
}

/**===================================================
* T getObject(String objectId) throws DataAccessException, SQLException
* ===================================================
*/
@SuppressWarnings("unchecked")
public T getObject(String objectId) throws DataAccessException,
SQLException {

return oReturnSure((T) super.getHibernateTemplate().get(T, objectId));

}


public List<T> findObjectByLimit(Map<String, String> condition,
int firstResult, int maxResult) throws DataAccessException,
SQLException {

StringBuffer sb = new StringBuffer(" from " + T + " as model ");

if (condition != null) {
Set keySet = condition.keySet();
for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
Object object = (Object) iterator.next();
sb.append(" and model." + object + "=" + condition.get(object));
}

}
return getResult(sb.toString(), firstResult, maxResult);
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值