Permalink
Browse files

Rename Database to MongoDatabase which is more consistent and better …

…to find.

Some cleanups.
  • Loading branch information...
1 parent 4452213 commit 7fd80e91ed23b8905fd0317cf23696ba46cb3db9 @lanwin lanwin committed Mar 12, 2010
View
20 MongoDB.Driver.Benchmark/Main.cs
@@ -26,7 +26,7 @@ public static void Main (string[] args)
Mongo m = new Mongo();
m.Connect();
- Database db = m["benchmark"];
+ MongoDatabase db = m["benchmark"];
db.MetaData.DropDatabase();
Console.WriteLine("Starting Tests");
@@ -104,7 +104,7 @@ public static void Main (string[] args)
large.Append("harvested_words", harvestedWords);
}
#region Insert Tests
- static void RunInsertTest(string name, Database db, string col, Document doc, bool index, bool bulk){
+ static void RunInsertTest(string name, MongoDatabase db, string col, Document doc, bool index, bool bulk){
TimeSpan lowest = TimeSpan.MaxValue;
for(int i = 0; i < trials; i++){
SetupInsert(db,"col",index);
@@ -115,7 +115,7 @@ public static void Main (string[] args)
Console.Out.WriteLine(String.Format("{0}{1} {2}", name + new string('.', 55 - name.Length), opsSec, lowest));
}
- static void SetupInsert(Database db, string col, bool index){
+ static void SetupInsert(MongoDatabase db, string col, bool index){
try{
db.MetaData.DropCollection(col);
if(index){
@@ -127,7 +127,7 @@ public static void Main (string[] args)
}
}
- static TimeSpan TimeInsert(Database db, string col, Document doc, bool bulk){
+ static TimeSpan TimeInsert(MongoDatabase db, string col, Document doc, bool bulk){
DateTime start = DateTime.Now;
if(bulk){
DoBulkInsert(db,col,doc, batchSize);
@@ -139,7 +139,7 @@ public static void Main (string[] args)
return t;
}
- static void DoInsert(Database db, string col, Document doc){
+ static void DoInsert(MongoDatabase db, string col, Document doc){
for(int i = 0; i < perTrial; i++){
Document ins = new Document();
doc.CopyTo(ins);
@@ -148,7 +148,7 @@ public static void Main (string[] args)
}
}
- static void DoBulkInsert(Database db, string col, Document doc, int size){
+ static void DoBulkInsert(MongoDatabase db, string col, Document doc, int size){
for(int i = 0; i < perTrial / size; i++){
Document[] docs = new Document[size];
for(int f = 0; f < docs.Length; f++){
@@ -224,7 +224,7 @@ public static void Main (string[] args)
}
#region Find Tests
- static void RunFindTest(string name, Database db, string col, Document spec, bool range){
+ static void RunFindTest(string name, MongoDatabase db, string col, Document spec, bool range){
TimeSpan lowest = TimeSpan.MaxValue;
for(int i = 0; i < trials; i++){
TimeSpan ret = TimeFind(db, col, spec, range);
@@ -234,7 +234,7 @@ public static void Main (string[] args)
Console.Out.WriteLine(String.Format("{0}{1} {2}", name + new string('.', 55 - name.Length), opsSec, lowest));
}
- static TimeSpan TimeFind(Database db, string col,Document psec, bool range){
+ static TimeSpan TimeFind(MongoDatabase db, string col,Document psec, bool range){
DateTime start = DateTime.Now;
if(range){
DoFindOne(db,col,psec);
@@ -246,13 +246,13 @@ public static void Main (string[] args)
return t;
}
- static void DoFindOne(Database db, string col, Document spec){
+ static void DoFindOne(MongoDatabase db, string col, Document spec){
for(int i = 0; i < perTrial; i++){
db[col].FindOne(spec);
}
}
- static void DoFind(Database db, string col, Document spec){
+ static void DoFind(MongoDatabase db, string col, Document spec){
for(int i = 0; i < perTrial; i++){
ICursor<Document> cur = db[col].Find(spec);
foreach(Document d in cur.Documents){
View
6 MongoDB.GridFS/GridFile.cs
@@ -6,7 +6,7 @@ namespace MongoDB.GridFS
{
public class GridFile{
- private Database db;
+ private MongoDatabase db;
private string name;
public string Name {
@@ -25,9 +25,9 @@ public IMongoCollection<Document> Chunks
get { return this.chunks; }
}
- public GridFile(Database db):this(db,"fs"){}
+ public GridFile(MongoDatabase db):this(db,"fs"){}
- public GridFile(Database db, string bucket){
+ public GridFile(MongoDatabase db, string bucket){
this.db = db;
this.files = db[bucket + ".files"];
this.chunks = db[bucket + ".chunks"];
View
6 MongoDB.GridFS/GridFileInfo.cs
@@ -17,7 +17,7 @@ public class GridFileInfo
private const string DEFAULT_CONTENT_TYPE = "text/plain";
private GridFile gridFile;
- private Database db;
+ private MongoDatabase db;
private string bucket;
@@ -82,15 +82,15 @@ public string FileName
}
#endregion
- public GridFileInfo(Database db, string bucket, string filename){
+ public GridFileInfo(MongoDatabase db, string bucket, string filename){
this.db = db;
this.bucket = bucket;
this.gridFile = new GridFile(db,bucket);
SetFileDataDefaults(filename);
if(gridFile.Exists(filename)) this.LoadFileData();
}
- public GridFileInfo(Database db, string filename){
+ public GridFileInfo(MongoDatabase db, string filename){
this.db = db;
this.bucket = "fs";
this.gridFile = new GridFile(db);
View
2 MongoDB.Net-Tests/MongoTestBase.cs
@@ -9,7 +9,7 @@ namespace MongoDB.Driver
public abstract class MongoTestBase
{
public Mongo Mongo{get;set;}
- public Database DB{
+ public MongoDatabase DB{
get{
return this.Mongo["tests"];
}
View
2 MongoDB.Net-Tests/TestCollectionMetaData.cs
@@ -9,7 +9,7 @@ namespace MongoDB.Driver
[TestFixture]
public class TestCollectionMetaData : MongoTestBase
{
- Database adminDb;
+ MongoDatabase adminDb;
public override string TestCollections {
get {
View
2 MongoDB.Net-Tests/TestMongo.cs
@@ -29,7 +29,7 @@ public void TestDefaults()
Mongo m = new Mongo(connectionString);
bool thrown = false;
try{
- Database db = m["admin"];
+ MongoDatabase db = m["admin"];
db["$cmd"].FindOne(new Document().Append("listDatabases", 1.0));
}catch(MongoCommException){
thrown = true;
View
4 MongoDBDriver/CollectionMetaData.cs
@@ -12,12 +12,12 @@ public class CollectionMetaData
{
private string fullName;
private string name;
- private Database db;
+ private MongoDatabase db;
public CollectionMetaData (string dbName, string name, Connection conn){
this.fullName = dbName + "." + name;
this.name = name;
- this.db = new Database (conn, dbName);
+ this.db = new MongoDatabase (conn, dbName);
}
private Document options = null;
View
4 MongoDBDriver/DatabaseJS.cs
@@ -9,10 +9,10 @@ namespace MongoDB.Driver{
public class DatabaseJS : ICollection<Document>
{
//private Connection connection;
- private Database db;
+ private MongoDatabase db;
private IMongoCollection<Document> js;
- internal DatabaseJS (Database db){
+ internal DatabaseJS (MongoDatabase db){
this.db = db;
this.js = db["system.js"];
//Needed for some versions of the db to retrieve the functions.
View
6 MongoDBDriver/DatabaseMetaData.cs
@@ -10,12 +10,12 @@ public class DatabaseMetaData
{
private Connection connection;
private string name;
- private Database db;
+ private MongoDatabase db;
public DatabaseMetaData(string name, Connection conn){
this.connection = conn;
this.name = name;
- this.db = new Database(conn, name);
+ this.db = new MongoDatabase(conn, name);
}
public MongoCollection<Document> CreateCollection(String name){
@@ -48,7 +48,7 @@ public Boolean DropCollection(MongoCollection<Document> col)
public void AddUser(string username, string password){
IMongoCollection<Document> users = db["system.users"];
- string pwd = Database.Hash(username + ":mongo:" + password);
+ string pwd = MongoDatabase.Hash(username + ":mongo:" + password);
Document user = new Document().Append("user", username).Append("pwd", pwd);
if (FindUser(username) != null){
View
2 MongoDBDriver/IMongoCollection.cs
@@ -9,7 +9,7 @@ public interface IMongoCollection<T> where T : class
/// Gets the database.
/// </summary>
/// <value>The database.</value>
- Database Database { get; }
+ MongoDatabase Database { get; }
/// <summary>
/// Gets or sets the name.
View
4 MongoDBDriver/MapReduce.cs
@@ -59,7 +59,7 @@ public class MapReduceResult{
}
- Database db;
+ MongoDatabase db;
Document cmd;
#region "Properties"
@@ -76,7 +76,7 @@ public class MapReduceResult{
get {return result;}
}
- internal MapReduce (Database db, string name){
+ internal MapReduce (MongoDatabase db, string name){
this.db = db;
this.cmd = new Document().Append("mapreduce", name);
this.Verbose = true;
View
8 MongoDBDriver/Mongo.cs
@@ -40,15 +40,15 @@ public class Mongo : IDisposable
/// </summary>
/// <param name="name">The name.</param>
/// <returns></returns>
- public Database GetDatabase (String name){
- return new Database (connection, name);
+ public MongoDatabase GetDatabase (String name){
+ return new MongoDatabase (connection, name);
}
/// <summary>
- /// Gets the <see cref="MongoDB.Driver.Database"/> with the specified name.
+ /// Gets the <see cref="MongoDatabase"/> with the specified name.
/// </summary>
/// <value></value>
- public Database this[String name] {
+ public MongoDatabase this[String name] {
get { return this.GetDatabase (name); }
}
View
6 MongoDBDriver/MongoCollection.cs
@@ -16,7 +16,7 @@ public class MongoCollection<T> : IMongoCollection<T>
private static readonly OidGenerator OidGenerator = new OidGenerator();
private readonly ObjectDescriptor _objectDescriptor = new ObjectDescriptor();
private readonly Connection _connection;
- private Database _database;
+ private MongoDatabase _database;
private CollectionMetaData _metaData;
/// <summary>
@@ -36,8 +36,8 @@ public class MongoCollection<T> : IMongoCollection<T>
/// Gets the database.
/// </summary>
/// <value>The database.</value>
- public Database Database{
- get { return _database ?? (_database = new Database(_connection, DatabaseName)); }
+ public MongoDatabase Database{
+ get { return _database ?? (_database = new MongoDatabase(_connection, DatabaseName)); }
}
/// <summary>
View
2 MongoDBDriver/MongoDB.Driver.csproj
@@ -86,7 +86,7 @@
<Compile Include="Connections\ConnectionState.cs" />
<Compile Include="Connections\IConnectionFactory.cs" />
<Compile Include="Connections\SimpleConnectionFactory.cs" />
- <Compile Include="Database.cs" />
+ <Compile Include="MongoDatabase.cs" />
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Bson\BsonWriter.cs" />
<Compile Include="DatabaseMetaData.cs" />
View
61 MongoDBDriver/Database.cs → MongoDBDriver/MongoDatabase.cs
@@ -6,30 +6,30 @@
namespace MongoDB.Driver
{
- public class Database
+ public class MongoDatabase
{
private readonly Connection _connection;
private DatabaseJS _javascript;
private DatabaseMetaData _metaData;
/// <summary>
- /// Initializes a new instance of the <see cref="Database"/> class.
+ /// Initializes a new instance of the <see cref="MongoDatabase"/> class.
/// </summary>
/// <param name="connectionString">The connection string.</param>
/// <param name="name">The name.</param>
- public Database(string connectionString, String name)
+ public MongoDatabase(string connectionString, String name)
:this(ConnectionFactory.GetConnection(connectionString),name)
{
if(name == null)
throw new ArgumentNullException("name");
}
/// <summary>
- /// Initializes a new instance of the <see cref="Database"/> class.
+ /// Initializes a new instance of the <see cref="MongoDatabase"/> class.
/// </summary>
/// <param name="connection">The conn.</param>
/// <param name="name">The name.</param>
- public Database(Connection connection, String name){
+ public MongoDatabase(Connection connection, String name){
//Todo: should be internal
Name = name;
_connection = connection;
@@ -124,35 +124,41 @@ public Database(string connectionString, String name)
}
/// <summary>
- /// Most operations do not have a return code in order to save the client from having to wait for results.
- /// GetLastError can be called to retrieve the return code if clients want one.
+ /// Most operations do not have a return code in order to save the client from having to wait for results.
+ /// GetLastError can be called to retrieve the return code if clients want one.
/// </summary>
+ /// <returns></returns>
public Document GetLastError(){
return SendCommand("getlasterror");
}
/// <summary>
- /// Retrieves the last error and forces the database to fsync all files before returning.
+ /// Retrieves the last error and forces the database to fsync all files before returning.
/// </summary>
+ /// <param name="fsync">if set to <c>true</c> [fsync].</param>
+ /// <returns></returns>
/// <remarks>
- /// Server version 1.3+
+ /// Server version 1.3+
/// </remarks>
- public Document GetLastErrorAndFSync(){
- return SendCommand(new Document{{"getlasterror", 1.0}, {"fsync", true}});
+ public Document GetLastError(bool fsync){
+ return SendCommand(new Document { { "getlasterror", 1.0 }, { "fsync", fsync } });
}
/// <summary>
- /// Call after sending a bulk operation to the database.
+ /// Call after sending a bulk operation to the database.
/// </summary>
+ /// <returns></returns>
public Document GetPreviousError(){
return SendCommand("getpreverror");
}
/// <summary>
- /// Gets the sister database on the same Mongo connection with the given name.
+ /// Gets the sister database on the same Mongo connection with the given name.
/// </summary>
- public Database GetSisterDatabase(string sisterDbName){
- return new Database(_connection, sisterDbName);
+ /// <param name="sisterDatabaseName">Name of the sister database.</param>
+ /// <returns></returns>
+ public MongoDatabase GetSisterDatabase(string sisterDatabaseName){
+ return new MongoDatabase(_connection, sisterDatabaseName);
}
/// <summary>
@@ -194,31 +200,22 @@ public Database(string connectionString, String name)
/// <summary>
/// Sends the command.
/// </summary>
- /// <param name="command">The command.</param>
+ /// <param name="commandName">The command name.</param>
/// <returns></returns>
- public Document SendCommand(string command){
+ public Document SendCommand(string commandName){
AuthenticateIfRequired();
- return SendCommandCore(command);
+ var cmd = new Document().Append(commandName, 1.0);
+ return SendCommandCore(cmd);
}
/// <summary>
/// Sends the command.
/// </summary>
- /// <param name="cmd">The CMD.</param>
+ /// <param name="command">The CMD.</param>
/// <returns></returns>
- public Document SendCommand(Document cmd){
+ public Document SendCommand(Document command){
AuthenticateIfRequired();
- return SendCommandCore(cmd);
- }
-
- /// <summary>
- /// Sends the command core.
- /// </summary>
- /// <param name="command">The command.</param>
- /// <returns></returns>
- private Document SendCommandCore(string command){
- var cmd = new Document().Append(command, 1.0);
- return SendCommandCore(cmd);
+ return SendCommandCore(command);
}
/// <summary>
@@ -270,7 +267,7 @@ public Database(string connectionString, String name)
if(string.IsNullOrEmpty(builder.Username))
return;
- var nonceResult = SendCommandCore("getnonce");
+ var nonceResult = SendCommandCore(new Document().Append("getnonce", 1.0));
var nonce = (String)nonceResult["nonce"];
if(nonce == null)
View
2 examples/Simple/Main.cs
@@ -16,7 +16,7 @@ namespace Simple
class MainClass
{
Mongo mongo;
- Database simple;
+ MongoDatabase simple;
IMongoCollection<Document> categories;
public static void Main (string[] args){

0 comments on commit 7fd80e9

Please sign in to comment.