Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

moved around a couple things

  • Loading branch information...
commit 3be9d2172c06ea59af1c9d8524c8dde28300ab40 1 parent fc335e7
Nick Berardi nberardi authored
67 src/FluentColumnFamily.cs
View
@@ -80,18 +80,8 @@ public CassandraObject Key
/// <returns></returns>
public CassandraObject this[CassandraObject columnName]
{
- get
- {
- object value;
- if (!TryGetColumn(columnName, out value))
- throw new CassandraException(String.Format("Column, {0}, could not be found.", columnName));
-
- return (CassandraObject)value;
- }
- set
- {
- TrySetColumn(columnName, value);
- }
+ get { return GetColumnValue(columnName); }
+ set { SetColumn(columnName, value); }
}
/// <summary>
@@ -145,35 +135,6 @@ public override IList<FluentColumn> Columns
{
get { return _columns; }
}
-
- public override void RemoveColumn(object name)
- {
- FluentColumn col = Columns.FirstOrDefault(c => c.ColumnName == name);
-
- if (col != null)
- {
- Columns.Remove(col);
- }
- else
- {
- var cfSchema = GetSchema();
- var schema = cfSchema.Columns.FirstOrDefault(c => c.Name == name);
-
- if (schema != null)
- {
- col = new FluentColumn(schema);
- col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
- }
- else
- {
- col = new FluentColumn();
- col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name);
- }
-
- col.SetParent(GetSelf());
- MutationTracker.ColumnMutated(MutationType.Removed, col);
- }
- }
/// <summary>
/// Gets the path.
@@ -278,9 +239,31 @@ public override bool TrySetColumn(object name, object value)
return true;
}
+ public override bool TryRemoveColumn(object name)
+ {
+ var col = Columns.FirstOrDefault(c => c.ColumnName == name);
+
+ if (col != null) {
+ Columns.Remove(col);
+ return true;
+ }
+
+ var schema = GetColumnSchema(name);
+ var mutationType = MutationType.Removed;
+
+ col = new FluentColumn(schema);
+ col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
+ col.SetParent(GetSelf());
+
+ // notify the tracker that the column has changed
+ OnColumnMutated(mutationType, col);
+
+ return true;
+ }
+
public override string ToString()
{
return String.Format("{0} - {1}", FamilyName, Key);
}
}
-}
+}
10 src/FluentCqlRow.cs
View
@@ -95,6 +95,11 @@ public override bool TrySetColumn(object name, object value)
throw new NotSupportedException();
}
+ public override bool TryRemoveColumn(object name)
+ {
+ throw new NotSupportedException();
+ }
+
public string FamilyName
{
get;
@@ -112,11 +117,6 @@ public override IList<FluentColumn> Columns
get { return _columns; }
}
- public override void RemoveColumn(object name)
- {
- throw new NotSupportedException();
- }
-
public CassandraObject this[CassandraObject columnName]
{
get
92 src/FluentRecord.cs
View
@@ -9,7 +9,7 @@ namespace FluentCassandra
/// <summary>
///
/// </summary>
- /// <typeparam name="T">A type that impliments <see cref="IFluentColumn"/>.</typeparam>
+ /// <typeparam name="T">A type that implements <see cref="IFluentColumn"/>.</typeparam>
public abstract class FluentRecord<T> : DynamicObject, IFluentRecord, INotifyPropertyChanged, IEnumerable<IFluentBaseColumn>, ILoadable
where T : IFluentBaseColumn
{
@@ -27,6 +27,53 @@ public FluentRecord()
/// </summary>
public abstract IList<T> Columns { get; }
+ public T GetColumn(object name)
+ {
+ var col = Columns.FirstOrDefault(c => c.ColumnName == name);
+
+ if (col == null)
+ return default(T);
+
+ return col;
+ }
+
+ public bool SetColumn(object name, object value)
+ {
+ return TrySetColumn(name, value);
+ }
+
+ public bool RemoveColumn(object name)
+ {
+ return TryRemoveColumn(name);
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="name"></param>
+ /// <param name="result"></param>
+ /// <returns></returns>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public abstract bool TryGetColumn(object name, out object result);
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="name"></param>
+ /// <param name="value"></param>
+ /// <returns></returns>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public abstract bool TrySetColumn(object name, object value);
+
+
+ ///
+ /// </summary>
+ /// <param name="name"></param>
+ /// <param name="value"></param>
+ /// <returns></returns>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public abstract bool TryRemoveColumn(object name);
+
/// <summary>
///
/// </summary>
@@ -66,15 +113,6 @@ public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out ob
/// <summary>
///
/// </summary>
- /// <param name="name"></param>
- /// <param name="result"></param>
- /// <returns></returns>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public abstract bool TryGetColumn(object name, out object result);
-
- /// <summary>
- ///
- /// </summary>
/// <param name="binder"></param>
/// <param name="value"></param>
/// <returns></returns>
@@ -105,7 +143,24 @@ public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object
/// <param name="value"></param>
/// <returns></returns>
[EditorBrowsable(EditorBrowsableState.Never)]
- public abstract bool TrySetColumn(object name, object value);
+ public override bool TryDeleteMember(DeleteMemberBinder binder)
+ {
+ return TryRemoveColumn(binder.Name);
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="binder"></param>
+ /// <param name="indexes"></param>
+ /// <param name="value"></param>
+ /// <returns></returns>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override bool TryDeleteIndex(DeleteIndexBinder binder, object[] indexes)
+ {
+ object index0 = indexes[0];
+ return TryRemoveColumn(index0);
+ }
protected bool SuppressMutationTracking { get; private set; }
@@ -170,21 +225,6 @@ public IFluentMutationTracker MutationTracker
private set;
}
- public abstract void RemoveColumn(object name);
-
- public bool TryRemoveColumn(object name)
- {
- var col = Columns.FirstOrDefault(c => c.ColumnName == name);
-
- if (col != null)
- {
- Columns.Remove(col);
- return true;
- }
-
- return false;
- }
-
#endregion
}
}
53 src/FluentSuperColumn.cs
View
@@ -87,34 +87,6 @@ public override IList<FluentColumn> Columns
get { return _columns; }
}
- public override void RemoveColumn(object name)
- {
- FluentColumn col = Columns.FirstOrDefault(c => c.ColumnName == name);
-
- if (col != null)
- {
- Columns.Remove(col);
- }
- else
- {
- var schema = GetColumnSchema(name);
-
- if (schema != null)
- {
- col = new FluentColumn(schema);
- col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
- }
- else
- {
- col = new FluentColumn();
- col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name);
- }
-
- col.SetParent(GetPath());
- MutationTracker.ColumnMutated(MutationType.Removed, col);
- }
- }
-
/// <summary>
///
/// </summary>
@@ -254,7 +226,7 @@ public override bool TrySetColumn(object name, object value)
var col = Columns.FirstOrDefault(c => c.ColumnName == name);
var mutationType = MutationType.Changed;
- // if column doesn't exisit create it and add it to the columns
+ // if column doesn't exist create it and add it to the columns
if (col == null)
{
var schema = GetColumnSchema(name);
@@ -277,6 +249,29 @@ public override bool TrySetColumn(object name, object value)
return true;
}
+ public override bool TryRemoveColumn(object name)
+ {
+ var col = Columns.FirstOrDefault(c => c.ColumnName == name);
+
+ if (col != null)
+ {
+ Columns.Remove(col);
+ return true;
+ }
+
+ var schema = GetColumnSchema(name);
+ var mutationType = MutationType.Removed;
+
+ col = new FluentColumn(schema);
+ col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
+ col.SetParent(GetPath());
+
+ // notify the tracker that the column has changed
+ OnColumnMutated(mutationType, col);
+
+ return true;
+ }
+
public void SetParent(FluentColumnParent parent)
{
UpdateParent(parent);
52 src/FluentSuperColumnFamily.cs
View
@@ -130,35 +130,6 @@ public override IList<FluentSuperColumn> Columns
get { return _columns; }
}
- public override void RemoveColumn(object name)
- {
- var col = Columns.FirstOrDefault(c => c.ColumnName == name);
-
- if (col != null)
- {
- Columns.Remove(col);
- }
- else
- {
- var cfSchema = GetSchema();
- var schema = cfSchema.Columns.FirstOrDefault(c => c.Name == name);
-
- if (schema != null)
- {
- col = new FluentSuperColumn(schema);
- col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
- }
- else
- {
- col = new FluentSuperColumn();
- col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name);
- }
-
- col.SetParent(GetSelf());
- MutationTracker.ColumnMutated(MutationType.Removed, col);
- }
- }
-
/// <summary>
///
/// </summary>
@@ -280,6 +251,29 @@ public override bool TrySetColumn(object name, object value)
return true;
}
+ public override bool TryRemoveColumn(object name)
+ {
+ var col = Columns.FirstOrDefault(c => c.ColumnName == name);
+
+ if (col != null)
+ {
+ Columns.Remove(col);
+ return true;
+ }
+
+ var schema = GetColumnSchema(name);
+ var mutationType = MutationType.Removed;
+
+ col = new FluentSuperColumn(schema);
+ col.ColumnName = CassandraObject.GetCassandraObjectFromObject(name, schema.NameType);
+ col.SetParent(GetSelf());
+
+ // notify the tracker that the column has changed
+ OnColumnMutated(mutationType, col);
+
+ return true;
+ }
+
public override string ToString()
{
return String.Format("{0} - {1}", FamilyName, Key);
13 src/Types/CassandraObject.cs
View
@@ -207,16 +207,13 @@ public static CassandraObject GetCassandraObjectFromDatabaseByteArray(byte[] val
return GetCassandraObjectFromDatabaseByteArray(value, cassandraType);
}
- public static CassandraObject GetCassandraObjectFromObject(object obj)
+ public static CassandraObject GetCassandraObjectFromObject(object obj, CassandraType cassandraType = null)
{
- var sourceType = obj.GetType();
- var cassandraType = CassandraType.GetCassandraType(sourceType);
+ if (cassandraType == null) {
+ var sourceType = obj.GetType();
+ cassandraType = CassandraType.GetCassandraType(sourceType);
+ }
- return GetCassandraObjectFromObject(obj, cassandraType);
- }
-
- public static CassandraObject GetCassandraObjectFromObject(object obj, CassandraType cassandraType)
- {
if (obj == null)
return null;
Please sign in to comment.
Something went wrong with that request. Please try again.