moved cache merge into the JAXRS layer
This commit is contained in:
@@ -3,6 +3,7 @@ package com.poststats.golf.api;
|
|||||||
import com.brianlong.util.FlexMap;
|
import com.brianlong.util.FlexMap;
|
||||||
import com.poststats.golf.api.model.Course;
|
import com.poststats.golf.api.model.Course;
|
||||||
import com.poststats.golf.service.CourseService;
|
import com.poststats.golf.service.CourseService;
|
||||||
|
import com.poststats.service.FacilityService;
|
||||||
import com.poststats.transformer.impl.DaoConverter;
|
import com.poststats.transformer.impl.DaoConverter;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
@@ -39,6 +40,9 @@ public class CourseApi {
|
|||||||
@Inject
|
@Inject
|
||||||
private CourseService courseService;
|
private CourseService courseService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private FacilityService facilityService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private DaoConverter converter;
|
private DaoConverter converter;
|
||||||
|
|
||||||
@@ -59,6 +63,7 @@ public class CourseApi {
|
|||||||
throw new WebApplicationException("Course not found", Status.NOT_FOUND);
|
throw new WebApplicationException("Course not found", Status.NOT_FOUND);
|
||||||
this.logger.trace("found: {}", this.courseId);
|
this.logger.trace("found: {}", this.courseId);
|
||||||
|
|
||||||
|
this.facilityService.inject("facilityID", row, "facility");
|
||||||
return this.converter.convertValue(row, Course.class);
|
return this.converter.convertValue(row, Course.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||||||
import com.poststats.api.Constants;
|
import com.poststats.api.Constants;
|
||||||
import com.poststats.golf.api.model.Event;
|
import com.poststats.golf.api.model.Event;
|
||||||
import com.poststats.golf.service.EventService;
|
import com.poststats.golf.service.EventService;
|
||||||
|
import com.poststats.golf.service.SeriesService;
|
||||||
import com.poststats.transformer.impl.DaoConverter;
|
import com.poststats.transformer.impl.DaoConverter;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
@@ -38,6 +39,9 @@ public class EventApi {
|
|||||||
@Inject
|
@Inject
|
||||||
private EventService eventService;
|
private EventService eventService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private SeriesService seriesService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private DaoConverter converter;
|
private DaoConverter converter;
|
||||||
|
|
||||||
@@ -61,6 +65,7 @@ public class EventApi {
|
|||||||
if (row == null)
|
if (row == null)
|
||||||
throw new WebApplicationException("Event not found", Status.NOT_FOUND);
|
throw new WebApplicationException("Event not found", Status.NOT_FOUND);
|
||||||
|
|
||||||
|
this.seriesService.inject("seriesID", row, "series");
|
||||||
return this.converter.convertValue(row, Event.class);
|
return this.converter.convertValue(row, Event.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +85,7 @@ public class EventApi {
|
|||||||
if (row == null)
|
if (row == null)
|
||||||
throw new WebApplicationException("Event not found", Status.NOT_FOUND);
|
throw new WebApplicationException("Event not found", Status.NOT_FOUND);
|
||||||
|
|
||||||
|
this.seriesService.inject("seriesID", row, "series");
|
||||||
return this.converter.convertValue(row, Event.class);
|
return this.converter.convertValue(row, Event.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@ package com.poststats.golf.api;
|
|||||||
import com.brianlong.util.FlexMap;
|
import com.brianlong.util.FlexMap;
|
||||||
import com.poststats.api.Constants;
|
import com.poststats.api.Constants;
|
||||||
import com.poststats.golf.api.model.EventRound;
|
import com.poststats.golf.api.model.EventRound;
|
||||||
|
import com.poststats.golf.service.CourseService;
|
||||||
import com.poststats.golf.service.EventRoundService;
|
import com.poststats.golf.service.EventRoundService;
|
||||||
import com.poststats.transformer.impl.DaoConverter;
|
import com.poststats.transformer.impl.DaoConverter;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
@@ -39,6 +40,9 @@ public class EventRoundApi {
|
|||||||
@Inject
|
@Inject
|
||||||
private EventRoundService roundService;
|
private EventRoundService roundService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private CourseService courseService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private DaoConverter converter;
|
private DaoConverter converter;
|
||||||
|
|
||||||
@@ -48,7 +52,7 @@ public class EventRoundApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/r{number}")
|
@Path("/rounds/next")
|
||||||
@Produces(Constants.V1_JSON)
|
@Produces(Constants.V1_JSON)
|
||||||
@Operation(
|
@Operation(
|
||||||
summary = "Retrieves limited meta-data about an event.",
|
summary = "Retrieves limited meta-data about an event.",
|
||||||
@@ -56,18 +60,22 @@ public class EventRoundApi {
|
|||||||
)
|
)
|
||||||
@ApiResponses({
|
@ApiResponses({
|
||||||
@ApiResponse(responseCode = "200", description = "Success"),
|
@ApiResponse(responseCode = "200", description = "Success"),
|
||||||
@ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found")
|
@ApiResponse(
|
||||||
|
responseCode = "404",
|
||||||
|
description = "An event with the specified ID or upcoming event rounds could not be found"
|
||||||
|
)
|
||||||
})
|
})
|
||||||
public EventRound getOne(@PathParam("number") short roundNumber) {
|
public List<EventRound> getNext() {
|
||||||
FlexMap row = this.roundService.get(this.eventId, roundNumber);
|
List<? extends FlexMap> rows = this.roundService.getUpcoming(this.eventId);
|
||||||
if (row == null)
|
if (rows == null || rows.isEmpty())
|
||||||
throw new WebApplicationException("Event round not found", Status.NOT_FOUND);
|
throw new WebApplicationException("No event round was found", Status.NOT_FOUND);
|
||||||
|
|
||||||
return this.converter.convertValue(row, EventRound.class);
|
this.courseService.injectDeep("courseID", rows, "course");
|
||||||
|
return this.converter.convertValue(rows, EventRound.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/round/{eroundId}")
|
@Path("/round/{eroundId:[0-9]+}")
|
||||||
@Produces(Constants.V1_JSON)
|
@Produces(Constants.V1_JSON)
|
||||||
@Operation(
|
@Operation(
|
||||||
summary = "Retrieves limited meta-data about an event.",
|
summary = "Retrieves limited meta-data about an event.",
|
||||||
@@ -75,7 +83,10 @@ public class EventRoundApi {
|
|||||||
)
|
)
|
||||||
@ApiResponses({
|
@ApiResponses({
|
||||||
@ApiResponse(responseCode = "200", description = "Success"),
|
@ApiResponse(responseCode = "200", description = "Success"),
|
||||||
@ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found")
|
@ApiResponse(
|
||||||
|
responseCode = "404",
|
||||||
|
description = "An event or event round with the specified ID could not be found"
|
||||||
|
)
|
||||||
})
|
})
|
||||||
public EventRound getOne(@PathParam("eroundId") long eroundId) {
|
public EventRound getOne(@PathParam("eroundId") long eroundId) {
|
||||||
FlexMap row = this.roundService.get(eroundId);
|
FlexMap row = this.roundService.get(eroundId);
|
||||||
@@ -87,6 +98,7 @@ public class EventRoundApi {
|
|||||||
throw new WebApplicationException("Event round not found", Status.NOT_FOUND);
|
throw new WebApplicationException("Event round not found", Status.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.courseService.injectDeep("courseID", row, "course");
|
||||||
return this.converter.convertValue(row, EventRound.class);
|
return this.converter.convertValue(row, EventRound.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +111,10 @@ public class EventRoundApi {
|
|||||||
)
|
)
|
||||||
@ApiResponses({
|
@ApiResponses({
|
||||||
@ApiResponse(responseCode = "200", description = "Success"),
|
@ApiResponse(responseCode = "200", description = "Success"),
|
||||||
@ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found")
|
@ApiResponse(
|
||||||
|
responseCode = "404",
|
||||||
|
description = "An event with the specified ID or any event rounds could not be found"
|
||||||
|
)
|
||||||
})
|
})
|
||||||
public List<EventRound> getAll() {
|
public List<EventRound> getAll() {
|
||||||
Map<Long, ? extends FlexMap> rows = this.roundService.getByEventId(this.eventId);
|
Map<Long, ? extends FlexMap> rows = this.roundService.getByEventId(this.eventId);
|
||||||
|
@@ -38,6 +38,9 @@ public class GolferApi {
|
|||||||
@Inject
|
@Inject
|
||||||
private PersonService personService;
|
private PersonService personService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private com.poststats.service.PersonService poststatsPersonService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private DaoConverter converter;
|
private DaoConverter converter;
|
||||||
|
|
||||||
@@ -61,6 +64,7 @@ public class GolferApi {
|
|||||||
if (row == null)
|
if (row == null)
|
||||||
throw new WebApplicationException("Event not found", Status.NOT_FOUND);
|
throw new WebApplicationException("Event not found", Status.NOT_FOUND);
|
||||||
|
|
||||||
|
this.poststatsPersonService.inject("personID", row, "person");
|
||||||
return this.converter.convertValue(row, Golfer.class);
|
return this.converter.convertValue(row, Golfer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@ public abstract class BaseCourse<ConcreteT extends BaseCourse<ConcreteT>> extend
|
|||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
@MapEntry("coursePrefix")
|
@MapEntry("prefix")
|
||||||
private String namePrefix;
|
private String namePrefix;
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
|
@@ -28,6 +28,10 @@ public interface CourseService extends CacheableService<Integer> {
|
|||||||
*/
|
*/
|
||||||
Map<Integer, ? extends FlexMap> get(Collection<Integer> courseIds);
|
Map<Integer, ? extends FlexMap> get(Collection<Integer> courseIds);
|
||||||
|
|
||||||
|
FlexMap injectDeep(String idKey, FlexMap parentMap, String mapKey);
|
||||||
|
|
||||||
|
Collection<? extends FlexMap> injectDeep(String idKey, Collection<? extends FlexMap> parentMaps, String mapKey);
|
||||||
|
|
||||||
default SubList<? extends FlexMap> findByName(String name) {
|
default SubList<? extends FlexMap> findByName(String name) {
|
||||||
return this.findByName(name, 1, 10);
|
return this.findByName(name, 1, 10);
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package com.poststats.golf.service;
|
package com.poststats.golf.service;
|
||||||
|
|
||||||
import com.brianlong.util.FlexMap;
|
import com.brianlong.util.FlexMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface EventRoundService {
|
public interface EventRoundService {
|
||||||
@@ -14,13 +15,16 @@ public interface EventRoundService {
|
|||||||
FlexMap get(long eroundId);
|
FlexMap get(long eroundId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method retrieves meta-data about the specified event round.
|
* This method retrieves meta-data about the next event round in the specified
|
||||||
|
* event.
|
||||||
|
*
|
||||||
|
* It will only return more than one event round if the next date has more than
|
||||||
|
* one round. It will return today's round(s) until 6p EST.
|
||||||
*
|
*
|
||||||
* @param eventId A unique identifier for the event.
|
* @param eventId A unique identifier for the event.
|
||||||
* @param number A sequential number for the event round, starting with 1.
|
* @return A list of meta-data about each event round.
|
||||||
* @return A map of meta-data specific to the event round.
|
|
||||||
*/
|
*/
|
||||||
FlexMap get(long eventId, short number);
|
List<? extends FlexMap> getUpcoming(long eventId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method retrieves meta-data about the specified event rounds.
|
* This method retrieves meta-data about the specified event rounds.
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package com.poststats.golf.service.db;
|
package com.poststats.golf.service.db;
|
||||||
|
|
||||||
import com.brianlong.sql.DataSet;
|
import com.brianlong.sql.DataSet;
|
||||||
|
import com.brianlong.sql.FlexManyToOneDef;
|
||||||
import com.brianlong.sql.FlexPreparedStatement;
|
import com.brianlong.sql.FlexPreparedStatement;
|
||||||
import com.brianlong.sql.ResultSubSetFeature;
|
import com.brianlong.sql.ResultSubSetFeature;
|
||||||
import com.brianlong.util.FlexMap;
|
import com.brianlong.util.FlexMap;
|
||||||
@@ -24,6 +25,7 @@ import java.util.Map;
|
|||||||
public class CourseServiceDAO extends CacheableServiceDAO<Integer> implements CourseService {
|
public class CourseServiceDAO extends CacheableServiceDAO<Integer> implements CourseService {
|
||||||
|
|
||||||
private final int defaultCacheExpirationInSeconds = 600;
|
private final int defaultCacheExpirationInSeconds = 600;
|
||||||
|
private final FlexManyToOneDef facilityManyToOneDef = new FlexManyToOneDef("facilityID", "facility");
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private FacilityService facilityService;
|
private FacilityService facilityService;
|
||||||
@@ -34,27 +36,20 @@ public class CourseServiceDAO extends CacheableServiceDAO<Integer> implements Co
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FlexMap get(Integer courseId) {
|
public FlexMap injectDeep(String idKey, FlexMap parentMap, String mapKey) {
|
||||||
FlexMap row = super.get(Integer.valueOf(courseId));
|
FlexMap map = this.inject(idKey, parentMap, mapKey);
|
||||||
if (row == null)
|
return this.facilityService.inject("facilityID", map, "facility");
|
||||||
return null;
|
|
||||||
|
|
||||||
this.injectCache(row, this.facilityService, "facilityID", "facility");
|
|
||||||
return row;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Integer, ? extends FlexMap> get(Collection<Integer> courseIds) {
|
public Collection<? extends FlexMap> injectDeep(String idKey, Collection<? extends FlexMap> parentMaps,
|
||||||
Map<Integer, ? extends FlexMap> rows = super.get(courseIds);
|
String mapKey) {
|
||||||
|
Collection<? extends FlexMap> maps = this.inject(idKey, parentMaps, mapKey);
|
||||||
this.injectCache(rows.values(), this.facilityService, "facilityID", "facility");
|
return this.facilityService.inject("facilityID", maps, "facility");
|
||||||
return rows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SubList<? extends FlexMap> findByName(String name, int page, int perPage) {
|
public SubList<? extends FlexMap> findByName(String name, int page, int perPage) {
|
||||||
SubList<? extends FlexMap> rows;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FlexPreparedStatement fps = this.sqlSelectByName.buildPreparedStatement();
|
FlexPreparedStatement fps = this.sqlSelectByName.buildPreparedStatement();
|
||||||
try {
|
try {
|
||||||
@@ -62,34 +57,32 @@ public class CourseServiceDAO extends CacheableServiceDAO<Integer> implements Co
|
|||||||
fps.setVarchar(2, "%" + name + "%");
|
fps.setVarchar(2, "%" + name + "%");
|
||||||
fps.setSmallintU(3, (page - 1) * perPage);
|
fps.setSmallintU(3, (page - 1) * perPage);
|
||||||
fps.setSmallintU(4, perPage);
|
fps.setSmallintU(4, perPage);
|
||||||
rows = (SubList<? extends FlexMap>) fps.executeQuery().getAllRows();
|
return (SubList<? extends FlexMap>) fps.executeQuery().getAllRows(this.facilityManyToOneDef);
|
||||||
} finally {
|
} finally {
|
||||||
fps.close();
|
fps.close();
|
||||||
}
|
}
|
||||||
} catch (SQLException se) {
|
} catch (SQLException se) {
|
||||||
throw new ServiceException(se);
|
throw new ServiceException(se);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.injectCache(rows, this.facilityService, "facilityID", "facility");
|
|
||||||
return rows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named(Constants.STATEMENT_PROVIDER_GOLF)
|
@Named(Constants.STATEMENT_PROVIDER_GOLF)
|
||||||
@Statement(
|
@Statement(
|
||||||
feature = ResultSubSetFeature.class,
|
feature = ResultSubSetFeature.class,
|
||||||
sql = "SELECT CP.*, C.* "
|
sql = "SELECT C.courseID, C.course, C.access, CP.prefix, "
|
||||||
|
+ " F.*, FP.prefix, FS.suffix, FS.suffixAbbrev "
|
||||||
+ "FROM ~g~.Course C "
|
+ "FROM ~g~.Course C "
|
||||||
+ " LEFT JOIN ~g~.CoursePrefix CP ON (C.prefixID=CP.prefixID) "
|
+ " LEFT JOIN ~g~.CoursePrefix CP ON (C.prefixID=CP.prefixID) "
|
||||||
+ " INNER JOIN ~p~.Facility F ON (C.facilityID=F.facilityID) "
|
+ " INNER JOIN ~p~.Facility F ON (C.facilityID=F.facilityID) "
|
||||||
+ "WHERE course LIKE ? OR facility LIKE ? "
|
+ " LEFT JOIN ~p~.FacilityPrefix FP ON (F.prefixID=FP.prefixID) "
|
||||||
|
+ " LEFT JOIN ~p~.FacilitySuffix FS ON (F.suffixID=FS.suffixID) "
|
||||||
|
+ "WHERE C.course LIKE ? OR F.facility LIKE ? "
|
||||||
)
|
)
|
||||||
private StatementProvider sqlSelectByName;
|
private StatementProvider sqlSelectByName;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SubList<? extends FlexMap> findByJurisdiction(String country, String state, int page, int perPage) {
|
public SubList<? extends FlexMap> findByJurisdiction(String country, String state, int page, int perPage) {
|
||||||
SubList<? extends FlexMap> rows;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FlexPreparedStatement fps = this.sqlSelectByJurisdiction.buildPreparedStatement();
|
FlexPreparedStatement fps = this.sqlSelectByJurisdiction.buildPreparedStatement();
|
||||||
try {
|
try {
|
||||||
@@ -97,26 +90,26 @@ public class CourseServiceDAO extends CacheableServiceDAO<Integer> implements Co
|
|||||||
fps.setVarchar(2, state);
|
fps.setVarchar(2, state);
|
||||||
fps.setSmallintU(3, (page - 1) * perPage);
|
fps.setSmallintU(3, (page - 1) * perPage);
|
||||||
fps.setSmallintU(4, perPage);
|
fps.setSmallintU(4, perPage);
|
||||||
rows = (SubList<? extends FlexMap>) fps.executeQuery().getAllRows();
|
return (SubList<? extends FlexMap>) fps.executeQuery().getAllRows(this.facilityManyToOneDef);
|
||||||
} finally {
|
} finally {
|
||||||
fps.close();
|
fps.close();
|
||||||
}
|
}
|
||||||
} catch (SQLException se) {
|
} catch (SQLException se) {
|
||||||
throw new ServiceException(se);
|
throw new ServiceException(se);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.injectCache(rows, this.facilityService, "facilityID", "facility");
|
|
||||||
return rows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named(Constants.STATEMENT_PROVIDER_GOLF)
|
@Named(Constants.STATEMENT_PROVIDER_GOLF)
|
||||||
@Statement(
|
@Statement(
|
||||||
feature = ResultSubSetFeature.class,
|
feature = ResultSubSetFeature.class,
|
||||||
sql = "SELECT CP.*, C.* "
|
sql = "SELECT C.courseID, C.course, C.access, CP.prefix, "
|
||||||
|
+ " F.*, FP.prefix, FS.suffix, FS.suffixAbbrev "
|
||||||
+ "FROM ~g~.Course C "
|
+ "FROM ~g~.Course C "
|
||||||
+ " LEFT JOIN ~g~.CoursePrefix CP ON (C.prefixID=CP.prefixID) "
|
+ " LEFT JOIN ~g~.CoursePrefix CP ON (C.prefixID=CP.prefixID) "
|
||||||
+ " INNER JOIN ~p~.Facility F ON (C.facilityID=F.facilityID) "
|
+ " INNER JOIN ~p~.Facility F ON (C.facilityID=F.facilityID) "
|
||||||
|
+ " LEFT JOIN ~p~.FacilityPrefix FP ON (F.prefixID=FP.prefixID) "
|
||||||
|
+ " LEFT JOIN ~p~.FacilitySuffix FS ON (F.suffixID=FS.suffixID) "
|
||||||
+ "WHERE F.addrcountry=? AND F.addrstate=? "
|
+ "WHERE F.addrcountry=? AND F.addrstate=? "
|
||||||
+ " AND C.deadline IS NULL "
|
+ " AND C.deadline IS NULL "
|
||||||
)
|
)
|
||||||
@@ -126,7 +119,6 @@ public class CourseServiceDAO extends CacheableServiceDAO<Integer> implements Co
|
|||||||
public SubList<? extends FlexMap> findByLocation(double latitude, double longitude, int radiusInMiles, int page,
|
public SubList<? extends FlexMap> findByLocation(double latitude, double longitude, int radiusInMiles, int page,
|
||||||
int perPage) {
|
int perPage) {
|
||||||
double degrees = PostStatsSQL.miles2degrees(radiusInMiles);
|
double degrees = PostStatsSQL.miles2degrees(radiusInMiles);
|
||||||
SubList<? extends FlexMap> rows;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FlexPreparedStatement fps = this.sqlSelectByGeolocation.buildPreparedStatement();
|
FlexPreparedStatement fps = this.sqlSelectByGeolocation.buildPreparedStatement();
|
||||||
@@ -137,26 +129,26 @@ public class CourseServiceDAO extends CacheableServiceDAO<Integer> implements Co
|
|||||||
fps.setDouble(4, longitude + degrees);
|
fps.setDouble(4, longitude + degrees);
|
||||||
fps.setSmallintU(5, (page - 1) * perPage);
|
fps.setSmallintU(5, (page - 1) * perPage);
|
||||||
fps.setSmallintU(6, perPage);
|
fps.setSmallintU(6, perPage);
|
||||||
rows = (SubList<? extends FlexMap>) fps.executeQuery().getAllRows();
|
return (SubList<? extends FlexMap>) fps.executeQuery().getAllRows(this.facilityManyToOneDef);
|
||||||
} finally {
|
} finally {
|
||||||
fps.close();
|
fps.close();
|
||||||
}
|
}
|
||||||
} catch (SQLException se) {
|
} catch (SQLException se) {
|
||||||
throw new ServiceException(se);
|
throw new ServiceException(se);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.injectCache(rows, this.facilityService, "facilityID", "facility");
|
|
||||||
return rows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named(Constants.STATEMENT_PROVIDER_GOLF)
|
@Named(Constants.STATEMENT_PROVIDER_GOLF)
|
||||||
@Statement(
|
@Statement(
|
||||||
feature = ResultSubSetFeature.class,
|
feature = ResultSubSetFeature.class,
|
||||||
sql = "SELECT CP.*, C.* "
|
sql = "SELECT C.courseID, C.course, C.access, CP.prefix, "
|
||||||
|
+ " F.*, FP.prefix, FS.suffix, FS.suffixAbbrev "
|
||||||
+ "FROM ~g~.Course C "
|
+ "FROM ~g~.Course C "
|
||||||
+ " LEFT JOIN ~g~.CoursePrefix CP ON (C.prefixID=CP.prefixID) "
|
+ " LEFT JOIN ~g~.CoursePrefix CP ON (C.prefixID=CP.prefixID) "
|
||||||
+ " INNER JOIN ~p~.Facility F ON (C.facilityID=F.facilityID) "
|
+ " INNER JOIN ~p~.Facility F ON (C.facilityID=F.facilityID) "
|
||||||
|
+ " LEFT JOIN ~p~.FacilityPrefix FP ON (F.prefixID=FP.prefixID) "
|
||||||
|
+ " LEFT JOIN ~p~.FacilitySuffix FS ON (F.suffixID=FS.suffixID) "
|
||||||
+ "WHERE F.latitude>=? AND F.latitude<=? AND F.longitude>=? AND F.longitude<=? "
|
+ "WHERE F.latitude>=? AND F.latitude<=? AND F.longitude>=? AND F.longitude<=? "
|
||||||
+ " AND C.deadline IS NULL "
|
+ " AND C.deadline IS NULL "
|
||||||
)
|
)
|
||||||
@@ -181,13 +173,10 @@ public class CourseServiceDAO extends CacheableServiceDAO<Integer> implements Co
|
|||||||
@Inject
|
@Inject
|
||||||
@Named(Constants.STATEMENT_PROVIDER_GOLF)
|
@Named(Constants.STATEMENT_PROVIDER_GOLF)
|
||||||
@Statement(
|
@Statement(
|
||||||
sql = "SELECT FP.*, FS.*, F.*, CP.prefix coursePrefix, C.* "
|
sql = "SELECT CP.*, C.* "
|
||||||
+ "FROM ~g~.Course C "
|
+ "FROM ~g~.Course C "
|
||||||
+ " LEFT JOIN ~g~.CoursePrefix CP ON (C.prefixID=CP.prefixID) "
|
+ " LEFT JOIN ~g~.CoursePrefix CP ON (C.prefixID=CP.prefixID) "
|
||||||
+ " INNER JOIN ~p~.Facility F ON (C.facilityID=F.facilityID) "
|
+ "WHERE C.courseID=? "
|
||||||
+ " LEFT JOIN ~p~.FacilityPrefix FP ON (F.prefixID=FP.prefixID) "
|
|
||||||
+ " LEFT JOIN ~p~.FacilitySuffix FS ON (F.suffixID=FS.suffixID) "
|
|
||||||
+ "WHERE courseID=? "
|
|
||||||
)
|
)
|
||||||
private StatementProvider sqlSelectCourse;
|
private StatementProvider sqlSelectCourse;
|
||||||
|
|
||||||
@@ -202,15 +191,12 @@ public class CourseServiceDAO extends CacheableServiceDAO<Integer> implements Co
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named(Constants.STATEMENT_PROVIDER_POSTSTATS)
|
@Named(Constants.STATEMENT_PROVIDER_GOLF)
|
||||||
@Statement(
|
@Statement(
|
||||||
sql = "SELECT FP.*, FS.*, F.*, CP.prefix coursePrefix, C.* "
|
sql = "SELECT CP.*, C.* "
|
||||||
+ "FROM ~g~.Course C "
|
+ "FROM ~g~.Course C "
|
||||||
+ " LEFT JOIN ~g~.CoursePrefix CP ON (C.prefixID=CP.prefixID) "
|
+ " LEFT JOIN ~g~.CoursePrefix CP ON (C.prefixID=CP.prefixID) "
|
||||||
+ " INNER JOIN ~p~.Facility F ON (C.facilityID=F.facilityID) "
|
+ "WHERE C.courseID IN (??) "
|
||||||
+ " LEFT JOIN ~p~.FacilityPrefix FP ON (F.prefixID=FP.prefixID) "
|
|
||||||
+ " LEFT JOIN ~p~.FacilitySuffix FS ON (F.suffixID=FS.suffixID) "
|
|
||||||
+ "WHERE courseID IN (??) "
|
|
||||||
)
|
)
|
||||||
private StatementProvider sqlSelectCourses;
|
private StatementProvider sqlSelectCourses;
|
||||||
|
|
||||||
|
@@ -4,7 +4,6 @@ import com.brianlong.sql.DataSet;
|
|||||||
import com.brianlong.sql.FlexPreparedStatement;
|
import com.brianlong.sql.FlexPreparedStatement;
|
||||||
import com.brianlong.util.FlexMap;
|
import com.brianlong.util.FlexMap;
|
||||||
import com.poststats.golf.api.Constants;
|
import com.poststats.golf.api.Constants;
|
||||||
import com.poststats.golf.service.CourseService;
|
|
||||||
import com.poststats.golf.service.EventRoundService;
|
import com.poststats.golf.service.EventRoundService;
|
||||||
import com.poststats.provider.Statement;
|
import com.poststats.provider.Statement;
|
||||||
import com.poststats.provider.StatementProvider;
|
import com.poststats.provider.StatementProvider;
|
||||||
@@ -14,7 +13,9 @@ import jakarta.enterprise.context.ApplicationScoped;
|
|||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import jakarta.inject.Named;
|
import jakarta.inject.Named;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
@@ -22,33 +23,23 @@ public class EventRoundServiceDAO extends CacheableServiceDAO<Long> implements E
|
|||||||
|
|
||||||
private final long defaultCacheExpirationInSeconds = 3600;
|
private final long defaultCacheExpirationInSeconds = 3600;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private CourseService courseService;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FlexMap get(long eroundId) {
|
public FlexMap get(long eroundId) {
|
||||||
return this.get(Long.valueOf(eroundId));
|
return this.get(Long.valueOf(eroundId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FlexMap get(Long eventId) {
|
public List<? extends FlexMap> getUpcoming(long eventId) {
|
||||||
FlexMap row = super.get(Long.valueOf(eventId));
|
LocalDateTime now = LocalDateTime.now();
|
||||||
if (row == null)
|
if (now.getHour() > 17)
|
||||||
return null;
|
now.plusDays(1);
|
||||||
|
|
||||||
this.injectCache(row, this.courseService, "courseID", "course");
|
|
||||||
row.put("course", this.courseService.get(row.getInteger("courseID")));
|
|
||||||
return row;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FlexMap get(long eventId, short number) {
|
|
||||||
try {
|
try {
|
||||||
FlexPreparedStatement fps = this.sqlSelectByNumber.buildPreparedStatement();
|
FlexPreparedStatement fps = this.sqlSelectUpcoming.buildPreparedStatement();
|
||||||
try {
|
try {
|
||||||
fps.setIntegerU(1, eventId);
|
fps.setIntegerU(1, eventId);
|
||||||
fps.setTinyintU(2, number);
|
fps.setDate(2, now.toLocalDate());
|
||||||
return fps.executeQuery().getNextRow();
|
return fps.executeQuery().getAllRows();
|
||||||
} finally {
|
} finally {
|
||||||
fps.close();
|
fps.close();
|
||||||
}
|
}
|
||||||
@@ -63,9 +54,9 @@ public class EventRoundServiceDAO extends CacheableServiceDAO<Long> implements E
|
|||||||
sql = "SELECT TF.*, ER.* "
|
sql = "SELECT TF.*, ER.* "
|
||||||
+ "FROM ~g~.EventRound ER "
|
+ "FROM ~g~.EventRound ER "
|
||||||
+ " LEFT JOIN ~g~.TeeFormat TF ON (ER.teeFormatID=TF.teeFormatID) "
|
+ " LEFT JOIN ~g~.TeeFormat TF ON (ER.teeFormatID=TF.teeFormatID) "
|
||||||
+ "WHERE ER.eventID=? AND ER.round=? "
|
+ "WHERE ER.eventID=? AND ER.date>=? AND MIN(ER.date)=ER.date "
|
||||||
)
|
)
|
||||||
private StatementProvider sqlSelectByNumber;
|
private StatementProvider sqlSelectUpcoming;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Long, DataSet> getByEventId(long eventId) {
|
public Map<Long, DataSet> getByEventId(long eventId) {
|
||||||
|
@@ -5,7 +5,6 @@ import com.brianlong.sql.FlexPreparedStatement;
|
|||||||
import com.brianlong.util.FlexMap;
|
import com.brianlong.util.FlexMap;
|
||||||
import com.poststats.golf.api.Constants;
|
import com.poststats.golf.api.Constants;
|
||||||
import com.poststats.golf.service.EventService;
|
import com.poststats.golf.service.EventService;
|
||||||
import com.poststats.golf.service.SeriesService;
|
|
||||||
import com.poststats.provider.Statement;
|
import com.poststats.provider.Statement;
|
||||||
import com.poststats.provider.StatementProvider;
|
import com.poststats.provider.StatementProvider;
|
||||||
import com.poststats.service.ServiceException;
|
import com.poststats.service.ServiceException;
|
||||||
@@ -24,32 +23,11 @@ public class EventServiceDAO extends CacheableServiceDAO<Long> implements EventS
|
|||||||
|
|
||||||
private final long defaultCacheExpirationInSeconds = 3600;
|
private final long defaultCacheExpirationInSeconds = 3600;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private SeriesService seriesService;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FlexMap get(long eventId) {
|
public FlexMap get(long eventId) {
|
||||||
return this.get(Long.valueOf(eventId));
|
return this.get(Long.valueOf(eventId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public FlexMap get(Long eventId) {
|
|
||||||
FlexMap row = super.get(Long.valueOf(eventId));
|
|
||||||
if (row == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
this.injectCache(row, this.seriesService, "seriesID", "series");
|
|
||||||
return row;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<Long, ? extends FlexMap> get(Collection<Long> eventIds) {
|
|
||||||
Map<Long, ? extends FlexMap> rows = super.get(eventIds);
|
|
||||||
|
|
||||||
this.injectCache(rows.values(), this.seriesService, "seriesID", "series");
|
|
||||||
return rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Long> getIdsBySeriesId(int seriesId) {
|
public Set<Long> getIdsBySeriesId(int seriesId) {
|
||||||
try {
|
try {
|
||||||
|
@@ -68,24 +68,6 @@ public class PersonServiceDAO extends CacheableServiceDAO<Long> implements Perso
|
|||||||
return this.get(Long.valueOf(personId));
|
return this.get(Long.valueOf(personId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public FlexMap get(Long personId) {
|
|
||||||
FlexMap row = this.get(Long.valueOf(personId));
|
|
||||||
if (row == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
this.injectCache(row, this.poststatsPersonService, "personID", "person");
|
|
||||||
return row;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<Long, ? extends FlexMap> get(Collection<Long> ids) {
|
|
||||||
Map<Long, ? extends FlexMap> rows = super.get(ids);
|
|
||||||
|
|
||||||
this.injectCache(rows.values(), this.poststatsPersonService, "personID", "person");
|
|
||||||
return rows;
|
|
||||||
}
|
|
||||||
|
|
||||||
private abstract class PrincipalCacheableFetcher implements CacheableFetcher<Long, AuthenticatedPerson> {
|
private abstract class PrincipalCacheableFetcher implements CacheableFetcher<Long, AuthenticatedPerson> {
|
||||||
|
|
||||||
public abstract com.poststats.security.AuthenticatedPerson getPerson();
|
public abstract com.poststats.security.AuthenticatedPerson getPerson();
|
||||||
|
Reference in New Issue
Block a user