Extracted RegionStore.save(Collection<Region> added, Collection<Region> updated, Collection<Region> removed) into PartiallyUpdatableStore.

This is necessary because some stores need to always save the entire database at a time (namely the YAML store), and adding an "all" parameter to the partial save method would mean that partial stores could not be supported in the future.
This commit is contained in:
sk89q 2012-11-16 15:52:37 -08:00
parent 723f17b782
commit 58fa6d1c0b
2 changed files with 55 additions and 13 deletions

View File

@ -0,0 +1,45 @@
// $Id$
/*
* This file is a part of WorldGuard.
* Copyright (c) sk89q <http://www.sk89q.com>
* Copyright (c) the WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY), without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.region.stores;
import java.io.IOException;
import java.util.Collection;
import com.sk89q.worldguard.region.Region;
/**
* A store that can accept a subset of regions to update.
* <p>
* This store is suitable for stores that don't need to have the entire copy of the
* region database at a time to perform a load or save operation.
*/
public interface PartiallyUpdatableStore extends RegionStore {
/**
* Save only selected regions to the region store.
*
* @param added a list of regions that were added
* @param updated a list of regions that were updated
* @param removed a list of regions that were removed
* @throws IOException on I/O error
*/
void save(Collection<Region> added, Collection<Region> updated,
Collection<Region> removed) throws IOException;
}

View File

@ -19,6 +19,7 @@
package com.sk89q.worldguard.region.stores;
import java.io.IOException;
import java.util.Collection;
import com.sk89q.worldguard.region.Region;
import com.sk89q.worldguard.region.indices.RegionIndex;
@ -44,21 +45,17 @@ public interface RegionStore {
RegionIndex load(RegionIndexFactory factory) throws IOException;
/**
* Save the entirety of a region index to the store. All existing entries in the
* store need to be removed.
* Save the entirety of a region collection to the store.
* <p>
* It must be assumed that the given list of regions is the complete list of all
* regions. With the case of partial stores, this also means that the given list
* is to be assumed as non-partial. It is therefore recommended that use of
* this method is limited to only special cases, such as creation of brand new
* region indexes.
*
* @param index the index to replace the store's list of regions with
* @param regions the collection of regions to store in its entirety
* @throws IOException on I/O error
*/
void save(RegionIndex index) throws IOException;
/**
* Save only selected regions to the region store.
*
* @param added a list of regions that were added
* @param updated a list of regions that were updated
* @param removed a list of regions that were removed
*/
void save(Region added[], Region updated[], Region removed[]) throws IOException;
void save(Collection<Region> regions) throws IOException;
}