Changeset 7573


Ignore:
Timestamp:
Jan 9, 2019, 1:28:53 PM (3 years ago)
Author:
Nicklas Nordborg
Message:

References #2135: Remove support for secondary storage

Removed File.getAction() property which was used to transfer a file between primary and secondary storage. A schema update is needed since it removes the Files.action column from the database. The update will also fix the Files.location property and remove the action property from context filtering and sorting.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/initdb.bat

    r6269 r7573  
    2929
    3030REM Execute install class
    31 java -cp %CP% net.sf.basedb.install.InitDB install %1 %2 %3 %4 %5 %6 %7 %8 %9
     31C:\Software\Java\jdk-11.0.1\bin\java --illegal-access=warn -cp %CP% net.sf.basedb.install.InitDB install %1 %2 %3 %4 %5 %6 %7 %8 %9
  • trunk/src/core/net/sf/basedb/core/File.java

    r7548 r7573  
    5656import java.text.SimpleDateFormat;
    5757import java.util.Date;
    58 import java.util.HashMap;
    5958import java.util.LinkedList;
    6059import java.util.List;
    61 import java.util.Map;
    6260import java.util.Random;
    6361import java.util.Set;
     
    193191  {
    194192    File file = dc.newItem(File.class);
    195     file.setAction(File.Action.NOTHING);
    196193    file.setDirectory(directory);
    197194    file.setLocation(Location.OFFLINE);
     
    767764
    768765  /**
    769     Get the {@link File.Action} of this file.
    770     @return the action
    771     @deprecated In 3.14, no replacement
    772   */
    773   @Deprecated
    774   public File.Action getAction()
    775   {
    776     return File.Action.fromValue(getData().getAction());
    777   }
    778 
    779   /**
    780     Set the action of this <code>File</code> item. This method call
    781     has no affect on external files.
    782     @param action The new <code>File.Action</code>
    783     @throws PermissionDeniedException If the logged in user doesn't have
    784       write permission
    785     @throws InvalidUseOfNullException If action is null
    786     @deprecated In 3.14, no replacement
    787   */
    788   @Deprecated
    789   public void setAction(File.Action action)
    790     throws PermissionDeniedException, InvalidUseOfNullException
    791   {
    792     checkPermission(Permission.WRITE);
    793     if (action == null) throw new InvalidUseOfNullException("action");
    794     if (getLocation() == Location.EXTERNAL) return;
    795     getData().setAction(action.getValue());
    796   }
    797 
    798   /**
    799766    Get the (uncompressed) size of this file.
    800767    @return The size in bytes or -1 if not known
     
    1014981    @throws PermissionDeniedException If the logged in user doesn't have write permission
    1015982  */
    1016   @SuppressWarnings("deprecation")
    1017983  public void setUrl(String url, boolean loadMetadata)
    1018984  {
     
    10381004    data.setCompressed(false);
    10391005    data.setMd5(null);
    1040     data.setAction(Action.NOTHING.getValue());
    10411006   
    10421007    // Reset metadata (will be updated later if loadMetadata is true)
     
    10651030    @throws PermissionDeniedException If the logged in user doesn't have write permission
    10661031  */
    1067   @SuppressWarnings("deprecation")
    10681032  public void setUrl(String url, UriMetadata metadata)
    10691033  {
     
    10871051    data.setCompressed(false);
    10881052    data.setMd5(null);
    1089     data.setAction(Action.NOTHING.getValue());
    10901053   
    10911054    if (metadata != null) setMetadataFromURI(metadata);
     
    16871650    return new java.io.File(Application.getUserFilesDirectory(), relativePath);
    16881651  }
    1689  
    1690   /**
    1691     A fileaction describes if a file should be moved to secondary storage
    1692     or brought back from it. The actual moving of the file is done by an
    1693     external progam. 
    1694    
    1695     @author enell
    1696     @deprecated In 3.14, no replacement
    1697   */
    1698   @Deprecated
    1699   public enum Action
    1700   {
    1701     /**
    1702       Do nothing.
    1703     */
    1704     NOTHING(0),
    1705     /**
    1706       The file should be brought back from secondary storage.
    1707     */
    1708     MOVE_TO_PRIMARY(1),
    1709     /**
    1710       The file should be moved to secondary storage
    1711     */
    1712     MOVE_TO_SECONDARY(2);
    1713 
    1714     /**
    1715       Maps the integer that is stored in the database with an fileaction.
    1716     */
    1717     private static final Map<Integer, File.Action> valueMapping = new HashMap<Integer, File.Action>();
    1718    
    1719     static
    1720     {
    1721       for(Action action : Action.values())
    1722       {
    1723         Action a = valueMapping.put(action.getValue(), action);
    1724         assert a == null : "Another File.Action with the value "+action.getValue()+" already exists";
    1725       }
    1726     }
    1727    
    1728     /**
    1729       The integer value of this fileaction.
    1730     */
    1731     private final int value;
    1732    
    1733     /**
    1734       Creates a new fileaction. Only used internal.
    1735      
    1736       @param value The int value of en action.
    1737     */
    1738     private Action(int value)
    1739     {
    1740       this.value = value;
    1741     }
    1742    
    1743     /**
    1744       Get the <code>File.Action</code> object when you know the integer code.
    1745      
    1746       @param value The integer value.
    1747       @return The fileaction for the integer value.
    1748     */
    1749     public static Action fromValue(int value)
    1750     {
    1751       Action action = valueMapping.get(value);
    1752       assert action != null : "action == null for value "+value;
    1753       return action;
    1754     }
    1755    
    1756     /**
    1757       Get the integer value that is used when storing an File.Action to the database.
    1758       @return The intger value of this action.
    1759     */
    1760     public int getValue()
    1761     {
    1762       return value;
    1763     }
    1764   }
    17651652
    17661653  /**
  • trunk/src/core/net/sf/basedb/core/Install.java

    r7548 r7573  
    119119    method.
    120120  */
    121   public static final int NEW_SCHEMA_VERSION = Integer.valueOf(142).intValue();
     121  public static final int NEW_SCHEMA_VERSION = Integer.valueOf(144).intValue();
    122122 
    123123  public static synchronized int createTables(SchemaGenerator.Mode mode, ProgressReporter progress,
  • trunk/src/core/net/sf/basedb/core/Update.java

    r7536 r7573  
    5151import net.sf.basedb.core.data.DerivedBioAssayData;
    5252import net.sf.basedb.core.data.ExperimentData;
     53import net.sf.basedb.core.data.FileData;
    5354import net.sf.basedb.core.data.FileServerData;
    5455import net.sf.basedb.core.data.FileSetMemberData;
     
    406407    </td>
    407408  </tr>
     409  <tr>
     410    <td>143 and 144</td>
     411    <td>
     412      Remvoving support for secondary storage. {@link FileData}.action has been deleted.
     413      The update works in two step and the first step is to set FileData.location=0 (offline)
     414      on all files with FileData.location=2 (secondary) and remove filters on the action column
     415      The second step is to drop the action column.
     416    </td>
     417  </tr>
    408418 
    409419  </table>
     
    662672        progress_current += progress_step;
    663673      }
    664 
     674     
     675      if (schemaVersion < 143)
     676      {
     677        // Note! 143 and 144 is a two-step update due to DROP COLUMN
     678        if (progress != null) progress.display((int)(progress_current), "--Updating schema version: " + schemaVersion + " -> 144...");
     679        schemaVersion = updateToSchemaVersion144(session, schemaVersion);
     680        progress_current += 2 * progress_step;
     681      }
     682     
    665683      sc.logout();
    666684      if (progress != null) progress.display(100, "Database updated successfully.");
     
    20562074    return schemaVersion;
    20572075  }
     2076
     2077  /**
     2078    Update the Files table by setting location=0 (offline) on
     2079    all files with location=2 (secondary), remove the 'action'
     2080    column and all stored contexts using the 'action' column.
     2081    @return The new schema version (=144)
     2082  */
     2083  private static int updateToSchemaVersion144(org.hibernate.Session session, int currentSchemaVersion)
     2084    throws BaseException
     2085  {
     2086    final int schemaVersion = 144;
     2087    try
     2088    {
     2089      if (currentSchemaVersion < 143)
     2090      {
     2091        // First step is to update/delete existing information to the new tables
     2092        org.hibernate.Transaction tx = null;
     2093        try
     2094        {
     2095          tx = HibernateUtil.newTransaction(session);
     2096         
     2097          // Update 'location'
     2098          org.hibernate.query.Query<?> query = HibernateUtil.createQuery(session,
     2099            "UPDATE FileData f " +
     2100            "SET f.location=0 " +
     2101            "WHERE f.location=2");
     2102          query.executeUpdate();
     2103     
     2104          // Remove table filters, etc. that use the 'action' property
     2105          cleanContextFromProperty(session, Item.FILE, "action", null, true);
     2106         
     2107          setSchemaVersion(session, 143);
     2108 
     2109          // Commit the changes
     2110          HibernateUtil.commit(tx);
     2111        }
     2112        finally
     2113        {
     2114          if (tx != null && tx.getStatus() != TransactionStatus.COMMITTED) HibernateUtil.rollback(tx);
     2115        }
     2116      }
     2117     
     2118      // Drop the 'Files.action' column
     2119      dropColumn(session, "Files", "action", null);
     2120       
     2121      // Update the schema version number
     2122      setSchemaVersionInTransaction(session, schemaVersion);
     2123 
     2124      log.info("updateToSchemaVersion144: OK");
     2125    }
     2126    catch (SQLException ex)
     2127    {
     2128      log.error("updateToSchemaVersion144: FAILED", ex);
     2129      throw new BaseException(ex);
     2130    }
     2131    catch (RuntimeException ex)
     2132    {
     2133      log.error("updateToSchemaVersion144: FAILED", ex);
     2134      throw ex;
     2135    }
     2136    return schemaVersion;
     2137  }
     2138 
    20582139  /**
    20592140    Vefify and update the remaining quantity of all biomaterials.
  • trunk/src/core/net/sf/basedb/core/data/FileData.java

    r7548 r7573  
    118118  }
    119119
    120   private int action;
    121   /**
    122     Get the value of the action variable for this <code>FileData</code>
    123     object.
    124     @hibernate.property column="`action`" type="int" not-null="true"
    125     @deprecated In 3.14, no replacement
    126   */
    127   @Deprecated
    128   public int getAction()
    129   {
    130     return action;
    131   }
    132   @Deprecated
    133   public void setAction(int action)
    134   {
    135     this.action = action;
    136   }
    137  
    138120  private int location;
    139121  /**
Note: See TracChangeset for help on using the changeset viewer.