Commit c09f05eb authored by Michael Ritter's avatar Michael Ritter
Browse files

Use the collection parameter to query by name instead of id

parent 86c73cbf
...@@ -56,7 +56,6 @@ public class SummaryQuery { ...@@ -56,7 +56,6 @@ public class SummaryQuery {
"AND l1.logtype = 20 "; "AND l1.logtype = 20 ";
// Optional parameters to query on for the log event // Optional parameters to query on for the log event
final String LE_COLLECTION = "AND collection_id = ? ";
final String LE_AFTER = "AND l1.date > ? "; final String LE_AFTER = "AND l1.date > ? ";
final String LE_BEFORE = "AND l1.date < ? "; final String LE_BEFORE = "AND l1.date < ? ";
...@@ -66,6 +65,7 @@ public class SummaryQuery { ...@@ -66,6 +65,7 @@ public class SummaryQuery {
final String COL_JOIN = "JOIN ( " + final String COL_JOIN = "JOIN ( " +
" SELECT id, name, COALESCE(colgroup, '') AS colgroup FROM collection "; " SELECT id, name, COALESCE(colgroup, '') AS colgroup FROM collection ";
final String COL_JOIN_GROUP = "WHERE colgroup = ? "; final String COL_JOIN_GROUP = "WHERE colgroup = ? ";
final String COL_JOIN_NAME = "name LIKE ? ";
final String COL_JOIN_END = ") AS c " + final String COL_JOIN_END = ") AS c " +
"ON l1.collection_id = c.id "; "ON l1.collection_id = c.id ";
...@@ -86,27 +86,11 @@ public class SummaryQuery { ...@@ -86,27 +86,11 @@ public class SummaryQuery {
public List<IngestSummary> getSummary() { public List<IngestSummary> getSummary() {
List<String> params = new ArrayList<>(); List<String> params = new ArrayList<>();
/*
StringBuilder query = new StringBuilder(SELECT);
// Start our LogEvent Join
query.append(LE_JOIN);
updateParams(params, query, LE_COLLECTION, collection);
query.append(LE_JOIN_FINISH);
updateParams(params, query, LE_AFTER, after);
updateParams(params, query, LE_BEFORE, before);
// Start our collection join
query.append(COL_JOIN);
updateParams(params, query, COL_JOIN_GROUP, group);
// Finish + MonitoredItem join
query.append(COL_JOIN_END).append(MI_JOIN);
*/
EntityManager em = PersistUtil.getEntityManager(); EntityManager em = PersistUtil.getEntityManager();
// IngestSummaryMapping defined in META-INF/orm.xml // IngestSummaryMapping defined in META-INF/orm.xml
Query nq = em.createNativeQuery(buildQuery(params).toString(), "IngestSummaryMapping"); StringBuilder query = buildQuery(params);
Query nq = em.createNativeQuery(query.toString(), "IngestSummaryMapping");
int i = 1; int i = 1;
for (String param : params) { for (String param : params) {
...@@ -168,14 +152,21 @@ public class SummaryQuery { ...@@ -168,14 +152,21 @@ public class SummaryQuery {
// Start our LogEvent Join // Start our LogEvent Join
query.append(LE_JOIN); query.append(LE_JOIN);
updateParams(params, query, LE_COLLECTION, collection);
query.append(LE_JOIN_FINISH); query.append(LE_JOIN_FINISH);
updateParams(params, query, LE_AFTER, after); updateParams(params, query, LE_AFTER, after);
updateParams(params, query, LE_BEFORE, before); updateParams(params, query, LE_BEFORE, before);
// Start our collection join // Start our collection join
query.append(COL_JOIN); query.append(COL_JOIN);
updateParams(params, query, COL_JOIN_GROUP, group);
// Setup our conditional clauses
// todo: could wrap the two collection == null checks together
String groupQuery = collection == null ? COL_JOIN_GROUP : COL_JOIN_GROUP + " AND ";
String collVal = collection == null ? null : "%" + collection + "%";
String collQuery = group == null ? "WHERE " + COL_JOIN_NAME : COL_JOIN_NAME;
updateParams(params, query, groupQuery, group);
updateParams(params, query, collQuery, collVal);
// Finish + MonitoredItem join // Finish + MonitoredItem join
query.append(COL_JOIN_END).append(MI_JOIN); query.append(COL_JOIN_END).append(MI_JOIN);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment