列表视图ListView之一
2015-10-29 16:01
309 查看
查询当前节点的所有子字节:
@SuppressWarnings("unchecked")
public List<String> findAllChildColumnIdById(long id) throws Exception {
return em
.createNativeQuery(
"select to_char(i.id) FROM columns i start with i.id=:id connect by PRIOR i.id=i.f_parentId order by i.id asc")
.setParameter("id", id).getResultList();
}
当前节点找根节点
public String findRootIdByColumnId(long id) throws Exception {
return (String)em
.createNativeQuery(
"select to_char(i.id) FROM columns i where i.f_parentId=0 start with i.id=:id connect by PRIOR i.f_parentId=i.id ")
.setParameter("id", id).getSingleResult();
}
根据根节点找所有节点:
@SuppressWarnings("unchecked")
public List<InfoColumn> findAllChildColumnIdByRootId(long id) throws Exception {
List objects =em
.createNativeQuery(
"select i.id,i.f_name,i.f_parentId FROM columns i start with i.id=:id connect by PRIOR i.id=i.f_parentId order by i.id asc")
.setParameter("id", id).getResultList();
if(objects!=null&&objects.size()>0){
List<InfoColumn> infocs = new ArrayList<InfoColumn>();
for (Object o : objects) {
InfoColumn i = new InfoColumn();
Object[] os = (Object[]) o;
i.setId(Long.parseLong(os[0].toString()));
i.setName(os[1] != null ? os[1].toString() : "");
i.setParentId(Long.parseLong(os[2].toString()));
infocs.add(i);
}
return infocs;
}else{
return null;
}
}
多表查询:
@SuppressWarnings("unchecked")
public List<Info> findInfoByColumnIds(List<String> ids, int pageindex,
int max) throws Exception {
String QL = "select distinct o.id,o.title,o.path,o.updateDate FROM Info o,InfoColumn i where o in elements(i.infos) ";
StringBuffer temp = new StringBuffer();
if (ids != null && ids.size() > 0) {
for (String id : ids) {
temp.append(",");
temp.append(id);
}
}
List objects= em.createQuery(QL + " and i.id in("
+ temp.substring(1).toString()
+ ") and (o.state=2 or o.state=3) order by o.updateDate desc").setFirstResult(
pageindex).setMaxResults(max).getResultList();
if(objects!=null&&objects.size()>0){
List<Info> infos = new ArrayList<Info>();
for (Object o : objects) {
Info i = new Info();
Object[] os = (Object[]) o;
i.setId(Long.parseLong(os[0].toString()));
i.setTitle(os[1] != null ? os[1].toString() : "");
i.setPath(os[2] != null ? os[2].toString() : "");
infos.add(i);
}
return infos;
}else{
return null;
}
}
@SuppressWarnings("unchecked")
public List<String> findAllChildColumnIdById(long id) throws Exception {
return em
.createNativeQuery(
"select to_char(i.id) FROM columns i start with i.id=:id connect by PRIOR i.id=i.f_parentId order by i.id asc")
.setParameter("id", id).getResultList();
}
当前节点找根节点
public String findRootIdByColumnId(long id) throws Exception {
return (String)em
.createNativeQuery(
"select to_char(i.id) FROM columns i where i.f_parentId=0 start with i.id=:id connect by PRIOR i.f_parentId=i.id ")
.setParameter("id", id).getSingleResult();
}
根据根节点找所有节点:
@SuppressWarnings("unchecked")
public List<InfoColumn> findAllChildColumnIdByRootId(long id) throws Exception {
List objects =em
.createNativeQuery(
"select i.id,i.f_name,i.f_parentId FROM columns i start with i.id=:id connect by PRIOR i.id=i.f_parentId order by i.id asc")
.setParameter("id", id).getResultList();
if(objects!=null&&objects.size()>0){
List<InfoColumn> infocs = new ArrayList<InfoColumn>();
for (Object o : objects) {
InfoColumn i = new InfoColumn();
Object[] os = (Object[]) o;
i.setId(Long.parseLong(os[0].toString()));
i.setName(os[1] != null ? os[1].toString() : "");
i.setParentId(Long.parseLong(os[2].toString()));
infocs.add(i);
}
return infocs;
}else{
return null;
}
}
多表查询:
@SuppressWarnings("unchecked")
public List<Info> findInfoByColumnIds(List<String> ids, int pageindex,
int max) throws Exception {
String QL = "select distinct o.id,o.title,o.path,o.updateDate FROM Info o,InfoColumn i where o in elements(i.infos) ";
StringBuffer temp = new StringBuffer();
if (ids != null && ids.size() > 0) {
for (String id : ids) {
temp.append(",");
temp.append(id);
}
}
List objects= em.createQuery(QL + " and i.id in("
+ temp.substring(1).toString()
+ ") and (o.state=2 or o.state=3) order by o.updateDate desc").setFirstResult(
pageindex).setMaxResults(max).getResultList();
if(objects!=null&&objects.size()>0){
List<Info> infos = new ArrayList<Info>();
for (Object o : objects) {
Info i = new Info();
Object[] os = (Object[]) o;
i.setId(Long.parseLong(os[0].toString()));
i.setTitle(os[1] != null ? os[1].toString() : "");
i.setPath(os[2] != null ? os[2].toString() : "");
infos.add(i);
}
return infos;
}else{
return null;
}
}
相关文章推荐
- git stash 常用命令用法
- Android ANR 分析解决方法
- 开博客的第一篇文章,分享点心得,希望对大家有用
- AQS详解
- jquery expand
- Java中关于单例模式的10个面试问题
- **msf 连接不上数据库**
- Python性能鸡汤
- 会话(session)、工作站(WindowStation)、桌面(Desktop)、窗口(window)
- 基于easyui开发Web版Activiti流程定制器详解(一)——目录结构
- HVM的调试方法
- uploadify上传导致session丢失解决方案
- Linkedlist中Update和search的实现
- iOS开发日记40-详解React Native
- 使用 rem 设置文字大小
- hdu3917 最大权闭合图
- 读书笔记-整洁代码编写
- Google开源的Deep-Learning项目word2vec处理中文
- ViewGroup 中onDraw不被调用设置 setWillNotDraw()
- 50%的人在手机上一天也不搜索一次