mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-11 06:40:53 +00:00
remove DB parameter from Mongo factory interfaces
This commit is contained in:
1 parent
be6697850c
commit
b0c2cdfa41
11 files changed
+45
-46
No files matched your search
+2
-3
@@ -180,7 +180,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
|
||||
@Override
|
||||
public List<TracTracConfigurationDAO> getPreviousConfigurations() throws Exception {
|
||||
DomainObjectFactory domainObjectFactory = DomainObjectFactory.INSTANCE;
|
||||
Iterable<TracTracConfiguration> configs = domainObjectFactory.getTracTracConfigurations(domainObjectFactory.getDefaultDatabase());
|
||||
Iterable<TracTracConfiguration> configs = domainObjectFactory.getTracTracConfigurations();
|
||||
List<TracTracConfigurationDAO> result = new ArrayList<TracTracConfigurationDAO>();
|
||||
for (TracTracConfiguration ttConfig : configs) {
|
||||
result.add(new TracTracConfigurationDAO(ttConfig.getName(), ttConfig.getJSONURL().toString(),
|
||||
@@ -193,8 +193,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
|
||||
public void storeTracTracConfiguration(String name, String jsonURL, String liveDataURI, String storedDataURI) throws Exception {
|
||||
DomainFactory domainFactory = DomainFactory.INSTANCE;
|
||||
MongoObjectFactory mongoObjectFactory = MongoObjectFactory.INSTANCE;
|
||||
mongoObjectFactory.storeTracTracConfiguration(DomainObjectFactory.INSTANCE.getDefaultDatabase(),
|
||||
domainFactory.createTracTracConfiguration(name, jsonURL, liveDataURI, storedDataURI));
|
||||
mongoObjectFactory.storeTracTracConfiguration(domainFactory.createTracTracConfiguration(name, jsonURL, liveDataURI, storedDataURI));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -23,6 +23,7 @@ import com.sap.sailing.domain.tracking.Wind;
|
||||
import com.sap.sailing.domain.tracking.impl.WindImpl;
|
||||
import com.sap.sailing.mongodb.DomainObjectFactory;
|
||||
import com.sap.sailing.mongodb.MongoObjectFactory;
|
||||
import com.sap.sailing.mongodb.impl.DomainObjectFactoryImpl;
|
||||
import com.sap.sailing.mongodb.impl.MongoWindStoreFactoryImpl;
|
||||
|
||||
public class TestStoringAndRetrievingWindData implements MongoDBTest {
|
||||
@@ -99,7 +100,7 @@ public class TestStoringAndRetrievingWindData implements MongoDBTest {
|
||||
DBCollection coll = db.getCollection(WIND_TEST_COLLECTION);
|
||||
assertNotNull(coll);
|
||||
DBObject object = coll.findOne();
|
||||
Wind readWind = DomainObjectFactory.INSTANCE.loadWind(object);
|
||||
Wind readWind = ((DomainObjectFactoryImpl) DomainObjectFactory.INSTANCE).loadWind(object);
|
||||
assertEquals(wind.getPosition(), readWind.getPosition());
|
||||
assertEquals(wind.getKnots(), readWind.getKnots(), 0.00000001);
|
||||
assertEquals(wind.getBearing().getDegrees(), readWind.getBearing().getDegrees(), 0.00000001);
|
||||
|
||||
+4
-4
@@ -32,8 +32,8 @@ import com.sap.sailing.domain.tracking.impl.WindImpl;
|
||||
import com.sap.sailing.domain.tractracadapter.DomainFactory;
|
||||
import com.sap.sailing.domain.tractracadapter.Receiver;
|
||||
import com.sap.sailing.domain.tractracadapter.ReceiverType;
|
||||
import com.sap.sailing.mongodb.DomainObjectFactory;
|
||||
import com.sap.sailing.mongodb.MongoObjectFactory;
|
||||
import com.sap.sailing.mongodb.impl.DomainObjectFactoryImpl;
|
||||
import com.sap.sailing.mongodb.impl.MongoWindStoreFactoryImpl;
|
||||
|
||||
public class TestStoringAndRetrievingWindTracks extends AbstractTracTracLiveTest implements MongoDBTest {
|
||||
@@ -72,7 +72,7 @@ public class TestStoringAndRetrievingWindTracks extends AbstractTracTracLiveTest
|
||||
EmptyWindStore.INSTANCE, /* millisecondsOverWhichToAverageSpeed */
|
||||
30000, 10000, getEvent(), this);
|
||||
WindSource windSource = WindSource.WEB;
|
||||
MongoObjectFactory.INSTANCE.addWindTrackDumper(trackedEvent, trackedRace, windSource, db);
|
||||
MongoObjectFactory.INSTANCE.addWindTrackDumper(trackedEvent, trackedRace, windSource);
|
||||
WindTrack windTrack = trackedRace.getWindTrack(windSource);
|
||||
Position pos = new DegreePosition(54, 9);
|
||||
for (double bearingDeg = 123.4; bearingDeg<140; bearingDeg += 1.1) {
|
||||
@@ -83,8 +83,8 @@ public class TestStoringAndRetrievingWindTracks extends AbstractTracTracLiveTest
|
||||
|
||||
Mongo myMongo = newMongo();
|
||||
DB database = myMongo.getDB(WIND_TEST_DB);
|
||||
WindTrack result = DomainObjectFactory.INSTANCE.loadWindTrack(domainEvent, race, windSource, /* millisecondsOverWhichToAverage */
|
||||
30000, database);
|
||||
WindTrack result = new DomainObjectFactoryImpl(database).loadWindTrack(domainEvent, race, windSource, /* millisecondsOverWhichToAverage */
|
||||
30000);
|
||||
double myBearingDeg = 123.4;
|
||||
for (Wind wind : result.getRawFixes()) {
|
||||
assertEquals(pos, wind.getPosition());
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
package com.sap.sailing.mongodb;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import com.mongodb.DB;
|
||||
import com.mongodb.DBObject;
|
||||
import com.sap.sailing.domain.base.Event;
|
||||
import com.sap.sailing.domain.base.RaceDefinition;
|
||||
import com.sap.sailing.domain.tracking.Wind;
|
||||
import com.sap.sailing.domain.tracking.WindSource;
|
||||
import com.sap.sailing.domain.tracking.WindTrack;
|
||||
import com.sap.sailing.domain.tractracadapter.TracTracConfiguration;
|
||||
import com.sap.sailing.mongodb.impl.DomainObjectFactoryImpl;
|
||||
import com.sap.sailing.mongodb.impl.MongoWindStoreFactoryImpl;
|
||||
|
||||
/**
|
||||
* Offers methods to construct domain objects from {@link DBObject MongoDB objects}.
|
||||
@@ -19,13 +16,9 @@ import com.sap.sailing.mongodb.impl.DomainObjectFactoryImpl;
|
||||
*
|
||||
*/
|
||||
public interface DomainObjectFactory {
|
||||
DomainObjectFactory INSTANCE = new DomainObjectFactoryImpl();
|
||||
DomainObjectFactory INSTANCE = new DomainObjectFactoryImpl(MongoWindStoreFactoryImpl.getDefaultInstance().getDB());
|
||||
|
||||
Wind loadWind(DBObject object);
|
||||
|
||||
WindTrack loadWindTrack(Event event, RaceDefinition race, WindSource windSource, long millisecondsOverWhichToAverage, DB database);
|
||||
WindTrack loadWindTrack(Event event, RaceDefinition race, WindSource windSource, long millisecondsOverWhichToAverage);
|
||||
|
||||
Iterable<TracTracConfiguration> getTracTracConfigurations(DB database);
|
||||
|
||||
DB getDefaultDatabase() throws UnknownHostException;
|
||||
Iterable<TracTracConfiguration> getTracTracConfigurations();
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.sap.sailing.mongodb;
|
||||
|
||||
import com.mongodb.DB;
|
||||
import com.mongodb.DBCollection;
|
||||
import com.mongodb.DBObject;
|
||||
import com.sap.sailing.domain.base.Event;
|
||||
@@ -11,6 +10,7 @@ import com.sap.sailing.domain.tracking.Wind;
|
||||
import com.sap.sailing.domain.tracking.WindSource;
|
||||
import com.sap.sailing.domain.tractracadapter.TracTracConfiguration;
|
||||
import com.sap.sailing.mongodb.impl.MongoObjectFactoryImpl;
|
||||
import com.sap.sailing.mongodb.impl.MongoWindStoreFactoryImpl;
|
||||
|
||||
/**
|
||||
* Offers methods to construct {@link DBObject MongoDB objects} from domain objects.
|
||||
@@ -19,7 +19,7 @@ import com.sap.sailing.mongodb.impl.MongoObjectFactoryImpl;
|
||||
*
|
||||
*/
|
||||
public interface MongoObjectFactory {
|
||||
MongoObjectFactory INSTANCE = new MongoObjectFactoryImpl();
|
||||
MongoObjectFactory INSTANCE = new MongoObjectFactoryImpl(MongoWindStoreFactoryImpl.getDefaultInstance().getDB());
|
||||
|
||||
DBObject storeWind(Wind wind);
|
||||
|
||||
@@ -27,21 +27,18 @@ public interface MongoObjectFactory {
|
||||
* Registers for changes of the wind coming from <code>windSource</code> on the <code>trackedRace</code>. Each
|
||||
* update received will be appended to the MongoDB and can later be retrieved. The key used to identify the race is
|
||||
* the {@link RaceDefinition#getName() race name} and the {@link Event#getName() event name}.
|
||||
*
|
||||
* @param database
|
||||
* the MongoDB database to dump the wind received by the {@link TrackedRace}'s <code>windSource</code> to
|
||||
*/
|
||||
void addWindTrackDumper(TrackedEvent trackedEvent, TrackedRace trackedRace, WindSource windSource, DB database);
|
||||
void addWindTrackDumper(TrackedEvent trackedEvent, TrackedRace trackedRace, WindSource windSource);
|
||||
|
||||
DBCollection getWindTrackCollection(DB database);
|
||||
DBCollection getWindTrackCollection();
|
||||
|
||||
DBObject storeWindTrackEntry(Event event, RaceDefinition race, WindSource windSource, Wind wind);
|
||||
|
||||
/**
|
||||
* Inserts/updates based on the {@link TracTracConfiguration#getName() name}. Any equally-named
|
||||
* config previously contained in the DB will be replaced / updated. Afterwards,
|
||||
* {@link DomainObjectFactory#getTracTracConfigurations(DB)} called for the same <code>database</code>
|
||||
* {@link DomainObjectFactory#getTracTracConfigurations()} called for the same <code>database</code>
|
||||
* will return an equal <code>tracTracConfiguration</code> in its results.
|
||||
*/
|
||||
void storeTracTracConfiguration(DB database, TracTracConfiguration tracTracConfiguration);
|
||||
void storeTracTracConfiguration(TracTracConfiguration tracTracConfiguration);
|
||||
}
|
||||
@@ -22,6 +22,6 @@ public interface MongoWindStoreFactory {
|
||||
* system properties and/or OSGi bundle properties, respectively. See also
|
||||
* {@link #getMongoWindStore(MongoObjectFactory)}.
|
||||
*/
|
||||
DB getDB() throws UnknownHostException;
|
||||
DB getDB();
|
||||
|
||||
}
|
||||
+9
-10
@@ -1,6 +1,5 @@
|
||||
package com.sap.sailing.mongodb.impl;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
@@ -31,7 +30,13 @@ import com.sap.sailing.mongodb.DomainObjectFactory;
|
||||
public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
private static final Logger logger = Logger.getLogger(DomainObjectFactoryImpl.class.getName());
|
||||
|
||||
@Override
|
||||
private final DB database;
|
||||
|
||||
public DomainObjectFactoryImpl(DB db) {
|
||||
super();
|
||||
this.database = db;
|
||||
}
|
||||
|
||||
public Wind loadWind(DBObject object) {
|
||||
return new WindImpl(loadPosition(object), loadTimePoint(object), loadSpeedWithBearing(object));
|
||||
}
|
||||
@@ -56,8 +61,7 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public WindTrack loadWindTrack(Event event, RaceDefinition race, WindSource windSource, long millisecondsOverWhichToAverage,
|
||||
DB database) {
|
||||
public WindTrack loadWindTrack(Event event, RaceDefinition race, WindSource windSource, long millisecondsOverWhichToAverage) {
|
||||
WindTrack result = new WindTrackImpl(millisecondsOverWhichToAverage);
|
||||
try {
|
||||
BasicDBObject query = new BasicDBObject();
|
||||
@@ -78,7 +82,7 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<TracTracConfiguration> getTracTracConfigurations(DB database) {
|
||||
public Iterable<TracTracConfiguration> getTracTracConfigurations() {
|
||||
List<TracTracConfiguration> result = new ArrayList<TracTracConfiguration>();
|
||||
try {
|
||||
DBCollection ttConfigs = database.getCollection(CollectionNames.TRACTRAC_CONFIGURATIONS.name());
|
||||
@@ -101,9 +105,4 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
(String) object.get(FieldNames.TT_CONFIG_STORED_DATA_URI.name()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DB getDefaultDatabase() throws UnknownHostException {
|
||||
return MongoWindStoreFactoryImpl.getDefaultInstance().getDB();
|
||||
}
|
||||
|
||||
}
|
||||
+9
-3
@@ -20,7 +20,13 @@ import com.sap.sailing.domain.tractracadapter.TracTracConfiguration;
|
||||
import com.sap.sailing.mongodb.MongoObjectFactory;
|
||||
|
||||
public class MongoObjectFactoryImpl implements MongoObjectFactory {
|
||||
private final DB database;
|
||||
|
||||
public MongoObjectFactoryImpl(DB database) {
|
||||
super();
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DBObject storeWind(Wind wind) {
|
||||
DBObject result = new BasicDBObject();
|
||||
@@ -56,13 +62,13 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addWindTrackDumper(TrackedEvent trackedEvent, TrackedRace trackedRace, WindSource windSource, DB database) {
|
||||
public void addWindTrackDumper(TrackedEvent trackedEvent, TrackedRace trackedRace, WindSource windSource) {
|
||||
WindTrack windTrack = trackedRace.getWindTrack(windSource);
|
||||
windTrack.addListener(new MongoWindListener(trackedEvent, trackedRace, windSource, this, database));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DBCollection getWindTrackCollection(DB database) {
|
||||
public DBCollection getWindTrackCollection() {
|
||||
return database.getCollection(CollectionNames.WIND_TRACKS.name());
|
||||
}
|
||||
|
||||
@@ -77,7 +83,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeTracTracConfiguration(DB database, TracTracConfiguration tracTracConfiguration) {
|
||||
public void storeTracTracConfiguration(TracTracConfiguration tracTracConfiguration) {
|
||||
DBCollection ttConfigCollection = database.getCollection(CollectionNames.TRACTRAC_CONFIGURATIONS.name());
|
||||
BasicDBObject result = new BasicDBObject();
|
||||
result.put(FieldNames.TT_CONFIG_NAME.name(), tracTracConfiguration.getName());
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ public class MongoWindListener implements com.sap.sailing.domain.tracking.WindLi
|
||||
this.trackedRace = trackedRace;
|
||||
this.windSource = windSource;
|
||||
this.mongoObjectFactory = mongoObjectFactory;
|
||||
this.windTracksCollection = mongoObjectFactory.getWindTrackCollection(database);
|
||||
this.windTracksCollection = mongoObjectFactory.getWindTrackCollection();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-2
@@ -51,8 +51,12 @@ public class MongoWindStoreFactoryImpl implements MongoWindStoreFactory, BundleA
|
||||
}
|
||||
|
||||
@Override
|
||||
public DB getDB() throws UnknownHostException {
|
||||
return getDB(defaultHostName, defaultPort, defaultDatabaseName);
|
||||
public DB getDB() {
|
||||
try {
|
||||
return getDB(defaultHostName, defaultPort, defaultDatabaseName);
|
||||
} catch (UnknownHostException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized DB getDB(String hostname, int port, String dbName) throws UnknownHostException {
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ public class MongoWindStoreImpl implements MongoWindStore {
|
||||
public WindTrack getWindTrack(TrackedEvent trackedEvent, TrackedRace trackedRace, WindSource windSource,
|
||||
long millisecondsOverWhichToAverage) {
|
||||
WindTrack result = DomainObjectFactoryImpl.INSTANCE.loadWindTrack(trackedEvent.getEvent(),
|
||||
trackedRace.getRace(), windSource, millisecondsOverWhichToAverage, db);
|
||||
trackedRace.getRace(), windSource, millisecondsOverWhichToAverage);
|
||||
result.addListener(new MongoWindListener(trackedEvent, trackedRace, windSource, mongoObjectFactory, db));
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user