Search in sources :

Example 1 with StatementKey

use of au.com.mineauz.minigames.backend.StatementKey in project Minigames by AddstarMC.

the class MySQLBackend method createStatements.

private void createStatements() {
    insertMinigame = new StatementKey("INSERT INTO `Minigames` (`name`) VALUES (?) ON DUPLICATE KEY UPDATE `minigame_id`=LAST_INSERT_ID(`minigame_id`);", true);
    insertPlayer = new StatementKey("INSERT INTO `Players` VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE `name` = VALUES(`name`), `displayname` = VALUES(`displayname`);");
    loadStatSettings = new StatementKey("SELECT `stat`, `display_name`, `format` FROM `StatMetadata` WHERE `minigame_id`=?;");
    saveStatSettings = new StatementKey("REPLACE INTO `StatMetadata` VALUES (?, ?, ?, ?);");
}
Also used : StatementKey(au.com.mineauz.minigames.backend.StatementKey)

Example 2 with StatementKey

use of au.com.mineauz.minigames.backend.StatementKey in project Minigames by AddstarMC.

the class MySQLStatLoader method loadStats.

// Loads from the stats table
private List<StoredStat> loadStats(ConnectionHandler handler, int minigameId, MinigameStat stat, StatValueField field, ScoreboardOrder order, int offset, int length) throws SQLException {
    String statName = stat.getName() + field.getSuffix();
    try {
        StatementKey statement;
        switch(order) {
            case ASCENDING:
                statement = getSingleAsc;
                break;
            case DESCENDING:
                statement = getSingleDesc;
                break;
            default:
                throw new AssertionError();
        }
        ResultSet rs = handler.executeQuery(statement, minigameId, statName, offset, length);
        List<StoredStat> stats = Lists.newArrayList();
        try {
            while (rs.next()) {
                stats.add(loadStat(rs));
            }
            return stats;
        } finally {
            rs.close();
        }
    } finally {
        handler.release();
    }
}
Also used : ResultSet(java.sql.ResultSet) StatementKey(au.com.mineauz.minigames.backend.StatementKey) StoredStat(au.com.mineauz.minigames.stats.StoredStat)

Example 3 with StatementKey

use of au.com.mineauz.minigames.backend.StatementKey in project Minigames by AddstarMC.

the class SQLiteStatLoader method loadStats.

// Loads from the stats table
private List<StoredStat> loadStats(ConnectionHandler handler, int minigameId, MinigameStat stat, StatValueField field, ScoreboardOrder order, int offset, int length) throws SQLException {
    String statName = stat.getName() + field.getSuffix();
    StatementKey statement;
    switch(order) {
        case ASCENDING:
            statement = getSingleAsc;
            break;
        case DESCENDING:
            statement = getSingleDesc;
            break;
        default:
            throw new AssertionError();
    }
    ResultSet rs = handler.executeQuery(statement, minigameId, statName, offset, length);
    List<StoredStat> stats = Lists.newArrayList();
    try {
        while (rs.next()) {
            stats.add(loadStat(rs));
        }
        return stats;
    } finally {
        rs.close();
    }
}
Also used : ResultSet(java.sql.ResultSet) StatementKey(au.com.mineauz.minigames.backend.StatementKey) StoredStat(au.com.mineauz.minigames.stats.StoredStat)

Example 4 with StatementKey

use of au.com.mineauz.minigames.backend.StatementKey in project Minigames by AddstarMC.

the class SQLiteBackend method createStatements.

private void createStatements() {
    insertMinigame = new StatementKey("INSERT OR IGNORE INTO `Minigames` (`name`) VALUES (?);", true);
    getMinigameId = new StatementKey("SELECT `minigame_id` FROM `Minigames` WHERE `name` = ?;");
    insertPlayer = new StatementKey("INSERT OR REPLACE INTO `Players` VALUES (?, ?, ?);");
    loadStatSettings = new StatementKey("SELECT `stat`, `display_name`, `format` FROM `StatMetadata` WHERE `minigame_id`=?;");
    saveStatSettings = new StatementKey("INSERT OR REPLACE INTO `StatMetadata` VALUES (?, ?, ?, ?);");
}
Also used : StatementKey(au.com.mineauz.minigames.backend.StatementKey)

Aggregations

StatementKey (au.com.mineauz.minigames.backend.StatementKey)4 StoredStat (au.com.mineauz.minigames.stats.StoredStat)2 ResultSet (java.sql.ResultSet)2