read and save logs
This commit is contained in:
@@ -26,10 +26,7 @@
|
|||||||
package de.geofroggerfx.dao.jdbc;
|
package de.geofroggerfx.dao.jdbc;
|
||||||
|
|
||||||
import de.geofroggerfx.dao.CacheDAO;
|
import de.geofroggerfx.dao.CacheDAO;
|
||||||
import de.geofroggerfx.model.Attribute;
|
import de.geofroggerfx.model.*;
|
||||||
import de.geofroggerfx.model.Cache;
|
|
||||||
import de.geofroggerfx.model.CacheListEntry;
|
|
||||||
import de.geofroggerfx.model.Waypoint;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
@@ -57,6 +54,7 @@ public class JdbcCacheDAO implements CacheDAO {
|
|||||||
private static final String CACHE_TABLE = "cache";
|
private static final String CACHE_TABLE = "cache";
|
||||||
private static final String WAYPOINT_TABLE = "waypoint";
|
private static final String WAYPOINT_TABLE = "waypoint";
|
||||||
private static final String ATTRIBUTE_TABLE = "attribute";
|
private static final String ATTRIBUTE_TABLE = "attribute";
|
||||||
|
private static final String LOG_TABLE = "log";
|
||||||
|
|
||||||
private String[] columnListCache = new String[] {
|
private String[] columnListCache = new String[] {
|
||||||
"id",
|
"id",
|
||||||
@@ -94,6 +92,15 @@ public class JdbcCacheDAO implements CacheDAO {
|
|||||||
"id",
|
"id",
|
||||||
"cache_id"};
|
"cache_id"};
|
||||||
|
|
||||||
|
private String[] columnListLog = new String[] {
|
||||||
|
"id",
|
||||||
|
"cache_id",
|
||||||
|
"date",
|
||||||
|
"user_id",
|
||||||
|
"type",
|
||||||
|
"text"};
|
||||||
|
|
||||||
|
|
||||||
private JdbcTemplate jdbcTemplate;
|
private JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -107,6 +114,7 @@ public class JdbcCacheDAO implements CacheDAO {
|
|||||||
batchInsertCaches(listOfCaches);
|
batchInsertCaches(listOfCaches);
|
||||||
batchInsertAttributes(listOfCaches);
|
batchInsertAttributes(listOfCaches);
|
||||||
batchInsertWaypoints(listOfCaches);
|
batchInsertWaypoints(listOfCaches);
|
||||||
|
batchInsertLogs(listOfCaches);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -144,6 +152,8 @@ public class JdbcCacheDAO implements CacheDAO {
|
|||||||
waypoint.setCache(cache);
|
waypoint.setCache(cache);
|
||||||
List<Attribute> attributes = getAttributesForCacheId(cache.getId());
|
List<Attribute> attributes = getAttributesForCacheId(cache.getId());
|
||||||
cache.getAttributes().setAll(attributes);
|
cache.getAttributes().setAll(attributes);
|
||||||
|
List<Log> logs = getLogsForCacheId(cache.getId());
|
||||||
|
cache.getLogs().setAll(logs);
|
||||||
return cache;
|
return cache;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -253,6 +263,33 @@ public class JdbcCacheDAO implements CacheDAO {
|
|||||||
LOGGER.info("try to save "+batch.size()+" attributes -> done in "+(endInsert-startInsert)+" ms");
|
LOGGER.info("try to save "+batch.size()+" attributes -> done in "+(endInsert-startInsert)+" ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void batchInsertLogs(List<Cache> listOfCaches) {
|
||||||
|
long startInsert = System.currentTimeMillis();
|
||||||
|
|
||||||
|
List<Object[]> batch = listOfCaches.
|
||||||
|
parallelStream().
|
||||||
|
flatMap(cache -> cache.getLogs().stream().map(log -> valuesFromLog(cache, log))).
|
||||||
|
collect(Collectors.toList());
|
||||||
|
LOGGER.info("try to save "+batch.size()+" logs");
|
||||||
|
|
||||||
|
try {
|
||||||
|
String insertSQL = generateInsertSQL(LOG_TABLE, columnListLog);
|
||||||
|
int[] updateCounts = jdbcTemplate.batchUpdate(
|
||||||
|
insertSQL,
|
||||||
|
batch);
|
||||||
|
int updatedRows = 0;
|
||||||
|
for (int count:updateCounts) {
|
||||||
|
updatedRows += count;
|
||||||
|
}
|
||||||
|
LOGGER.info("batch inserted "+updatedRows+" logs");
|
||||||
|
} catch (Throwable e) {
|
||||||
|
LOGGER.log(Level.SEVERE, e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
long endInsert = System.currentTimeMillis();
|
||||||
|
LOGGER.info("try to save "+batch.size()+" logs -> done in "+(endInsert-startInsert)+" ms");
|
||||||
|
}
|
||||||
|
|
||||||
private Waypoint getWaypointForCacheId(long cacheId) {
|
private Waypoint getWaypointForCacheId(long cacheId) {
|
||||||
return this.jdbcTemplate.queryForObject(
|
return this.jdbcTemplate.queryForObject(
|
||||||
generateSelectSQL(WAYPOINT_TABLE, columnListWaypoint) + " WHERE cache_id=?",
|
generateSelectSQL(WAYPOINT_TABLE, columnListWaypoint) + " WHERE cache_id=?",
|
||||||
@@ -273,6 +310,17 @@ public class JdbcCacheDAO implements CacheDAO {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Log> getLogsForCacheId(long cacheId) {
|
||||||
|
return this.jdbcTemplate.query(
|
||||||
|
generateSelectSQL(LOG_TABLE, columnListLog) + " WHERE cache_id=?",
|
||||||
|
new Object[]{cacheId},
|
||||||
|
(rs, rowNum) -> {
|
||||||
|
return getLogFromResultSet(rs);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Cache getCacheFromResultSet(ResultSet rs) throws SQLException {
|
private Cache getCacheFromResultSet(ResultSet rs) throws SQLException {
|
||||||
@@ -339,6 +387,15 @@ public class JdbcCacheDAO implements CacheDAO {
|
|||||||
return attribute;
|
return attribute;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Log getLogFromResultSet(ResultSet rs) throws SQLException {
|
||||||
|
Log log = new Log();
|
||||||
|
log.setId(rs.getLong("id"));
|
||||||
|
log.setDate(rs.getDate("date"));
|
||||||
|
log.setText(rs.getString("text"));
|
||||||
|
log.setType(LogType.groundspeakStringToType(rs.getString("type")));
|
||||||
|
return log;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private Object[] valuesFromWaypoint(Cache cache) {
|
private Object[] valuesFromWaypoint(Cache cache) {
|
||||||
return new Object[]{
|
return new Object[]{
|
||||||
@@ -362,6 +419,16 @@ public class JdbcCacheDAO implements CacheDAO {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object[] valuesFromLog(Cache cache, Log log) {
|
||||||
|
return new Object[]{
|
||||||
|
log.getId(),
|
||||||
|
cache.getId(),
|
||||||
|
log.getDate(),
|
||||||
|
null, //log.getFinder().getId(),
|
||||||
|
log.getType().toGroundspeakString(),
|
||||||
|
log.getText()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private Object[] valuesFromCache(Cache cache, long id) {
|
private Object[] valuesFromCache(Cache cache, long id) {
|
||||||
return Arrays.asList(valuesFromCache(cache), id).toArray();
|
return Arrays.asList(valuesFromCache(cache), id).toArray();
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ public class GroundspeakGPXReader implements GPXReader {
|
|||||||
|
|
||||||
Waypoint waypoint = null;
|
Waypoint waypoint = null;
|
||||||
Cache cache = null;
|
Cache cache = null;
|
||||||
|
Log log = null;
|
||||||
String currentLevel = null;
|
String currentLevel = null;
|
||||||
String startTag;
|
String startTag;
|
||||||
StringBuffer tagContent = new StringBuffer();
|
StringBuffer tagContent = new StringBuffer();
|
||||||
@@ -150,6 +151,9 @@ public class GroundspeakGPXReader implements GPXReader {
|
|||||||
break;
|
break;
|
||||||
case LOG:
|
case LOG:
|
||||||
currentLevel = LOG;
|
currentLevel = LOG;
|
||||||
|
log = new Log();
|
||||||
|
log.setId(Long.parseLong(reader.getAttributeValue(0)));
|
||||||
|
cache.getLogs().add(log);
|
||||||
break;
|
break;
|
||||||
case ATTRIBUTE:
|
case ATTRIBUTE:
|
||||||
cache.getAttributes().add(
|
cache.getAttributes().add(
|
||||||
@@ -207,7 +211,9 @@ public class GroundspeakGPXReader implements GPXReader {
|
|||||||
case TYPE:
|
case TYPE:
|
||||||
if (CACHE.equals(currentLevel)) {
|
if (CACHE.equals(currentLevel)) {
|
||||||
cache.setType(Type.groundspeakStringToType(tagContent.toString()));
|
cache.setType(Type.groundspeakStringToType(tagContent.toString()));
|
||||||
}
|
} else if (LOG.equals(currentLevel)) {
|
||||||
|
log.setType(LogType.groundspeakStringToType(tagContent.toString()));
|
||||||
|
} else
|
||||||
break;
|
break;
|
||||||
case PLACED_BY:
|
case PLACED_BY:
|
||||||
cache.setPlacedBy(tagContent.toString());
|
cache.setPlacedBy(tagContent.toString());
|
||||||
@@ -241,6 +247,13 @@ public class GroundspeakGPXReader implements GPXReader {
|
|||||||
case ENCODED_HINTS:
|
case ENCODED_HINTS:
|
||||||
cache.setEncodedHints(tagContent.toString());
|
cache.setEncodedHints(tagContent.toString());
|
||||||
break;
|
break;
|
||||||
|
case DATE:
|
||||||
|
log.setDate(DATE_FORMAT.parse(tagContent.toString()));
|
||||||
|
break;
|
||||||
|
case TEXT:
|
||||||
|
log.setText(tagContent.toString());
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public class Cache {
|
|||||||
private BooleanProperty longDescriptionHtml = new SimpleBooleanProperty();
|
private BooleanProperty longDescriptionHtml = new SimpleBooleanProperty();
|
||||||
private StringProperty encodedHints = new SimpleStringProperty();
|
private StringProperty encodedHints = new SimpleStringProperty();
|
||||||
private ObjectProperty<Waypoint> mainWayPoint = new SimpleObjectProperty<>();
|
private ObjectProperty<Waypoint> mainWayPoint = new SimpleObjectProperty<>();
|
||||||
|
private ObjectProperty<ObservableList<Log>> logs = new SimpleObjectProperty<>(FXCollections.observableArrayList());
|
||||||
|
|
||||||
public long getId() {
|
public long getId() {
|
||||||
return id.get();
|
return id.get();
|
||||||
@@ -291,6 +292,18 @@ public class Cache {
|
|||||||
this.mainWayPoint.set(mainWayPoint);
|
this.mainWayPoint.set(mainWayPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ObservableList<Log> getLogs() {
|
||||||
|
return logs.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectProperty<ObservableList<Log>> logsProperty() {
|
||||||
|
return logs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLogs(ObservableList<Log> logs) {
|
||||||
|
this.logs.set(logs);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Cache{" +
|
return "Cache{" +
|
||||||
|
|||||||
77
src/main/java/de/geofroggerfx/model/Log.java
Normal file
77
src/main/java/de/geofroggerfx/model/Log.java
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
package de.geofroggerfx.model;
|
||||||
|
|
||||||
|
import javafx.beans.property.*;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Andreas on 25.03.2015.
|
||||||
|
*/
|
||||||
|
public class Log {
|
||||||
|
|
||||||
|
private LongProperty id = new SimpleLongProperty();
|
||||||
|
private ObjectProperty<Date> date = new SimpleObjectProperty<>();
|
||||||
|
private ObjectProperty<LogType> type = new SimpleObjectProperty<>();
|
||||||
|
private ObjectProperty<User> finder = new SimpleObjectProperty<>();
|
||||||
|
private StringProperty text = new SimpleStringProperty();
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LongProperty idProperty() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id.set(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LogType getType() {
|
||||||
|
return type.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectProperty<LogType> typeProperty() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(LogType type) {
|
||||||
|
this.type.set(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getFinder() {
|
||||||
|
return finder.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectProperty<User> finderProperty() {
|
||||||
|
return finder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFinder(User finder) {
|
||||||
|
this.finder.set(finder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText() {
|
||||||
|
return text.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringProperty textProperty() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setText(String text) {
|
||||||
|
this.text.set(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectProperty<Date> dateProperty() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDate(Date date) {
|
||||||
|
this.date.set(date);
|
||||||
|
}
|
||||||
|
}
|
||||||
44
src/main/java/de/geofroggerfx/model/LogType.java
Normal file
44
src/main/java/de/geofroggerfx/model/LogType.java
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package de.geofroggerfx.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Andreas on 25.03.2015.
|
||||||
|
*/
|
||||||
|
public enum LogType {
|
||||||
|
FOUND_IT("Found it"),
|
||||||
|
WRITE_NOTE("Write note"),
|
||||||
|
ATTENDED("Attended"),
|
||||||
|
WILL_ATTEND("Will Attend"),
|
||||||
|
OWNER_MAINTENANCE("Owner Maintenance"),
|
||||||
|
DIDNT_FIND_IT("Didn't find it"),
|
||||||
|
ENABLE_LISTING("Enable Listing"),
|
||||||
|
PUBLISH_LISTING("Publish Listing"),
|
||||||
|
Needs_Maintenance("Needs Maintenance"),
|
||||||
|
TEMPORARILY_DISABLE_LISTING("Temporarily Disable Listing"),
|
||||||
|
POST_REVIEWER_NOTE("Post Reviewer Note"),
|
||||||
|
ARCHIVE("Archive"),
|
||||||
|
ANNOUNCEMENT("Announcement"),
|
||||||
|
NEEDS_ARCHIVED("Needs Archived"),
|
||||||
|
UPDATE_COORDINATES("Update Coordinates"),
|
||||||
|
WEBCAM_PHOTO_TAKEN("Webcam Photo Taken"),
|
||||||
|
UNARCHIVE("Unarchive"),
|
||||||
|
RETRACT_LISTING("Retract Listing");
|
||||||
|
|
||||||
|
private String groundspeakString;
|
||||||
|
|
||||||
|
private LogType(String groundspeakString) {
|
||||||
|
this.groundspeakString = groundspeakString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toGroundspeakString() {
|
||||||
|
return groundspeakString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LogType groundspeakStringToType(String groundspeakString) {
|
||||||
|
for (LogType t : LogType.values()) {
|
||||||
|
if (t.toGroundspeakString().equals(groundspeakString)) {
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("unknown logtype:" + groundspeakString);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,7 +45,6 @@ public enum Type {
|
|||||||
MEGA_EVENT("Mega-Event Cache"),
|
MEGA_EVENT("Mega-Event Cache"),
|
||||||
MYSTERY_CACHE("Mystery Cache");
|
MYSTERY_CACHE("Mystery Cache");
|
||||||
|
|
||||||
private int id;
|
|
||||||
private String groundspeakString;
|
private String groundspeakString;
|
||||||
|
|
||||||
private Type(String groundspeakString) {
|
private Type(String groundspeakString) {
|
||||||
|
|||||||
11
src/main/resources/de/geofroggerfx/dao/jdbc/updates/3.sql
Normal file
11
src/main/resources/de/geofroggerfx/dao/jdbc/updates/3.sql
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
CREATE TABLE log (
|
||||||
|
id INT PRIMARY KEY ,
|
||||||
|
cache_id INT,
|
||||||
|
date DATETIME,
|
||||||
|
user_id INT,
|
||||||
|
type VARCHAR(100),
|
||||||
|
text VARCHAR(2147483647),
|
||||||
|
FOREIGN KEY(cache_id) REFERENCES cache(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
UPDATE version SET version=3;
|
||||||
Reference in New Issue
Block a user