minimum list management implemented

This commit is contained in:
2014-06-15 08:38:22 +02:00
parent 2cc63e28f8
commit dccfd18415
10 changed files with 135 additions and 24 deletions

View File

@@ -63,9 +63,22 @@ public interface CacheService {
*/
List<CacheList> getAllCacheLists();
/**
* Test if a cache list with the given name already exists
* @param name of the cache list
* @return true if a list with the given name exists
*/
boolean doesCacheListNameExist(String name);
/**
* Stores a cache list
* @param list list of caches
*/
void storeCacheList(CacheList list);
/**
* Deletes a cache list
* @param cacheList deletes the given cache list
*/
void deleteCacheList(CacheList cacheList);
}

View File

@@ -135,6 +135,33 @@ public class CacheServiceImpl implements CacheService {
return lists;
}
@Override
public boolean doesCacheListNameExist(String name) {
boolean doesExist = false;
try {
EntityManager em = dbService.getEntityManager();
String query = "select count(l) from CacheList l where l.name = :name";
Long result = (Long)em.createQuery(query).setParameter("name", name).getSingleResult();
doesExist = result > 0;
} catch (Exception e) {
e.printStackTrace();
}
return doesExist;
}
@Override
public void deleteCacheList(CacheList cacheList) {
EntityManager em = dbService.getEntityManager();
try {
em.getTransaction().begin();
em.remove(cacheList);
em.getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
em.getTransaction().rollback();
}
}
/**
* {@inheritDoc}
*/