Changeset 4006


Ignore:
Timestamp:
Nov 27, 2007, 9:00:56 AM (15 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #844: File.isUsed() doesn't check if a file has been used in a FileSet?.
References #721

Location:
trunk/src/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/common-queries.xml

    r3999 r4006  
    10071007      A Hibernate query that gets spot images where a given
    10081008      file is used as one of the color components or holds the generated spot images.
     1009    </description>
     1010  </query>
     1011 
     1012  <query id="GET_FILESETMEMBERS_FOR_FILE" type="HQL">
     1013    <sql>
     1014      SELECT {1}
     1015      FROM FileSetMemberData fsm
     1016      WHERE fsm.file = :file
     1017    </sql>
     1018    <description>
     1019      A Hibernate query that gets file set membership
     1020      for a given file
    10091021    </description>
    10101022  </query>
  • trunk/src/core/net/sf/basedb/core/File.java

    r3929 r4006  
    2929import net.sf.basedb.core.data.FileAttachableData;
    3030import net.sf.basedb.core.data.FileData;
     31import net.sf.basedb.core.data.FileSetData;
    3132import net.sf.basedb.core.data.FileTypeData;
    3233import net.sf.basedb.core.data.MimeTypeData;
     
    4647import java.util.HashMap;
    4748import java.util.LinkedList;
     49import java.util.List;
    4850import java.util.Map;
    4951import java.util.Random;
     
    393395    {
    394396      query = HibernateUtil.getPredefinedQuery(session,
     397        "GET_FILESETMEMBERS_FOR_FILE", "count(*)");
     398      /*
     399        SELECT {1}
     400        FROM FileSetMemberData fsm
     401        WHERE fsm.file = :file
     402      */
     403      query.setEntity("file", this.getData());
     404      used = HibernateUtil.loadData(Long.class, query) > 0;
     405    }
     406    if (!used)
     407    {
     408      query = HibernateUtil.getPredefinedQuery(session,
    395409        "GET_SPOTIMAGES_FOR_FILE", "count(*)");
    396410      /*
     
    431445    query.setEntity("file", this.getData());
    432446    addUsingItems(using, query);
     447   
     448    // It is the FileStoreEnabled item that is the using item, not the FileSet
     449    // So, we need to do a bit of hard work to make it happen
     450    query = HibernateUtil.getPredefinedQuery(session,
     451      "GET_FILESETMEMBERS_FOR_FILE", "fsm.fileSet");
     452      /*
     453        SELECT {1}
     454        FROM FileSetMemberData fsm
     455        WHERE fsm.file = :file
     456      */
     457    query.setEntity("file", this.getData());
     458    List<FileSetData> fileSets = HibernateUtil.loadList(FileSetData.class, query, getSessionControl());
     459    for (FileSetData fs : fileSets)
     460    {
     461      Item itemType = Item.fromValue(fs.getItemType());
     462      String hql = "SELECT item.id"+
     463        " FROM "+itemType.getDataClass().getName()+" item"+
     464        " WHERE item.fileSet = :fileSet";
     465      query = HibernateUtil.createQuery(session, hql);
     466      query.setEntity("fileSet", fs);
     467      int itemId = HibernateUtil.loadData(Integer.class, query);
     468      using.add(new ItemProxy(itemId, itemType));
     469    }   
    433470   
    434471    // SpotImages
Note: See TracChangeset for help on using the changeset viewer.