Expand driver functionality

This commit is contained in:
Olof Larsson 2014-09-18 00:17:42 +02:00
parent b732a26a9e
commit 7065d5c824
4 changed files with 25 additions and 0 deletions

View File

@ -53,4 +53,5 @@ public class DbFlatfile extends DbAbstract
{
return new File(dir, coll.getName());
}
}

View File

@ -18,6 +18,9 @@ public interface Driver
// What collections are in the database?
public Set<String> getCollnames(Db db);
// Rename a collection
public boolean renameColl(Db db, String from, String to);
// Is id X in the collection?
public boolean containsId(Coll<?> coll, String id);

View File

@ -58,6 +58,15 @@ public class DriverFlatfile extends DriverAbstract
return ret;
}
@Override
public boolean renameColl(Db db, String from, String to)
{
File dir = ((DbFlatfile)db).dir;
File fileFrom = new File(dir, from);
File fileTo = new File(dir, to);
return fileFrom.renameTo(fileTo);
}
@Override
public boolean containsId(Coll<?> coll, String id)

View File

@ -59,6 +59,18 @@ public class DriverMongo extends DriverAbstract
return ret;
}
@Override
public boolean renameColl(Db db, String from, String to)
{
if (!this.getCollnames(db).contains(from)) return false;
if (this.getCollnames(db).contains(to)) return false;
DB mdb = ((DbMongo)db).db;
mdb.getCollection(from).rename(to);
return true;
}
@Override
public boolean containsId(Coll<?> coll, String id)
{