Changeset 3561
- Timestamp:
- Jul 16, 2007, 12:04:35 PM (16 years ago)
- Location:
- trunk/src/core/net/sf/basedb/core
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/AnnotationBetweenRestriction.java
r2304 r3561 45 45 Create a new annotation restriction. 46 46 47 @deprecated Use {@link #AnnotationBetweenRestriction(String, AnnotationType, Object, Object, boolean)} 48 instead with alias=null 49 */ 50 public AnnotationBetweenRestriction(AnnotationType annotationType, Object lowValue, Object highValue, boolean includeInheriting) 51 throws InvalidDataException 52 { 53 this(null, annotationType, lowValue, highValue, includeInheriting); 54 } 55 56 /** 57 Create a new annotation restriction. 58 59 @param alias The alias of a joined item where the annotations are 60 located or null to use the root entity of the query 47 61 @param annotationType The annotation type to use in the query 48 62 @param lowValue The low value to use in the query, it must be of the … … 56 70 @throws InvalidDataException If any of the parameters are null 57 71 or not follow the rules above. 72 @since 2.4 58 73 */ 59 public AnnotationBetweenRestriction( AnnotationType annotationType, Object lowValue, Object highValue, boolean includeInheriting)74 public AnnotationBetweenRestriction(String alias, AnnotationType annotationType, Object lowValue, Object highValue, boolean includeInheriting) 60 75 throws InvalidDataException 61 76 { 62 super(a nnotationType, includeInheriting);77 super(alias, annotationType, includeInheriting); 63 78 if (lowValue == null) throw new InvalidUseOfNullException("lowValue"); 64 79 if (highValue == null) throw new InvalidUseOfNullException("highValue"); … … 76 91 this.highValue = highValue; 77 92 } 93 78 94 79 95 /* -
trunk/src/core/net/sf/basedb/core/AnnotationInRestriction.java
r2304 r3561 46 46 Create a new annotation restriction. 47 47 48 @deprecated Use {@link #AnnotationInRestriction(String, AnnotationType, boolean, Object[])} 49 instead with alias=null 50 */ 51 public AnnotationInRestriction(AnnotationType annotationType, boolean includeInheriting, Object... values) 52 throws InvalidDataException 53 { 54 this(null, annotationType, includeInheriting, values); 55 } 56 57 /** 58 Create a new annotation restriction. 59 48 60 @param annotationType The annotation type to use in the query 49 61 @param includeInheriting If items inherting the annotation should be returned … … 54 66 @throws InvalidDataException If any of the parameters are null 55 67 or the array is empty or not follow the rules above. 68 @since 2.4 56 69 */ 57 public AnnotationInRestriction( AnnotationType annotationType, boolean includeInheriting, Object... values)70 public AnnotationInRestriction(String alias, AnnotationType annotationType, boolean includeInheriting, Object... values) 58 71 throws InvalidDataException 59 72 { 60 super(a nnotationType, includeInheriting);73 super(alias, annotationType, includeInheriting); 61 74 if (values == null || values.length == 0) throw new InvalidUseOfNullException("values"); 62 75 for (int i = 0; i < values.length; ++i) … … 71 84 this.values = Arrays.asList(values); 72 85 } 73 74 86 /* 75 87 From the AnnotationRestriction class -
trunk/src/core/net/sf/basedb/core/AnnotationRestriction.java
r2667 r3561 61 61 final int annotationTypeId; 62 62 final boolean includeInheriting; 63 final String alias; 63 64 64 65 /** … … 66 67 @param annotationType The annotation type to use in the query 67 68 */ 68 AnnotationRestriction( AnnotationType annotationType, boolean includeInheriting)69 AnnotationRestriction(String alias, AnnotationType annotationType, boolean includeInheriting) 69 70 throws InvalidDataException 70 71 { … … 73 74 this.valueType = annotationType.getValueType(); 74 75 this.includeInheriting = includeInheriting; 76 this.alias = alias; 75 77 } 76 78 … … 84 86 @param valueType The type of values for annotations 85 87 */ 86 AnnotationRestriction( int annotationTypeId, Type valueType, boolean includeInheriting)88 AnnotationRestriction(String alias, int annotationTypeId, Type valueType, boolean includeInheriting) 87 89 throws InvalidDataException 88 90 { … … 91 93 this.valueType = valueType; 92 94 this.includeInheriting = includeInheriting; 95 this.alias = alias; 93 96 } 94 97 … … 207 210 annotationSetIds = annotationSets.toString(); 208 211 } 209 String hql = query.getRootAlias()+".annotationSet IN ("+annotationSetIds+")"; 212 String hql = (alias == null ? query.getRootAlias() : alias) + 213 ".annotationSet IN ("+annotationSetIds+")"; 210 214 return hql; 211 215 } -
trunk/src/core/net/sf/basedb/core/AnnotationSimpleRestriction.java
r2610 r3561 45 45 /** 46 46 Create a new annotation restriction using a simple expression: 47 <code>annotation operator value</code>. 47 <code>annotation operator value</code>. The restriction is applied to 48 the root element of the query. 48 49 50 @deprecated Use {@link #AnnotationSimpleRestriction(String, AnnotationType, Operator, Object, boolean)} 51 instead with alias=null 52 */ 53 public AnnotationSimpleRestriction(AnnotationType annotationType, Operator operator, Object value, boolean includeInheriting) 54 throws InvalidDataException 55 { 56 this(null, annotationType, operator, value, includeInheriting); 57 } 58 59 /** 60 Create a new annotation restriction using a simple expression: 61 <code>annotation operator value</code>. 62 63 @param alias The alias of a joined item where the annotations are 64 located or null to use the root entity of the query 49 65 @param annotationType The annotation type to use in the query 50 66 @param operator The operator, it must be one of the expression … … 57 73 @throws InvalidDataException If any of the parameters are null 58 74 or not follow the rules above. 75 @since 2.4 59 76 */ 60 public AnnotationSimpleRestriction( AnnotationType annotationType, Operator operator, Object value, boolean includeInheriting)77 public AnnotationSimpleRestriction(String alias, AnnotationType annotationType, Operator operator, Object value, boolean includeInheriting) 61 78 throws InvalidDataException 62 79 { 63 super(a nnotationType, includeInheriting);80 super(alias, annotationType, includeInheriting); 64 81 if (operator == null) throw new InvalidUseOfNullException("operator"); 65 82 if (value == null) throw new InvalidUseOfNullException("value"); … … 77 94 } 78 95 96 79 97 /** 80 Creates a new annotation restriction for a specific <code>valueType 98 Creates a new annotation restriction for a specific <code>valueType</code>. 99 The restriction is applied to the root element of the query. 100 101 @deprecated Use {@link #AnnotationSimpleRestriction(String, int, Type, Operator, Object, boolean)} 102 instead with alias=null 103 */ 104 public AnnotationSimpleRestriction(int annotationTypeId, Type valueType, Operator operator, Object value, boolean includeInheriting) 105 throws InvalidDataException 106 { 107 this(null, annotationTypeId, valueType, operator, value, includeInheriting); 108 } 109 110 /** 111 Creates a new annotation restriction for a specific <code>valueType</code>. 112 113 @param alias The alias of a joined item where the annotations are 114 located or null to use the root entity of the query 81 115 @param annotationTypeId the id of the annotation type to use in the query 82 116 @param valueType the type of values for annotations … … 89 123 @throws InvalidDataException If any of the parameters are null 90 124 or not follow the rules above 125 @since 2.4 91 126 */ 92 public AnnotationSimpleRestriction( int annotationTypeId, Type valueType, Operator operator, Object value, boolean includeInheriting)127 public AnnotationSimpleRestriction(String alias, int annotationTypeId, Type valueType, Operator operator, Object value, boolean includeInheriting) 93 128 throws InvalidDataException 94 129 { 95 super(a nnotationTypeId, valueType, includeInheriting);130 super(alias, annotationTypeId, valueType, includeInheriting); 96 131 if (operator == null) throw new InvalidUseOfNullException("operator"); 97 132 if (value == null) throw new InvalidUseOfNullException("value"); -
trunk/src/core/net/sf/basedb/core/PropertyFilter.java
r3453 r3561 183 183 Create a restriction from the filter. There are a few special cases: 184 184 <p> 185 If the property starts with a $ it is interpreted as a <code>alias.property</code> 186 value, ignoring the root alias of the query. The alias is removed from the 187 property before proceeding. 188 <p> 185 189 If the property starts with a # it is a filter on annotations. The rest of 186 190 the property is the ID of the annotation type, and we use a 187 191 {@link AnnotationSimpleRestriction} object for the restriction. 188 <p>189 If the property starts with a $ it is interpreted as a <code>alias.property</code>190 value, ignoring the root alias of the query.191 192 <p> 192 193 If the property starts with a @ the property is a collection of values and … … 201 202 Restriction restriction = null; 202 203 String property = getProperty(); 204 String alias = null; 205 206 if (property != null && property.startsWith("$")) 207 { 208 // Property is alias.property or alias only 209 int dotIndex = property.indexOf("."); 210 if (dotIndex == -1) 211 { 212 // Alias only 213 alias = property.substring(1); 214 property = null; 215 } 216 else if (property != null) 217 { 218 // Alias.property 219 alias = property.substring(1, dotIndex); 220 property = property.substring(dotIndex+1); 221 } 222 } 203 223 204 224 if (property != null && property.startsWith("#")) … … 206 226 // Property is id of annotation type: #id 207 227 int annotationTypeId = (Integer)Type.INT.parseString(property.substring(1)); 208 restriction = new AnnotationSimpleRestriction(a nnotationTypeId, getValueType(),228 restriction = new AnnotationSimpleRestriction(alias, annotationTypeId, getValueType(), 209 229 getOperator(), getValueAsObject(), false); 210 230 } … … 214 234 Expression parameter = getValue() == null ? null : 215 235 Expressions.parameter(parameterName, getValueAsObject(), getValueType()); 216 String alias = null; 217 if (property != null && property.startsWith("$")) 218 { 219 // Property is alias.property or alias only 220 int dotIndex = property.indexOf("."); 221 if (dotIndex == -1) 222 { 223 // Alias only 224 alias = property.substring(1); 225 property = null; 226 } 227 else if (property != null) 228 { 229 // Alias.property 230 alias = property.substring(1, dotIndex); 231 property = property.substring(dotIndex+1); 232 } 233 } 236 234 237 if (property != null && property.startsWith("@")) 235 238 { -
trunk/src/core/net/sf/basedb/core/query/Annotations.java
r2304 r3561 42 42 /** 43 43 Create a restriction that searches for annotations 44 equal to a given value. 45 @param annotationType The annotation type to search 46 @param value The value to search for 47 @param includeInheriting If items inherting the annotation should be returned 48 by the query or not 44 equal to a given value on the root entity of a query. 45 @param annotationType The annotation type to search 46 @param value The value to search for 47 @param includeInheriting If items inherting the annotation should be returned 48 by the query or not 49 @deprecated Use {@link #eq(String, AnnotationType, Object, boolean)} instead with alias=null 49 50 */ 50 51 public static Restriction eq(AnnotationType annotationType, Object value, boolean includeInheriting) 51 52 throws InvalidDataException 52 53 { 53 return new AnnotationSimpleRestriction(annotationType, Operator.EQ, value, includeInheriting); 54 } 55 56 /** 57 Create a restriction that searches for annotations 58 not equal to a given value. 59 @param annotationType The annotation type to search 60 @param value The value to search for 61 @param includeInheriting If items inherting the annotation should be returned 62 by the query or not 54 return eq(null, annotationType, value, includeInheriting); 55 } 56 57 /** 58 Create a restriction that searches for annotations 59 equal to a given value on the root or a joined entity of a 60 query. 61 62 @param alias The alias of the joined entity or null to use the root element 63 @param annotationType The annotation type to search 64 @param value The value to search for 65 @param includeInheriting If items inherting the annotation should be returned 66 by the query or not 67 @since 2.4 68 */ 69 public static Restriction eq(String alias, AnnotationType annotationType, Object value, boolean includeInheriting) 70 throws InvalidDataException 71 { 72 return new AnnotationSimpleRestriction(null, annotationType, Operator.EQ, value, includeInheriting); 73 } 74 75 /** 76 Create a restriction that searches for annotations 77 not equal to a given value on the root entity of a query. 78 @param annotationType The annotation type to search 79 @param value The value to search for 80 @param includeInheriting If items inherting the annotation should be returned 81 by the query or not 82 @deprecated Use {@link #neq(String, AnnotationType, Object, boolean)} instead with alias=null 63 83 */ 64 84 public static Restriction neq(AnnotationType annotationType, Object value, boolean includeInheriting) 65 85 throws InvalidDataException 66 86 { 67 return new AnnotationSimpleRestriction(annotationType, Operator.NEQ, value, includeInheriting); 68 } 69 70 /** 71 Create a restriction that searches for annotations 72 less than a given value. 73 @param annotationType The annotation type to search 74 @param value The value to search for 75 @param includeInheriting If items inherting the annotation should be returned 76 by the query or not 87 return neq(null, annotationType, value, includeInheriting); 88 } 89 90 /** 91 Create a restriction that searches for annotations 92 not equal to a given value on the root or a joined entity of a 93 query. 94 95 @param alias The alias of the joined entity or null to use the root element 96 @param annotationType The annotation type to search 97 @param value The value to search for 98 @param includeInheriting If items inherting the annotation should be returned 99 by the query or not 100 @since 2.4 101 */ 102 public static Restriction neq(String alias, AnnotationType annotationType, Object value, boolean includeInheriting) 103 throws InvalidDataException 104 { 105 return new AnnotationSimpleRestriction(alias, annotationType, Operator.NEQ, value, includeInheriting); 106 } 107 108 /** 109 Create a restriction that searches for annotations 110 less than a given value on the root entity of a query. 111 @param annotationType The annotation type to search 112 @param value The value to search for 113 @param includeInheriting If items inherting the annotation should be returned 114 by the query or not 115 @deprecated Use {@link #lt(String, AnnotationType, Object, boolean)} instead with alias=null 77 116 */ 78 117 public static Restriction lt(AnnotationType annotationType, Object value, boolean includeInheriting) 79 118 throws InvalidDataException 80 119 { 81 return new AnnotationSimpleRestriction(annotationType, Operator.LT, value, includeInheriting); 82 } 83 84 /** 85 Create a restriction that searches for annotations 86 less than or equal to a given value. 87 @param annotationType The annotation type to search 88 @param value The value to search for 89 @param includeInheriting If items inherting the annotation should be returned 90 by the query or not 120 return lt(null, annotationType, value, includeInheriting); 121 } 122 123 /** 124 Create a restriction that searches for annotations 125 less than a given value on the root or a joined entity of a 126 query. 127 128 @param alias The alias of the joined entity or null to use the root element 129 @param annotationType The annotation type to search 130 @param value The value to search for 131 @param includeInheriting If items inherting the annotation should be returned 132 by the query or not 133 @since 2.4 134 */ 135 public static Restriction lt(String alias, AnnotationType annotationType, Object value, boolean includeInheriting) 136 throws InvalidDataException 137 { 138 return new AnnotationSimpleRestriction(alias, annotationType, Operator.LT, value, includeInheriting); 139 } 140 141 /** 142 Create a restriction that searches for annotations 143 less than or equal to a given value on the root entity of a query. 144 @param annotationType The annotation type to search 145 @param value The value to search for 146 @param includeInheriting If items inherting the annotation should be returned 147 by the query or not 148 @deprecated Use {@link #lteq(String, AnnotationType, Object, boolean)} instead with alias=null 91 149 */ 92 150 public static Restriction lteq(AnnotationType annotationType, Object value, boolean includeInheriting) 93 151 throws InvalidDataException 94 152 { 95 return new AnnotationSimpleRestriction(annotationType, Operator.LTEQ, value, includeInheriting); 96 } 97 98 /** 99 Create a restriction that searches for annotations 100 greater than a given value. 101 @param annotationType The annotation type to search 102 @param value The value to search for 103 @param includeInheriting If items inherting the annotation should be returned 104 by the query or not 153 return lteq(null, annotationType, value, includeInheriting); 154 } 155 156 /** 157 Create a restriction that searches for annotations 158 less than or equal to a given value on the root or a joined entity of a 159 query. 160 161 @param alias The alias of the joined entity or null to use the root element 162 @param annotationType The annotation type to search 163 @param value The value to search for 164 @param includeInheriting If items inherting the annotation should be returned 165 by the query or not 166 @since 2.4 167 */ 168 public static Restriction lteq(String alias, AnnotationType annotationType, Object value, boolean includeInheriting) 169 throws InvalidDataException 170 { 171 return new AnnotationSimpleRestriction(alias, annotationType, Operator.LTEQ, value, includeInheriting); 172 } 173 174 /** 175 Create a restriction that searches for annotations 176 greater than a given value on the root entity of a query. 177 @param annotationType The annotation type to search 178 @param value The value to search for 179 @param includeInheriting If items inherting the annotation should be returned 180 by the query or not 181 @deprecated Use {@link #gt(String, AnnotationType, Object, boolean)} instead with alias=null 105 182 */ 106 183 public static Restriction gt(AnnotationType annotationType, Object value, boolean includeInheriting) 107 184 throws InvalidDataException 108 185 { 109 return new AnnotationSimpleRestriction(annotationType, Operator.GTEQ, value, includeInheriting); 110 } 111 112 /** 113 Create a restriction that searches for annotations 114 greater than or equal to a given value. 115 @param annotationType The annotation type to search 116 @param value The value to search for 117 @param includeInheriting If items inherting the annotation should be returned 118 by the query or not 186 return gt(null, annotationType, value, includeInheriting); 187 } 188 189 /** 190 Create a restriction that searches for annotations 191 greater than a given value on the root or a joined entity of a 192 query. 193 194 @param alias The alias of the joined entity or null to use the root element 195 @param annotationType The annotation type to search 196 @param value The value to search for 197 @param includeInheriting If items inherting the annotation should be returned 198 by the query or not 199 @since 2.4 200 */ 201 public static Restriction gt(String alias, AnnotationType annotationType, Object value, boolean includeInheriting) 202 throws InvalidDataException 203 { 204 return new AnnotationSimpleRestriction(alias, annotationType, Operator.GTEQ, value, includeInheriting); 205 } 206 207 208 /** 209 Create a restriction that searches for annotations 210 greater than or equal to a given value on the root entity of a query. 211 @param annotationType The annotation type to search 212 @param value The value to search for 213 @param includeInheriting If items inherting the annotation should be returned 214 by the query or not 215 @deprecated Use {@link #gteq(String, AnnotationType, Object, boolean)} instead with alias=null 119 216 */ 120 217 public static Restriction gteq(AnnotationType annotationType, Object value, boolean includeInheriting) 121 218 throws InvalidDataException 122 219 { 123 return new AnnotationSimpleRestriction(annotationType, Operator.GTEQ, value, includeInheriting); 124 } 125 126 /** 127 Create a restriction that searches for annotations 128 matching a given value. 129 @param annotationType The annotation type to search 130 @param value The value to search for 131 @param includeInheriting If items inherting the annotation should be returned 132 by the query or not 220 return gteq(null, annotationType, value, includeInheriting); 221 } 222 223 /** 224 Create a restriction that searches for annotations 225 greater than or equal to a given value on the root or a joined entity of a 226 query. 227 228 @param alias The alias of the joined entity or null to use the root element 229 @param annotationType The annotation type to search 230 @param value The value to search for 231 @param includeInheriting If items inherting the annotation should be returned 232 by the query or not 233 @since 2.4 234 */ 235 public static Restriction gteq(String alias, AnnotationType annotationType, Object value, boolean includeInheriting) 236 throws InvalidDataException 237 { 238 return new AnnotationSimpleRestriction(alias, annotationType, Operator.GTEQ, value, includeInheriting); 239 } 240 241 /** 242 Create a restriction that searches for annotations 243 matching a given value on the root entity of a query. 244 @param annotationType The annotation type to search 245 @param value The value to search for 246 @param includeInheriting If items inherting the annotation should be returned 247 by the query or not 248 @deprecated Use {@link #like(String, AnnotationType, Object, boolean)} instead with alias=null 133 249 */ 134 250 public static Restriction like(AnnotationType annotationType, Object value, boolean includeInheriting) 135 251 throws InvalidDataException 136 252 { 137 return new AnnotationSimpleRestriction(annotationType, Operator.LIKE, value, includeInheriting); 138 } 139 140 /** 141 Create a restriction that searches for annotations 142 between two given values. If the end values are included or excluded 253 return like(null, annotationType, value, includeInheriting); 254 } 255 256 /** 257 Create a restriction that searches for annotations 258 matching a given value on the root or a joined entity of a 259 query. 260 261 @param alias The alias of the joined entity or null to use the root element 262 @param annotationType The annotation type to search 263 @param value The value to search for 264 @param includeInheriting If items inherting the annotation should be returned 265 by the query or not 266 @since 2.4 267 */ 268 public static Restriction like(String alias, AnnotationType annotationType, Object value, boolean includeInheriting) 269 throws InvalidDataException 270 { 271 return new AnnotationSimpleRestriction(alias, annotationType, Operator.LIKE, value, includeInheriting); 272 } 273 274 275 /** 276 Create a restriction that searches for annotations 277 between two given values on the root entity of a query. 278 If the end values are included or excluded 143 279 depends on the database. 280 144 281 @param annotationType The annotation type to search 145 282 @param lowValue The lower bound … … 147 284 @param includeInheriting If items inherting the annotation should be returned 148 285 by the query or not 286 @deprecated Use {@link #between(String, AnnotationType, Object, Object, boolean)} 287 instead with alias=null 149 288 */ 150 289 public static Restriction between(AnnotationType annotationType, Object lowValue, Object highValue, boolean includeInheriting) 151 290 throws InvalidDataException 152 291 { 153 return new AnnotationBetweenRestriction(annotationType, lowValue, highValue, includeInheriting); 154 } 155 156 /** 157 Create a restriction that searches for annotations 292 return between(null, annotationType, lowValue, highValue, includeInheriting); 293 } 294 295 /** 296 Create a restriction that searches for annotations 297 between two given values on the root or a joined entity of a 298 query. If the end values are included or excluded 299 depends on the database. 300 301 @param alias The alias of the joined entity or null to use the root element 302 @param annotationType The annotation type to search 303 @param lowValue The lower bound 304 @param highValue The higher bound 305 @param includeInheriting If items inherting the annotation should be returned 306 by the query or not 307 @since 2.4 308 */ 309 public static Restriction between(String alias, AnnotationType annotationType, Object lowValue, Object highValue, boolean includeInheriting) 310 throws InvalidDataException 311 { 312 return new AnnotationBetweenRestriction(alias, annotationType, lowValue, highValue, includeInheriting); 313 } 314 315 /** 316 Create a restriction that searches for annotations on the root entity of a query 158 317 equal to any value in a list of given values. 159 318 @param annotationType The annotation type to search … … 161 320 by the query or not 162 321 @param values An array of values 322 @deprecated Use {@link #in(String, AnnotationType, boolean, Object[])} 323 instead with alias=null 163 324 */ 164 325 public static Restriction in(AnnotationType annotationType, boolean includeInheriting, Object... values) 165 326 throws InvalidDataException 166 327 { 167 return new AnnotationInRestriction(annotationType, includeInheriting, values); 168 } 169 328 return in(null, annotationType, includeInheriting, values); 329 } 330 331 /** 332 Create a restriction that searches for annotations 333 on the root or a joined entity 334 equal to any value in a list of given values. 335 336 @param alias The alias of the joined entity or null to use the root element 337 @param annotationType The annotation type to search 338 @param includeInheriting If items inherting the annotation should be returned 339 by the query or not 340 @param values An array of values 341 @since 2.4 342 */ 343 public static Restriction in(String alias, AnnotationType annotationType, boolean includeInheriting, Object... values) 344 throws InvalidDataException 345 { 346 return new AnnotationInRestriction(alias, annotationType, includeInheriting, values); 347 } 170 348 171 349 }
Note: See TracChangeset
for help on using the changeset viewer.