break-fix
This commit is contained in:
@@ -2,6 +2,12 @@ package com.poststats.golf.api;
|
||||
|
||||
public class Constants extends com.poststats.api.Constants {
|
||||
|
||||
public static final String DATASOURCE_PROVIDER_GOLF = "dbds-golf";
|
||||
public static final String CONNECTION_PROVIDER_GOLF = "dbcon-golf";
|
||||
public static final String CONNECTION_PROVIDER_GOLF_TX = "dbcon-golf-tx";
|
||||
public static final String STATEMENT_PROVIDER_GOLF = "dbstmt-golf";
|
||||
public static final String STATEMENT_PROVIDER_GOLF_TX = "dbstmt-golf-tx";
|
||||
|
||||
public static final String EVENT_ROLE_PREFIX = "event:";
|
||||
public static final String EVENT_SERIES_ROLE_PREFIX = "series:";
|
||||
public static final String COURSE_ROLE_PREFIX = "course:";
|
||||
|
@@ -5,7 +5,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.poststats.api.model.Person;
|
||||
import com.poststats.golf.service.EventPersonService;
|
||||
import com.poststats.golf.service.EventService;
|
||||
import com.poststats.transformer.PersonTransformer;
|
||||
import com.poststats.transformer.impl.PublicPersonTransformer;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
@@ -43,7 +43,7 @@ public class EventPersonApi {
|
||||
private EventPersonService eventPersonService;
|
||||
|
||||
@Inject
|
||||
private PersonTransformer personTransformer;
|
||||
private PublicPersonTransformer personTransformer;
|
||||
|
||||
@GET
|
||||
@Path("/people")
|
||||
@@ -56,7 +56,7 @@ public class EventPersonApi {
|
||||
@ApiResponse(responseCode = "403", description = "Authenticated, but not permitted"),
|
||||
@ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found")
|
||||
})
|
||||
public List<Person> get() {
|
||||
public List<? extends Person> get() {
|
||||
return this.personTransformer.toModel(this.eventPersonService.getPeople(this.eventId, false));
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class EventPersonApi {
|
||||
@ApiResponse(responseCode = "403", description = "Authenticated, but not permitted"),
|
||||
@ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found")
|
||||
})
|
||||
public List<Person> getDetail() {
|
||||
public List<? extends Person> getDetail() {
|
||||
return this.personTransformer.toModel(this.eventPersonService.getPeople(this.eventId, true));
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class EventPersonApi {
|
||||
@ApiResponse(responseCode = "200", description = "Success"),
|
||||
@ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found")
|
||||
})
|
||||
public List<Person> getParticipants() {
|
||||
public List<? extends Person> getParticipants() {
|
||||
return this.personTransformer.toModel(this.eventPersonService.getParticipants(this.eventId, false));
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public class EventPersonApi {
|
||||
@ApiResponse(responseCode = "403", description = "Authenticated, but not permitted"),
|
||||
@ApiResponse(responseCode = "404", description = "An event with the specified ID could not be found")
|
||||
})
|
||||
public List<Person> getSeriesParticipants() throws JsonProcessingException, IOException {
|
||||
public List<? extends Person> getSeriesParticipants() throws JsonProcessingException, IOException {
|
||||
int seriesId = this.eventService.getSeriesId(this.eventId);
|
||||
Set<Long> eventIds = this.eventService.getIdsBySeriesId(seriesId);
|
||||
|
||||
|
@@ -1,18 +0,0 @@
|
||||
package com.poststats.golf.service.db;
|
||||
|
||||
import com.poststats.golf.sql.GolfDataSource;
|
||||
import java.sql.Connection;
|
||||
|
||||
public abstract class CacheableServiceDAO<T> extends com.poststats.service.db.CacheableServiceDAO<T> {
|
||||
|
||||
@Override
|
||||
protected Connection acquireConnection() {
|
||||
return GolfDataSource.getInstance().acquire(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void releaseConnection(Connection dbcon) {
|
||||
GolfDataSource.getInstance().release(dbcon);
|
||||
}
|
||||
|
||||
}
|
@@ -3,11 +3,17 @@ package com.poststats.golf.service.db;
|
||||
import com.brianlong.sql.DataSet;
|
||||
import com.brianlong.sql.FlexPreparedStatement;
|
||||
import com.brianlong.util.FlexMap;
|
||||
import com.poststats.golf.api.Constants;
|
||||
import com.poststats.golf.service.EventService;
|
||||
import com.poststats.golf.sql.GolfDataSource;
|
||||
import com.poststats.golf.sql.GolfSQL;
|
||||
import com.poststats.provider.Statement;
|
||||
import com.poststats.provider.StatementProvider;
|
||||
import com.poststats.service.ServiceException;
|
||||
import com.poststats.service.db.CacheableServiceDAO;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
@@ -81,9 +87,8 @@ public class EventServiceDAO extends CacheableServiceDAO<Long> implements EventS
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DataSet fetchOne(Connection dbcon, Long eventId) throws SQLException {
|
||||
String sql = SQL_SELECT + "WHERE E.eventID=?";
|
||||
FlexPreparedStatement fps = new FlexPreparedStatement(dbcon, sql);
|
||||
protected DataSet fetchOne(Long eventId) throws SQLException {
|
||||
FlexPreparedStatement fps = this.sqlSelectEvent.buildPreparedStatement();
|
||||
try {
|
||||
fps.setIntegerU(1, eventId);
|
||||
return fps.executeQuery().getNextRow();
|
||||
@@ -92,10 +97,19 @@ public class EventServiceDAO extends CacheableServiceDAO<Long> implements EventS
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Named(Constants.STATEMENT_PROVIDER_GOLF)
|
||||
@Statement(
|
||||
sql = "SELECT EF.*, E.* "
|
||||
+ "FROM ~g~.Event E "
|
||||
+ " INNER JOIN ~g~.EventFeature EF ON (E.eventID=EF.eventID) "
|
||||
+ "WHERE eventID=? "
|
||||
)
|
||||
private StatementProvider sqlSelectEvent;
|
||||
|
||||
@Override
|
||||
protected Map<Long, DataSet> fetchBulk(Connection dbcon, Collection<Long> eventIds) throws SQLException {
|
||||
String sql = SQL_SELECT + "WHERE E.eventID IN (??)";
|
||||
FlexPreparedStatement fps = new FlexPreparedStatement(dbcon, sql, eventIds);
|
||||
protected Map<Long, DataSet> fetchBulk(Collection<Long> eventIds) throws SQLException {
|
||||
FlexPreparedStatement fps = this.sqlSelectEvents.buildPreparedStatement(eventIds);
|
||||
try {
|
||||
return fps.executeQuery().getAllRows("eventID", Long.class);
|
||||
} finally {
|
||||
@@ -103,10 +117,15 @@ public class EventServiceDAO extends CacheableServiceDAO<Long> implements EventS
|
||||
}
|
||||
}
|
||||
|
||||
private static final String SQL_SELECT = GolfSQL.changeSchema(
|
||||
"SELECT E.*, EF.* "
|
||||
+ "FROM ~g~.Event E "
|
||||
+ " INNER JOIN ~g~.EventFeature EF ON (E.eventID=EF.eventID) ");
|
||||
@Inject
|
||||
@Named(Constants.STATEMENT_PROVIDER_GOLF)
|
||||
@Statement(
|
||||
sql = "SELECT EF.*, E.* "
|
||||
+ "FROM ~g~.Event E "
|
||||
+ " INNER JOIN ~g~.EventFeature EF ON (E.eventID=EF.eventID) "
|
||||
+ "WHERE eventID IN (??) "
|
||||
)
|
||||
private StatementProvider sqlSelectEvents;
|
||||
|
||||
private void queryEventIds(Connection dbcon, int seriesId, Boolean chronological, Collection<Long> eventIds)
|
||||
throws SQLException {
|
||||
|
@@ -5,15 +5,21 @@ import com.brianlong.cache.CacheableFetcher;
|
||||
import com.brianlong.cache.ClusterAwareMemoryCacher;
|
||||
import com.brianlong.sql.DataSet;
|
||||
import com.brianlong.sql.FlexPreparedStatement;
|
||||
import com.brianlong.sql.FlexStatement;
|
||||
import com.brianlong.util.FlexMap;
|
||||
import com.poststats.golf.api.Constants;
|
||||
import com.poststats.golf.security.Person;
|
||||
import com.poststats.golf.service.PersonService;
|
||||
import com.poststats.golf.sql.GolfDataSource;
|
||||
import com.poststats.golf.sql.GolfSQL;
|
||||
import com.poststats.provider.Statement;
|
||||
import com.poststats.provider.StatementProvider;
|
||||
import com.poststats.service.ServiceException;
|
||||
import com.poststats.sql.Constants;
|
||||
import com.poststats.service.db.CacheableServiceDAO;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
@@ -105,9 +111,8 @@ public class PersonServiceDAO extends CacheableServiceDAO<Long> implements Perso
|
||||
};
|
||||
|
||||
@Override
|
||||
protected DataSet fetchOne(Connection dbcon, Long personId) throws SQLException {
|
||||
String sql = SQL_SELECT_PERSON + "WHERE personID=?";
|
||||
FlexPreparedStatement fps = new FlexPreparedStatement(dbcon, sql);
|
||||
protected DataSet fetchOne(Long personId) throws SQLException {
|
||||
FlexPreparedStatement fps = this.sqlSelectPerson.buildPreparedStatement();
|
||||
try {
|
||||
fps.setIntegerU(1, personId);
|
||||
return fps.executeQuery().getNextRow();
|
||||
@@ -116,21 +121,27 @@ public class PersonServiceDAO extends CacheableServiceDAO<Long> implements Perso
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Named(Constants.STATEMENT_PROVIDER_GOLF)
|
||||
@Statement(sql = "SELECT GP.strokeHandicap FROM ~g~.Person GP WHERE personID=?")
|
||||
private StatementProvider sqlSelectPerson;
|
||||
|
||||
@Override
|
||||
protected Map<Long, DataSet> fetchBulk(Connection dbcon, Collection<Long> personIds) throws SQLException {
|
||||
String sql = SQL_SELECT_PERSON + "WHERE personID IN (??)";
|
||||
FlexPreparedStatement fps = new FlexPreparedStatement(dbcon, sql, personIds);
|
||||
protected Map<Long, DataSet> fetchBulk(Collection<Long> personIds) throws SQLException {
|
||||
FlexStatement fs = this.sqlSelectPersons.buildStatement(personIds);
|
||||
try {
|
||||
return fps.executeQuery().getAllRows(Constants.PERSON_ID, Long.class);
|
||||
return fs.executeQuery().getAllRows("personID", Long.class);
|
||||
} finally {
|
||||
fps.close();
|
||||
fs.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Named(Constants.STATEMENT_PROVIDER_GOLF)
|
||||
@Statement(sql = "SELECT GP.strokeHandicap FROM ~g~.Person P WHERE personID IN (??)")
|
||||
private StatementProvider sqlSelectPersons;
|
||||
|
||||
|
||||
private static final String SQL_SELECT_PERSON = GolfSQL.changeSchema(
|
||||
"SELECT P.* FROM ~g~.Person P ");
|
||||
|
||||
private static final String SQL_SELECT_ACS = GolfSQL.changeSchema(
|
||||
"SELECT AC.acSID "
|
||||
|
@@ -3,11 +3,17 @@ package com.poststats.golf.service.db;
|
||||
import com.brianlong.sql.DataSet;
|
||||
import com.brianlong.sql.FlexPreparedStatement;
|
||||
import com.brianlong.util.FlexMap;
|
||||
import com.poststats.golf.api.Constants;
|
||||
import com.poststats.golf.service.SeriesService;
|
||||
import com.poststats.golf.sql.GolfDataSource;
|
||||
import com.poststats.golf.sql.GolfSQL;
|
||||
import com.poststats.provider.Statement;
|
||||
import com.poststats.provider.StatementProvider;
|
||||
import com.poststats.service.ServiceException;
|
||||
import com.poststats.service.db.CacheableServiceDAO;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
@@ -41,9 +47,8 @@ public class SeriesServiceDAO extends CacheableServiceDAO<Integer> implements Se
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DataSet fetchOne(Connection dbcon, Integer seriesId) throws SQLException {
|
||||
String sql = SQL_SELECT + "WHERE seriesID=?";
|
||||
FlexPreparedStatement fps = new FlexPreparedStatement(dbcon, sql);
|
||||
protected DataSet fetchOne(Integer seriesId) throws SQLException {
|
||||
FlexPreparedStatement fps = this.sqlSelectSeries.buildPreparedStatement();
|
||||
try {
|
||||
fps.setSmallintU(1, seriesId);
|
||||
return fps.executeQuery().getNextRow();
|
||||
@@ -52,10 +57,14 @@ public class SeriesServiceDAO extends CacheableServiceDAO<Integer> implements Se
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Named(Constants.STATEMENT_PROVIDER_GOLF)
|
||||
@Statement(sql = "SELECT S.* FROM ~g~.Series S WHERE seriesID=? ")
|
||||
private StatementProvider sqlSelectSeries;
|
||||
|
||||
@Override
|
||||
protected Map<Integer, DataSet> fetchBulk(Connection dbcon, Collection<Integer> seriesIds) throws SQLException {
|
||||
String sql = SQL_SELECT + "WHERE seriesID IN (??)";
|
||||
FlexPreparedStatement fps = new FlexPreparedStatement(dbcon, sql, seriesIds);
|
||||
protected Map<Integer, DataSet> fetchBulk(Collection<Integer> seriesIds) throws SQLException {
|
||||
FlexPreparedStatement fps = this.sqlSelectSerieses.buildPreparedStatement(seriesIds);
|
||||
try {
|
||||
return fps.executeQuery().getAllRows("seriesID", Integer.class);
|
||||
} finally {
|
||||
@@ -63,6 +72,11 @@ public class SeriesServiceDAO extends CacheableServiceDAO<Integer> implements Se
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Named(Constants.STATEMENT_PROVIDER_GOLF)
|
||||
@Statement(sql = "SELECT S.* FROM ~g~.Series S WHERE seriesID IN (??) ")
|
||||
private StatementProvider sqlSelectSerieses;
|
||||
|
||||
private DataSet querySeries(Connection dbcon, long eventId) throws SQLException {
|
||||
FlexPreparedStatement fps = new FlexPreparedStatement(dbcon, SQL_SELECT_SERIES_BY_EVENT_ID);
|
||||
try {
|
||||
|
@@ -0,0 +1,38 @@
|
||||
package com.poststats.golf.service.provider.impl;
|
||||
|
||||
import com.poststats.golf.api.Constants;
|
||||
import com.poststats.provider.ConnectionProvider;
|
||||
import com.poststats.provider.DataSourceProvider;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import jakarta.enterprise.context.RequestScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import java.sql.Connection;
|
||||
|
||||
@RequestScoped
|
||||
@Named(Constants.CONNECTION_PROVIDER_GOLF)
|
||||
public class DefaultConnectionProvider implements ConnectionProvider {
|
||||
|
||||
@Inject
|
||||
@Named(Constants.DATASOURCE_PROVIDER_GOLF)
|
||||
private DataSourceProvider dsp;
|
||||
|
||||
private Connection dbcon;
|
||||
|
||||
@PostConstruct
|
||||
public void acquire() {
|
||||
this.dbcon = this.dsp.get().acquire(true);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void release() {
|
||||
this.dsp.get().release(this.dbcon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection get() {
|
||||
return this.dbcon;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.poststats.golf.service.provider.impl;
|
||||
|
||||
import com.brianlong.sql.DataSource;
|
||||
import com.poststats.golf.api.Constants;
|
||||
import com.poststats.golf.sql.GolfDataSource;
|
||||
import com.poststats.provider.impl.AbstractDataSourceProvider;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Named;
|
||||
|
||||
@ApplicationScoped
|
||||
@Named(Constants.DATASOURCE_PROVIDER_GOLF)
|
||||
public class DefaultDataSourceProvider extends AbstractDataSourceProvider {
|
||||
|
||||
public DataSource createDataSource() {
|
||||
return GolfDataSource.getInstance();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.poststats.golf.service.provider.impl;
|
||||
|
||||
import com.poststats.golf.api.Constants;
|
||||
import com.poststats.golf.sql.GolfSQL;
|
||||
import com.poststats.provider.ConnectionProvider;
|
||||
import com.poststats.provider.impl.AbstractStatementProvider;
|
||||
import jakarta.enterprise.context.Dependent;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
|
||||
@Dependent
|
||||
@Named(Constants.STATEMENT_PROVIDER_GOLF)
|
||||
public class DefaultStatementProvider extends AbstractStatementProvider {
|
||||
|
||||
@Inject
|
||||
@Named(Constants.CONNECTION_PROVIDER_GOLF)
|
||||
private ConnectionProvider cp;
|
||||
|
||||
@Override
|
||||
protected ConnectionProvider getConnectionProvider() {
|
||||
return this.cp;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String transformSchema(String sql) {
|
||||
return GolfSQL.changeSchema(sql);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package com.poststats.golf.service.provider.impl;
|
||||
|
||||
import com.poststats.golf.api.Constants;
|
||||
import com.poststats.provider.ConnectionProvider;
|
||||
import com.poststats.provider.DataSourceProvider;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import jakarta.enterprise.context.RequestScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import java.sql.Connection;
|
||||
|
||||
@RequestScoped
|
||||
@Named(Constants.CONNECTION_PROVIDER_GOLF_TX)
|
||||
public class TxConnectionProvider implements ConnectionProvider {
|
||||
|
||||
@Inject
|
||||
@Named(Constants.DATASOURCE_PROVIDER_GOLF)
|
||||
private DataSourceProvider dsp;
|
||||
|
||||
private Connection dbcon;
|
||||
|
||||
@PostConstruct
|
||||
public void acquire() {
|
||||
this.dbcon = this.dsp.get().acquireTX(true);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void release() {
|
||||
this.dsp.get().releaseTX(this.dbcon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection get() {
|
||||
return this.dbcon;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.poststats.golf.service.provider.impl;
|
||||
|
||||
import com.poststats.golf.api.Constants;
|
||||
import com.poststats.golf.sql.GolfSQL;
|
||||
import com.poststats.provider.ConnectionProvider;
|
||||
import com.poststats.provider.impl.AbstractStatementProvider;
|
||||
import jakarta.enterprise.context.Dependent;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
|
||||
@Dependent
|
||||
@Named(Constants.STATEMENT_PROVIDER_GOLF_TX)
|
||||
public class TxStatementProvider extends AbstractStatementProvider {
|
||||
|
||||
@Inject
|
||||
@Named(Constants.CONNECTION_PROVIDER_GOLF_TX)
|
||||
private ConnectionProvider cp;
|
||||
|
||||
@Override
|
||||
protected ConnectionProvider getConnectionProvider() {
|
||||
return this.cp;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String transformSchema(String sql) {
|
||||
return GolfSQL.changeSchema(sql);
|
||||
}
|
||||
|
||||
}
|
@@ -1,20 +1,20 @@
|
||||
package com.poststats.golf.transformer;
|
||||
|
||||
import com.brianlong.util.FlexMap;
|
||||
import com.poststats.api.model.Person;
|
||||
import com.poststats.api.model.PublicPerson;
|
||||
import com.poststats.transformer.Transformer;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
@ApplicationScoped
|
||||
public class GolferTransformer implements Transformer<Person> {
|
||||
public class GolferTransformer implements Transformer<PublicPerson> {
|
||||
|
||||
@Override
|
||||
public Person toModel(FlexMap row) {
|
||||
return this.toModel(row, new Person());
|
||||
public PublicPerson toModel(FlexMap row) {
|
||||
return this.toModel(row, new PublicPerson());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Person toModel(FlexMap row, Person person) {
|
||||
public PublicPerson toModel(FlexMap row, PublicPerson person) {
|
||||
person.withId(row.getLong("personID")).withFirstName(row.getString("fname"))
|
||||
.withLastName(row.getString("lname"));
|
||||
|
||||
|
Reference in New Issue
Block a user