Creating only one instance of LotroCardBlueprintLibrary.
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
package com.gempukku.lotro.server.provider;
|
||||
|
||||
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
|
||||
import com.sun.jersey.core.spi.component.ComponentContext;
|
||||
import com.sun.jersey.core.spi.component.ComponentScope;
|
||||
import com.sun.jersey.spi.inject.Injectable;
|
||||
import com.sun.jersey.spi.inject.InjectableProvider;
|
||||
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
@Provider
|
||||
public class CardLibraryProvider implements InjectableProvider<Context, Type>, Injectable<LotroCardBlueprintLibrary> {
|
||||
private LotroCardBlueprintLibrary _library;
|
||||
|
||||
public CardLibraryProvider() {
|
||||
_library = new LotroCardBlueprintLibrary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentScope getScope() {
|
||||
return ComponentScope.Singleton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LotroCardBlueprintLibrary getValue() {
|
||||
return _library;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Injectable getInjectable(ComponentContext ic, Context context, Type type) {
|
||||
if (type.equals(LotroCardBlueprintLibrary.class))
|
||||
return this;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -30,12 +30,11 @@ public class DaoProvider implements InjectableProvider<Context, Type> {
|
||||
private Injectable<TournamentDAO> _tournamentDAOInjectable;
|
||||
private Injectable<TournamentPlayerDAO> _tournamentPlayerDAOInjectable;
|
||||
private Injectable<TournamentMatchDAO> _tournamentMatchDAOInjectable;
|
||||
private Injectable<LotroCardBlueprintLibrary> _lotroCardBlueprintLibraryInjectable;
|
||||
|
||||
private DbAccess _dbAccess;
|
||||
private CollectionSerializer _collectionSerializer;
|
||||
|
||||
private LotroCardBlueprintLibrary _library = new LotroCardBlueprintLibrary();
|
||||
|
||||
public DaoProvider() {
|
||||
_dbAccess = new DbAccess();
|
||||
_collectionSerializer = new CollectionSerializer();
|
||||
@@ -65,6 +64,8 @@ public class DaoProvider implements InjectableProvider<Context, Type> {
|
||||
return getTournamentPlayerDaoSafely();
|
||||
else if (type.equals(TournamentMatchDAO.class))
|
||||
return getTournamentMatchDaoSafely();
|
||||
else if (type.equals(LotroCardBlueprintLibrary.class))
|
||||
return getLotroCardBlueprintLibrarySafely();
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -81,6 +82,19 @@ public class DaoProvider implements InjectableProvider<Context, Type> {
|
||||
return _leagueParticipationDAOInjectable;
|
||||
}
|
||||
|
||||
private synchronized Injectable<LotroCardBlueprintLibrary> getLotroCardBlueprintLibrarySafely() {
|
||||
if (_lotroCardBlueprintLibraryInjectable == null) {
|
||||
final LotroCardBlueprintLibrary library = new LotroCardBlueprintLibrary();
|
||||
_lotroCardBlueprintLibraryInjectable = new Injectable<LotroCardBlueprintLibrary>() {
|
||||
@Override
|
||||
public LotroCardBlueprintLibrary getValue() {
|
||||
return library;
|
||||
}
|
||||
};
|
||||
}
|
||||
return _lotroCardBlueprintLibraryInjectable;
|
||||
}
|
||||
|
||||
private synchronized Injectable<LeagueMatchDAO> getLeagueMatchDaoSafely() {
|
||||
if (_leagueMatchDAOInjectable == null) {
|
||||
final LeagueMatchDAO leagueMatchDao = new DbLeagueMatchDAO(_dbAccess);
|
||||
@@ -174,7 +188,7 @@ public class DaoProvider implements InjectableProvider<Context, Type> {
|
||||
|
||||
private synchronized Injectable<DeckDAO> getDeckDaoSafely() {
|
||||
if (_deckDaoInjectable == null) {
|
||||
final DeckDAO deckDao = new DeckDAO(_dbAccess, _library);
|
||||
final DeckDAO deckDao = new DeckDAO(_dbAccess, getLotroCardBlueprintLibrarySafely().getValue());
|
||||
_deckDaoInjectable = new Injectable<DeckDAO>() {
|
||||
@Override
|
||||
public DeckDAO getValue() {
|
||||
|
||||
Reference in New Issue
Block a user