19 package org.turro.contacts;
21 import java.io.Serializable;
22 import java.util.Collection;
23 import java.util.List;
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.fieldit.FieldItSet;
32 import org.turro.fieldit.FieldItUtil;
33 import org.turro.jpa.Dao;
40 @org.hibernate.annotations.GenericGenerator(name =
"hibernate-uuid", strategy =
"uuid")
41 public class GroupIt implements Serializable {
44 @GeneratedValue(generator =
"hibernate-uuid")
45 @Column(name=
"IDENTIFIER")
48 private String category;
50 @Column(name=
"GROUPIT_NAME")
53 private String pathName;
58 private boolean publishable;
73 this.category = category;
89 this.pathName = pathName;
105 this.publishable = publishable;
111 return !Strings.isBlank(name) &&
117 return dao.getResultList(
118 " select distinct g.category from GroupIt g"
122 public static Collection<GroupIt>
roots(String category) {
124 return dao.getResultList(
125 " select g from GroupIt g " +
126 " where g.category = ? " +
127 " and g.parent is null",
128 new Object[] { category }
132 public static Collection<GroupIt>
roots(String category, String entityPath) {
134 return dao.getResultList(
135 " select g from GroupIt g " +
136 " where g.category = ? " +
137 " and g.parent is null " +
139 " select gd from Grouped gd " +
140 " where (gd.parent.pathName like concat(g.pathName, '/%') " +
141 " or gd.parent.pathName = g.pathName) " +
142 " and gd.path like ? " +
144 new Object[] { category, entityPath +
"/%" }
150 return dao.getResultList(
151 " select g from GroupIt g " +
152 " where g.category = ? " +
158 public Collection<GroupIt>
children(String entityPath) {
160 return dao.getResultList(
161 " select g from GroupIt g " +
162 " where g.category = ? " +
163 " and g.parent = ? " +
165 " select gd from Grouped gd " +
166 " where (gd.parent.pathName like concat(g.pathName, '/%') " +
167 " or gd.parent.pathName = g.pathName) " +
168 " and gd.path like ? " +
170 new Object[] { this.
getCategory(),
this, entityPath +
"/%" }
176 return dao.getResultList(
177 " select g from Grouped g " +
178 " where g.parent.category = ? " +
186 return dao.getResultList(
187 " select g from Grouped g " +
188 " where g.parent.category = ? " +
189 " and (g.parent = ? or g.parent.path like ?)",
196 return dao.getResultList(
197 " select g from Grouped g " +
198 " where g.parent.category = ? " +
199 " and (g.parent = ? or g.parent.path like ?) " +
200 " and g.path like ? ",
208 String d =
"/" + group.
getName();
215 return dao.saveObject(group);
220 for(
GroupIt group : (List<GroupIt>) dao.getResultList(
221 "select g from GroupIt g where g.pathName like ?",
222 new Object[] { oldPath +
"/%" })) {
223 String d =
"/" + group.getName();
230 dao.saveObject(group);
234 public static void delete(String path) {
237 "delete from Grouped where parent in (select gi from GroupIt gi where gi.pathName = ? or gi.pathName like ?)",
238 new Object[] { path, path +
"/%" });
240 "delete from GroupIt where pathName = ? or pathName like ?",
241 new Object[] { path, path +
"/%" });
246 String parentPath = parent !=
null ? parent.
getPathName() +
"/" :
"/";
248 "select g from GroupIt g where g.category = ? and g.pathName = ?",
249 new Object[] { category, parentPath + node });
252 gi.setCategory(category);
254 gi.setParent(parent);
255 gi.setPublishable(
true);
256 gi = gi.normalizePaths(gi);
static FieldItSet fields(Object entity)
int executeUpdate(String query)
Object getSingleResultOrNull(SqlClause sc)