switch from jpa to orientdb
This commit is contained in:
@@ -53,10 +53,13 @@ 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: 'orient-server', version: '2.0-SNAPSHOT'
|
||||
compile group: 'com.orientechnologies', name: 'orientdb-object', version: '2.0-SNAPSHOT'
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -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
|
||||
|
||||
@@ -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>
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -53,6 +53,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;
|
||||
@@ -227,7 +228,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);
|
||||
|
||||
@@ -36,16 +36,11 @@ 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
|
||||
@@ -95,6 +90,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 +202,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 +257,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 +303,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);
|
||||
}
|
||||
|
||||
@@ -424,12 +422,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 +443,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);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,16 +25,11 @@
|
||||
*/
|
||||
package de.geofroggerfx.model;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
/**
|
||||
* @author Andreas Billmann
|
||||
*/
|
||||
@Entity
|
||||
public class Attribute {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
private boolean inc;
|
||||
private String text;
|
||||
|
||||
@@ -25,16 +25,13 @@
|
||||
*/
|
||||
package de.geofroggerfx.model;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Andreas Billmann
|
||||
*/
|
||||
@Entity
|
||||
public class Cache {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
private boolean available;
|
||||
private boolean archived;
|
||||
@@ -58,7 +55,6 @@ public class Cache {
|
||||
private List<TravelBug> travelBugs;
|
||||
private Waypoint mainWayPoint;
|
||||
|
||||
@OneToOne(fetch=FetchType.LAZY)
|
||||
public Waypoint getMainWayPoint() {
|
||||
return mainWayPoint;
|
||||
}
|
||||
@@ -107,7 +103,6 @@ public class Cache {
|
||||
this.placedBy = placedBy;
|
||||
}
|
||||
|
||||
@OneToOne(fetch=FetchType.LAZY)
|
||||
public User getOwner() {
|
||||
return owner;
|
||||
}
|
||||
@@ -116,7 +111,6 @@ public class Cache {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
@@ -133,7 +127,6 @@ public class Cache {
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
@ManyToMany(fetch=FetchType.LAZY)
|
||||
public List<Attribute> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
@@ -214,7 +207,6 @@ public class Cache {
|
||||
this.encodedHints = encodedHints;
|
||||
}
|
||||
|
||||
@OneToMany(fetch=FetchType.LAZY)
|
||||
public List<Log> getLogs() {
|
||||
return logs;
|
||||
}
|
||||
@@ -223,7 +215,6 @@ public class Cache {
|
||||
this.logs = logs;
|
||||
}
|
||||
|
||||
@OneToMany(fetch=FetchType.LAZY)
|
||||
public List<TravelBug> getTravelBugs() {
|
||||
return travelBugs;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -25,18 +25,16 @@
|
||||
*/
|
||||
package de.geofroggerfx.model;
|
||||
|
||||
import javax.persistence.*;
|
||||
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;
|
||||
private User finder;
|
||||
private boolean textEncoded;
|
||||
@@ -50,11 +48,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 +64,6 @@ public class Log {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@OneToOne(cascade = CascadeType.PERSIST)
|
||||
public User getFinder() {
|
||||
return finder;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,13 +5,15 @@
|
||||
*/
|
||||
package de.geofroggerfx.service;
|
||||
|
||||
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.model.Cache;
|
||||
import de.geofroggerfx.model.CacheList;
|
||||
import de.geofroggerfx.sql.DatabaseService;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -35,10 +37,9 @@ public class CacheServiceImpl implements CacheService {
|
||||
|
||||
@Override
|
||||
public void storeCaches(List<Cache> caches) {
|
||||
EntityManager em = dbService.getEntityManager();
|
||||
OObjectDatabaseTx database = dbService.getDatabase();
|
||||
|
||||
try {
|
||||
int transactionNumber = 0;
|
||||
int currentCacheNumber = 0;
|
||||
int numberOfCaches = caches.size();
|
||||
for (Cache cache : caches) {
|
||||
@@ -48,42 +49,10 @@ public class CacheServiceImpl implements CacheService {
|
||||
"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());
|
||||
}
|
||||
|
||||
for (Attribute attribute: cache.getAttributes()) {
|
||||
em.merge(attribute);
|
||||
}
|
||||
|
||||
for (TravelBug bug: cache.getTravelBugs()) {
|
||||
em.merge(bug);
|
||||
}
|
||||
|
||||
em.merge(cache);
|
||||
|
||||
// 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();
|
||||
database.save(cache);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
|
||||
fireEvent(new ProgressEvent("Database",
|
||||
@@ -98,9 +67,9 @@ public class CacheServiceImpl implements CacheService {
|
||||
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 +91,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 +108,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,14 +122,11 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,14 +135,11 @@ public class CacheServiceImpl implements CacheService {
|
||||
*/
|
||||
@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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user