The copy command seem to work like this.

This commit is contained in:
Olof Larsson 2013-05-01 14:29:40 +02:00
parent 00304be8a2
commit 81be88fca8
2 changed files with 46 additions and 3 deletions

View File

@ -41,6 +41,8 @@ permissions:
mcore.cmd.mcore: true mcore.cmd.mcore: true
mcore.cmd.mcore.id: true mcore.cmd.mcore.id: true
mcore.cmd.mcore.version: true mcore.cmd.mcore.version: true
mcore.cmd.mcore.mstore: true
mcore.cmd.mcore.mstore.copydb: true
mcore.cmd.mcore.usys: true mcore.cmd.mcore.usys: true
mcore.cmd.mcore.usys.multiverse: true mcore.cmd.mcore.usys.multiverse: true
mcore.cmd.mcore.usys.multiverse.list: true mcore.cmd.mcore.usys.multiverse.list: true

View File

@ -1,9 +1,18 @@
package com.massivecraft.mcore.mcorecmd; package com.massivecraft.mcore.mcorecmd;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import com.massivecraft.mcore.MCore;
import com.massivecraft.mcore.MCorePerm; import com.massivecraft.mcore.MCorePerm;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.store.Coll;
import com.massivecraft.mcore.store.Db;
import com.massivecraft.mcore.store.Driver;
import com.massivecraft.mcore.store.MStore;
import com.massivecraft.mcore.xlib.gson.JsonElement;
public class CmdMCoreMStoreCopydb extends MCoreCommand public class CmdMCoreMStoreCopydb extends MCoreCommand
{ {
@ -11,8 +20,8 @@ public class CmdMCoreMStoreCopydb extends MCoreCommand
{ {
super(aliases); super(aliases);
this.addRequiredArg("fromuri"); this.addRequiredArg("from");
this.addRequiredArg("touri"); this.addRequiredArg("to");
this.addRequirements(ReqHasPerm.get(MCorePerm.CMD_MCORE_MSTORE_COPYDB.node)); this.addRequirements(ReqHasPerm.get(MCorePerm.CMD_MCORE_MSTORE_COPYDB.node));
} }
@ -20,7 +29,39 @@ public class CmdMCoreMStoreCopydb extends MCoreCommand
@Override @Override
public void perform() public void perform()
{ {
// TODO // Args
final String fromAlias = this.arg(0);
final String toAlias = this.arg(1);
// Prepare
final Db fromDb = MStore.getDb(fromAlias);
final Db toDb = MStore.getDb(toAlias);
final Driver fromDriver = fromDb.getDriver();
final Driver toDriver = toDb.getDriver();
Set<String> collnames = fromDb.getCollnames();
// Statistics
int countCollCurrent = 0;
int countCollTotal = collnames.size();
// Do it!
msg("<i>Now copying database with <h>%d <i>collections.", countCollTotal);
for (String collname : fromDb.getCollnames())
{
countCollCurrent++;
final Coll<?> fromColl = new Coll<Object>(collname, Object.class, fromDb, MCore.get());
final Coll<?> toColl = new Coll<Object>(collname, Object.class, toDb, MCore.get());
Collection<String> ids = fromDriver.getIds(fromColl);
msg("<i>Now copying collection <h>%d/%d %s <i>with <h>%d <i>documents.", countCollCurrent, countCollTotal, collname, ids.size());
for (String id : ids)
{
Entry<JsonElement, Long> data = fromDriver.load(fromColl, id);
toDriver.save(toColl, id, data.getKey());
}
}
} }
} }