Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
only in Cassandra does TTL mean Seconds Until Deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Berardi committed Jan 27, 2012
1 parent a427c04 commit dc0875f
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/CassandraColumnFamilyOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void InsertColumn<CompareWith>(this CassandraColumnFamily<CompareW
var columnName = path.Column.ColumnName;
var columnValue = path.Column.ColumnValue;
var timestamp = path.Column.ColumnTimestamp;
var timeToLive = path.Column.ColumnTimeToLive;
var timeToLive = path.Column.ColumnSecondsUntilDeleted;

var op = new InsertColumn(key, columnName, columnValue, timestamp, timeToLive);
family.ExecuteOperation(op);
Expand All @@ -50,10 +50,10 @@ public static void InsertColumn<CompareWith>(this CassandraColumnFamily<CompareW
public static void InsertColumn<CompareWith>(this CassandraColumnFamily<CompareWith> family, BytesType key, CompareWith columnName, BytesType columnValue)
where CompareWith : CassandraType
{
InsertColumn<CompareWith>(family, key, columnName, columnValue, DateTimeOffset.UtcNow, 1);
InsertColumn<CompareWith>(family, key, columnName, columnValue, DateTimeOffset.UtcNow, null);
}

public static void InsertColumn<CompareWith>(this CassandraColumnFamily<CompareWith> family, BytesType key, CompareWith columnName, BytesType columnValue, DateTimeOffset timestamp, int timeToLive)
public static void InsertColumn<CompareWith>(this CassandraColumnFamily<CompareWith> family, BytesType key, CompareWith columnName, BytesType columnValue, DateTimeOffset timestamp, int? timeToLive)
where CompareWith : CassandraType
{
var op = new InsertColumn(key, columnName, columnValue, timestamp, timeToLive);
Expand Down
6 changes: 3 additions & 3 deletions src/CassandraSuperColumnFamilyOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void InsertColumn<CompareWith, CompareSubcolumnWith>(this Cassandr
var name = path.Column.ColumnName;
var value = path.Column.ColumnValue;
var timestamp = path.Column.ColumnTimestamp;
var timeToLive = path.Column.ColumnTimeToLive;
var timeToLive = path.Column.ColumnSecondsUntilDeleted;

var op = new InsertColumn(key, superColumnName, name, value, timestamp, timeToLive);
family.ExecuteOperation(op);
Expand All @@ -71,10 +71,10 @@ public static void InsertColumn<CompareWith, CompareSubcolumnWith>(this Cassandr
where CompareWith : CassandraType
where CompareSubcolumnWith : CassandraType
{
InsertColumn<CompareWith, CompareSubcolumnWith>(family, key, superColumnName, name, value, DateTimeOffset.UtcNow, 1);
InsertColumn<CompareWith, CompareSubcolumnWith>(family, key, superColumnName, name, value, DateTimeOffset.UtcNow, null);
}

public static void InsertColumn<CompareWith, CompareSubcolumnWith>(this CassandraSuperColumnFamily<CompareWith, CompareSubcolumnWith> family, BytesType key, CompareWith superColumnName, CompareSubcolumnWith name, BytesType value, DateTimeOffset timestamp, int timeToLive)
public static void InsertColumn<CompareWith, CompareSubcolumnWith>(this CassandraSuperColumnFamily<CompareWith, CompareSubcolumnWith> family, BytesType key, CompareWith superColumnName, CompareSubcolumnWith name, BytesType value, DateTimeOffset timestamp, int? timeToLive)
where CompareWith : CassandraType
where CompareSubcolumnWith : CassandraType
{
Expand Down
15 changes: 11 additions & 4 deletions src/FluentColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ public class FluentColumn<CompareWith> : IFluentColumn<CompareWith>
private BytesType _value;
private FluentColumnParent _parent;
private IFluentBaseColumnFamily _family;
private int? _ttl;

public FluentColumn()
{
ColumnTimestamp = DateTimeOffset.UtcNow;
ColumnTimeToLive = 1;
ColumnSecondsUntilDeleted = null;
}

/// <summary>
Expand Down Expand Up @@ -66,10 +67,16 @@ internal set
/// <summary>
///
/// </summary>
public int ColumnTimeToLive
public int? ColumnSecondsUntilDeleted
{
get;
set;
get { return _ttl; }
set
{
if (value.HasValue && value <= 0)
throw new CassandraException("ColumnSecondsUntilDeleted needs to be set to a postive value that is greater than zero");

_ttl = value;
}
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/IFluentColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public interface IFluentColumn : IFluentBaseColumn
{
BytesType ColumnValue { get; set; }
DateTimeOffset ColumnTimestamp { get; }
int ColumnTimeToLive { get; set; }
int? ColumnSecondsUntilDeleted { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/Operations/CassandraColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class CassandraColumn
public CassandraType Name { get; set; }
public BytesType Value { get; set; }
public DateTimeOffset Timestamp { get; set; }
public int Ttl { get; set; }
public int? Ttl { get; set; }
}
}
16 changes: 12 additions & 4 deletions src/Operations/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,16 @@ public static SlicePredicate CreateSlicePredicate(CassandraSlicePredicate predic

public static Column CreateColumn(CassandraColumn column)
{
return new Column {
var ccol = new Column {
Name = column.Name.TryToBigEndian(),
Value = column.Value.TryToBigEndian(),
Ttl = column.Ttl,
Timestamp = column.Timestamp.ToTimestamp()
};

if (column.Ttl.HasValue && column.Ttl.Value > 0)
ccol.Ttl = column.Ttl.Value;

return ccol;
}

public static CounterColumn CreateCounterColumn(CassandraCounterColumn column)
Expand Down Expand Up @@ -129,12 +133,16 @@ public static FluentColumn<CompareWith> ConvertColumnToFluentColumn<CompareWith>
where CompareWith : CassandraType
{

return new FluentColumn<CompareWith> {
var fcol = new FluentColumn<CompareWith> {
ColumnName = CassandraType.FromBigEndian<CompareWith>(col.Name),
ColumnValue = CassandraType.FromBigEndian<BytesType>(col.Value),
ColumnTimestamp = new DateTimeOffset(col.Timestamp, TimeSpan.Zero),
ColumnTimeToLive = col.Ttl
};

if (col.__isset.ttl)
fcol.ColumnSecondsUntilDeleted = col.Ttl;

return fcol;
}

public static FluentSuperColumn<CompareWith, CompareSubcolumnWith> ConvertSuperColumnToFluentSuperColumn<CompareWith, CompareSubcolumnWith>(SuperColumn col)
Expand Down
6 changes: 3 additions & 3 deletions src/Operations/InsertColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class InsertColumn : ColumnFamilyOperation<Void>

public BytesType ColumnValue { get; private set; }

public int TimeToLive { get; private set; }
public int? TimeToLive { get; private set; }

public DateTimeOffset Timestamp { get; private set; }

Expand Down Expand Up @@ -51,7 +51,7 @@ public override Void Execute()

#endregion

public InsertColumn(BytesType key, CassandraType name, BytesType value, DateTimeOffset timestamp, int timeToLive)
public InsertColumn(BytesType key, CassandraType name, BytesType value, DateTimeOffset timestamp, int? timeToLive)
{
Key = key;
ColumnName = name;
Expand All @@ -60,7 +60,7 @@ public InsertColumn(BytesType key, CassandraType name, BytesType value, DateTime
TimeToLive = timeToLive;
}

public InsertColumn(BytesType key, CassandraType superColumnName, CassandraType name, BytesType value, DateTimeOffset timestamp, int timeToLive)
public InsertColumn(BytesType key, CassandraType superColumnName, CassandraType name, BytesType value, DateTimeOffset timestamp, int? timeToLive)
{
Key = key;
SuperColumnName = superColumnName;
Expand Down
3 changes: 1 addition & 2 deletions test/FluentCassandra.Tests/TypesToDatabase/AsciiTypeTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Linq;
using System.Threading;
using NUnit.Framework;
using FluentCassandra.Types;
using NUnit.Framework;

namespace FluentCassandra.TypesToDatabase
{
Expand Down

0 comments on commit dc0875f

Please sign in to comment.