deal with updates
This commit is contained in:
@@ -25,6 +25,8 @@
|
|||||||
*/
|
*/
|
||||||
package de.geofroggerfx.model;
|
package de.geofroggerfx.model;
|
||||||
|
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
|
import javax.persistence.OneToOne;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,9 +40,12 @@ public class Cache {
|
|||||||
private boolean found;
|
private boolean found;
|
||||||
private String name;
|
private String name;
|
||||||
private String placedBy;
|
private String placedBy;
|
||||||
|
@OneToOne(orphanRemoval = true)
|
||||||
private User owner;
|
private User owner;
|
||||||
|
@OneToOne(orphanRemoval = true)
|
||||||
private Type type;
|
private Type type;
|
||||||
private String container;
|
private String container;
|
||||||
|
@OneToMany(orphanRemoval = true)
|
||||||
private List<Attribute> attributes;
|
private List<Attribute> attributes;
|
||||||
private String difficulty;
|
private String difficulty;
|
||||||
private String terrain;
|
private String terrain;
|
||||||
@@ -51,8 +56,11 @@ public class Cache {
|
|||||||
private String longDescription;
|
private String longDescription;
|
||||||
private boolean longDescriptionHtml;
|
private boolean longDescriptionHtml;
|
||||||
private String encodedHints;
|
private String encodedHints;
|
||||||
|
@OneToMany(orphanRemoval = true)
|
||||||
private List<Log> logs;
|
private List<Log> logs;
|
||||||
|
@OneToMany(orphanRemoval = true)
|
||||||
private List<TravelBug> travelBugs;
|
private List<TravelBug> travelBugs;
|
||||||
|
@OneToOne(orphanRemoval = true)
|
||||||
private Waypoint mainWayPoint;
|
private Waypoint mainWayPoint;
|
||||||
|
|
||||||
public Waypoint getMainWayPoint() {
|
public Waypoint getMainWayPoint() {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
package de.geofroggerfx.model;
|
package de.geofroggerfx.model;
|
||||||
|
|
||||||
|
import javax.persistence.OneToOne;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -36,6 +37,7 @@ public class Log {
|
|||||||
private Long id;
|
private Long id;
|
||||||
private Date date;
|
private Date date;
|
||||||
private String type;
|
private String type;
|
||||||
|
@OneToOne(orphanRemoval = true)
|
||||||
private User finder;
|
private User finder;
|
||||||
private boolean textEncoded;
|
private boolean textEncoded;
|
||||||
private String text;
|
private String text;
|
||||||
|
|||||||
@@ -43,6 +43,13 @@ public interface CacheService {
|
|||||||
*/
|
*/
|
||||||
void storeCaches(List<Cache> caches);
|
void storeCaches(List<Cache> caches);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* find a single cache by id
|
||||||
|
* @param id id of the cache
|
||||||
|
* @return single cache
|
||||||
|
*/
|
||||||
|
Cache findCacheById(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receive all caches from the database
|
* Receive all caches from the database
|
||||||
* @param sortField sort the list based on the field
|
* @param sortField sort the list based on the field
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
|
|||||||
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
|
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
|
||||||
import de.geofroggerfx.application.ProgressEvent;
|
import de.geofroggerfx.application.ProgressEvent;
|
||||||
import de.geofroggerfx.application.ProgressListener;
|
import de.geofroggerfx.application.ProgressListener;
|
||||||
import de.geofroggerfx.model.Cache;
|
import de.geofroggerfx.model.*;
|
||||||
import de.geofroggerfx.model.CacheList;
|
|
||||||
import de.geofroggerfx.sql.DatabaseService;
|
import de.geofroggerfx.sql.DatabaseService;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@@ -22,8 +21,6 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class CacheServiceImpl implements CacheService {
|
public class CacheServiceImpl implements CacheService {
|
||||||
|
|
||||||
private static final int TRANSACTION_SIZE = 100;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private DatabaseService dbService;
|
private DatabaseService dbService;
|
||||||
private final List<ProgressListener> listeners = new ArrayList<>();
|
private final List<ProgressListener> listeners = new ArrayList<>();
|
||||||
@@ -49,23 +46,50 @@ public class CacheServiceImpl implements CacheService {
|
|||||||
"Save caches to Database " + currentCacheNumber + " / " + numberOfCaches,
|
"Save caches to Database " + currentCacheNumber + " / " + numberOfCaches,
|
||||||
(double) currentCacheNumber / (double) numberOfCaches));
|
(double) currentCacheNumber / (double) numberOfCaches));
|
||||||
|
|
||||||
|
Cache existingCache = findCacheById(cache.getId());
|
||||||
|
if (existingCache != null) {
|
||||||
|
database.delete(existingCache);
|
||||||
|
}
|
||||||
database.save(cache);
|
database.save(cache);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("cache count: " + database.countClass(Cache.class));
|
||||||
|
System.out.println("Log count: "+ database.countClass(Log.class));
|
||||||
|
System.out.println("Waypoint count: "+ database.countClass(Waypoint.class));
|
||||||
|
System.out.println("Attribute count: "+ database.countClass(Attribute.class));
|
||||||
|
|
||||||
fireEvent(new ProgressEvent("Database",
|
fireEvent(new ProgressEvent("Database",
|
||||||
ProgressEvent.State.FINISHED,
|
ProgressEvent.State.FINISHED,
|
||||||
"Caches are saved to Database"));
|
"Caches are saved to Database"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
public Cache findCacheById(Long id) {
|
||||||
|
Cache foundCache = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
OObjectDatabaseTx database = dbService.getDatabase();
|
||||||
|
String query = "select * from Cache where id="+id;
|
||||||
|
List<Cache> result = database.query(new OSQLSynchQuery<Cache>(query));
|
||||||
|
if (result != null && result.size() > 0) {
|
||||||
|
foundCache = result.get(0);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return foundCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<Cache> getAllCaches(CacheSortField sortField, SortDirection direction) {
|
public List<Cache> getAllCaches(CacheSortField sortField, SortDirection direction) {
|
||||||
|
|
||||||
List<Cache> caches = new ArrayList<>();
|
List<Cache> caches = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OObjectDatabaseTx database = dbService.getDatabase();
|
OObjectDatabaseTx database = dbService.getDatabase();
|
||||||
String query = "select * from Cache order by "+sortField.getFieldName()+" "+direction.toString();
|
String query = "select * from Cache order by "+sortField.getFieldName()+" "+direction.toString();
|
||||||
@@ -130,9 +154,6 @@ public class CacheServiceImpl implements CacheService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void storeCacheList(CacheList list) {
|
public void storeCacheList(CacheList list) {
|
||||||
OObjectDatabaseTx database = dbService.getDatabase();
|
OObjectDatabaseTx database = dbService.getDatabase();
|
||||||
|
|||||||
Reference in New Issue
Block a user