Permalink
Browse files

Allowed usage of Reversed Types in Columns

  • Loading branch information...
Mike Williams
Mike Williams committed May 3, 2012
1 parent 4b0c6bb commit 1c2099ec32bb376d92d8987e16e7e2b3f58545fc
Showing with 32 additions and 7 deletions.
  1. +17 −6 src/Types/CassandraType.cs
  2. +15 −1 test/FluentCassandra.Tests/Types/CassandraTypeTest.cs
View
@@ -35,7 +35,7 @@ public sealed class CassandraType
public CassandraType(string type)
{
- if (type == null || type.Length == 0)
+ if (string.IsNullOrEmpty(type))
throw new ArgumentNullException("type");
_dbType = type;
@@ -76,16 +76,27 @@ public Type FluentType
private void Parse()
{
- int compositeStart = _dbType.IndexOf('(');
+ // Pay attention to any ReversedType on the Column Index
+ const string reversedTypeString = ".ReversedType(";
+ var reversedIndex = _dbType.IndexOf(reversedTypeString, StringComparison.Ordinal);
+ var workingtype = _dbType;
+ if (reversedIndex > 0)
+ {
+ workingtype = workingtype.Substring(reversedIndex + reversedTypeString.Length);
+ var lastClosing = workingtype.LastIndexOf(")", StringComparison.Ordinal);
+ workingtype = workingtype.Substring(0, lastClosing);
+ }
+
+ var compositeStart = workingtype.IndexOf('(');
// check for composite type
if (compositeStart == -1) {
- _type = Parse(_dbType);
+ _type = Parse(workingtype);
return;
}
- var part1 = _dbType.Substring(0, compositeStart);
- var part2 = _dbType.Substring(compositeStart);
+ var part1 = workingtype.Substring(0, compositeStart);
+ var part2 = workingtype.Substring(compositeStart);
_type = Parse(part1);
@@ -157,7 +168,7 @@ private Type Parse(string dbType)
case "compositetype": type = typeof(CompositeType); break;
case "dynamiccompositetype": type = typeof(DynamicCompositeType); break;
case "countercolumntype": type = typeof(CounterColumnType); break;
- default: throw new CassandraException("Type '" + _dbType + "' not found.");
+ default: throw new CassandraException("Type '" + _dbType + "' not found.");
}
return type;
@@ -43,7 +43,21 @@ public void Parse_Type()
Assert.AreEqual(expected, actual);
}
- [Test, ExpectedException(typeof(CassandraException))]
+ [Test]
+ public void Parse_Reverse_Type()
+ {
+ // arrange
+ Type expected = typeof(LongType);
+ string cassandraString = "org.apache.cassandra.db.marshal.ReversedType(LongType)";
+
+ // act
+ Type actual = new CassandraType(cassandraString).FluentType;
+
+ // assert
+ Assert.AreEqual(expected, actual);
+ }
+
+ [Test, ExpectedException(typeof(CassandraException))]
public void Parse_CompositeType_UnknownInnerType()
{
// arranage

0 comments on commit 1c2099e

Please sign in to comment.