Skip to content

Commit bc6c878

Browse files
committed
added comments and minor refactoring
1 parent 47aee61 commit bc6c878

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

src/NHibernate/Dialect/BitwiseFunctionOperation.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,22 @@
77

88
namespace NHibernate.Dialect
99
{
10+
/// <summary>
11+
/// Treats bitwise operations as SQL function calls.
12+
/// </summary>
1013
[Serializable]
1114
public class BitwiseFunctionOperation : ISQLFunction
1215
{
1316
private readonly string _functionName;
1417
private SqlStringBuilder _sqlBuffer;
1518
private Queue _args;
1619

20+
/// <summary>
21+
/// Creates an instance of this class using the provided function name
22+
/// </summary>
23+
/// <param name="functionName">
24+
/// The bitwise function name as defined by the SQL-Dialect
25+
/// </param>
1726
public BitwiseFunctionOperation(string functionName)
1827
{
1928
_functionName = functionName;
@@ -40,12 +49,12 @@ public SqlString Render(IList args, ISessionFactoryImplementor factory)
4049
{
4150
Prepare(args);
4251

43-
Function();
52+
AddFunctionName();
4453
OpenParens();
45-
Arguments();
54+
AddArguments();
4655
CloseParens();
4756

48-
return _sqlBuffer.ToSqlString();
57+
return SqlResult();
4958
}
5059

5160
#endregion
@@ -66,7 +75,7 @@ private static bool IsParens(string candidate)
6675
return candidate == "(" || candidate == ")";
6776
}
6877

69-
private void Function()
78+
private void AddFunctionName()
7079
{
7180
_sqlBuffer.Add(_functionName);
7281
}
@@ -76,7 +85,7 @@ private void OpenParens()
7685
_sqlBuffer.Add("(");
7786
}
7887

79-
private void Arguments()
88+
private void AddArguments()
8089
{
8190
while (_args.Count > 0)
8291
{
@@ -94,5 +103,10 @@ private void CloseParens()
94103
{
95104
_sqlBuffer.Add(")");
96105
}
106+
107+
private SqlString SqlResult()
108+
{
109+
return _sqlBuffer.ToSqlString();
110+
}
97111
}
98112
}

src/NHibernate/Dialect/BitwiseNativeOperation.cs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,41 @@
77

88
namespace NHibernate.Dialect
99
{
10+
/// <summary>
11+
/// Treats bitwise operations as native operations.
12+
/// </summary>
13+
/// </remarks>
1014
[Serializable]
1115
public class BitwiseNativeOperation : ISQLFunction
1216
{
13-
private readonly string _sqlToken;
17+
private readonly string _sqlOpToken;
18+
private readonly bool _isNot;
1419
private Queue _args;
1520
private SqlStringBuilder _sqlBuffer;
1621

17-
public BitwiseNativeOperation(string sqlToken)
22+
/// <summary>
23+
/// creates an instance using the giving token
24+
/// </summary>
25+
/// <param name="sqlOpToken">
26+
/// The operation token
27+
/// </param>
28+
/// <remarks>
29+
/// Use this constructor only if the token DOES NOT represent a NOT-Operation
30+
/// </remarks>
31+
public BitwiseNativeOperation(string sqlOpToken)
32+
: this(sqlOpToken, false)
1833
{
19-
_sqlToken = sqlToken;
34+
}
35+
36+
/// <summary>
37+
/// creates an instance using the giving token and the flag indicating a NOT-Operation
38+
/// </summary>
39+
/// <param name="sqlOpToken"></param>
40+
/// <param name="isNot"></param>
41+
public BitwiseNativeOperation(string sqlOpToken, bool isNot)
42+
{
43+
_sqlOpToken = sqlOpToken;
44+
_isNot = isNot;
2045
}
2146

2247
#region ISQLFunction Members
@@ -39,7 +64,7 @@ public bool HasParenthesesIfNoArguments
3964
public SqlString Render(IList args, ISessionFactoryImplementor factory)
4065
{
4166
Prepare(args);
42-
if (_sqlToken != "~")
67+
if (_isNot == false)
4368
AddFirstArgument();
4469
AddToken();
4570
AddRestOfArguments();
@@ -62,7 +87,7 @@ private void AddFirstArgument()
6287

6388
private void AddToken()
6489
{
65-
AddToBuffer(string.Format(" {0} ", _sqlToken));
90+
AddToBuffer(string.Format(" {0} ", _sqlOpToken));
6691
}
6792

6893
private void AddRestOfArguments()

src/NHibernate/Dialect/Dialect.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected Dialect()
117117
RegisterFunction("band", new BitwiseNativeOperation("&"));
118118
RegisterFunction("bor", new BitwiseNativeOperation("|"));
119119
RegisterFunction("bxor", new BitwiseNativeOperation("^"));
120-
RegisterFunction("bnot", new BitwiseNativeOperation("~"));
120+
RegisterFunction("bnot", new BitwiseNativeOperation("~", true));
121121

122122
RegisterFunction("str", new SQLFunctionTemplate(NHibernateUtil.String, "cast(?1 as char)"));
123123

0 commit comments

Comments
 (0)