@@ -32,9 +32,23 @@ namespace NHibernate.Spatial.Criterion
32
32
[ Serializable ]
33
33
public class SpatialRelationCriterion : AbstractCriterion
34
34
{
35
- private readonly string propertyName ;
36
- private readonly SpatialRelation relation ;
37
- private readonly object anotherGeometry ;
35
+ private readonly string _propertyName ;
36
+ private readonly SpatialRelation _relation ;
37
+ private readonly object _anotherGeometry ;
38
+ private readonly object _parameter ;
39
+
40
+ /// <summary>
41
+ /// Initializes a new instance of the <see cref="SpatialRelationCriterion"/> class.
42
+ /// </summary>
43
+ /// <param name="propertyName">Name of the property.</param>
44
+ /// <param name="relation">The relation.</param>
45
+ /// <param name="anotherGeometry">Another geometry.</param>
46
+ /// <param name="parameter">Additional parameter value</param>
47
+ public SpatialRelationCriterion ( string propertyName , SpatialRelation relation , object anotherGeometry , object parameter )
48
+ : this ( propertyName , relation , anotherGeometry )
49
+ {
50
+ _parameter = parameter ;
51
+ }
38
52
39
53
/// <summary>
40
54
/// Initializes a new instance of the <see cref="SpatialRelationCriterion"/> class.
@@ -44,9 +58,9 @@ public class SpatialRelationCriterion : AbstractCriterion
44
58
/// <param name="anotherGeometry">Another geometry.</param>
45
59
public SpatialRelationCriterion ( string propertyName , SpatialRelation relation , object anotherGeometry )
46
60
{
47
- this . propertyName = propertyName ;
48
- this . relation = relation ;
49
- this . anotherGeometry = anotherGeometry ;
61
+ _propertyName = propertyName ;
62
+ _relation = relation ;
63
+ _anotherGeometry = anotherGeometry ;
50
64
}
51
65
52
66
/// <summary>
@@ -59,9 +73,9 @@ public SpatialRelationCriterion(string propertyName, SpatialRelation relation, o
59
73
/// </returns>
60
74
public override TypedValue [ ] GetTypedValues ( ICriteria criteria , ICriteriaQuery criteriaQuery )
61
75
{
62
- if ( anotherGeometry is Geometry )
76
+ if ( _anotherGeometry is Geometry )
63
77
{
64
- return new [ ] { criteriaQuery . GetTypedValue ( criteria , propertyName , anotherGeometry ) } ;
78
+ return new [ ] { criteriaQuery . GetTypedValue ( criteria , _propertyName , _anotherGeometry ) } ;
65
79
}
66
80
return Array . Empty < TypedValue > ( ) ;
67
81
}
@@ -81,9 +95,8 @@ public override IProjection[] GetProjections()
81
95
/// </returns>
82
96
public override SqlString ToSqlString ( ICriteria criteria , ICriteriaQuery criteriaQuery )
83
97
{
84
- //criteriaQuery.AddUsedTypedValues(GetTypedValues(criteria, criteriaQuery));
85
98
var spatialDialect = ( ISpatialDialect ) criteriaQuery . Factory . Dialect ;
86
- string [ ] columns1 = GetColumnNames ( criteria , criteriaQuery , propertyName ) ;
99
+ string [ ] columns1 = GetColumnNames ( criteria , criteriaQuery , _propertyName ) ;
87
100
88
101
var builder = new SqlStringBuilder ( 10 * columns1 . Length ) ;
89
102
for ( int i = 0 ; i < columns1 . Length ; i ++ )
@@ -92,17 +105,25 @@ public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteri
92
105
{
93
106
builder . Add ( " AND " ) ;
94
107
}
95
- if ( anotherGeometry is Geometry )
108
+
109
+ object anotherGeometry ;
110
+ if ( _anotherGeometry is Geometry )
96
111
{
97
112
var parameters = criteriaQuery . NewQueryParameter ( GetTypedValues ( criteria , criteriaQuery ) [ 0 ] ) . ToArray ( ) ;
98
- builder . Add ( spatialDialect . GetSpatialRelationString ( columns1 [ i ] , relation , parameters . Single ( ) , true ) ) ;
113
+ anotherGeometry = parameters . Single ( ) ;
99
114
}
100
115
else
101
116
{
102
- string [ ] columns2 = GetColumnNames ( criteria , criteriaQuery , ( string ) anotherGeometry ) ;
103
- builder . Add ( spatialDialect . GetSpatialRelationString ( columns1 [ i ] , relation , columns2 [ i ] , true ) ) ;
117
+ string [ ] columns2 = GetColumnNames ( criteria , criteriaQuery , ( string ) _anotherGeometry ) ;
118
+ anotherGeometry = columns2 [ i ] ;
104
119
}
120
+
121
+ var spatialRelationString = _parameter == null
122
+ ? spatialDialect . GetSpatialRelationString ( columns1 [ i ] , _relation , anotherGeometry , true )
123
+ : spatialDialect . GetSpatialRelationString ( columns1 [ i ] , _relation , anotherGeometry , _parameter , true ) ;
124
+ builder . Add ( spatialRelationString ) ;
105
125
}
126
+
106
127
return builder . ToSqlString ( ) ;
107
128
}
108
129
@@ -119,11 +140,11 @@ public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteri
119
140
public override string ToString ( )
120
141
{
121
142
return new StringBuilder ( )
122
- . Append ( relation )
143
+ . Append ( _relation )
123
144
. Append ( "(" )
124
- . Append ( propertyName )
145
+ . Append ( _propertyName )
125
146
. Append ( ", " )
126
- . Append ( anotherGeometry is Geometry ? "<Geometry>" : anotherGeometry . ToString ( ) )
147
+ . Append ( _anotherGeometry is Geometry ? "<Geometry>" : _anotherGeometry . ToString ( ) )
127
148
. Append ( ")" )
128
149
. ToString ( ) ;
129
150
}
0 commit comments