Changeset 4620


Ignore:
Timestamp:
Oct 31, 2008, 9:54:10 AM (15 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #394: Make it possible to export and properly query values in components

The query problem was solved by using # instead of . to separate paths in a component. The export problem was solved by introducing a new interface (ComponentData?) that all components must implement.

Location:
trunk
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/Metadata.java

    r4517 r4620  
    2626import net.sf.basedb.core.data.BasicData;
    2727import net.sf.basedb.core.data.BatchableData;
     28import net.sf.basedb.core.data.ComponentData;
     29
    2830import java.util.Date;
    2931import java.util.Collection;
     
    3537
    3638import org.hibernate.metadata.ClassMetadata;
     39import org.hibernate.type.ComponentType;
    3740import org.hibernate.EntityMode;
    3841
     
    288291    if (item == null) throw new InvalidUseOfNullException("item");
    289292    if (propertyName == null) throw new InvalidUseOfNullException("propertyName");
    290     String[] propertyPath = propertyName.split("\\.");
     293    String[] propertyPath = propertyName.split("\\.|\\#");
    291294    ClassMetadata currentClassMetadata = classMetadata;
    292295    String currentIdProperty = currentClassMetadata.getIdentifierPropertyName();
     
    333336          currentIdProperty = currentClassMetadata.getIdentifierPropertyName();
    334337        }
     338       
    335339        if (propertyPath[i].equals(currentIdProperty))
    336340        {
    337341          value = currentClassMetadata.getIdentifier(data, EntityMode.POJO);
     342        }
     343        else if (value instanceof ComponentData)
     344        {
     345          ComponentType type = (ComponentType)currentClassMetadata.getPropertyType(propertyPath[i-1]);
     346          data = value;
     347          // There is no get-by-name method, we need to find the index
     348          String[] subProperties = type.getPropertyNames();
     349          for (int index = 0; index < subProperties.length; ++index)
     350          {
     351            if (subProperties[index].equals(propertyPath[i]))
     352            {
     353              value = type.getPropertyValue(data, index, EntityMode.POJO);
     354              break;
     355            }
     356          }
    338357        }
    339358        else
     
    392411    return value;
    393412  }
    394 
     413 
    395414  public String toString()
    396415  {
  • trunk/src/core/net/sf/basedb/core/data/ColoringData.java

    r4517 r4620  
    3232*/
    3333public class ColoringData
     34  implements ComponentData
    3435{
    3536
  • trunk/src/core/net/sf/basedb/core/query/Hql.java

    r4516 r4620  
    5454 
    5555  /**
    56     A property can only contain the characters a-zA-Z0-9 and period(.)
    57     It cannot begin or end with a period and cannot have two periods in a sequence.
    58   */
    59   public static final Pattern PROPERTY_REGEXP = Pattern.compile("[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+)*");
     56    A property can only contain the characters a-zA-Z0-9, period(.) or hash (#)
     57    It cannot begin or end with a period/hash and cannot have two periods/hashes in a sequence.
     58    A hash indicates a path to a component while a period indicates a path to another
     59    entity.
     60  */
     61  public static final Pattern PROPERTY_REGEXP = Pattern.compile("[a-zA-Z0-9]+((\\.|\\#)[a-zA-Z0-9]+)*");
    6062
    6163  /**
  • trunk/src/core/net/sf/basedb/core/query/HqlElementsExpression.java

    r4516 r4620  
    6363    if (query.getQueryType() == QueryType.HQL)
    6464    {
    65       return "elements("+(alias == null ? query.getRootAlias() : alias) + (property == null ? "" : "." +property)+")";
     65      return "elements("+(alias == null ? query.getRootAlias() : alias) +
     66        (property == null ? "" : "." +property.replace("#", "."))+")";
    6667    }
    6768    else
  • trunk/src/core/net/sf/basedb/core/query/HqlIndexExpression.java

    r4516 r4620  
    6262    if (query.getQueryType() == QueryType.HQL)
    6363    {
    64       return "index("+(alias == null ? query.getRootAlias() : alias) + (property == null ? "" : "." +property)+")";
     64      return "index("+(alias == null ? query.getRootAlias() : alias) +
     65        (property == null ? "" : "." +property.replace("#", "."))+")";
    6566    }
    6667    else
  • trunk/src/core/net/sf/basedb/core/query/HqlInnerJoin.java

    r4516 r4620  
    7272      // Count queries can't use the fetch parameter; they are not selecting the root item
    7373      return "INNER JOIN " + (fetch && !query.isCounting() ? "FETCH " : "") +
    74         (alias == null ? query.getRootAlias() : alias) + "." + property + " " + joinedAlias +
     74        (alias == null ? query.getRootAlias() : alias) + "." + property.replace("#", ".") + " " + joinedAlias +
    7575        (on == null ? "" : " WITH " + on.toQl(query, dc));
    7676    }
  • trunk/src/core/net/sf/basedb/core/query/HqlLeftJoin.java

    r4516 r4620  
    7272    {
    7373      return "LEFT JOIN " + (fetch && !query.isCounting() ? "FETCH " : "") +
    74         (alias == null ? query.getRootAlias() : alias) + "." + property + " " + joinedAlias +
     74        (alias == null ? query.getRootAlias() : alias) + "." + property.replace("#", ".") + " " + joinedAlias +
    7575        (on == null ? "" : " WITH " + on.toQl(query, dc));
    7676    }
  • trunk/src/core/net/sf/basedb/core/query/HqlPropertyExpression.java

    r4600 r4620  
    6161    if (query.getQueryType() == QueryType.HQL)
    6262    {
    63       return (alias == null ? query.getRootAlias() : alias) + (property == null ? "" : "." +property);
     63      return (alias == null ? query.getRootAlias() : alias) +
     64        (property == null ? "" : "." +property.replace("#", "."));
    6465    }
    6566    else
  • trunk/src/core/net/sf/basedb/core/query/HqlSizeExpression.java

    r4516 r4620  
    6464    {
    6565      return "size("+(alias == null ? query.getRootAlias() : alias) +
    66         (property == null ? "" : "." +property)+")";
     66        (property == null ? "" : "." +property.replace("#", "."))+")";
    6767    }
    6868    else
  • trunk/src/core/net/sf/basedb/core/query/ReporterListExpression.java

    r4516 r4620  
    101101    else if (query.getQueryType() == QueryType.HQL && hqlMode)
    102102    {
    103       return tableAlias + "." + property;
     103      return tableAlias + "." + property.replace("#", ".");
    104104    }
    105105    else
  • trunk/www/views/formulas/list_formulas.jsp

    r4578 r4620  
    9797  try
    9898  {
    99     final ItemQuery<Formula> query = Base.getConfiguredQuery(cc, false, Formula.getQuery(), mode);
     99    final ItemQuery<Formula> query = Base.getConfiguredQuery(dc, cc, true, Formula.getQuery(), mode);
    100100    formulas = query.iterate(dc);
    101101  }
     
    107107  int numListed = 0;
    108108  %>
     109 
    109110  <base:page title="<%=title==null ? "Formulas" : title%>" type="<%=mode.getPageType()%>">
    110111  <base:head scripts="menu.js,table.js" styles="menu.css,table.css">
     
    298299      <tbl:columndef
    299300        id="useColors"
    300         property="coloring.usingColors"
     301        property="coloring#usingColors"
    301302        datatype="boolean"
    302303        title="Use colors"
     
    307308      <tbl:columndef
    308309        id="logarithmic"
    309         property="coloring.logarithmic"
     310        property="coloring#logarithmic"
    310311        datatype="boolean"
    311312        title="Logarithmic"
    312313        sortable="true"
    313314        filterable="true"
    314         exportable="false"
     315        exportable="true"
    315316      />
    316317      <tbl:columndef
    317318        id="minValue"
    318         property="coloring.minValue"
     319        property="coloring#minValue"
    319320        datatype="float"
    320321        title="Min value"
     
    325326      <tbl:columndef
    326327        id="midValue"
    327         property="coloring.midValue"
     328        property="coloring#midValue"
    328329        datatype="float"
    329330        title="Mid value"
     
    334335      <tbl:columndef
    335336        id="maxValue"
    336         property="coloring.maxValue"
     337        property="coloring#maxValue"
    337338        datatype="float"
    338339        title="Max value"
Note: See TracChangeset for help on using the changeset viewer.