19 package org.turro.contacts;
21 import java.io.Serializable;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.GeneratedValue;
27 import javax.persistence.Id;
28 import javax.persistence.ManyToOne;
29 import org.turro.string.Strings;
30 import org.turro.contacts.db.ContactsPU;
31 import org.turro.elephant.db.WhereClause;
32 import org.turro.entities.Entities;
33 import org.turro.jpa.Dao;
40 @org.hibernate.annotations.GenericGenerator(name =
"hibernate-uuid", strategy =
"uuid")
41 public class Grouped implements Serializable {
44 @GeneratedValue(generator =
"hibernate-uuid")
45 @Column(name=
"IDENTIFIER")
51 @Column(name=
"GROUPED_PATH")
80 private transient String category;
83 if(category ==
null && parent !=
null) {
84 category = parent.getCategory();
90 this.category = category;
94 return parent !=
null &&
95 !Strings.isBlank(path);
98 public static Collection<Grouped>
groups(Object entity, String category) {
101 return groups(path, category);
103 return new ArrayList<>();
106 public static Collection<Grouped>
groups(String path, String category) {
108 return dao.getResultList(
109 " select g from Grouped g " +
110 " where g.parent.category = ? " +
112 " order by g.parent.category, g.parent.name ",
113 new Object[] { category, path }
117 public static Collection<Grouped>
groups(Object entity) {
122 return new ArrayList<>();
125 public static Collection<Grouped>
groups(String path) {
127 return dao.getResultList(
128 " select g from Grouped g " +
129 " where g.path = ? " +
130 " order by g.parent.category, g.parent.name ",
131 new Object[] { path }
135 public static Collection<String>
paths(String path, String selectedGroup, String selectedCategory,
boolean exact) {
138 wc.
addClause(
"select g.path from Grouped g");
141 if(Strings.isBlank(selectedGroup)) {
145 wc.
addClause(
"and g.parent.pathName = :pathName01");
148 wc.
addClause(
"and (g.parent.pathName = :pathName01 or g.parent.pathName like :pathName02)");
152 wc.
addClause(
"and g.parent.category = :category");
154 return dao.getResultList(wc);
159 return dao.getResultList(
160 " select g.path from Grouped g " +
161 " where g.path like ? " +
162 " and g.parent.category = ?",
163 new Object[] { path +
"/%", category }
void addClause(String clause)
void addNamedValue(String name, Object value)
static IElephantEntity getController(String path)