Changeset 1644


Ignore:
Timestamp:
May 15, 2012, 10:18:11 AM (10 years ago)
Author:
Nicklas Nordborg
Message:

References #390: Search for subtype and annotation type among proper main item type

Fixes some ItemNotFoundException:s that could happen during the check phase of the installation if some subtypes doesn't already exists.

Location:
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/dao/Subtype.java

    r1640 r1644  
    230230 
    231231  /**
    232     Load the subtype as a BASE item.
     232    Load the subtype as a BASE item. Same as {@link #get(DbControl)}
     233    but throw an exception instead of returning null if no BASE
     234    item exists.
    233235    @param dc The DbControl to use for database access
    234236    @return An ItemSubtype object
     
    259261 
    260262  /**
     263    Load the subtype as a BASE item. Same as {@link #load(DbControl)} but return null
     264    if no BASE item is found instead of throwing an exception.
     265    @param dc The DbControl to use for database access
     266    @return An ItemSubtype object
     267    @since 2.6
     268  */
     269  public ItemSubtype get(DbControl dc)
     270  {
     271    ItemSubtype subtype = null;
     272    if (id == 0)
     273    {
     274      List<ItemSubtype> result = list(dc);
     275      if (result.size() == 1)
     276      {
     277        subtype = result.get(0);
     278        id = subtype.getId();
     279      }
     280    }
     281    else
     282    {
     283      subtype = ItemSubtype.getById(dc, id);
     284    }
     285    return subtype;
     286   
     287  }
     288 
     289  /**
    261290    List all subtypes registered in BASE with a name and main item type
    262291    matching this subtype definition. Normally, only a single subtype
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/InstallServlet.java

    r1639 r1644  
    569569      subtype = ItemSubtype.getNew(dc, def.getMainType());
    570570      subtype.setName(def.getName());
     571      subtype.setPushAnnotations(def.getPushAnnotations());
    571572     
    572573      if (relatedTo != null)
     
    574575        for (Subtype related : relatedTo)
    575576        {
    576           subtype.setRelatedSubtype(related.load(dc));
     577          ItemSubtype r = related.get(dc);
     578          if (r != null) subtype.setRelatedSubtype(r);
    577579        }
    578580      }
     
    653655          if (r == null)
    654656          {
    655             r = related.load(dc);
     657            r = related.get(dc);
    656658            if (createIfMissing && r != null)
    657659            {
     
    834836      if (def.getSubtype() != null)
    835837      {
    836         plateType.setItemSubtype(def.getSubtype().load(dc));
     838        ItemSubtype subtype = def.getSubtype().get(dc);
     839        if (subtype != null)
     840        {
     841          plateType.setItemSubtype(subtype);
     842        }
    837843      }
    838844      plateType.setLockMode(def.getLockMode());
     
    910916      if (subtype != null)
    911917      {
    912         if (!subtype.load(dc).equals(t.getItemSubtype()))
     918        ItemSubtype st = subtype.get(dc);
     919        if (st == null || !st.equals(t.getItemSubtype()))
    913920        {
    914921          json.put("status", "error");
     
    946953      if (def.getFileType() != null)
    947954      {
    948         type.setFileType(def.getFileType().load(dc));
     955        ItemSubtype subtype = def.getFileType().get(dc);
     956        if (subtype != null) type.setFileType(subtype);
    949957      }
    950958     
Note: See TracChangeset for help on using the changeset viewer.