Changeset 3900


Ignore:
Timestamp:
Nov 1, 2007, 11:33:14 AM (14 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #612: Add checks in the core so that unsaved objects are not used in queries.

Location:
trunk/src
Files:
4 added
4 edited

Legend:

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

    r3898 r3900  
    334334    </ol>
    335335    If no annotation of the specified type is found, an empty list is returned.
     336    <p>
     337    Note! This method only looks in the database. Changes that have been made in
     338    the current transaction and not yet committed to the database are not included
     339    in the result.
    336340   
    337341    @param dc The DbControl to use for database access
  • trunk/src/core/net/sf/basedb/core/HibernateUtil.java

    r3882 r3900  
    4040import net.sf.basedb.core.dbengine.TableInfo.ForeignKeyInfo;
    4141import net.sf.basedb.core.dbengine.TableInfo.IndexInfo;
     42import net.sf.basedb.core.hibernate.EntityQueryWrapper;
    4243import net.sf.basedb.core.query.QueryType;
    4344import net.sf.basedb.util.XMLUtil;
     
    13441345    try
    13451346    {
    1346       return session.createQuery(hql);
     1347      return new EntityQueryWrapper(session.createQuery(hql));
    13471348    }
    13481349    catch (HibernateException ex)
     
    13621363    try
    13631364    {
    1364       return session.createQuery(hql);
     1365      return new EntityQueryWrapper(session.createQuery(hql));
    13651366    }
    13661367    catch (HibernateException ex)
  • trunk/src/core/net/sf/basedb/core/query/Hql.java

    r3846 r3900  
    2929import net.sf.basedb.core.InvalidDataException;
    3030import net.sf.basedb.core.InvalidUseOfNullException;
     31import net.sf.basedb.core.UnsavedItemException;
    3132import net.sf.basedb.core.data.BasicData;
    3233
     
    7071
    7172    @param entity The entity
    72     @throws InvalidDataException If the entity is null
     73    @throws InvalidDataException If the entity is null or isn't saved to the database
    7374    @see #entity(BasicData)
    7475  */
     
    7778  {
    7879    if (entity == null) throw new InvalidUseOfNullException("entity");
     80    if (!entity.isInDatabase())
     81    {
     82      throw new UnsavedItemException("Can't use an unsaved item in query: " + entity);
     83    }
    7984    return new HqlEntityExpression(entity);
    8085  }
     
    9499  {
    95100    if (entity == null) throw new InvalidUseOfNullException("entity");
     101    if (entity.getId() == 0)
     102    {
     103      throw new UnsavedItemException("Can't use an unsaved item in query: " + entity);
     104    }
    96105    return new HqlEntityExpression(entity);
    97106  }
  • trunk/src/install/net/sf/basedb/install/Webclient.java

    r3679 r3900  
    159159  {
    160160    ClientDefaultSetting setting = null;
    161     try
    162     {
    163       setting = client.getDefaultSetting(name);
     161    if (client.isInDatabase())
     162    {
     163      try
     164      {
     165        setting = client.getDefaultSetting(name);
     166      }
     167      catch (ItemNotFoundException ex)
     168      {}
     169    }
     170    if (setting == null)
     171    {
     172      setting = client.newDefaultSetting(name, value);
     173      client.getDbControl().saveItem(setting);
     174    }
     175    else
     176    {
    164177      String oldValue = setting.getValue();
    165178      if (oldValue == null || "".equals(oldValue))
     
    167180        setting.setValue(value);
    168181      }
    169     }
    170     catch (ItemNotFoundException ex)
    171     {
    172       setting = client.newDefaultSetting(name, value);
    173       client.getDbControl().saveItem(setting);
    174182    }
    175183    return setting;
Note: See TracChangeset for help on using the changeset viewer.