Merge branch 'nosql'

This commit is contained in:
2014-08-29 00:46:33 +02:00
21 changed files with 495 additions and 263 deletions

View File

@@ -53,10 +53,12 @@ dependencies {
compile files('lib/JFXtras/jfxtras-labs-8.0-r1-SNAPSHOT.jar', 'lib/ScenicView/ScenicView.jar')
compile group: 'org.jdom', name: 'jdom2', version: '2.0.5'
compile group: 'org.controlsfx', name: 'controlsfx', version: '8.0.6'
compile group: 'com.h2database', name: 'h2', version: '1.4.178'
compile group: 'org.eclipse.persistence', name: 'eclipselink', version: '2.5.0'
compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.2.1'
compile group: 'org.jboss.weld.se', name: 'weld-se', version: '2.2.0.Final'
compile group: 'com.orientechnologies', name: 'orient-commons', version: '2.0-SNAPSHOT'
compile group: 'com.orientechnologies', name: 'orientdb-core', version: '2.0-SNAPSHOT'
compile group: 'com.orientechnologies', name: 'orientdb-server', version: '2.0-SNAPSHOT'
compile group: 'com.orientechnologies', name: 'orientdb-object', version: '2.0-SNAPSHOT'
}
///////////////////////////////////////////////////////////////////////////////////

View File

@@ -1,6 +1,6 @@
#Sun Sep 22 11:48:27 CEST 2013
#Fri Aug 15 19:56:32 CEST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.7-bin.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-1.7-all.zip

View File

@@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="geocaches" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>de.geofroggerfx.model.Attribute</class>
<class>de.geofroggerfx.model.Cache</class>
<class>de.geofroggerfx.model.Log</class>
<class>de.geofroggerfx.model.TravelBug</class>
<class>de.geofroggerfx.model.Type</class>
<class>de.geofroggerfx.model.User</class>
<class>de.geofroggerfx.model.Waypoint</class>
<class>de.geofroggerfx.model.CacheList</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:./geofroggerfxdb"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.password" value="sa"/>
<!--<property name="eclipselink.logging.level" value="FINEST"/>-->
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>
</persistence>

View File

@@ -75,10 +75,10 @@ public class SessionContext {
private void fireSessionEvent(String key) {
if (sessionListeners.containsKey(key)) {
final List<SessionContextListener> listenerList = sessionListeners.get(key);
for (final SessionContextListener listener : listenerList) {
listener.sessionContextChanged();
}
sessionListeners.
get(key).
stream().
forEach(SessionContextListener::sessionContextChanged);
}
}
}

View File

@@ -84,7 +84,7 @@ public class GeoFroggerFXMain extends Application {
@Override
public void stop() throws Exception {
weldContainer.instance().select(DatabaseService.class).get().getEntityManager().close();
weldContainer.instance().select(DatabaseService.class).get().close();
weld.shutdown();
super.stop();
}

View File

@@ -25,12 +25,11 @@
*/
package de.geofroggerfx.fx.cachedetails;
import de.geofroggerfx.application.SessionConstants;
import de.geofroggerfx.application.SessionContext;
import de.geofroggerfx.application.SessionContextListener;
import de.geofroggerfx.fx.components.MapPaneWrapper;
import de.geofroggerfx.fx.components.GeocachingIcons;
import de.geofroggerfx.fx.components.IconManager;
import de.geofroggerfx.fx.components.MapPaneWrapper;
import de.geofroggerfx.model.Cache;
import de.geofroggerfx.model.CacheList;
import de.geofroggerfx.service.CacheService;
@@ -53,6 +52,7 @@ import jfxtras.labs.map.render.MapMarkable;
import javax.inject.Inject;
import java.net.URL;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.List;
import java.util.ResourceBundle;
@@ -116,12 +116,6 @@ public class CacheDetailsController implements Initializable, SessionContextList
@Inject
private CacheService cacheService;
/**
* Initializes the controller class.
*
* @param url
* @param rb
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
setSessionListener();
@@ -227,7 +221,7 @@ public class CacheDetailsController implements Initializable, SessionContextList
icon.setImage(GeocachingIcons.getIcon(currentCache));
placedByTextfield.setText(currentCache.getPlacedBy());
ownerTextfield.setText(currentCache.getOwner().getName());
date.setValue(currentCache.getMainWayPoint().getTime().toLocalDate());
date.setValue(currentCache.getMainWayPoint().getTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
typeTextfield.setText(currentCache.getType().toGroundspeakString());
containerTextfield.setText(currentCache.getContainer());
fillShortDescription(currentCache);

View File

@@ -25,7 +25,6 @@
*/
package de.geofroggerfx.fx.cachelist;
import de.geofroggerfx.application.SessionConstants;
import de.geofroggerfx.application.SessionContext;
import de.geofroggerfx.fx.components.CacheListCell;
import de.geofroggerfx.fx.components.IconManager;
@@ -35,14 +34,10 @@ import de.geofroggerfx.model.CacheList;
import de.geofroggerfx.service.CacheService;
import de.geofroggerfx.service.CacheSortField;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.util.Callback;
import org.scenicview.ScenicView;
import javax.inject.Inject;
import java.net.URL;
@@ -84,12 +79,6 @@ public class CacheListController implements Initializable {
@FXML
private ComboBox cacheListComboBox;
/**
* Initializes the controller class.
*
* @param url
* @param rb
*/
@Override
@SuppressWarnings("unchecked")
public void initialize(URL url, ResourceBundle rb) {
@@ -99,10 +88,10 @@ public class CacheListController implements Initializable {
setCellFactory();
cacheListView.getSelectionModel().selectedItemProperty().addListener(
(ChangeListener<Cache>) (ObservableValue<? extends Cache> ov, Cache oldValue, Cache newValue) ->
sessionContext.setData(CURRENT_CACHE, newValue)
observable -> sessionContext.setData(CURRENT_CACHE, cacheListView.getSelectionModel().getSelectedItem())
);
initCacheListComboBox();
initListMenuButton();
}
@@ -110,8 +99,8 @@ public class CacheListController implements Initializable {
@SuppressWarnings("unchecked")
private void setCellFactory() {
cacheListView.setCellFactory(
(Callback<ListView<Cache>, CacheListCell>)
(ListView<Cache> p) -> new CacheListCell());
param -> new CacheListCell()
);
}
private void setSessionListener() {

View File

@@ -26,8 +26,6 @@
package de.geofroggerfx.fx.components;
import de.geofroggerfx.fx.utils.JavaFXUtils;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.layout.Pane;
import jfxtras.labs.map.MapPane;
import jfxtras.labs.map.render.MapMarkable;
@@ -63,20 +61,14 @@ public class MapPaneWrapper extends Pane {
}
private void setSizeListener() {
this.widthProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue observable, Object oldValue, Object newValue) {
this.widthProperty().addListener((observable, oldValue, newValue) -> {
Double width = (Double) newValue;
mapPane.setMapWidth(width);
}
});
this.heightProperty().addListener(new ChangeListener() {
@Override
public void changed(ObservableValue observable, Object oldValue, Object newValue) {
this.heightProperty().addListener((observable, oldValue, newValue) -> {
Double height = (Double) newValue;
mapPane.setMapHeight(height);
}
});
}
}

View File

@@ -36,20 +36,13 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* TODO: describe the class
*
* @author Andreas Billmann
*/
public class GroundspeakGPXReader implements GPXReader {
@@ -95,6 +88,9 @@ public class GroundspeakGPXReader implements GPXReader {
public static final String DEFAULT_NAMESPACE_URL = "http://www.topografix.com/GPX/1/0";
public static final String GROUNDSPEAK_NAMESPACE_URL = "http://www.groundspeak.com/cache/1/0/1";
// 2011-12-03T10:15:30+01:00
private final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
private final List<ProgressListener> listeners = new ArrayList<>();
private final Map<Long, User> userCache = new HashMap<>();
@@ -204,14 +200,14 @@ public class GroundspeakGPXReader implements GPXReader {
final Element cacheElement = waypointElement.getChild(CACHE, groundspeakNamespace);
setId(cacheElement, mainWaypoint);
parseCacheElement(cacheElement, cache);
} catch (DataConversionException | MalformedURLException e) {
} catch (DataConversionException | ParseException e) {
// TODO: do some batch error handling
e.printStackTrace();
}
return cache;
}
private void parseCacheElement(Element cacheElement, Cache cache) throws DataConversionException {
private void parseCacheElement(Element cacheElement, Cache cache) throws DataConversionException, ParseException {
setId(cacheElement, cache);
setAvailable(cacheElement, cache);
setArchived(cacheElement, cache);
@@ -259,7 +255,7 @@ public class GroundspeakGPXReader implements GPXReader {
travelBug.setId(travelBugElement.getAttribute(ID).getLongValue());
}
private void setLogs(Element cacheElement, Cache cache) throws DataConversionException {
private void setLogs(Element cacheElement, Cache cache) throws DataConversionException, ParseException {
final Element logsElement = cacheElement.getChild(LOGS, groundspeakNamespace);
if (logsElement != null) {
final List<Log> logs = new ArrayList<>();
@@ -305,9 +301,9 @@ public class GroundspeakGPXReader implements GPXReader {
log.setId(logElement.getAttribute(ID).getLongValue());
}
private void setDate(Element logElement, Log log) {
private void setDate(Element logElement, Log log) throws ParseException {
final String dateText = logElement.getChild(DATE, groundspeakNamespace).getTextTrim();
final LocalDateTime date = LocalDateTime.parse(dateText, DateTimeFormatter.ISO_DATE_TIME);
final Date date = DATE_FORMAT.parse(dateText);
log.setDate(date);
}
@@ -349,25 +345,17 @@ public class GroundspeakGPXReader implements GPXReader {
final List attributes = new ArrayList<>();
cache.setAttributes(attributes);
for (Element attributeElement : attributesElement.getChildren()) {
final Attribute attribute = new Attribute();
try {
final Attribute attribute = Attribute.groundspeakAttributeToAttribute(
attributeElement.getAttribute(ID).getLongValue(),
attributeElement.getAttribute(INC).getBooleanValue(),
attributeElement.getTextTrim());
attributes.add(attribute);
setId(attributeElement, attribute);
setInc(attributeElement, attribute);
setText(attributeElement, attribute);
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void setText(Element attributeElement, Attribute attribute) {
attribute.setText(attributeElement.getTextTrim());
}
private void setInc(Element attributeElement, Attribute attribute) throws DataConversionException {
attribute.setInc(attributeElement.getAttribute(INC).getBooleanValue());
}
private void setId(Element attributeElement, Attribute attribute) throws DataConversionException {
attribute.setId(attributeElement.getAttribute(ID).getLongValue());
}
private void setContainer(Element cacheElement, Cache cache) {
@@ -424,12 +412,12 @@ public class GroundspeakGPXReader implements GPXReader {
waypoint.setSymbol(cacheElement.getChild(SYM, defaultNamespace).getTextTrim());
}
private void setUrlName(Element cacheElement, Waypoint waypoint) throws MalformedURLException {
private void setUrlName(Element cacheElement, Waypoint waypoint) {
waypoint.setUrlName(cacheElement.getChild(URLNAME, defaultNamespace).getTextTrim());
}
private void setUrl(Element cacheElement, Waypoint waypoint) throws MalformedURLException {
waypoint.setUrl(new URL(cacheElement.getChild(URL, defaultNamespace).getTextTrim()));
private void setUrl(Element cacheElement, Waypoint waypoint) {
waypoint.setUrl(cacheElement.getChild(URL, defaultNamespace).getTextTrim());
}
private void setDescription(Element cacheElement, Waypoint waypoint) {
@@ -445,9 +433,9 @@ public class GroundspeakGPXReader implements GPXReader {
waypoint.setLongitude(cacheElement.getAttribute(LON).getDoubleValue());
}
private void setTime(Element cacheElement, Waypoint waypoint) {
private void setTime(Element cacheElement, Waypoint waypoint) throws ParseException {
final String timeText = cacheElement.getChild(TIME, defaultNamespace).getTextTrim();
final LocalDateTime date = LocalDateTime.parse(timeText, DateTimeFormatter.ISO_DATE_TIME);
final Date date = DATE_FORMAT.parse(timeText);
waypoint.setTime(date);
}

View File

@@ -25,41 +25,319 @@
*/
package de.geofroggerfx.model;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.ArrayList;
import java.util.List;
/**
* @author Andreas Billmann
*/
@Entity
public class Attribute {
public enum Attribute {
@Id
private Long id;
private boolean inc;
private String text;
// id:1 text:Dogs
DOGS_TRUE(1),
DOGS_FALSE(-1),
public Long getId() {
return id;
}
// id:2 text:Access or parking fee
ACCESS_OR_PARKING_FEE_TRUE(2),
ACCESS_OR_PARKING_FEE_FALSE(-2),
public void setId(Long id) {
// id:3 text:Climbing gear
CLIMBING_GEAR_TRUE(3),
CLIMBING_GEAR_FALSE(-3),
// id:4 text:Boat
BOAT_TRUE(4),
BOAT_FALSE(-4),
// id:5 text:Scuba gear
SCUBA_GEAR_TRUE(5),
SCUBA_GEAR_FALSE(-5),
// id:6 text:Recommended for kids
RECOMMENDED_FOR_KIDS_TRUE(6),
RECOMMENDED_FOR_KIDS_FALSE(-6),
// id:7 text:Takes less than an hour
TAKES_LESS_THAN_AN_HOUR_TRUE(7),
TAKES_LESS_THAN_AN_HOUR_FALSE(-7),
// id:8 text:Scenic view
SCENIC_VIEW_TRUE(8),
SCENIC_VIEW_FALSE(-8),
// id:9 text:Significant Hike
SIGNIFICANT_HIKE_TRUE(9),
SIGNIFICANT_HIKE_FALSE(-9),
// id:10 text:Difficult climbing
DIFFICULT_CLIMBING_TRUE(10),
DIFFICULT_CLIMBING_FALSE(-10),
// id:11 text:May require wading
MAY_REQUIRE_WADING_TRUE(11),
MAY_REQUIRE_WADING_FALSE(-11),
// id:12 text:May require swimming
MAY_REQUIRE_SWIMMING_TRUE(12),
MAY_REQUIRE_SWIMMING_FALSE(-12),
// id:13 text:Available at all times
AVAILABLE_AT_ALL_TIMES_TRUE(13),
AVAILABLE_AT_ALL_TIMES_FALSE(-13),
// id:14 text:Recommended at night
RECOMMENDED_AT_NIGHT_TRUE(14),
RECOMMENDED_AT_NIGHT_FALSE(-14),
// id:15 text:Available during winter
AVAILABLE_DURING_WINTER_TRUE(15),
AVAILABLE_DURING_WINTER_FALSE(-15),
// id:17 text:Poison plants
POISON_PLANTS_TRUE(17),
POISON_PLANTS_FALSE(-17),
// id:18 text:Dangerous Animals
DANGEROUS_ANIMALS_TRUE(18),
DANGEROUS_ANIMALS_FALSE(-18),
// id:19 text:Ticks
TICKS_TRUE(19),
TICKS_FALSE(-19),
// id:20 text:Abandoned mines
ABANDONED_MINES_TRUE(20),
ABANDONED_MINES_FALSE(-20),
// id:21 text:Cliff / falling rocks
CLIFF_FALLING_ROCKS_TRUE(21),
CLIFF_FALLING_ROCKS_FALSE(-21),
// id:22 text:Hunting
HUNTING_TRUE(22),
HUNTING_FALSE(-22),
// id:23 text:Dangerous area
DANGEROUS_AREA_TRUE(23),
DANGEROUS_AREA_FALSE(-23),
// id:24 text:Wheelchair accessible
WHEELCHAIR_ACCESSIBLE_TRUE(24),
WHEELCHAIR_ACCESSIBLE_FALSE(-24),
// id:25 text:Parking available
PARKING_AVAILABLE_TRUE(25),
PARKING_AVAILABLE_FALSE(-25),
// id:26 text:Public transportation
PUBLIC_TRANSPORTATION_TRUE(26),
PUBLIC_TRANSPORTATION_FALSE(-26),
// id:27 text:Drinking water nearby
DRINKING_WATER_NEARBY_TRUE(27),
DRINKING_WATER_NEARBY_FALSE(-27),
// id:28 text:Public restrooms nearby
PUBLIC_RESTROOMS_NEARBY_TRUE(28),
PUBLIC_RESTROOMS_NEARBY_FALSE(-28),
// id:29 text:Telephone nearby
TELEPHONE_NEARBY_TRUE(29),
TELEPHONE_NEARBY_FALSE(-29),
// id:30 text:Picnic tables nearby
PICNIC_TABLES_NEARBY_TRUE(30),
PICNIC_TABLES_NEARBY_FALSE(-30),
// id:31 text:Camping available
CAMPING_AVAILABLE_TRUE(31),
CAMPING_AVAILABLE_FALSE(-31),
// id:32 text:Bicycles
BICYCLES_TRUE(32),
BICYCLES_FALSE(-32),
// id:33 text:Motorcycles
MOTORCYCLES_TRUE(33),
MOTORCYCLES_FALSE(-33),
// id:34 text:Quads
QUADS_TRUE(34),
QUADS_FALSE(-34),
// id:35 text:Off-road vehicles
OFF_ROAD_VEHICLES_TRUE(35),
OFF_ROAD_VEHICLES_FALSE(-35),
// id:36 text:Snowmobiles
SNOWMOBILES_TRUE(36),
SNOWMOBILES_FALSE(-36),
// id:37 text:Horses
HORSES_TRUE(37),
HORSES_FALSE(-37),
// id:38 text:Campfires
CAMPFIRES_TRUE(38),
CAMPFIRES_FALSE(-38),
// id:39 text:Thorns
THORNS_TRUE(39),
THORNS_FALSE(-39),
// id:40 text:Stealth required
STEALTH_REQUIRED_TRUE(40),
STEALTH_REQUIRED_FALSE(-40),
// id:41 text:Stroller accessible
STROLLER_ACCESSIBLE_TRUE(41),
STROLLER_ACCESSIBLE_FALSE(-41),
// id:43 text:Watch for livestock
WATCH_FOR_LIVESTOCK_TRUE(43),
WATCH_FOR_LIVESTOCK_FALSE(-43),
// id:42 text:Needs maintenance
NEEDS_MAINTENANCE_TRUE(42),
NEEDS_MAINTENANCE_FALSE(-42),
// id:44 text:Flashlight required
FLASHLIGHT_REQUIRED_TRUE(44),
FLASHLIGHT_REQUIRED_FALSE(-44),
// id:45 text:Lost and Found Tour
LOST_AND_FOUND_TOUR_TRUE(45),
LOST_AND_FOUND_TOUR_FALSE(-45),
// id:46 text:Truck Driver/RV
TRUCK_DRIVER_RV_TRUE(46),
TRUCK_DRIVER_RV_FALSE(-46),
// id:47 text:Field Puzzle
FIELD_PUZZLE_TRUE(47),
FIELD_PUZZLE_FALSE(-47),
// id:48 text:UV Light Required
UV_LIGHT_REQUIRED_TRUE(48),
UV_LIGHT_REQUIRED_FALSE(-48),
// id:49 text:Snowshoes
SNOWSHOES_TRUE(49),
SNOWSHOES_FALSE(-49),
// id:50 text:Cross Country Skis
CROSS_COUNTRY_SKIS_TRUE(50),
CROSS_COUNTRY_SKIS_FALSE(-50),
// id:51 text:Special Tool Required
SPECIAL_TOOL_REQUIRED_TRUE(51),
SPECIAL_TOOL_REQUIRED_FALSE(-51),
// id:52 text:Night Cache
NIGHT_CACHE_TRUE(52),
NIGHT_CACHE_FALSE(-52),
// id:53 text:Park and Grab
PARK_AND_GRAB_TRUE(53),
PARK_AND_GRAB_FALSE(-53),
// id:54 text:Abandoned Structure
ABANDONED_STRUCTURE_TRUE(54),
ABANDONED_STRUCTURE_FALSE(-54),
// id:55 text:Short hike (less than 1km)
SHORT_HIKE_LESS_THAN_1KM_TRUE(55),
SHORT_HIKE_LESS_THAN_1KM_FALSE(-55),
// id:56 text:Medium hike (1km-10km)
MEDIUM_HIKE_1KM_10KM_TRUE(56),
MEDIUM_HIKE_1KM_10KM_FALSE(-56),
// id:57 text:Long Hike (+10km)
LONG_HIKE_10KM_TRUE(57),
LONG_HIKE_10KM_FALSE(-57),
// id:58 text:Fuel Nearby
FUEL_NEARBY_TRUE(58),
FUEL_NEARBY_FALSE(-58),
// id:59 text:Food Nearby
FOOD_NEARBY_TRUE(59),
FOOD_NEARBY_FALSE(-59),
// id:60 text:Wireless Beacon
WIRELESS_BEACON_TRUE(60),
WIRELESS_BEACON_FALSE(-60),
// id:61 text:Partnership cache
PARTNERSHIP_CACHE_TRUE(61),
PARTNERSHIP_CACHE_FALSE(-61),
// id:62 text:Seasonal Access
SEASONAL_ACCESS_TRUE(62),
SEASONAL_ACCESS_FALSE(-62),
// id:63 text:Tourist Friendly
TOURIST_FRIENDLY_TRUE(63),
TOURIST_FRIENDLY_FALSE(-63),
// id:64 text:Tree Climbing
TREE_CLIMBING_TRUE(64),
TREE_CLIMBING_FALSE(-64),
// id:65 text:Front Yard (Private Residence)
FRONT_YARD_PRIVATE_RESIDENCE_TRUE(65),
FRONT_YARD_PRIVATE_RESIDENCE_FALSE(-65),
// id:66 text:Teamwork Required
TEAMWORK_REQUIRED_TRUE(66),
TEAMWORK_REQUIRED_FALSE(-66),
// id:67 text:geotour
GEOTOUR_TRUE(67),
GEOTOUR_FALSE(-67);
private final static List<Long> attributes = new ArrayList<>();
private int id;
private Attribute(int id) {
this.id = id;
}
public boolean isInc() {
return inc;
public int getId() {
return id;
}
public void setInc(boolean inc) {
this.inc = inc;
public void setId(int id) {
this.id = id;
}
public String getText() {
return text;
public static Attribute groundspeakAttributeToAttribute(Long id, boolean inc, String text) {
int idToCompare = id.intValue();
if (!inc) {
idToCompare = -idToCompare;
}
public void setText(String text) {
this.text = text;
for (Attribute t: Attribute.values()) {
if (t.getId() == idToCompare) {
return t;
}
}
if (!attributes.contains(id)) {
attributes.add(id);
System.out.println();
System.out.println("// id:"+id+" text:"+text);
System.out.println(text.toUpperCase().replace(' ','_') + "_TRUE" + "(" + id + "),");
System.out.println(text.toUpperCase().replace(' ','_') + "_FALSE" + "(-" + id + "),");
}
throw new IllegalArgumentException("unknown attribute id:"+id+" inc:"+inc+" text:"+text);
}
}

View File

@@ -25,22 +25,22 @@
*/
package de.geofroggerfx.model;
import javax.persistence.*;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import java.util.List;
/**
* @author Andreas Billmann
*/
@Entity
public class Cache {
@Id
private Long id;
private boolean available;
private boolean archived;
private boolean found;
private String name;
private String placedBy;
@OneToOne(orphanRemoval = true)
private User owner;
private Type type;
private String container;
@@ -54,11 +54,13 @@ public class Cache {
private String longDescription;
private boolean longDescriptionHtml;
private String encodedHints;
@OneToMany(orphanRemoval = true)
private List<Log> logs;
@OneToMany(orphanRemoval = true)
private List<TravelBug> travelBugs;
@OneToOne(orphanRemoval = true)
private Waypoint mainWayPoint;
@OneToOne(fetch=FetchType.LAZY)
public Waypoint getMainWayPoint() {
return mainWayPoint;
}
@@ -107,7 +109,6 @@ public class Cache {
this.placedBy = placedBy;
}
@OneToOne(fetch=FetchType.LAZY)
public User getOwner() {
return owner;
}
@@ -116,7 +117,6 @@ public class Cache {
this.owner = owner;
}
@Enumerated(EnumType.STRING)
public Type getType() {
return type;
}
@@ -133,7 +133,6 @@ public class Cache {
this.container = container;
}
@ManyToMany(fetch=FetchType.LAZY)
public List<Attribute> getAttributes() {
return attributes;
}
@@ -214,7 +213,6 @@ public class Cache {
this.encodedHints = encodedHints;
}
@OneToMany(fetch=FetchType.LAZY)
public List<Log> getLogs() {
return logs;
}
@@ -223,7 +221,6 @@ public class Cache {
this.logs = logs;
}
@OneToMany(fetch=FetchType.LAZY)
public List<TravelBug> getTravelBugs() {
return travelBugs;
}

View File

@@ -25,19 +25,13 @@
*/
package de.geofroggerfx.model;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import java.util.List;
/**
* @author Andreas Billmann
*/
@Entity
public class CacheList {
@Id
private String name;
private List<Cache> caches;
@@ -50,7 +44,6 @@ public class CacheList {
this.name = name;
}
@OneToMany(fetch= FetchType.LAZY)
public List<Cache> getCaches() {
return caches;
}

View File

@@ -25,19 +25,19 @@
*/
package de.geofroggerfx.model;
import javax.persistence.*;
import javax.persistence.OneToOne;
import java.time.LocalDateTime;
import java.util.Date;
/**
* @author Andreas Billmann
*/
@Entity
public class Log {
@Id
private Long id;
private LocalDateTime date;
private Date date;
private String type;
@OneToOne(orphanRemoval = true)
private User finder;
private boolean textEncoded;
private String text;
@@ -50,11 +50,11 @@ public class Log {
this.id = id;
}
public LocalDateTime getDate() {
public Date getDate() {
return date;
}
public void setDate(LocalDateTime date) {
public void setDate(Date date) {
this.date = date;
}
@@ -66,7 +66,6 @@ public class Log {
this.type = type;
}
@OneToOne(cascade = CascadeType.PERSIST)
public User getFinder() {
return finder;
}

View File

@@ -1,17 +1,12 @@
package de.geofroggerfx.model;
import javax.persistence.Entity;
import javax.persistence.Id;
/**
* This class represents the application settings, like current user, etc.
*
* @author abi
*/
@Entity
public class Settings {
@Id
private Long id;
private Long currentUserID = new Long(3906456);

View File

@@ -25,16 +25,11 @@
*/
package de.geofroggerfx.model;
import javax.persistence.Entity;
import javax.persistence.Id;
/**
* @author Andreas Billmann
*/
@Entity
public class TravelBug {
@Id
private Long id;
private String ref;
private String name;

View File

@@ -25,16 +25,11 @@
*/
package de.geofroggerfx.model;
import javax.persistence.Entity;
import javax.persistence.Id;
/**
* @author Andreas Billmann
*/
@Entity
public class User {
@Id
private Long id;
private String name;

View File

@@ -25,25 +25,22 @@
*/
package de.geofroggerfx.model;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.net.URL;
import java.time.LocalDateTime;
import java.util.Date;
/**
* @author Andreas Billmann
*/
@Entity
public class Waypoint {
@Id
private Long id;
private double latitude;
private double longitude;
private String name;
private LocalDateTime time;
private Date time;
private String description;
private URL url;
private String url;
private String urlName;
private String symbol;
private String type;
@@ -72,11 +69,11 @@ public class Waypoint {
this.longitude = longitude;
}
public void setTime(LocalDateTime time) {
public void setTime(Date time) {
this.time = time;
}
public LocalDateTime getTime() {
public Date getTime() {
return time;
}
@@ -96,11 +93,11 @@ public class Waypoint {
this.description = description;
}
public URL getUrl() {
public String getUrl() {
return url;
}
public void setUrl(URL url) {
public void setUrl(String url) {
this.url = url;
}

View File

@@ -43,6 +43,13 @@ public interface CacheService {
*/
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
* @param sortField sort the list based on the field

View File

@@ -1,17 +1,39 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
* Copyright (c) 2013, Andreas Billmann <abi@geofroggerfx.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package de.geofroggerfx.service;
import com.orientechnologies.orient.core.intent.OIntentMassiveInsert;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
import de.geofroggerfx.application.ProgressEvent;
import de.geofroggerfx.application.ProgressListener;
import de.geofroggerfx.model.*;
import de.geofroggerfx.sql.DatabaseService;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import java.util.ArrayList;
import java.util.List;
@@ -20,8 +42,6 @@ import java.util.List;
*/
public class CacheServiceImpl implements CacheService {
private static final int TRANSACTION_SIZE = 100;
@Inject
private DatabaseService dbService;
private final List<ProgressListener> listeners = new ArrayList<>();
@@ -35,72 +55,79 @@ public class CacheServiceImpl implements CacheService {
@Override
public void storeCaches(List<Cache> caches) {
EntityManager em = dbService.getEntityManager();
OObjectDatabaseTx database = dbService.getDatabase();
try {
int transactionNumber = 0;
long start = System.currentTimeMillis();
for (Cache cache : caches) {
Cache existingCache = findCacheById(cache.getId());
if (existingCache != null) {
database.delete(existingCache);
}
}
long deletes = System.currentTimeMillis();
int currentCacheNumber = 0;
int numberOfCaches = caches.size();
database.declareIntent( new OIntentMassiveInsert() );
for (Cache cache : caches) {
currentCacheNumber++;
fireEvent(new ProgressEvent("Database",
ProgressEvent.State.RUNNING,
"Save caches to Database " + currentCacheNumber + " / " + numberOfCaches,
(double) currentCacheNumber / (double) numberOfCaches));
// begin transaction if the transaction counter is set to zero
if (transactionNumber == 0) { em.getTransaction().begin(); }
transactionNumber++;
em.merge(cache.getOwner());
em.merge(cache.getMainWayPoint());
for (Log log: cache.getLogs()) {
em.merge(log);
em.merge(log.getFinder());
database.save(cache);
}
for (Attribute attribute: cache.getAttributes()) {
em.merge(attribute);
}
for (TravelBug bug: cache.getTravelBugs()) {
em.merge(bug);
}
long saves = System.currentTimeMillis();
em.merge(cache);
System.out.println("Time to delete: "+(deletes-start));
System.out.println("Time to save: "+(saves-deletes));
System.out.println("Time total: "+(saves-start));
// comit every X caches
if (transactionNumber == TRANSACTION_SIZE) {
em.getTransaction().commit();
transactionNumber = 0;
}
}
// if there wasn?t a commit right before, commit the rest
if (transactionNumber != 0) {
em.getTransaction().commit();
}
} catch (Exception e) {
e.printStackTrace();
em.getTransaction().rollback();
} finally {
database.declareIntent( null );
}
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));
fireEvent(new ProgressEvent("Database",
ProgressEvent.State.FINISHED,
"Caches are saved to Database"));
}
@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) {
List<Cache> caches = new ArrayList<>();
try {
EntityManager em = dbService.getEntityManager();
String query = "select c from Cache c order by c."+sortField.getFieldName()+" "+direction.toString();
List<Cache> result = em.createQuery(query).getResultList();
OObjectDatabaseTx database = dbService.getDatabase();
String query = "select * from Cache order by "+sortField.getFieldName()+" "+direction.toString();
List<Cache> result = database.query(new OSQLSynchQuery<Cache>(query));
if (result != null) {
caches = result;
}
@@ -122,9 +149,9 @@ public class CacheServiceImpl implements CacheService {
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();
OObjectDatabaseTx database = dbService.getDatabase();
String query = "select * from CacheList order by name";
List<CacheList> result = database.query(new OSQLSynchQuery<CacheList>(query));
if (result != null) {
lists = result;
}
@@ -139,10 +166,12 @@ public class CacheServiceImpl implements CacheService {
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;
OObjectDatabaseTx database = dbService.getDatabase();
String query = "select * from CacheList l where l.name = :name";
List<CacheList> result = database.query(new OSQLSynchQuery<CacheList>(query));
if (result != null) {
doesExist = result.size() > 0;
}
} catch (Exception e) {
e.printStackTrace();
}
@@ -151,30 +180,21 @@ public class CacheServiceImpl implements CacheService {
@Override
public void deleteCacheList(CacheList cacheList) {
EntityManager em = dbService.getEntityManager();
OObjectDatabaseTx database = dbService.getDatabase();
try {
em.getTransaction().begin();
em.remove(cacheList);
em.getTransaction().commit();
database.delete(cacheList);
} catch (Exception e) {
e.printStackTrace();
em.getTransaction().rollback();
}
}
/**
* {@inheritDoc}
*/
@Override
public void storeCacheList(CacheList list) {
EntityManager em = dbService.getEntityManager();
OObjectDatabaseTx database = dbService.getDatabase();
try {
em.getTransaction().begin();
em.merge(list);
em.getTransaction().commit();
database.save(list);
} catch (Exception e) {
e.printStackTrace();
em.getTransaction().rollback();
}
}
}

View File

@@ -25,11 +25,13 @@
*/
package de.geofroggerfx.sql;
import javax.persistence.EntityManager;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
/**
* @author Andreas
*/
public interface DatabaseService {
EntityManager getEntityManager();
OObjectDatabaseTx getDatabase();
void close();
}

View File

@@ -25,9 +25,9 @@
*/
package de.geofroggerfx.sql;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
import com.orientechnologies.orient.core.db.record.ODatabaseRecord;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
/**
* @author Andreas
@@ -35,18 +35,34 @@ import javax.persistence.Persistence;
public class DatabaseServiceImpl implements DatabaseService {
private static final String PERSISTENCE_UNIT_NAME = "geocaches";
private EntityManagerFactory factory;
private EntityManager em;
private OObjectDatabaseTx db ;
public DatabaseServiceImpl() {
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
em = factory.createEntityManager();
db = new OObjectDatabaseTx("plocal:./"+PERSISTENCE_UNIT_NAME);
if (!db.exists()) {
db.create();
} else {
db.open("admin", "admin");
}
db.getEntityManager().registerEntityClasses("de.geofroggerfx.model");
}
@Override
public OObjectDatabaseTx getDatabase() {
assert (db != null) : "no database available";
ODatabaseRecordThreadLocal.INSTANCE.set(db.getUnderlying().getUnderlying());
return db;
}
@Override
public EntityManager getEntityManager() {
assert (em != null) : "no entity manager available";
return em;
public void close() {
assert (db != null) : "no database available";
if (!db.isClosed()) {
db.close();
}
}
}