Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allowing to define indexes with SaveEnumAsIntegers

  • Loading branch information...
commit c74e11e74cda5b926c7d5cad3dd1c36f2e75edfa 1 parent ee4e545
@ayende ayende authored
View
9 Raven.Client.Lightweight/Connection/ReplicationInformer.cs
@@ -113,6 +113,15 @@ private class IntHolder
public int Value;
}
+
+ /// <summary>
+ /// Get the current failure count for the url
+ /// </summary>
+ public int GetFailureCount(string operationUrl)
+ {
+ return GetHolder(operationUrl).Value;
+ }
+
/// <summary>
/// Should execute the operation using the specified operation URL
/// </summary>
View
9 Raven.Client.Lightweight/Connection/ServerClient.cs
@@ -138,6 +138,15 @@ private void ExecuteWithReplication(string method, Action<string> operation)
});
}
+ /// <summary>
+ /// Allow to query whatever we are in failover mode or not
+ /// </summary>
+ /// <returns></returns>
+ public bool InFailoverMode()
+ {
+ return replicationInformer.GetFailureCount(url) > 0;
+ }
+
private T ExecuteWithReplication<T>(string method, Func<string, T> operation)
{
var currentRequest = Interlocked.Increment(ref requestCount);
View
20 Raven.Client.Lightweight/Indexes/ExpressionStringBuilder.cs
@@ -371,7 +371,6 @@ private Expression VisitBinary(BinaryExpression node, ExpressionOperatorPreceden
var rightOp = node.Right;
FixupEnumBinaryExpression(ref leftOp, ref rightOp);
-
switch (node.NodeType)
{
case ExpressionType.Add:
@@ -626,7 +625,7 @@ private Expression VisitBinary(BinaryExpression node, ExpressionOperatorPreceden
return node;
}
- private static void FixupEnumBinaryExpression(ref Expression left, ref Expression right)
+ private void FixupEnumBinaryExpression(ref Expression left, ref Expression right)
{
switch (left.NodeType)
{
@@ -639,9 +638,24 @@ private static void FixupEnumBinaryExpression(ref Expression left, ref Expressio
if (constantExpression == null)
return;
left = expression;
- right = Expression.Constant(Enum.ToObject(expression.Type, constantExpression.Value).ToString());
+ right = convention.SaveEnumsAsIntegers ?
+ Expression.Constant((int)constantExpression.Value) :
+ Expression.Constant(Enum.ToObject(expression.Type, constantExpression.Value).ToString());
break;
}
+
+ while (true)
+ {
+ switch (left.NodeType)
+ {
+ case ExpressionType.ConvertChecked:
+ case ExpressionType.Convert:
+ left = ((UnaryExpression)left).Operand;
+ break;
+ default:
+ return;
+ }
+ }
}
/// <summary>
View
39 Raven.Tests/MailingList/EnumAsInts.cs
@@ -0,0 +1,39 @@
+using System.Linq;
+using Raven.Client.Indexes;
+using Xunit;
+
+namespace Raven.Tests.MailingList
+{
+ public class EnumAsInts : RavenTest
+ {
+ public enum Flags
+ {
+ One = 1,
+ Two = 2,
+ Four = 4
+ }
+ public class Item
+ {
+ public Flags Flags { get; set; }
+ }
+ public class Index : AbstractIndexCreationTask<Item>
+ {
+ public Index()
+ {
+ Map = items => from item in items
+ where (item.Flags & Flags.Four) == Flags.Four
+ select new {item.Flags};
+ }
+ }
+
+ [Fact]
+ public void CanWork()
+ {
+ using(var store = NewDocumentStore())
+ {
+ store.Conventions.SaveEnumsAsIntegers = true;
+ new Index().Execute(store);
+ }
+ }
+ }
+}
View
1  Raven.Tests/Raven.Tests.csproj
@@ -555,6 +555,7 @@
<Compile Include="Linq\WhereClause.cs" />
<Compile Include="LocalClientTest.cs" />
<Compile Include="MailingList\DynamicQueryIndexSelection.cs" />
+ <Compile Include="MailingList\EnumAsInts.cs" />
<Compile Include="MailingList\GuidProjection.cs" />
<Compile Include="MailingList\LazyStats.cs" />
<Compile Include="MailingList\NicolasGarfinkiel.cs" />
View
13 Raven.Tryouts/Program.cs
@@ -3,7 +3,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
+using Raven.Abstractions.Data;
using Raven.Client;
+using Raven.Client.Document;
using Raven.Client.Embedded;
using Raven.Client.Indexes;
using Raven.Database.Extensions;
@@ -15,7 +17,16 @@ internal class Program
{
static void Main(string[] args)
{
-
+ var documentStore = new DocumentStore
+ {
+ Url = "http://localhost:8080"
+ }.Initialize();
+
+ documentStore.DatabaseCommands.DeleteByIndex("Temp/AllDocs/By_metadata_Raven_Document_Revision_Status",
+ new IndexQuery
+ {
+ Query = "_metadata_Raven_Document_Revision_Status:Historical"
+ });
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.