use of com.massivecraft.massivecore.store.Db in project MassiveCore by MassiveCraft.
the class CmdMassiveCoreStoreListcolls method perform.
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform() throws MassiveException {
// Args
final String dbAlias = this.readArg(ConfServer.dburi);
final Db db = MStore.getDb(dbAlias);
if (db == null) {
msg("<b>could not get the database.");
return;
}
// Prepare
Set<String> collnames = new TreeSet<>(ComparatorNaturalOrder.get());
collnames.addAll(db.getCollnames());
// Do it!
message(Txt.titleize("Collections in " + db.getDbName()));
for (String collname : collnames) {
String message = Txt.parse("<h>") + collname;
Coll<?> coll = null;
for (Coll<?> collCandidate : Coll.getInstances()) {
if (!collCandidate.getName().equals(collname))
continue;
if (collCandidate.getDb() != db)
continue;
coll = collCandidate;
break;
}
if (coll == null) {
message += Txt.parse(" <b>UNUSED");
} else {
message += Txt.parse(" <i>(%d documents)", coll.getIds().size());
}
message(message);
}
}
use of com.massivecraft.massivecore.store.Db in project MassiveCore by MassiveCraft.
the class CmdMassiveCoreStoreCopydb method perform.
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void perform() throws MassiveException {
// Args
final String fromAlias = this.readArg();
final Db fromDb = MStore.getDb(fromAlias);
if (fromDb == null) {
msg("<b>could not get the from-database.");
return;
}
final String toAlias = this.readArg();
final Db toDb = MStore.getDb(toAlias);
if (toDb == null) {
msg("<b>could not get the to-database.");
return;
}
// Prepare
Set<String> collnames = fromDb.getCollnames();
// Statistics
int countCollCurrent = 0;
int countCollTotal = collnames.size();
// Do it!
long before = System.currentTimeMillis();
msg("<i>Now copying database with <h>%d <i>collections.", countCollTotal);
for (String collname : fromDb.getCollnames()) {
countCollCurrent++;
final Coll fromColl = new Coll(collname, Entity.class, fromDb, MassiveCore.get());
final Coll toColl = new Coll(collname, Entity.class, toDb, MassiveCore.get());
Collection<String> ids = fromDb.getIds(fromColl);
msg("<i>Now copying collection <h>%d/%d %s <i>with <h>%d <i>documents.", countCollCurrent, countCollTotal, collname, ids.size());
// Do a load check to verify we have access to this folder.
if (ids.size() > 0 && fromDb.load(fromColl, ids.iterator().next()) == null) {
msg("<b>Skipping <h>%s <b>since could not load data.", collname);
continue;
}
for (String id : ids) {
Entry<JsonObject, Long> data = fromDb.load(fromColl, id);
toDb.save(toColl, id, data.getKey());
}
}
long after = System.currentTimeMillis();
long duration = after - before;
msg("<g>The copy is now complete. <i>It took <h>%dms<i>.", duration);
}
Aggregations