Changeset 5543


Ignore:
Timestamp:
Jan 19, 2011, 12:02:22 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1571: Cannot sort on 'Bioplate' and 'Biowell row'

Order the joins so that shorter paths are joined before longer paths which should make sure that they appear in the correct order.

This also triggered a second issue in the search-and-replace step. We need to reset the regular expression matcher after a replacement have been made since otherwise we are looking for strings that no longer exists in the query.

Location:
branches/2.16-stable/src/core/net/sf/basedb
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.16-stable/src/core/net/sf/basedb/core/AbstractHqlQuery.java

    r5345 r5543  
    2929import net.sf.basedb.core.signal.SignalException;
    3030
     31import java.util.HashSet;
    3132import java.util.Set;
    3233import java.util.Map;
     
    283284  private String replaceWithJoinAliases(String query)
    284285  {
    285     Pattern p = Pattern.compile("join\\s+([a-zA-Z\\.]+)\\s+(\\w+)", Pattern.CASE_INSENSITIVE);
     286    Pattern p = Pattern.compile("join\\s+([a-zA-Z0-9\\.]+)\\s+(\\w+)", Pattern.CASE_INSENSITIVE);
    286287    Matcher m = p.matcher(query);
     288    Set<String> alreadyMatched = new HashSet<String>();
    287289    while (m.find())
    288290    {
    289291      String join = m.group(1);
    290292      String alias = m.group(2);
    291       query = query.replace(join + ".", alias + ".");
     293      if (alreadyMatched.add(alias))
     294      {
     295        query = query.replace(join + ".", alias + ".");
     296        m.reset(query);
     297        alreadyMatched.add(alias);
     298      }
    292299    }
    293300    return query;
  • branches/2.16-stable/src/core/net/sf/basedb/core/ItemContext.java

    r5450 r5543  
    3939import net.sf.basedb.core.data.UserData;
    4040import net.sf.basedb.core.data.ClientData;
     41import net.sf.basedb.util.StringLengthComparator;
    4142import net.sf.basedb.util.encode.EncodeUtil;
    4243import net.sf.basedb.util.encode.TabCrLfEncoderDecoder;
     
    5859import java.util.EnumSet;
    5960import java.util.List;
     61import java.util.TreeSet;
    6062
    6163/**
     
    11011103
    11021104    // Temporary storage for all associations that must be left joined
    1103     Set<String> leftJoins = autoLeftJoin ? new HashSet<String>() : null;
     1105    Set<String> leftJoins = autoLeftJoin ? new TreeSet<String>(new StringLengthComparator()) : null;
    11041106    Set<String> sortedProperties = autoLeftJoin ? new HashSet<String>() : null;
    11051107   
Note: See TracChangeset for help on using the changeset viewer.