19 package org.turro.contacts.log;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Date;
24 import java.util.List;
25 import org.turro.string.Strings;
26 import org.turro.annotation.ElephantPlugin;
27 import org.turro.contacts.db.ContactsPU;
28 import org.turro.elephant.db.WhereClause;
29 import org.turro.elephant.log.LogType;
30 import org.turro.jpa.Dao;
31 import org.turro.plugin.log.ILogLoader;
32 import org.turro.plugin.log.ILogRegister;
33 import org.turro.plugin.log.LogUtil;
34 import org.turro.util.PhraseBuilder;
44 public Collection<ILogRegister>
load(
LogType type, String pathOrigin,
int group, String comment) {
46 List<Object[]> list = dao.getResultList(createCriteria(type, pathOrigin, group, comment));
47 ArrayList<ILogRegister> result =
new ArrayList<ILogRegister>();
48 for(Object o[] : list) {
49 String path =
null, name =
null, actualComment =
null;
51 int count = 0, field = 0;
53 path = (String) o[field++];
54 }
else if(group ==
LogUtil.GROUP_USER) {
55 name = (String) o[field++];
57 if(Strings.isBlank(comment)) {
58 actualComment = (String) o[field++];
60 count = ((Long) o[field++]).intValue();
61 date = (Date) o[field++];
62 result.add(
new LogRegister(type, path,
null, name, date, actualComment,
null, count));
67 private WhereClause createCriteria(
LogType type, String pathOrigin,
int group, String comment) {
71 PhraseBuilder pb =
new PhraseBuilder();
73 pb.addWord(
"ce.path");
74 pb.addPendingSeparator(
",");
75 }
else if(group == LogUtil.GROUP_USER) {
78 pb.addWord(
"trim(ce.name)");
79 pb.addPendingSeparator(
",");
81 if(Strings.isBlank(comment)) {
82 pb.addWord(
"ce.comment");
83 pb.addPendingSeparator(
",");
85 pb.addWord(
"count(ce.id)");
86 pb.addPendingSeparator(
",");
87 pb.addWord(
"max(ce.dateLog)");
88 pb.addPendingSeparator(
",");
91 wc.
addClause(
"from LogEntry as ce where 1=1");
97 if(!Strings.isBlank(pathOrigin)) {
98 wc.
addClause(
"and ce.path like '" + pathOrigin +
"%'");
100 if(!Strings.isBlank(comment)) {
101 wc.
addClause(
"and ce.comment = :comment");
105 if(group != LogUtil.GROUP_NONE) {
106 pb =
new PhraseBuilder();
107 pb.addWord(
"group by");
108 if(group == LogUtil.GROUP_ENTITY) {
109 pb.addWord(
"ce.path");
110 pb.addPendingSeparator(
",");
111 }
else if(group == LogUtil.GROUP_USER) {
114 pb.addWord(
"trim(ce.name)");
115 pb.addPendingSeparator(
",");
117 if(Strings.isBlank(comment)) {
118 pb.addWord(
"ce.comment");
119 pb.addPendingSeparator(
",");
129 List<Object[]> list = dao.getResultList(createLoginCriteria());
130 ArrayList<ILogRegister> result =
new ArrayList<ILogRegister>();
131 for(Object o[] : list) {
134 int count = 0, field = 0;
135 path = (String) o[field++];
136 name = (String) o[field++];
137 count = ((Long) o[field++]).intValue();
138 date = (Date) o[field++];
139 result.add(
new LogRegister(
null,
null,
null, name, date, path,
null, count));
148 PhraseBuilder pb =
new PhraseBuilder();
149 pb.addWord(
"ce.path");
150 pb.addPendingSeparator(
",");
151 pb.addWord(
"trim(ce.name)");
152 pb.addPendingSeparator(
",");
153 pb.addWord(
"count(ce.id)");
154 pb.addPendingSeparator(
",");
155 pb.addWord(
"max(ce.dateLog)");
156 pb.addPendingSeparator(
",");
159 wc.
addClause(
"from LogEntry as ce where 1=1");
161 wc.
addClause(
"and ce.path like '/log/%'");
163 pb =
new PhraseBuilder();
164 pb.addWord(
"group by");
165 pb.addWord(
"ce.path");
166 pb.addPendingSeparator(
",");
167 pb.addWord(
"trim(ce.name)");
168 pb.addPendingSeparator(
",");
void addClause(String clause)
void addNamedValue(String name, Object value)