`
mickey_hou
  • 浏览: 245746 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

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);
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics