use of com.sk89q.worldguard.util.io.Closer in project WorldGuard by EngineHub.
the class RegionInserter method insertPolygons.
private void insertPolygons() throws SQLException {
Closer closer = Closer.create();
try {
PreparedStatement stmt = closer.register(conn.prepareStatement("INSERT INTO " + config.getTablePrefix() + "region_poly2d " + "(region_id, world_id, max_y, min_y) " + "VALUES " + "(?, " + worldId + ", ?, ?)"));
for (List<ProtectedPolygonalRegion> partition : Lists.partition(polygons, StatementBatch.MAX_BATCH_SIZE)) {
for (ProtectedPolygonalRegion region : partition) {
stmt.setString(1, region.getId());
stmt.setInt(2, region.getMaximumPoint().getBlockY());
stmt.setInt(3, region.getMinimumPoint().getBlockY());
stmt.addBatch();
}
stmt.executeBatch();
}
} finally {
closer.closeQuietly();
}
}
use of com.sk89q.worldguard.util.io.Closer in project WorldGuard by EngineHub.
the class RegionInserter method insertRegionTypes.
private void insertRegionTypes() throws SQLException {
Closer closer = Closer.create();
try {
PreparedStatement stmt = closer.register(conn.prepareStatement("INSERT INTO " + config.getTablePrefix() + "region " + "(id, world_id, type, priority, parent) " + "VALUES " + "(?, ?, ?, ?, NULL)"));
for (List<ProtectedRegion> partition : Lists.partition(all, StatementBatch.MAX_BATCH_SIZE)) {
for (ProtectedRegion region : partition) {
stmt.setString(1, region.getId());
stmt.setInt(2, worldId);
stmt.setString(3, SQLRegionDatabase.getRegionTypeName(region));
stmt.setInt(4, region.getPriority());
stmt.addBatch();
}
stmt.executeBatch();
}
} finally {
closer.closeQuietly();
}
}
use of com.sk89q.worldguard.util.io.Closer in project WorldGuard by EngineHub.
the class RegionRemover method removeRows.
private void removeRows(Collection<String> names, String table, String field) throws SQLException {
Closer closer = Closer.create();
try {
PreparedStatement stmt = closer.register(conn.prepareStatement("DELETE FROM " + config.getTablePrefix() + table + " WHERE " + field + " = ? AND world_id = " + worldId));
StatementBatch batch = new StatementBatch(stmt, StatementBatch.MAX_BATCH_SIZE);
for (String name : names) {
stmt.setString(1, name);
batch.addBatch();
}
batch.executeRemaining();
} finally {
closer.closeQuietly();
}
}
use of com.sk89q.worldguard.util.io.Closer in project WorldGuard by EngineHub.
the class DataLoader method loadGlobals.
private void loadGlobals() throws SQLException {
Closer closer = Closer.create();
try {
PreparedStatement stmt = closer.register(conn.prepareStatement("SELECT r.id, r.priority, p.id AS parent " + "FROM " + config.getTablePrefix() + "region AS r " + "LEFT JOIN " + config.getTablePrefix() + "region AS p " + " ON (r.parent = p.id AND r.world_id = p.world_id) " + "WHERE r.type = 'global' AND r.world_id = " + worldId));
ResultSet rs = closer.register(stmt.executeQuery());
while (rs.next()) {
ProtectedRegion region = new GlobalProtectedRegion(rs.getString("id"));
region.setPriority(rs.getInt("priority"));
loaded.put(rs.getString("id"), region);
String parentId = rs.getString("parent");
if (parentId != null) {
parentSets.put(region, parentId);
}
}
} finally {
closer.closeQuietly();
}
}
use of com.sk89q.worldguard.util.io.Closer in project WorldGuard by EngineHub.
the class DataLoader method loadFlags.
private void loadFlags() throws SQLException {
Closer closer = Closer.create();
try {
PreparedStatement stmt = closer.register(conn.prepareStatement("SELECT region_id, flag, value " + "FROM " + config.getTablePrefix() + "region_flag " + "WHERE world_id = " + worldId + " AND region_id IN " + "(SELECT id FROM " + config.getTablePrefix() + "region " + "WHERE world_id = " + worldId + ")"));
ResultSet rs = closer.register(stmt.executeQuery());
Table<String, String, Object> data = HashBasedTable.create();
while (rs.next()) {
data.put(rs.getString("region_id"), rs.getString("flag"), unmarshalFlagValue(rs.getString("value")));
}
for (Entry<String, Map<String, Object>> entry : data.rowMap().entrySet()) {
ProtectedRegion region = loaded.get(entry.getKey());
region.setFlags(flagRegistry.unmarshal(entry.getValue(), true));
}
} finally {
closer.closeQuietly();
}
}
Aggregations