|
1 |
| -using System; |
2 |
| -using System.Collections; |
3 |
| -using NHibernate.Dialect.Function; |
4 |
| -using NHibernate.Engine; |
5 |
| -using NHibernate.SqlCommand; |
6 |
| -using NHibernate.Type; |
7 |
| - |
8 |
| -namespace NHibernate.Dialect |
9 |
| -{ |
10 |
| - [Serializable] |
11 |
| - public class NativeBitwiseOperation : ISQLFunction |
12 |
| - { |
13 |
| - private readonly string _sqlToken; |
14 |
| - private Queue _args; |
15 |
| - private SqlStringBuilder _sqlBuffer; |
16 |
| - |
17 |
| - public NativeBitwiseOperation(string sqlToken) |
18 |
| - { |
19 |
| - _sqlToken = sqlToken; |
20 |
| - } |
21 |
| - |
22 |
| - #region ISQLFunction Members |
23 |
| - |
24 |
| - public IType ReturnType(IType columnType, IMapping mapping) |
25 |
| - { |
26 |
| - return NHibernateUtil.Int64; |
27 |
| - } |
28 |
| - |
29 |
| - public bool HasArguments |
30 |
| - { |
31 |
| - get { return true; } |
32 |
| - } |
33 |
| - |
34 |
| - public bool HasParenthesesIfNoArguments |
35 |
| - { |
36 |
| - get { return false; } |
37 |
| - } |
38 |
| - |
39 |
| - public SqlString Render(IList args, ISessionFactoryImplementor factory) |
40 |
| - { |
41 |
| - Prepare(args); |
42 |
| - if (_sqlToken != "~") |
43 |
| - AddFirstArgument(); |
44 |
| - AddToken(); |
45 |
| - AddRestOfArguments(); |
46 |
| - |
47 |
| - return _sqlBuffer.ToSqlString(); |
48 |
| - } |
49 |
| - |
50 |
| - #endregion |
51 |
| - |
52 |
| - private void Prepare(IList args) |
53 |
| - { |
54 |
| - _sqlBuffer = new SqlStringBuilder(); |
55 |
| - _args = new Queue(args); |
56 |
| - } |
57 |
| - |
58 |
| - private void AddFirstArgument() |
59 |
| - { |
60 |
| - AddToBuffer(_args.Dequeue()); |
61 |
| - } |
62 |
| - |
63 |
| - private void AddToken() |
64 |
| - { |
65 |
| - AddToBuffer(string.Format(" {0} ", _sqlToken)); |
66 |
| - } |
67 |
| - |
68 |
| - private void AddRestOfArguments() |
69 |
| - { |
70 |
| - while (_args.Count > 0) |
71 |
| - { |
72 |
| - AddToBuffer(_args.Dequeue()); |
73 |
| - } |
74 |
| - } |
75 |
| - |
76 |
| - private void AddToBuffer(object arg) |
77 |
| - { |
78 |
| - if (arg is Parameter || arg is SqlString) |
79 |
| - _sqlBuffer.AddObject(arg); |
80 |
| - else |
81 |
| - _sqlBuffer.Add(arg.ToString()); |
82 |
| - } |
83 |
| - } |
84 |
| -} |
| 1 | +using System; |
| 2 | +using System.Collections; |
| 3 | +using NHibernate.Dialect.Function; |
| 4 | +using NHibernate.Engine; |
| 5 | +using NHibernate.SqlCommand; |
| 6 | +using NHibernate.Type; |
| 7 | + |
| 8 | +namespace NHibernate.Dialect |
| 9 | +{ |
| 10 | + /// <summary> |
| 11 | + /// Treats bitwise operations as native operations. |
| 12 | + /// </summary> |
| 13 | + /// </remarks> |
| 14 | + [Serializable] |
| 15 | + public class BitwiseNativeOperation : ISQLFunction |
| 16 | + { |
| 17 | + private readonly string _sqlOpToken; |
| 18 | + private readonly bool _isNot; |
| 19 | + private Queue _args; |
| 20 | + private SqlStringBuilder _sqlBuffer; |
| 21 | + |
| 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) |
| 33 | + { |
| 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; |
| 45 | + } |
| 46 | + |
| 47 | + #region ISQLFunction Members |
| 48 | + |
| 49 | + public IType ReturnType(IType columnType, IMapping mapping) |
| 50 | + { |
| 51 | + return NHibernateUtil.Int64; |
| 52 | + } |
| 53 | + |
| 54 | + public bool HasArguments |
| 55 | + { |
| 56 | + get { return true; } |
| 57 | + } |
| 58 | + |
| 59 | + public bool HasParenthesesIfNoArguments |
| 60 | + { |
| 61 | + get { return false; } |
| 62 | + } |
| 63 | + |
| 64 | + public SqlString Render(IList args, ISessionFactoryImplementor factory) |
| 65 | + { |
| 66 | + Prepare(args); |
| 67 | + if (_isNot == false) |
| 68 | + AddFirstArgument(); |
| 69 | + AddToken(); |
| 70 | + AddRestOfArguments(); |
| 71 | + |
| 72 | + return _sqlBuffer.ToSqlString(); |
| 73 | + } |
| 74 | + |
| 75 | + #endregion |
| 76 | + |
| 77 | + private void Prepare(IList args) |
| 78 | + { |
| 79 | + _sqlBuffer = new SqlStringBuilder(); |
| 80 | + _args = new Queue(args); |
| 81 | + } |
| 82 | + |
| 83 | + private void AddFirstArgument() |
| 84 | + { |
| 85 | + AddToBuffer(_args.Dequeue()); |
| 86 | + } |
| 87 | + |
| 88 | + private void AddToken() |
| 89 | + { |
| 90 | + AddToBuffer(string.Format(" {0} ", _sqlOpToken)); |
| 91 | + } |
| 92 | + |
| 93 | + private void AddRestOfArguments() |
| 94 | + { |
| 95 | + while (_args.Count > 0) |
| 96 | + { |
| 97 | + AddToBuffer(_args.Dequeue()); |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + private void AddToBuffer(object arg) |
| 102 | + { |
| 103 | + if (arg is Parameter || arg is SqlString) |
| 104 | + _sqlBuffer.AddObject(arg); |
| 105 | + else |
| 106 | + _sqlBuffer.Add(arg.ToString()); |
| 107 | + } |
| 108 | + } |
| 109 | +} |
0 commit comments