Search in sources :

Example 1 with PlayersDao

use of com.alessiodp.parties.common.storage.sql.dao.players.PlayersDao in project Parties by AlessioDP.

the class SQLDispatcherTest method testListParties.

@Test
public void testListParties(@TempDir Path tempDir) {
    PartyManager mockPartyManager = mock(PartyManager.class);
    when(mockPlugin.getPartyManager()).thenReturn(mockPartyManager);
    when(mockPartyManager.initializeParty(any())).thenAnswer((mock) -> initializeParty(mockPlugin, mock.getArgument(0)));
    PlayerManager mockPlayerManager = mock(PlayerManager.class);
    when(mockPlugin.getPlayerManager()).thenReturn(mockPlayerManager);
    when(mockPlayerManager.initializePlayer(any())).thenAnswer((mock) -> initializePlayer(mockPlugin, mock.getArgument(0)));
    PartiesSQLDispatcher dispatcher = getSQLDispatcherH2();
    PartiesDao daoParties = dispatcher.getConnectionFactory().getJdbi().onDemand(H2PartiesDao.class);
    PlayersDao daoPlayers = dispatcher.getConnectionFactory().getJdbi().onDemand(H2PlayersDao.class);
    populateWithParties(dispatcher, daoParties, daoPlayers);
    listPartiesNumber(dispatcher);
    listPartiesByName(dispatcher);
    listPartiesByMembers(dispatcher);
    listPartiesByKills(dispatcher);
    listPartiesByExperience(dispatcher);
    dispatcher.stop();
    dispatcher = getSQLDispatcherSQLite(tempDir);
    daoParties = dispatcher.getConnectionFactory().getJdbi().onDemand(SQLitePartiesDao.class);
    daoPlayers = dispatcher.getConnectionFactory().getJdbi().onDemand(SQLitePlayersDao.class);
    populateWithParties(dispatcher, daoParties, daoPlayers);
    listPartiesNumber(dispatcher);
    listPartiesByName(dispatcher);
    listPartiesByMembers(dispatcher);
    listPartiesByKills(dispatcher);
    listPartiesByExperience(dispatcher);
    dispatcher.stop();
    dispatcher = getSQLDispatcherMySQL(mockPlugin);
    if (dispatcher != null) {
        daoParties = dispatcher.getConnectionFactory().getJdbi().onDemand(PartiesDao.class);
        daoPlayers = dispatcher.getConnectionFactory().getJdbi().onDemand(PlayersDao.class);
        populateWithParties(dispatcher, daoParties, daoPlayers);
        listPartiesNumber(dispatcher);
        listPartiesByName(dispatcher);
        listPartiesByMembers(dispatcher);
        listPartiesByKills(dispatcher);
        listPartiesByExperience(dispatcher);
        dispatcher.stop();
    }
    dispatcher = getSQLDispatcherMariaDB(mockPlugin);
    if (dispatcher != null) {
        daoParties = dispatcher.getConnectionFactory().getJdbi().onDemand(PartiesDao.class);
        daoPlayers = dispatcher.getConnectionFactory().getJdbi().onDemand(PlayersDao.class);
        populateWithParties(dispatcher, daoParties, daoPlayers);
        listPartiesNumber(dispatcher);
        listPartiesByName(dispatcher);
        listPartiesByMembers(dispatcher);
        listPartiesByKills(dispatcher);
        listPartiesByExperience(dispatcher);
        dispatcher.stop();
    }
    dispatcher = getSQLDispatcherPostgreSQL(mockPlugin);
    if (dispatcher != null) {
        daoParties = dispatcher.getConnectionFactory().getJdbi().onDemand(PostgreSQLPartiesDao.class);
        daoPlayers = dispatcher.getConnectionFactory().getJdbi().onDemand(PostgreSQLPlayersDao.class);
        populateWithParties(dispatcher, daoParties, daoPlayers);
        listPartiesNumber(dispatcher);
        listPartiesByName(dispatcher);
        listPartiesByMembers(dispatcher);
        listPartiesByKills(dispatcher);
        listPartiesByExperience(dispatcher);
        dispatcher.stop();
    }
}
Also used : PlayerManager(com.alessiodp.parties.common.players.PlayerManager) SQLitePartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.SQLitePartiesDao) PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PartiesDao) H2PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.H2PartiesDao) PostgreSQLPartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PostgreSQLPartiesDao) PartyManager(com.alessiodp.parties.common.parties.PartyManager) PartiesSQLDispatcher(com.alessiodp.parties.common.storage.dispatchers.PartiesSQLDispatcher) SQLitePartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.SQLitePartiesDao) PostgreSQLPartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PostgreSQLPartiesDao) SQLitePlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.SQLitePlayersDao) H2PlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.H2PlayersDao) PostgreSQLPlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.PostgreSQLPlayersDao) PlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.PlayersDao) SQLitePlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.SQLitePlayersDao) PostgreSQLPlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.PostgreSQLPlayersDao) Test(org.junit.jupiter.api.Test)

Example 2 with PlayersDao

use of com.alessiodp.parties.common.storage.sql.dao.players.PlayersDao in project Parties by AlessioDP.

the class PartiesSQLDispatcher method getPartyByName.

@Override
public PartyImpl getPartyByName(String name) {
    PartyImpl ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).getByName(name)).orElse(null);
    if (ret != null) {
        ret.setAccessible(true);
        ret.setMembers(this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(playersDao).getInParty(ret.getId().toString())));
        ret.setAccessible(false);
    }
    return ret;
}
Also used : PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PartiesDao) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) HashMap(java.util.HashMap) MySQLConnectionFactory(com.alessiodp.core.common.storage.sql.connection.MySQLConnectionFactory) H2PlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.H2PlayersDao) ConfigParties(com.alessiodp.parties.common.configuration.data.ConfigParties) TreeSet(java.util.TreeSet) PartyHomeImpl(com.alessiodp.parties.common.parties.objects.PartyHomeImpl) StorageType(com.alessiodp.core.common.storage.StorageType) ConfigMain(com.alessiodp.parties.common.configuration.data.ConfigMain) Handle(org.jdbi.v3.core.Handle) SQLDispatcher(com.alessiodp.core.common.storage.dispatchers.SQLDispatcher) PartiesDatabaseManager(com.alessiodp.parties.common.storage.PartiesDatabaseManager) LinkedList(java.util.LinkedList) ADPPlugin(com.alessiodp.core.common.ADPPlugin) LinkedHashSet(java.util.LinkedHashSet) H2PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.H2PartiesDao) PostgreSQLConnectionFactory(com.alessiodp.core.common.storage.sql.connection.PostgreSQLConnectionFactory) PostgreSQLPlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.PostgreSQLPlayersDao) SQLitePlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.SQLitePlayersDao) H2ConnectionFactory(com.alessiodp.core.common.storage.sql.connection.H2ConnectionFactory) Set(java.util.Set) PostgreSQLPartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PostgreSQLPartiesDao) UUID(java.util.UUID) ConnectionFactory(com.alessiodp.core.common.storage.sql.connection.ConnectionFactory) List(java.util.List) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) SQLitePartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.SQLitePartiesDao) MariaDBConnectionFactory(com.alessiodp.core.common.storage.sql.connection.MariaDBConnectionFactory) IPartiesDatabase(com.alessiodp.parties.common.storage.interfaces.IPartiesDatabase) PartiesConstants(com.alessiodp.parties.common.configuration.PartiesConstants) PlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.PlayersDao) SQLiteConnectionFactory(com.alessiodp.core.common.storage.sql.connection.SQLiteConnectionFactory) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 3 with PlayersDao

use of com.alessiodp.parties.common.storage.sql.dao.players.PlayersDao in project Parties by AlessioDP.

the class PartiesSQLDispatcher method getListFixed.

@Override
public Set<PartyImpl> getListFixed() {
    Set<PartyImpl> ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).getListFixed());
    // Load members
    for (PartyImpl party : ret) {
        party.setAccessible(true);
        party.setMembers(this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(playersDao).getInParty(party.getId().toString())));
        party.setAccessible(false);
    }
    return ret;
}
Also used : PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PartiesDao) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) HashMap(java.util.HashMap) MySQLConnectionFactory(com.alessiodp.core.common.storage.sql.connection.MySQLConnectionFactory) H2PlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.H2PlayersDao) ConfigParties(com.alessiodp.parties.common.configuration.data.ConfigParties) TreeSet(java.util.TreeSet) PartyHomeImpl(com.alessiodp.parties.common.parties.objects.PartyHomeImpl) StorageType(com.alessiodp.core.common.storage.StorageType) ConfigMain(com.alessiodp.parties.common.configuration.data.ConfigMain) Handle(org.jdbi.v3.core.Handle) SQLDispatcher(com.alessiodp.core.common.storage.dispatchers.SQLDispatcher) PartiesDatabaseManager(com.alessiodp.parties.common.storage.PartiesDatabaseManager) LinkedList(java.util.LinkedList) ADPPlugin(com.alessiodp.core.common.ADPPlugin) LinkedHashSet(java.util.LinkedHashSet) H2PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.H2PartiesDao) PostgreSQLConnectionFactory(com.alessiodp.core.common.storage.sql.connection.PostgreSQLConnectionFactory) PostgreSQLPlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.PostgreSQLPlayersDao) SQLitePlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.SQLitePlayersDao) H2ConnectionFactory(com.alessiodp.core.common.storage.sql.connection.H2ConnectionFactory) Set(java.util.Set) PostgreSQLPartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PostgreSQLPartiesDao) UUID(java.util.UUID) ConnectionFactory(com.alessiodp.core.common.storage.sql.connection.ConnectionFactory) List(java.util.List) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) SQLitePartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.SQLitePartiesDao) MariaDBConnectionFactory(com.alessiodp.core.common.storage.sql.connection.MariaDBConnectionFactory) IPartiesDatabase(com.alessiodp.parties.common.storage.interfaces.IPartiesDatabase) PartiesConstants(com.alessiodp.parties.common.configuration.PartiesConstants) PlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.PlayersDao) SQLiteConnectionFactory(com.alessiodp.core.common.storage.sql.connection.SQLiteConnectionFactory) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 4 with PlayersDao

use of com.alessiodp.parties.common.storage.sql.dao.players.PlayersDao in project Parties by AlessioDP.

the class PartiesSQLDispatcher method getParty.

@Override
public PartyImpl getParty(UUID id) {
    PartyImpl ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).get(id.toString())).orElse(null);
    if (ret != null) {
        ret.setAccessible(true);
        ret.setMembers(this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(playersDao).getInParty(id.toString())));
        ret.setAccessible(false);
    }
    return ret;
}
Also used : PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PartiesDao) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) HashMap(java.util.HashMap) MySQLConnectionFactory(com.alessiodp.core.common.storage.sql.connection.MySQLConnectionFactory) H2PlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.H2PlayersDao) ConfigParties(com.alessiodp.parties.common.configuration.data.ConfigParties) TreeSet(java.util.TreeSet) PartyHomeImpl(com.alessiodp.parties.common.parties.objects.PartyHomeImpl) StorageType(com.alessiodp.core.common.storage.StorageType) ConfigMain(com.alessiodp.parties.common.configuration.data.ConfigMain) Handle(org.jdbi.v3.core.Handle) SQLDispatcher(com.alessiodp.core.common.storage.dispatchers.SQLDispatcher) PartiesDatabaseManager(com.alessiodp.parties.common.storage.PartiesDatabaseManager) LinkedList(java.util.LinkedList) ADPPlugin(com.alessiodp.core.common.ADPPlugin) LinkedHashSet(java.util.LinkedHashSet) H2PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.H2PartiesDao) PostgreSQLConnectionFactory(com.alessiodp.core.common.storage.sql.connection.PostgreSQLConnectionFactory) PostgreSQLPlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.PostgreSQLPlayersDao) SQLitePlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.SQLitePlayersDao) H2ConnectionFactory(com.alessiodp.core.common.storage.sql.connection.H2ConnectionFactory) Set(java.util.Set) PostgreSQLPartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PostgreSQLPartiesDao) UUID(java.util.UUID) ConnectionFactory(com.alessiodp.core.common.storage.sql.connection.ConnectionFactory) List(java.util.List) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) SQLitePartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.SQLitePartiesDao) MariaDBConnectionFactory(com.alessiodp.core.common.storage.sql.connection.MariaDBConnectionFactory) IPartiesDatabase(com.alessiodp.parties.common.storage.interfaces.IPartiesDatabase) PartiesConstants(com.alessiodp.parties.common.configuration.PartiesConstants) PlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.PlayersDao) SQLiteConnectionFactory(com.alessiodp.core.common.storage.sql.connection.SQLiteConnectionFactory) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Example 5 with PlayersDao

use of com.alessiodp.parties.common.storage.sql.dao.players.PlayersDao in project Parties by AlessioDP.

the class PartiesSQLDispatcher method getListParties.

@Override
public LinkedHashSet<PartyImpl> getListParties(PartiesDatabaseManager.ListOrder order, int limit, int offset) {
    LinkedHashSet<PartyImpl> ret;
    List<String> blacklist = ConfigParties.ADDITIONAL_LIST_HIDDENPARTIES;
    if (order == PartiesDatabaseManager.ListOrder.NAME)
        ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).getListByName(blacklist, limit, offset));
    else if (order == PartiesDatabaseManager.ListOrder.MEMBERS)
        ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).getListByMembers(blacklist, limit, offset));
    else if (order == PartiesDatabaseManager.ListOrder.KILLS)
        ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).getListByKills(blacklist, limit, offset));
    else if (order == PartiesDatabaseManager.ListOrder.EXPERIENCE)
        ret = this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(partiesDao).getListByExperience(blacklist, limit, offset));
    else
        throw new IllegalStateException("Cannot get the list of parties with the order " + order.name());
    // Load members
    for (PartyImpl party : ret) {
        party.setAccessible(true);
        party.setMembers(this.connectionFactory.getJdbi().withHandle(handle -> handle.attach(playersDao).getInParty(party.getId().toString())));
        party.setAccessible(false);
    }
    return ret;
}
Also used : PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PartiesDao) PartyPlayerImpl(com.alessiodp.parties.common.players.objects.PartyPlayerImpl) HashMap(java.util.HashMap) MySQLConnectionFactory(com.alessiodp.core.common.storage.sql.connection.MySQLConnectionFactory) H2PlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.H2PlayersDao) ConfigParties(com.alessiodp.parties.common.configuration.data.ConfigParties) TreeSet(java.util.TreeSet) PartyHomeImpl(com.alessiodp.parties.common.parties.objects.PartyHomeImpl) StorageType(com.alessiodp.core.common.storage.StorageType) ConfigMain(com.alessiodp.parties.common.configuration.data.ConfigMain) Handle(org.jdbi.v3.core.Handle) SQLDispatcher(com.alessiodp.core.common.storage.dispatchers.SQLDispatcher) PartiesDatabaseManager(com.alessiodp.parties.common.storage.PartiesDatabaseManager) LinkedList(java.util.LinkedList) ADPPlugin(com.alessiodp.core.common.ADPPlugin) LinkedHashSet(java.util.LinkedHashSet) H2PartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.H2PartiesDao) PostgreSQLConnectionFactory(com.alessiodp.core.common.storage.sql.connection.PostgreSQLConnectionFactory) PostgreSQLPlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.PostgreSQLPlayersDao) SQLitePlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.SQLitePlayersDao) H2ConnectionFactory(com.alessiodp.core.common.storage.sql.connection.H2ConnectionFactory) Set(java.util.Set) PostgreSQLPartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.PostgreSQLPartiesDao) UUID(java.util.UUID) ConnectionFactory(com.alessiodp.core.common.storage.sql.connection.ConnectionFactory) List(java.util.List) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl) SQLitePartiesDao(com.alessiodp.parties.common.storage.sql.dao.parties.SQLitePartiesDao) MariaDBConnectionFactory(com.alessiodp.core.common.storage.sql.connection.MariaDBConnectionFactory) IPartiesDatabase(com.alessiodp.parties.common.storage.interfaces.IPartiesDatabase) PartiesConstants(com.alessiodp.parties.common.configuration.PartiesConstants) PlayersDao(com.alessiodp.parties.common.storage.sql.dao.players.PlayersDao) SQLiteConnectionFactory(com.alessiodp.core.common.storage.sql.connection.SQLiteConnectionFactory) PartyImpl(com.alessiodp.parties.common.parties.objects.PartyImpl)

Aggregations

H2PartiesDao (com.alessiodp.parties.common.storage.sql.dao.parties.H2PartiesDao)5 PartiesDao (com.alessiodp.parties.common.storage.sql.dao.parties.PartiesDao)5 PostgreSQLPartiesDao (com.alessiodp.parties.common.storage.sql.dao.parties.PostgreSQLPartiesDao)5 SQLitePartiesDao (com.alessiodp.parties.common.storage.sql.dao.parties.SQLitePartiesDao)5 H2PlayersDao (com.alessiodp.parties.common.storage.sql.dao.players.H2PlayersDao)5 PlayersDao (com.alessiodp.parties.common.storage.sql.dao.players.PlayersDao)5 PostgreSQLPlayersDao (com.alessiodp.parties.common.storage.sql.dao.players.PostgreSQLPlayersDao)5 SQLitePlayersDao (com.alessiodp.parties.common.storage.sql.dao.players.SQLitePlayersDao)5 ADPPlugin (com.alessiodp.core.common.ADPPlugin)4 StorageType (com.alessiodp.core.common.storage.StorageType)4 SQLDispatcher (com.alessiodp.core.common.storage.dispatchers.SQLDispatcher)4 ConnectionFactory (com.alessiodp.core.common.storage.sql.connection.ConnectionFactory)4 H2ConnectionFactory (com.alessiodp.core.common.storage.sql.connection.H2ConnectionFactory)4 MariaDBConnectionFactory (com.alessiodp.core.common.storage.sql.connection.MariaDBConnectionFactory)4 MySQLConnectionFactory (com.alessiodp.core.common.storage.sql.connection.MySQLConnectionFactory)4 PostgreSQLConnectionFactory (com.alessiodp.core.common.storage.sql.connection.PostgreSQLConnectionFactory)4 SQLiteConnectionFactory (com.alessiodp.core.common.storage.sql.connection.SQLiteConnectionFactory)4 PartiesConstants (com.alessiodp.parties.common.configuration.PartiesConstants)4 ConfigMain (com.alessiodp.parties.common.configuration.data.ConfigMain)4 ConfigParties (com.alessiodp.parties.common.configuration.data.ConfigParties)4