Changeset 3152 for branches


Ignore:
Timestamp:
Feb 26, 2007, 12:22:00 PM (16 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #499: Add Hql.entity(BasicData?) method

Location:
branches/2.2.2/src/core/net/sf/basedb/core/query
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.2/src/core/net/sf/basedb/core/query/Hql.java

    r2497 r3152  
    2727import net.sf.basedb.core.InvalidDataException;
    2828import net.sf.basedb.core.InvalidUseOfNullException;
     29import net.sf.basedb.core.data.BasicData;
    2930
    3031import java.util.regex.Pattern;
     
    5556
    5657  /**
    57     Create an expression representing an item. In the query the actual
    58     value used is the id of the entity. See {@link #property(String, String)}
    59     for a code example.
     58    Create an expression representing an item which is a subclass of BasicItem.
     59    In the query the actual value used is the id of the entity.
     60    See {@link #property(String, String)} for a code example.
    6061
    6162    @param entity The entity
    62     @throws InvalidDataException If the etity is null
     63    @throws InvalidDataException If the entity is null
     64    @see #entity(BasicData)
    6365  */
    6466  public static Expression entity(BasicItem entity)
     
    6971  }
    7072 
     73  /**
     74    Create an expression representing an item which is a subclass of BasicData,
     75    for example a reporter. In the query the actual value used is the id of the entity.
     76    See {@link #property(String, String)} for a code example.
     77 
     78    @param entity The entity
     79    @throws InvalidDataException If the entity is null
     80    @see #entity(BasicItem)
     81    @since 2.2.2
     82  */
     83  public static Expression entity(BasicData entity)
     84    throws InvalidDataException
     85  {
     86    if (entity == null) throw new InvalidUseOfNullException("entity");
     87    return new HqlEntityExpression(entity);
     88  }
     89   
    7190  /**
    7291    Same as <code>property(null, property)</code>.
  • branches/2.2.2/src/core/net/sf/basedb/core/query/HqlEntityExpression.java

    r2667 r3152  
    2929import net.sf.basedb.core.BasicItem;
    3030import net.sf.basedb.core.BaseException;
     31import net.sf.basedb.core.data.BasicData;
    3132
    3233/**
     
    3940  @version 2.0
    4041  @see Hql#entity(BasicItem)
     42  @see Hql#entity(BasicData)
    4143  @base.modified $Date$
    4244*/
     
    4446  implements Expression
    4547{
    46   private final BasicItem item;
     48  private final int id;
     49  private final String item;
    4750
    4851  HqlEntityExpression(BasicItem item)
    4952  {
    50     this.item = item;
     53    this.id = item.getId();
     54    this.item = item.toString();
     55  }
     56 
     57  /**
     58    @since 2.2.2
     59  */
     60  HqlEntityExpression(BasicData data)
     61  {
     62    this.id = data.getId();
     63    this.item = data.toString();
    5164  }
    5265
     
    6073    if (query.getQueryType() == QueryType.HQL)
    6174    {
    62       return Integer.toString(item.getId());
     75      return Integer.toString(id);
    6376    }
    6477    else
     
    8194  public String toString()
    8295  {
    83     return item.toString();
     96    return item;
    8497  }
    8598  // -------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.