basic support for multiple cache lists
This commit is contained in:
@@ -27,6 +27,7 @@ package de.geofroggerfx.service;
|
||||
|
||||
import de.geofroggerfx.application.ProgressListener;
|
||||
import de.geofroggerfx.model.Cache;
|
||||
import de.geofroggerfx.model.CacheList;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.util.List;
|
||||
@@ -35,9 +36,36 @@ import java.util.List;
|
||||
* @author Andreas
|
||||
*/
|
||||
public interface CacheService {
|
||||
|
||||
/**
|
||||
* Store the whole list of caches
|
||||
* @param caches list of caches
|
||||
*/
|
||||
void storeCaches(List<Cache> caches);
|
||||
|
||||
/**
|
||||
* Receive all caches from the database
|
||||
* @param sortField sort the list based on the field
|
||||
* @param direction sort direction (ASC/DESC)
|
||||
* @return sorted list of caches
|
||||
*/
|
||||
List<Cache> getAllCaches(CacheSortField sortField, SortDirection direction);
|
||||
|
||||
/**
|
||||
* Add a ProgressListener to inform about loading/storing progress.
|
||||
* @param listener progress listener
|
||||
*/
|
||||
void addListener(ProgressListener listener);
|
||||
|
||||
/**
|
||||
* Receive all cache lists
|
||||
* @return list of available cachelists
|
||||
*/
|
||||
List<CacheList> getAllCacheLists();
|
||||
|
||||
/**
|
||||
* Stores a cache list
|
||||
* @param list list of caches
|
||||
*/
|
||||
void storeCacheList(CacheList list);
|
||||
}
|
||||
|
||||
@@ -7,10 +7,7 @@ package de.geofroggerfx.service;
|
||||
|
||||
import de.geofroggerfx.application.ProgressEvent;
|
||||
import de.geofroggerfx.application.ProgressListener;
|
||||
import de.geofroggerfx.model.Attribute;
|
||||
import de.geofroggerfx.model.Cache;
|
||||
import de.geofroggerfx.model.Log;
|
||||
import de.geofroggerfx.model.TravelBug;
|
||||
import de.geofroggerfx.model.*;
|
||||
import de.geofroggerfx.sql.DatabaseService;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -99,6 +96,7 @@ public class CacheServiceImpl implements CacheService {
|
||||
public List<Cache> getAllCaches(CacheSortField sortField, SortDirection direction) {
|
||||
|
||||
List<Cache> caches = new ArrayList<>();
|
||||
|
||||
try {
|
||||
EntityManager em = dbService.getEntityManager();
|
||||
String query = "select c from Cache c order by c."+sortField.getFieldName()+" "+direction.toString();
|
||||
@@ -117,6 +115,39 @@ public class CacheServiceImpl implements CacheService {
|
||||
listeners.stream().forEach((l) -> l.progress(event));
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive all cache lists
|
||||
*/
|
||||
@Override
|
||||
public List<CacheList> getAllCacheLists() {
|
||||
List<CacheList> lists = new ArrayList<>();
|
||||
try {
|
||||
EntityManager em = dbService.getEntityManager();
|
||||
String query = "select l from CacheList l order by l.name";
|
||||
List<CacheList> result = em.createQuery(query).getResultList();
|
||||
if (result != null) {
|
||||
lists = result;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return lists;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void storeCacheList(CacheList list) {
|
||||
EntityManager em = dbService.getEntityManager();
|
||||
try {
|
||||
em.getTransaction().begin();
|
||||
em.persist(list);
|
||||
em.getTransaction().commit();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user