Expand driver functionality
This commit is contained in:
parent
b732a26a9e
commit
7065d5c824
@ -53,4 +53,5 @@ public class DbFlatfile extends DbAbstract
|
||||
{
|
||||
return new File(dir, coll.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -59,6 +59,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)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user