Skip to content
This repository was archived by the owner on Nov 14, 2018. It is now read-only.

Adaptions to better match MongoDB csharp driver + New Query API + Additional unit tests #1

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
244e402
Added support for generating an object id
oklemencic Dec 27, 2013
cce9838
Added support for serialization of regular types (not only anonymous …
oklemencic Dec 27, 2013
8569513
Added helper methods for querying data
oklemencic Dec 27, 2013
5858565
Refactoring of "BsonValue" so that it doesn' store the key any more
oklemencic Dec 27, 2013
9da19ba
Renaming of types to use the same names as the MongoDb wrapper
oklemencic Dec 27, 2013
0a8032c
Added further query helpers
oklemencic Dec 27, 2013
c38f9fd
Simplified array handling
oklemencic Dec 27, 2013
2d728cb
Further work on serialization (adaption so it's similar to MongoDb)
oklemencic Dec 27, 2013
15dd927
Added further tests, refactorings
oklemencic Dec 27, 2013
b0c9928
Fixed date/time serialization
oklemencic Dec 27, 2013
2fd4246
Added suport for ID generation on the C# side
oklemencic Dec 27, 2013
00d7a61
Added improved support for serialization of custom types
oklemencic Dec 27, 2013
f643731
Further work on the improved query API
oklemencic Dec 27, 2013
4180d41
Cleaned up whitespaced, braces and copyright text
oklemencic Dec 27, 2013
d323a0d
Added performance demo
Dec 27, 2013
e53ef2d
Added ignore.conf
Dec 27, 2013
ea2623f
Added support for deserialization of BSON results
Dec 28, 2013
f0ec7b0
Support for .NET class deserialization from BSON document
Jan 1, 2014
a777e00
Included missing file
Jan 1, 2014
50f4fc6
Added support for $set operation via typed query
Jan 1, 2014
c5873a8
Added empty query
Jan 2, 2014
aed06e9
Added update operation support
Jan 2, 2014
d8320f5
Added support for update queries
Jan 2, 2014
13d9357
Refactoring of query handling to support collection joins
Jan 2, 2014
8e0815a
Further work on queries
Jan 2, 2014
4e8e712
Added element match query support
Jan 2, 2014
dda0d29
Added element match support
Jan 2, 2014
0a740ff
Minor
Jan 2, 2014
1b90ea9
Further work on queries
Jan 2, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
319 changes: 91 additions & 228 deletions Ejdb.BSON/BSONArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,238 +14,101 @@
// Boston, MA 02111-1307 USA.
// ============================================================================================
using System;
using System.IO;
using System.Collections;
using System.Globalization;

namespace Ejdb.BSON {

[Serializable]
public class BSONArray : BSONDocument {

public override BSONType BSONType {
get {
return BSONType.ARRAY;
}
}

public object this[int key] {
get {
return GetObjectValue(key.ToString());
}
}

public BSONArray() {
}

public BSONArray(BSONUndefined[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetUndefined(i);
}
}

public BSONArray(BSONull[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetNull(i);
}
}

public BSONArray(ushort[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetNumber(i, (int) arr[i]);
}
}

public BSONArray(uint[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetNumber(i, (long) arr[i]);
}
}

public BSONArray(ulong[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetNumber(i, (long) arr[i]);
}
}

public BSONArray(short[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetNumber(i, (int) arr[i]);
}
}

public BSONArray(string[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetString(i, arr[i]);
}
}

public BSONArray(int[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetNumber(i, arr[i]);
}
}

public BSONArray(long[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetNumber(i, arr[i]);
}
}

public BSONArray(float[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetNumber(i, arr[i]);
}
}

public BSONArray(double[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetNumber(i, arr[i]);
}
}

public BSONArray(bool[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetBool(i, arr[i]);
}
}

public BSONArray(BSONOid[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetOID(i, arr[i]);
}
}

public BSONArray(DateTime[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetDate(i, arr[i]);
}
}

public BSONArray(BSONDocument[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetObject(i, arr[i]);
}
}

public BSONArray(BSONArray[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetArray(i, arr[i]);
}
}

public BSONArray(BSONRegexp[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetRegexp(i, arr[i]);
}
}

public BSONArray(BSONTimestamp[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetTimestamp(i, arr[i]);
}
}

public BSONArray(BSONCodeWScope[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetCodeWScope(i, arr[i]);
}
}

public BSONArray(BSONBinData[] arr) {
for (var i = 0; i < arr.Length; ++i) {
SetBinData(i, arr[i]);
}
}

public BSONDocument SetNull(int idx) {
return base.SetNull(idx.ToString());
}

public BSONDocument SetUndefined(int idx) {
return base.SetUndefined(idx.ToString());
}

public BSONDocument SetMaxKey(int idx) {
return base.SetMaxKey(idx.ToString());
}

public BSONDocument SetMinKey(int idx) {
return base.SetMinKey(idx.ToString());
}

public BSONDocument SetOID(int idx, string oid) {
return base.SetOID(idx.ToString(), oid);
}

public BSONDocument SetOID(int idx, BSONOid oid) {
return base.SetOID(idx.ToString(), oid);
}

public BSONDocument SetBool(int idx, bool val) {
return base.SetBool(idx.ToString(), val);
}

public BSONDocument SetNumber(int idx, int val) {
return base.SetNumber(idx.ToString(), val);
}

public BSONDocument SetNumber(int idx, long val) {
return base.SetNumber(idx.ToString(), val);
}

public BSONDocument SetNumber(int idx, double val) {
return base.SetNumber(idx.ToString(), val);
}

public BSONDocument SetNumber(int idx, float val) {
return base.SetNumber(idx.ToString(), val);
}

public BSONDocument SetString(int idx, string val) {
return base.SetString(idx.ToString(), val);
}

public BSONDocument SetCode(int idx, string val) {
return base.SetCode(idx.ToString(), val);
}

public BSONDocument SetSymbol(int idx, string val) {
return base.SetSymbol(idx.ToString(), val);
}

public BSONDocument SetDate(int idx, DateTime val) {
return base.SetDate(idx.ToString(), val);
}

public BSONDocument SetRegexp(int idx, BSONRegexp val) {
return base.SetRegexp(idx.ToString(), val);
}

public BSONDocument SetBinData(int idx, BSONBinData val) {
return base.SetBinData(idx.ToString(), val);
}

public BSONDocument SetObject(int idx, BSONDocument val) {
return base.SetDocument(idx.ToString(), val);
}

public BSONDocument SetArray(int idx, BSONArray val) {
return base.SetArray(idx.ToString(), val);
}

public BSONDocument SetTimestamp(int idx, BSONTimestamp val) {
return base.SetTimestamp(idx.ToString(), val);
}

public BSONDocument SetCodeWScope(int idx, BSONCodeWScope val) {
return base.SetCodeWScope(idx.ToString(), val);
}

protected override void CheckKey(string key) {
int idx;
if (key == null || !int.TryParse(key, out idx) || idx < 0) {
throw new InvalidBSONDataException(string.Format("Invalid array key: {0}", key));
}
}
public class BsonArray : BsonDocument {


public BsonArray()
{
}

public BsonArray(BsonDocument document)
{
var iterator = new BsonIterator(document);
while (iterator.Next() != BsonType.EOO)
Add(iterator.CurrentKey, iterator.FetchCurrentValue());
}

public BsonArray(IEnumerable objects)
{
AddRange(objects);
}

public override BsonType BSONType
{
get
{
return BsonType.ARRAY;
}
}

public object this[int key]
{
get { return GetObjectValue(key.ToString()); }
}

public void SetMaxKey(int idx)
{
Add(BsonValue.GetMaxKey());
}

public void SetMinKey(int idx)
{
Add(BsonValue.GetMinKey());
}

/// <summary>
/// Adds multiple elements to the array.
/// </summary>
/// <param name="values">A list of values to add to the array.</param>
/// <returns>The array (so method calls can be chained).</returns>
public BsonArray AddRange(IEnumerable values)
{
if (values != null)
{
foreach (var value in values)
Add(BsonValue.ValueOf(value));
}

return this;
}

/// <summary>
/// Adds an element to the array.
/// </summary>
/// <param name="value">The value to add to the array.</param>
/// <returns>The array (so method calls can be chained).</returns>
public BsonArray Add(BsonValue value)
{
if (value != null)
{
var key = Keys.Count.ToString(CultureInfo.InvariantCulture);
Add(key, value);
}

return this;
}

public BsonArray Add(object value)
{
if (value != null)
{
var bsonValue = BsonValue.ValueOf(value);
return Add(bsonValue);
}

return this;
}

public int Count
{
get { return KeysCount; }
}
}
}

6 changes: 3 additions & 3 deletions Ejdb.BSON/BSONBinData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace Ejdb.BSON {

[Serializable]
public sealed class BSONBinData {
public sealed class BsonBinData {
readonly byte _subtype;
readonly byte[] _data;

Expand All @@ -35,13 +35,13 @@ public byte[] Data {
}
}

public BSONBinData(byte subtype, byte[] data) {
public BsonBinData(byte subtype, byte[] data) {
_subtype = subtype;
_data = new byte[data.Length];
Array.Copy(data, _data, data.Length);
}

internal BSONBinData(byte subtype, int len, BinaryReader input) {
internal BsonBinData(byte subtype, int len, BinaryReader input) {
_subtype = subtype;
_data = input.ReadBytes(len);
}
Expand Down
Loading