Commit d0ec26f0 authored by shake's avatar shake
Browse files

Added check for case sensitivity when getting an item by path.

git-svn-id: https://subversion.umiacs.umd.edu/ace/trunk@200 f1b3a171-7291-4a19-a512-95ad0ad9394a
parent 1d5ab4b8
......@@ -34,6 +34,8 @@ package edu.umiacs.ace.monitor.core;
import edu.umiacs.ace.monitor.log.LogEnum;
import edu.umiacs.ace.monitor.log.LogEventManager;
import edu.umiacs.ace.util.PersistUtil;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
......@@ -42,7 +44,6 @@ import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import org.apache.log4j.Logger;
......@@ -101,19 +102,23 @@ public class MonitoredItemManager {
*
*
* @param path path to look for
* @return true if item exists, false otherwise
* @return MonitoredItem if exist, null otherwise
*/
public MonitoredItem getItemByPath( String path, Collection c ) {
lock.lock();
try {
MonitoredItem tmp = new MonitoredItem();
tmp.setPath(path);
Query q = em.createNamedQuery("MonitoredItem.getItemByPath");
q.setParameter("path", path);
q.setParameter("coll", c);
try {
return (MonitoredItem) q.getSingleResult();
} catch ( NoResultException ex ) {
return null;
}
// Make sure we have the correct item
List<MonitoredItem> li = q.getResultList();
Collections.sort(li, new PathComparator());
int idx = Collections.binarySearch(li, tmp, new PathComparator());
return (idx >= 0 ? li.get(idx): null);
} finally {
lock.unlock();
}
......@@ -236,4 +241,11 @@ public class MonitoredItemManager {
return (Long) q.getSingleResult();
}
// To compare MonitoredItems based on paths
private class PathComparator implements Comparator<MonitoredItem> {
public int compare(MonitoredItem m1, MonitoredItem m2) {
return m1.getPath().compareTo(m2.getPath());
}
}
}
Supports Markdown
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