Permalink
Browse files

added commenting to the demo

  • Loading branch information...
1 parent c8db5e9 commit a19e80cbfa0aa758da53d4b94beaa06b5ba720e0 @nberardi nberardi committed Jun 5, 2010
@@ -7,6 +7,7 @@
using FluentCassandra.Configuration;
using FluentCassandra.Types;
+using System.Threading;
namespace FluentCassandra.Sandbox
{
@@ -63,7 +64,64 @@ private static void Main(string[] args)
// show tags
Console.Write("tags:");
foreach (var tag in getPost.Tags)
- Console.Write(String.Format("{0}:{1},", tag.Name, tag.Value));
+ Console.Write(String.Format("{0}:{1},", tag.ColumnName, tag.ColumnValue));
+ Console.WriteLine();
+
+ // get the comments family
+ var commentsFamily = db.GetColumnFamily<TimeUUIDType, UTF8Type>("Comments");
+
+ dynamic postComments = commentsFamily.CreateRecord(key: "first-blog-post");
+
+ // lets attach it to the database before we add the comments
+ db.Attach(postComments);
+
+ // add 5 comments
+ for (int i = 0; i < 5; i++)
+ {
+ dynamic comment = postComments.CreateSuperColumn();
+ comment.Name = i + " Nick Berardi";
+ comment.Email = i + " nick@coderjournal.com";
+ comment.Website = i + " www.coderjournal.com";
+ comment.Comment = i + " Wow fluent cassandra is really great and easy to use.";
+
+ postComments[GuidGenerator.GenerateTimeBasedGuid()] = comment;
+
+ Console.WriteLine("Comment " + i + " Done");
+ Thread.Sleep(TimeSpan.FromSeconds(5));
+ }
+
+ // save the comments
+ db.SaveChanges();
+
+ DateTime lastDate = DateTime.Now;
+
+ for (int page = 0; page < 2; page++)
+ {
+ // lets back the date off by a millisecond so we don't get paging overlaps
+ lastDate = lastDate.AddMilliseconds(-1D);
+
+ Console.WriteLine("Showing page " + page + " starting at " + lastDate.ToLocalTime());
+
+ var comments = commentsFamily.Get("first-blog-post")
+ .Reverse()
+ .Fetch(lastDate)
+ .Take(4)
+ .FirstOrDefault();
+
+ foreach (dynamic comment in comments)
+ {
+ var dateTime = GuidGenerator.GetDateTime((Guid)comment.ColumnName);
+
+ Console.WriteLine(String.Format("{0:T} : {1} ({2} - {3})",
+ dateTime.ToLocalTime(),
+ comment.Name,
+ comment.Email,
+ comment.Website
+ ));
+
+ lastDate = dateTime;
+ }
+ }
}
Console.Read();
@@ -105,9 +105,9 @@ public void Query_Get_All_Columns()
// assert
Assert.AreEqual(expectedCount, actual.Columns.Count);
- Assert.AreEqual("Test1", (string)actual.Columns[0].Name);
- Assert.AreEqual("Test2", (string)actual.Columns[1].Name);
- Assert.AreEqual("Test3", (string)actual.Columns[2].Name);
+ Assert.AreEqual("Test1", (string)actual.Columns[0].ColumnName);
+ Assert.AreEqual("Test2", (string)actual.Columns[1].ColumnName);
+ Assert.AreEqual("Test3", (string)actual.Columns[2].ColumnName);
}
[TestMethod]
@@ -121,9 +121,9 @@ public void Query_Get_All_Columns_Reversed()
// assert
Assert.AreEqual(expectedCount, actual.Columns.Count);
- Assert.AreEqual("Test3", (string)actual.Columns[0].Name);
- Assert.AreEqual("Test2", (string)actual.Columns[1].Name);
- Assert.AreEqual("Test1", (string)actual.Columns[2].Name);
+ Assert.AreEqual("Test3", (string)actual.Columns[0].ColumnName);
+ Assert.AreEqual("Test2", (string)actual.Columns[1].ColumnName);
+ Assert.AreEqual("Test1", (string)actual.Columns[2].ColumnName);
}
[TestMethod]
@@ -139,9 +139,9 @@ public void Query_Get_All_Columns_DelayedLoading()
foreach (var actual in actualNotLoaded)
{
Assert.AreEqual(expectedCount, actual.Columns.Count);
- Assert.AreEqual("Test1", (string)actual.Columns[0].Name);
- Assert.AreEqual("Test2", (string)actual.Columns[1].Name);
- Assert.AreEqual("Test3", (string)actual.Columns[2].Name);
+ Assert.AreEqual("Test1", (string)actual.Columns[0].ColumnName);
+ Assert.AreEqual("Test2", (string)actual.Columns[1].ColumnName);
+ Assert.AreEqual("Test3", (string)actual.Columns[2].ColumnName);
}
}
}
@@ -38,8 +38,8 @@ public void Path_Set()
public void Constructor_Test()
{
// arrange
- var col1 = new FluentColumn<AsciiType> { Name = "Test1", Value = 300M };
- var col2 = new FluentColumn<AsciiType> { Name = "Test2", Value = "Hello" };
+ var col1 = new FluentColumn<AsciiType> { ColumnName = "Test1", ColumnValue = 300M };
+ var col2 = new FluentColumn<AsciiType> { ColumnName = "Test2", ColumnValue = "Hello" };
// act
var actual = new FluentColumnFamily<AsciiType>("Keyspace1", "Standard1");
@@ -77,8 +77,8 @@ public void Constructor_Dynamic_Test()
public void Mutation()
{
// arrange
- var col1 = new FluentColumn<AsciiType> { Name = "Test1", Value = 300M };
- var col2 = new FluentColumn<AsciiType> { Name = "Test2", Value = "Hello" };
+ var col1 = new FluentColumn<AsciiType> { ColumnName = "Test1", ColumnValue = 300M };
+ var col2 = new FluentColumn<AsciiType> { ColumnName = "Test2", ColumnValue = "Hello" };
// act
var actual = new FluentColumnFamily<AsciiType>("Keyspace1", "Standard1");
@@ -91,8 +91,8 @@ public void Mutation()
Assert.AreEqual(2, mutations.Count());
Assert.AreEqual(2, mutations.Count(x => x.Type == MutationType.Added));
- var mut1 = mutations.FirstOrDefault(x => x.Column.Name == "Test1");
- var mut2 = mutations.FirstOrDefault(x => x.Column.Name == "Test2");
+ var mut1 = mutations.FirstOrDefault(x => x.Column.ColumnName == "Test1");
+ var mut2 = mutations.FirstOrDefault(x => x.Column.ColumnName == "Test2");
Assert.AreSame(col1, mut1.Column);
Assert.AreSame(col2, mut2.Column);
@@ -121,8 +121,8 @@ public void Dynamic_Mutation()
Assert.AreEqual(2, mutations.Count());
Assert.AreEqual(2, mutations.Count(x => x.Type == MutationType.Added));
- var mut1 = mutations.FirstOrDefault(x => x.Column.Name == col1);
- var mut2 = mutations.FirstOrDefault(x => x.Column.Name == col2);
+ var mut1 = mutations.FirstOrDefault(x => x.Column.ColumnName == col1);
+ var mut2 = mutations.FirstOrDefault(x => x.Column.ColumnName == col2);
Assert.IsNotNull(mut1);
Assert.IsNotNull(mut2);
@@ -20,14 +20,14 @@ public void Constructor_Test()
// act
var actual = new FluentColumn<AsciiType> {
- Name = nameExpected,
- Value = valueExpected
+ ColumnName = nameExpected,
+ ColumnValue = valueExpected
};
// assert
- Assert.AreEqual(nameExpected, (string)actual.Name);
- Assert.AreEqual(valueExpected, (double)actual.Value);
- Assert.AreEqual(timestampExpected, actual.Timestamp.LocalDateTime.Date);
+ Assert.AreEqual(nameExpected, (string)actual.ColumnName);
+ Assert.AreEqual(valueExpected, (double)actual.ColumnValue);
+ Assert.AreEqual(timestampExpected, actual.ColumnTimestamp.LocalDateTime.Date);
}
}
}
@@ -38,8 +38,8 @@ public void Path_Set()
public void Constructor_Test()
{
// arrange
- var col1 = new FluentSuperColumn<AsciiType, AsciiType> { Name = "Test1" };
- var col2 = new FluentSuperColumn<AsciiType, AsciiType> { Name = "Test2" };
+ var col1 = new FluentSuperColumn<AsciiType, AsciiType> { ColumnName = "Test1" };
+ var col2 = new FluentSuperColumn<AsciiType, AsciiType> { ColumnName = "Test2" };
// act
var actual = new FluentSuperColumnFamily<AsciiType, AsciiType>("Keyspace1", "Standard1");
@@ -56,8 +56,8 @@ public void Constructor_Test()
public void Constructor_Dynamic_Test()
{
// arrange
- var col1 = new FluentSuperColumn<AsciiType, AsciiType> { Name = "Test1" };
- var col2 = new FluentSuperColumn<AsciiType, AsciiType> { Name = "Test2" };
+ var col1 = new FluentSuperColumn<AsciiType, AsciiType> { ColumnName = "Test1" };
+ var col2 = new FluentSuperColumn<AsciiType, AsciiType> { ColumnName = "Test2" };
// act
dynamic actual = new FluentSuperColumnFamily<AsciiType, AsciiType>("Keyspace1", "Standard1");
@@ -77,8 +77,8 @@ public void Constructor_Dynamic_Test()
public void Mutation()
{
// arrange
- var col1 = new FluentSuperColumn<AsciiType, AsciiType> { Name = "Test1" };
- var col2 = new FluentSuperColumn<AsciiType, AsciiType> { Name = "Test2" };
+ var col1 = new FluentSuperColumn<AsciiType, AsciiType> { ColumnName = "Test1" };
+ var col2 = new FluentSuperColumn<AsciiType, AsciiType> { ColumnName = "Test2" };
// act
var actual = new FluentSuperColumnFamily<AsciiType, AsciiType>("Keyspace1", "Standard1");
@@ -91,8 +91,8 @@ public void Mutation()
Assert.AreEqual(2, mutations.Count());
Assert.AreEqual(2, mutations.Count(x => x.Type == MutationType.Added));
- var mut1 = mutations.FirstOrDefault(x => x.Column.Name == "Test1");
- var mut2 = mutations.FirstOrDefault(x => x.Column.Name == "Test2");
+ var mut1 = mutations.FirstOrDefault(x => x.Column.ColumnName == "Test1");
+ var mut2 = mutations.FirstOrDefault(x => x.Column.ColumnName == "Test2");
Assert.AreSame(col1, mut1.Column);
Assert.AreSame(col2, mut2.Column);
@@ -105,8 +105,8 @@ public void Mutation()
public void Dynamic_Mutation()
{
// arrange
- var col1 = new FluentSuperColumn<AsciiType, AsciiType> { Name = "Test1" };
- var col2 = new FluentSuperColumn<AsciiType, AsciiType> { Name = "Test2" };
+ var col1 = new FluentSuperColumn<AsciiType, AsciiType> { ColumnName = "Test1" };
+ var col2 = new FluentSuperColumn<AsciiType, AsciiType> { ColumnName = "Test2" };
// act
dynamic actual = new FluentSuperColumnFamily<AsciiType, AsciiType>("Keyspace1", "Standard1");
@@ -119,8 +119,8 @@ public void Dynamic_Mutation()
Assert.AreEqual(2, mutations.Count());
Assert.AreEqual(2, mutations.Count(x => x.Type == MutationType.Added));
- var mut1 = mutations.FirstOrDefault(x => x.Column.Name == "Test1");
- var mut2 = mutations.FirstOrDefault(x => x.Column.Name == "Test2");
+ var mut1 = mutations.FirstOrDefault(x => x.Column.ColumnName == "Test1");
+ var mut2 = mutations.FirstOrDefault(x => x.Column.ColumnName == "Test2");
Assert.IsNotNull(mut1);
Assert.IsNotNull(mut2);
@@ -39,17 +39,17 @@ public void Constructor_Test()
{
// arrange
var colName = "This is a test name";
- var col1 = new FluentColumn<AsciiType> { Name = "Test1", Value = 300M };
- var col2 = new FluentColumn<AsciiType> { Name = "Test2", Value = "Hello" };
+ var col1 = new FluentColumn<AsciiType> { ColumnName = "Test1", ColumnValue = 300M };
+ var col2 = new FluentColumn<AsciiType> { ColumnName = "Test2", ColumnValue = "Hello" };
// act
var actual = new FluentSuperColumn<AsciiType, AsciiType>();
- actual.Name = colName;
+ actual.ColumnName = colName;
actual.Columns.Add(col1);
actual.Columns.Add(col2);
// assert
- Assert.AreEqual(colName, (string)actual.Name);
+ Assert.AreEqual(colName, (string)actual.ColumnName);
Assert.AreEqual(2, actual.Columns.Count);
}
@@ -83,12 +83,12 @@ public void Mutation()
{
// arrange
var colName = "This is a test name";
- var col1 = new FluentColumn<AsciiType> { Name = "Test1", Value = 300M };
- var col2 = new FluentColumn<AsciiType> { Name = "Test2", Value = "Hello" };
+ var col1 = new FluentColumn<AsciiType> { ColumnName = "Test1", ColumnValue = 300M };
+ var col2 = new FluentColumn<AsciiType> { ColumnName = "Test2", ColumnValue = "Hello" };
// act
var actual = new FluentSuperColumn<AsciiType, AsciiType>();
- actual.Name = colName;
+ actual.ColumnName = colName;
actual.Columns.Add(col1);
actual.Columns.Add(col2);
@@ -98,8 +98,8 @@ public void Mutation()
Assert.AreEqual(2, mutations.Count());
Assert.AreEqual(2, mutations.Count(x => x.Type == MutationType.Added));
- var mut1 = mutations.FirstOrDefault(x => x.Column.Name == "Test1");
- var mut2 = mutations.FirstOrDefault(x => x.Column.Name == "Test2");
+ var mut1 = mutations.FirstOrDefault(x => x.Column.ColumnName == "Test1");
+ var mut2 = mutations.FirstOrDefault(x => x.Column.ColumnName == "Test2");
Assert.AreSame(col1, mut1.Column);
Assert.AreSame(col2, mut2.Column);
@@ -120,7 +120,7 @@ public void Dynamic_Mutation()
// act
dynamic actual = new FluentSuperColumn<AsciiType, AsciiType>();
- actual.Name = colName;
+ actual.ColumnName = colName;
actual.Test1 = colValue1;
actual.Test2 = colValue2;
@@ -130,8 +130,8 @@ public void Dynamic_Mutation()
Assert.AreEqual(2, mutations.Count());
Assert.AreEqual(2, mutations.Count(x => x.Type == MutationType.Added));
- var mut1 = mutations.FirstOrDefault(x => x.Column.Name == col1);
- var mut2 = mutations.FirstOrDefault(x => x.Column.Name == col2);
+ var mut1 = mutations.FirstOrDefault(x => x.Column.ColumnName == col1);
+ var mut2 = mutations.FirstOrDefault(x => x.Column.ColumnName == col2);
Assert.IsNotNull(mut1);
Assert.IsNotNull(mut2);
@@ -49,8 +49,8 @@ public void Standard_GetColumn()
var column = _family.GetColumn(_testKey, _testName);
// assert
- Assert.AreEqual(_testName, (string)column.Name);
- Assert.AreEqual(expected, (double)column.Value);
+ Assert.AreEqual(_testName, (string)column.ColumnName);
+ Assert.AreEqual(expected, (double)column.ColumnValue);
}
[TestMethod]
@@ -63,8 +63,8 @@ public void Super_GetColumn()
var column = _superFamily.GetColumn(_testKey, _testSuperName, _testName);
// assert
- Assert.AreEqual(_testName, (string)column.Name);
- Assert.AreEqual(expected, (double)column.Value);
+ Assert.AreEqual(_testName, (string)column.ColumnName);
+ Assert.AreEqual(expected, (double)column.ColumnValue);
}
[TestMethod]
@@ -76,7 +76,7 @@ public void Super_GetSuperColumn()
var column = _superFamily.GetSuperColumn(_testKey, _testSuperName);
// assert
- Assert.AreEqual(_testSuperName, (string)column.Name);
+ Assert.AreEqual(_testSuperName, (string)column.ColumnName);
}
}
}
@@ -31,9 +31,9 @@ public static void InsertColumn<CompareWith>(this CassandraColumnFamily<CompareW
public static void InsertColumn<CompareWith>(this CassandraColumnFamily<CompareWith> family, string key, FluentColumnPath path)
where CompareWith : CassandraType
{
- var columnName = path.Column.Name;
- var columnValue = path.Column.Value;
- var timestamp = path.Column.Timestamp;
+ var columnName = path.Column.ColumnName;
+ var columnValue = path.Column.ColumnValue;
+ var timestamp = path.Column.ColumnTimestamp;
var op = new InsertColumn(key, columnName, columnValue, timestamp);
family.ExecuteOperation(op);
@@ -59,7 +59,7 @@ public static void InsertColumn<CompareWith>(this CassandraColumnFamily<CompareW
public static IFluentColumn<CompareWith> GetColumn<CompareWith>(this CassandraColumnFamily<CompareWith> family, string key, FluentColumnPath path)
where CompareWith : CassandraType
{
- var columnName = (CompareWith)path.Column.Name;
+ var columnName = (CompareWith)path.Column.ColumnName;
return GetColumn<CompareWith>(family, key, columnName);
}
@@ -77,7 +77,7 @@ public static IFluentColumn<CompareWith> GetColumn<CompareWith>(this CassandraCo
public static void RemoveColumn<CompareWith>(this CassandraColumnFamily<CompareWith> family, string key, FluentColumnPath path)
where CompareWith : CassandraType
{
- var columnName = (CompareWith)path.Column.Name;
+ var columnName = (CompareWith)path.Column.ColumnName;
RemoveColumn<CompareWith>(family, key, columnName);
}
Oops, something went wrong.

0 comments on commit a19e80c

Please sign in to comment.