Changeset 4607
- Timestamp:
- Oct 28, 2008, 9:16:02 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/AbstractQuery.java
r4600 r4607 488 488 public String toString() 489 489 { 490 return this.getClass().getSimpleName() + ": " +getMainQuery(null, !isReadonly());490 return getMainQuery(null, !isReadonly()); 491 491 } 492 492 // ------------------------------------------- -
trunk/src/core/net/sf/basedb/core/ItemContext.java
r4517 r4607 1056 1056 try 1057 1057 { 1058 Restriction r = filter.getRestriction(dc );1058 Restriction r = filter.getRestriction(dc, query); 1059 1059 if (r != null) 1060 1060 { … … 1066 1066 String filterProperty = filter.getProperty(); 1067 1067 int dotIndex = filterProperty == null ? -1 : filterProperty.lastIndexOf("."); 1068 if (dotIndex >= 0 && !filterProperty.startsWith("$") && !filterProperty.startsWith("£") )1068 if (dotIndex >= 0 && !filterProperty.startsWith("$") && !filterProperty.startsWith("£") && !filterProperty.startsWith("&")) 1069 1069 { 1070 1070 leftJoins.add(filterProperty.substring(0, dotIndex)); … … 1099 1099 { 1100 1100 boolean fetch = selectOrderBy && sortedProperties.contains(property); 1101 if (property.startsWith("@") || property.startsWith("£") )1101 if (property.startsWith("@") || property.startsWith("£") || property.startsWith("&")) 1102 1102 { 1103 1103 property = property.substring(1); -
trunk/src/core/net/sf/basedb/core/PropertyFilter.java
r4555 r4607 27 27 import java.util.Date; 28 28 import java.util.List; 29 import java.util.regex.Matcher; 30 import java.util.regex.Pattern; 29 31 30 32 import net.sf.basedb.core.data.AnnotationTypeData; … … 32 34 import net.sf.basedb.core.data.ReporterData; 33 35 import net.sf.basedb.core.data.UnitData; 36 import net.sf.basedb.core.query.EntityQuery; 37 import net.sf.basedb.core.query.Query; 34 38 import net.sf.basedb.core.query.Restriction; 35 39 import net.sf.basedb.core.query.Restrictions; … … 64 68 */ 65 69 private final String value_separator = "|"; 70 71 private final Pattern ENTITY_COLLECTION = Pattern.compile("\\&([\\w\\.]+)\\((.+)\\)"); 66 72 67 73 private final String property; … … 379 385 380 386 /** 381 This method will fail if used to filter on reporter lists .382 @deprecated Use {@link #getRestriction(DbControl )} instead387 This method will fail if used to filter on reporter lists or collections. 388 @deprecated Use {@link #getRestriction(DbControl, EntityQuery)} instead 383 389 */ 384 390 public Restriction getRestriction() 385 391 { 386 return getRestriction(null); 392 return getRestriction(null, null); 393 } 394 395 /** 396 This method will fail if used to filter on collections. 397 @deprecated Use {@link #getRestriction(DbControl, EntityQuery)} instead 398 */ 399 public Restriction getRestriction(DbControl dc) 400 { 401 return getRestriction(dc, null); 387 402 } 388 403 … … 407 422 we always use an IN restriction, ignoring the specified operator. 408 423 <p> 424 If the property starts with & it is a collection of entities. The property 425 must end with a property name from the entity in the collection within paranthesis. 426 Eg. &experiments(name). The filter is applied as a subquery. 427 <p> 409 428 The property may also start with $@. 410 429 @return The restriction 411 430 @since 2.8 412 431 */ 413 public Restriction getRestriction(DbControl dc )432 public Restriction getRestriction(DbControl dc, EntityQuery query) 414 433 { 415 434 … … 562 581 } 563 582 } 583 else if (property != null && property.startsWith("&")) 584 { 585 // Property is an entity collection: collection(filter-property) 586 Matcher m = ENTITY_COLLECTION.matcher(property); 587 if (!m.matches()) 588 { 589 throw new InvalidDataException("Invalid collection filter: " + property); 590 } 591 String entityCollection = m.group(1); 592 String collectionFilter = m.group(2); 593 594 /* 595 We are going to create a subquery like: 596 root-entity = ANY( 597 SELECT root-entity FROM root-entity 598 LEFT JOIN collection-path cp 599 WHERE cp.filter-property ........ 600 ) 601 */ 602 Query subquery = new AbstractEntityQuery(query.getItemType(), null, false, null) 603 {}; 604 // LEFT JOIN the parts in the collection path 605 String[] cPath = entityCollection.split("\\."); 606 String thisAlias = null; 607 for (int i = 0; i < cPath.length; ++i) 608 { 609 String nextAlias = "cp" + i; 610 subquery.join(Hql.leftJoin(thisAlias, cPath[i], nextAlias, null, false)); 611 thisAlias = nextAlias; 612 } 613 614 // Restrict the subquery 615 PropertyFilter pp = new PropertyFilter("$" + thisAlias + "." + collectionFilter, 616 operator, getValue(), getValueType()); 617 subquery.restrict(pp.getRestriction(dc, query)); 618 619 // Create the main restriction 620 restriction = Restrictions.eq(Hql.alias(query.getRootAlias()), 621 Expressions.any(subquery)); 622 } 564 623 else 565 { 624 { 566 625 Expression propertyExpression = Hql.property(alias, property); 567 626 if (getValueType() == Type.DATE) -
trunk/www/views/rawbioassays/list_rawbioassays.jsp
r4596 r4607 424 424 id="experiments" 425 425 title="Experiments" 426 property="&experiments(name)" 427 datatype="string" 428 filterable="true" 426 429 /> 427 430 <tbl:columndef
Note: See TracChangeset
for help on using the changeset viewer.