Search in sources :

Example 1 with Closer

use of com.sk89q.worldguard.util.io.Closer in project WorldGuard by EngineHub.

the class DataLoader method loadDomainGroups.

private void loadDomainGroups() throws SQLException {
    Closer closer = Closer.create();
    try {
        PreparedStatement stmt = closer.register(conn.prepareStatement("SELECT rg.region_id, g.name, rg.owner " + "FROM `" + config.getTablePrefix() + "region_groups` AS rg " + "INNER JOIN `" + config.getTablePrefix() + "group` AS g ON (rg.group_id = g.id) " + // LEFT JOIN is returning NULLS for reasons unknown
        "AND rg.world_id = " + this.worldId));
        ResultSet rs = closer.register(stmt.executeQuery());
        while (rs.next()) {
            ProtectedRegion region = loaded.get(rs.getString("region_id"));
            if (region != null) {
                DefaultDomain domain;
                if (rs.getBoolean("owner")) {
                    domain = region.getOwners();
                } else {
                    domain = region.getMembers();
                }
                domain.addGroup(rs.getString("name"));
            }
        }
    } finally {
        closer.closeQuietly();
    }
}
Also used : Closer(com.sk89q.worldguard.util.io.Closer) ResultSet(java.sql.ResultSet) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) PreparedStatement(java.sql.PreparedStatement) DefaultDomain(com.sk89q.worldguard.domains.DefaultDomain)

Example 2 with Closer

use of com.sk89q.worldguard.util.io.Closer in project WorldGuard by EngineHub.

the class DataLoader method loadDomainUsers.

private void loadDomainUsers() throws SQLException {
    Closer closer = Closer.create();
    try {
        PreparedStatement stmt = closer.register(conn.prepareStatement("SELECT p.region_id, u.name, u.uuid, p.owner " + "FROM " + config.getTablePrefix() + "region_players AS p " + "LEFT JOIN " + config.getTablePrefix() + "user AS u " + "          ON (p.user_id = u.id) " + "WHERE p.world_id = " + worldId));
        ResultSet rs = closer.register(stmt.executeQuery());
        while (rs.next()) {
            ProtectedRegion region = loaded.get(rs.getString("region_id"));
            if (region != null) {
                DefaultDomain domain;
                if (rs.getBoolean("owner")) {
                    domain = region.getOwners();
                } else {
                    domain = region.getMembers();
                }
                String name = rs.getString("name");
                String uuid = rs.getString("uuid");
                if (name != null) {
                    // noinspection deprecation
                    domain.addPlayer(name);
                } else if (uuid != null) {
                    try {
                        domain.addPlayer(UUID.fromString(uuid));
                    } catch (IllegalArgumentException e) {
                        log.warning("Invalid UUID '" + uuid + "' for region '" + region.getId() + "'");
                    }
                }
            }
        }
    } finally {
        closer.closeQuietly();
    }
}
Also used : Closer(com.sk89q.worldguard.util.io.Closer) ResultSet(java.sql.ResultSet) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) PreparedStatement(java.sql.PreparedStatement) DefaultDomain(com.sk89q.worldguard.domains.DefaultDomain)

Example 3 with Closer

use of com.sk89q.worldguard.util.io.Closer in project WorldGuard by EngineHub.

the class RegionInserter method insertPolygonVertices.

private void insertPolygonVertices() throws SQLException {
    Closer closer = Closer.create();
    try {
        PreparedStatement stmt = closer.register(conn.prepareStatement("INSERT INTO " + config.getTablePrefix() + "region_poly2d_point" + "(region_id, world_id, z, x) " + "VALUES " + "(?, " + worldId + ", ?, ?)"));
        StatementBatch batch = new StatementBatch(stmt, StatementBatch.MAX_BATCH_SIZE);
        for (ProtectedPolygonalRegion region : polygons) {
            for (BlockVector2 point : region.getPoints()) {
                stmt.setString(1, region.getId());
                stmt.setInt(2, point.getBlockZ());
                stmt.setInt(3, point.getBlockX());
                batch.addBatch();
            }
        }
        batch.executeRemaining();
    } finally {
        closer.closeQuietly();
    }
}
Also used : Closer(com.sk89q.worldguard.util.io.Closer) ProtectedPolygonalRegion(com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion) PreparedStatement(java.sql.PreparedStatement) BlockVector2(com.sk89q.worldedit.math.BlockVector2)

Example 4 with Closer

use of com.sk89q.worldguard.util.io.Closer in project WorldGuard by EngineHub.

the class RegionInserter method insertCuboids.

private void insertCuboids() throws SQLException {
    Closer closer = Closer.create();
    try {
        PreparedStatement stmt = closer.register(conn.prepareStatement("INSERT INTO " + config.getTablePrefix() + "region_cuboid " + "(region_id, world_id, min_z, min_y, min_x, max_z, max_y, max_x ) " + "VALUES " + "(?, " + worldId + ", ?, ?, ?, ?, ?, ?)"));
        for (List<ProtectedCuboidRegion> partition : Lists.partition(cuboids, StatementBatch.MAX_BATCH_SIZE)) {
            for (ProtectedCuboidRegion region : partition) {
                BlockVector3 min = region.getMinimumPoint();
                BlockVector3 max = region.getMaximumPoint();
                stmt.setString(1, region.getId());
                stmt.setInt(2, min.getBlockZ());
                stmt.setInt(3, min.getBlockY());
                stmt.setInt(4, min.getBlockX());
                stmt.setInt(5, max.getBlockZ());
                stmt.setInt(6, max.getBlockY());
                stmt.setInt(7, max.getBlockX());
                stmt.addBatch();
            }
            stmt.executeBatch();
        }
    } finally {
        closer.closeQuietly();
    }
}
Also used : Closer(com.sk89q.worldguard.util.io.Closer) PreparedStatement(java.sql.PreparedStatement) ProtectedCuboidRegion(com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Example 5 with Closer

use of com.sk89q.worldguard.util.io.Closer in project WorldGuard by EngineHub.

the class RegionUpdater method setParents.

private void setParents() throws SQLException {
    Closer closer = Closer.create();
    try {
        PreparedStatement stmt = closer.register(conn.prepareStatement("UPDATE " + config.getTablePrefix() + "region " + "SET parent = ? " + "WHERE id = ? AND world_id = " + worldId));
        for (List<ProtectedRegion> partition : Lists.partition(parentsToSet, StatementBatch.MAX_BATCH_SIZE)) {
            for (ProtectedRegion region : partition) {
                ProtectedRegion parent = region.getParent();
                if (parent != null) {
                    // Parent would be null due to a race condition
                    stmt.setString(1, parent.getId());
                    stmt.setString(2, region.getId());
                    stmt.addBatch();
                }
            }
            stmt.executeBatch();
        }
    } finally {
        closer.closeQuietly();
    }
}
Also used : Closer(com.sk89q.worldguard.util.io.Closer) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) PreparedStatement(java.sql.PreparedStatement)

Aggregations

Closer (com.sk89q.worldguard.util.io.Closer)25 PreparedStatement (java.sql.PreparedStatement)19 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)12 ResultSet (java.sql.ResultSet)10 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)7 SQLException (java.sql.SQLException)6 StorageException (com.sk89q.worldguard.protection.managers.storage.StorageException)5 ProtectedPolygonalRegion (com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion)3 Connection (java.sql.Connection)3 HashMap (java.util.HashMap)3 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)2 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)2 DefaultDomain (com.sk89q.worldguard.domains.DefaultDomain)2 ProtectedCuboidRegion (com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion)2 Statement (java.sql.Statement)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Flag (com.sk89q.worldguard.protection.flags.Flag)1 RegionDatabase (com.sk89q.worldguard.protection.managers.storage.RegionDatabase)1 Flyway (org.flywaydb.core.Flyway)1