3.2.1: 2012-12-13

net.sf.basedb.core
Class Update

java.lang.Object
  extended by net.sf.basedb.core.Update

public final class Update
extends Object

This class contains static methods used to update items already in the database.

Schema version Description
90 The schema as released in BASE 2.17. For information about schema changes before this check the BASE 2.17 code.
100 The schema as released in BASE 3.0. We don't list all changes here.
101 and 102 Fixes an issue with duplicate FileSetMemberData entries due to a bug in the upgrade program. Make sure that the unique constraint that should prevent duplicates exists.
103 Added ReporterCloneTemplateData and related classes. No special update is required.
104 Make ExperimentData AnnotatableData. No special update is required.
105 Added ItemSubtypeData.getPushAnnotations(). All existing subtypes are set to 'false'.
106 Added BioPlateData.getEntryDate() and BioPlateData.getEventDate(). All existing bioplates get a null value.
107 Added BioPlateTypeData#getStorageType() All existing bioplate types get a null value.
108 Added BioPlateData.getSection(), BioPlateData.getTray() and BioPlateData.getPosition() All existing bioplates get null values.
109 and 110 Added DerivedBioAssayData.getPhysicalBioAssays() and DerivedBioAssayData.getParents() and removed DerivedBioAssayData.getPhysicalBioAssay() and DerivedBioAssayData.getParent(). Existing derived bioassays are updated in a two-step procedure. The first step is to copy existing information to the new tables and the second step is to drop columns that are no longer needed.
111 Not an actual database schema change, but we need to remove annotation sets that have been created without any annotations by the annotation importer and BASE 1->2 migration.

Version:
2.0
Author:
Nicklas
Last modified
$Date: 2012-09-11 14:34:09 +0200 (Tue, 11 Sep 2012) $

Field Summary
private static int FILETYPE
           
private static int HARDWARETYPE
           
private static int HYBRIDIZATION
           
private static int IMAGE
           
private static int LABELEDEXTRACT
           
private static org.apache.log4j.Logger log
          Log core events.
private static int PROTOCOLTYPE
           
private static int SCAN
           
private static int SOFTWARETYPE
           
private static int TICK_INTERVAL
           
 
Constructor Summary
Update()
           
 
Method Summary
static void adjustExistingItems(ProgressReporter progress, String rootLogin, String rootPassword)
          Adjust the existing items in the database to be compatible with the latest mappings.
private static void cleanContextFromProperty(Session session, Item itemType, String propertyName, String replacementPropertyName, boolean forceRemoveFilter)
           
private static Map<Integer,Integer> copyFileTypes(Session session, ProgressReporter progress)
          Copy from 'FileTypes' table to 'ItemSubtypes' table.
private static Map<Integer,Integer> copyHardwareTypes(Session session, ProgressReporter progress)
          Copy from 'HardwareTypes' table to 'ItemSubtypes' table.
private static Map<Integer,Integer> copyHybridizations(Session session, ProgressReporter progress)
          Copy from 'Hybridizations' table to 'PhysicalBioAssays' table.
private static void copyJarPathToJarFile(Session session, String tableName)
           
private static Map<Integer,Integer> copyProtocolTypes(Session session, ProgressReporter progress)
          Copy from 'ProtocolTypes' table to 'ItemSubtypes' table.
private static Map<Integer,Integer> copyScans(Session session, Map<Integer,Integer> hybMap, ProgressReporter progress)
          Copy from 'Scans' table to 'DerivedBioAssays' table.
private static Map<Integer,Integer> copySoftwareTypes(Session session, ProgressReporter progress)
          Copy from 'SoftwareTypes' table to 'ItemSubtypes' table.
private static void createIndex(Session session, boolean unique, String indexName, String tableName, String... columnNames)
           
private static void disablePlugins(Session session)
           
private static void dropColumn(Session session, String tableName, String columnName, ProgressReporter progress)
           
private static void dropIndex(Session session, boolean unique, String tableName, String... columnNames)
           
private static void dropTable(Session session, String tableName, ProgressReporter progress)
           
private static void encryptPasswords(Session session, ProgressReporter progress)
           
private static String ensureUnique(String name, Set<String> names)
          Ensure that the given name is unique among the set of names.
private static void fixBioMaterialParents(Session session, ProgressReporter progress)
          Copy from 'BioMaterialEventSources' to 'BioMaterialEventSources2' table.
private static void fixLabeledExtracts(Session session, ProgressReporter progress)
           
private static void fixPlatformFileTypes(Session session)
          Set PlatformFileTypes.allow_multiple to false for all with a null value
private static void fixProjectDefaultItems(Session session, ProgressReporter progress)
          Copy project default items from 'AnyToAny' to 'ItemParameterValues'.
private static void fixRawBioAssays(Session session, Map<Integer,Integer> scanMap, ProgressReporter progress)
          Find the correct parent derived bioassay and extract for each raw bioassay using the old scan_id column.
private static void fixSoftLinks(Session session, int oldType, int newType, String oldDataClass, String newDataClass, Map<Integer,Integer> idMap, Map<Integer,Integer> annotationSetMap, ProgressReporter progress)
          Fix all "soft links" in the BASE database.
private static int getSchemaVersion(Session session)
          Get the current schema version number as it is stored in the database.
private static TableInfo getTableInfo(Session session, String tableName)
           
private static
<T> T
load(Session session, Class<T> clazz, Object id)
           
private static void removeContext(Session session, int itemType)
          Remove context-related information for the given item type.
private static String replaceInCommaSeparatedList(String list, String find, String replacement)
           
private static void setSchemaVersion(Session session, int schemaVersion)
          Update the database with a new schema version number.
private static int setSchemaVersionInTransaction(Session session, int schemaVersion)
          Update the schema version version number using a new transaction.
static void updateDatabase(ProgressReporter progress, String rootLogin, String rootPassword)
          Update the database by modifying existing items to follow new requirements.
static void updateToBase3(ProgressReporter progress, String rootLogin, String rootPassword)
           
private static int updateToSchemaVersion100(Session session)
          Set subtypes for hybridizations, scans, labeled extracts and labels moved from BASE 2.17
private static int updateToSchemaVersion101(Session session)
          Remove duplicate file set members.
private static int updateToSchemaVersion102(Session session)
          Add unique index on FileSetMembers(fileset_id,datafiletype_id,file_id)
private static int updateToSchemaVersion110(Session session, int currentSchemaVersion, boolean startedAtBase217)
          Move derived bioassay parent items to different tables.
private static int updateToSchemaVersion111(Session session, ProgressReporter progress)
          Remove annotation sets that have no annotation values and no inherited annotations.
(package private) static void verifyRootLoginAndPassword(String login, String password)
          Verify the root user login and password.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.log4j.Logger log
Log core events.


LABELEDEXTRACT

private static final int LABELEDEXTRACT
See Also:
Constant Field Values

HYBRIDIZATION

private static final int HYBRIDIZATION
See Also:
Constant Field Values

SCAN

private static final int SCAN
See Also:
Constant Field Values

IMAGE

private static final int IMAGE
See Also:
Constant Field Values

PROTOCOLTYPE

private static final int PROTOCOLTYPE
See Also:
Constant Field Values

HARDWARETYPE

private static final int HARDWARETYPE
See Also:
Constant Field Values

SOFTWARETYPE

private static final int SOFTWARETYPE
See Also:
Constant Field Values

FILETYPE

private static final int FILETYPE
See Also:
Constant Field Values

TICK_INTERVAL

private static final int TICK_INTERVAL
See Also:
Constant Field Values
Constructor Detail

Update

public Update()
Method Detail

updateDatabase

public static void updateDatabase(ProgressReporter progress,
                                  String rootLogin,
                                  String rootPassword)
                           throws BaseException
Update the database by modifying existing items to follow new requirements.

Parameters:
progress - An object implementing the ProgressReporter interface
rootLogin - The root user login
rootPassword - The root user password
Throws:
BaseException

verifyRootLoginAndPassword

static void verifyRootLoginAndPassword(String login,
                                       String password)
Verify the root user login and password. This method is called first in the update procedure, which means that tables, etc. are usually still from the old version.


getSchemaVersion

private static int getSchemaVersion(Session session)
                             throws BaseException
Get the current schema version number as it is stored in the database.

Returns:
The schema version number, or 0 if no schem version is found
Throws:
BaseException

setSchemaVersion

private static void setSchemaVersion(Session session,
                                     int schemaVersion)
                              throws BaseException
Update the database with a new schema version number. This method should be called from an open transaction.

Parameters:
schemaVersion - The new schema version number
Throws:
BaseException

setSchemaVersionInTransaction

private static int setSchemaVersionInTransaction(Session session,
                                                 int schemaVersion)
Update the schema version version number using a new transaction.

Parameters:
schemaVersion - The new schema version number

adjustExistingItems

public static void adjustExistingItems(ProgressReporter progress,
                                       String rootLogin,
                                       String rootPassword)
                                throws BaseException
Adjust the existing items in the database to be compatible with the latest mappings. No update to the schema version should be done here. The code must also consider the case that the update failes at a later stage and that the same update is executed again.

Parameters:
progress - An object implementing the ProgressReporter interface
rootLogin - The root user login
rootPassword - The root user password
Throws:
BaseException

updateToSchemaVersion100

private static int updateToSchemaVersion100(Session session)
                                     throws BaseException
Set subtypes for hybridizations, scans, labeled extracts and labels moved from BASE 2.17

Returns:
The new schema version (=100)
Throws:
BaseException

updateToSchemaVersion101

private static int updateToSchemaVersion101(Session session)
                                     throws BaseException
Remove duplicate file set members.

Returns:
The new schema version (=101)
Throws:
BaseException

updateToSchemaVersion102

private static int updateToSchemaVersion102(Session session)
                                     throws BaseException
Add unique index on FileSetMembers(fileset_id,datafiletype_id,file_id)

Returns:
The new schema version (=102)
Throws:
BaseException

updateToSchemaVersion110

private static int updateToSchemaVersion110(Session session,
                                            int currentSchemaVersion,
                                            boolean startedAtBase217)
                                     throws BaseException
Move derived bioassay parent items to different tables. Get rid of old columns in the DerivedBioAssays table.

Returns:
The new schema version (=110)
Throws:
BaseException

updateToSchemaVersion111

private static int updateToSchemaVersion111(Session session,
                                            ProgressReporter progress)
                                     throws BaseException
Remove annotation sets that have no annotation values and no inherited annotations.

Returns:
The new schema version (=111)
Throws:
BaseException

updateToBase3

public static void updateToBase3(ProgressReporter progress,
                                 String rootLogin,
                                 String rootPassword)
                          throws Exception
Throws:
Exception

encryptPasswords

private static void encryptPasswords(Session session,
                                     ProgressReporter progress)

copyJarPathToJarFile

private static void copyJarPathToJarFile(Session session,
                                         String tableName)

getTableInfo

private static TableInfo getTableInfo(Session session,
                                      String tableName)
                               throws SQLException
Throws:
SQLException

dropColumn

private static void dropColumn(Session session,
                               String tableName,
                               String columnName,
                               ProgressReporter progress)
                        throws SQLException
Throws:
SQLException

dropIndex

private static void dropIndex(Session session,
                              boolean unique,
                              String tableName,
                              String... columnNames)
                       throws SQLException
Throws:
SQLException

createIndex

private static void createIndex(Session session,
                                boolean unique,
                                String indexName,
                                String tableName,
                                String... columnNames)
                         throws SQLException
Throws:
SQLException

dropTable

private static void dropTable(Session session,
                              String tableName,
                              ProgressReporter progress)

disablePlugins

private static void disablePlugins(Session session)

removeContext

private static void removeContext(Session session,
                                  int itemType)
Remove context-related information for the given item type.


cleanContextFromProperty

private static void cleanContextFromProperty(Session session,
                                             Item itemType,
                                             String propertyName,
                                             String replacementPropertyName,
                                             boolean forceRemoveFilter)

replaceInCommaSeparatedList

private static String replaceInCommaSeparatedList(String list,
                                                  String find,
                                                  String replacement)

load

private static <T> T load(Session session,
                          Class<T> clazz,
                          Object id)

fixLabeledExtracts

private static void fixLabeledExtracts(Session session,
                                       ProgressReporter progress)

copyHybridizations

private static Map<Integer,Integer> copyHybridizations(Session session,
                                                       ProgressReporter progress)
Copy from 'Hybridizations' table to 'PhysicalBioAssays' table. Fix all "soft links" related to "HYBRIDIZATION", so that they now use "PHYSICALBIOASSAY" instead.

Returns:
A Map with oldId -> newId for hybridizations

copyScans

private static Map<Integer,Integer> copyScans(Session session,
                                              Map<Integer,Integer> hybMap,
                                              ProgressReporter progress)
Copy from 'Scans' table to 'DerivedBioAssays' table. Fix all "soft links" related to "SCAN", so that they now use "DERIVEDBIOASSAY" instead. Copy from 'Images' to `FileSetMembers`. Use a temporary file type that is later (in updateToSchemaVersion100) changed to the "Microarray image" type.

Parameters:
hybMap - A Map with oldId -> newId for hybridizations
Returns:
A Map with oldId -> newId for scans

fixRawBioAssays

private static void fixRawBioAssays(Session session,
                                    Map<Integer,Integer> scanMap,
                                    ProgressReporter progress)
Find the correct parent derived bioassay and extract for each raw bioassay using the old scan_id column.

Parameters:
scanMap - A Map with oldId -> newId for scans

copyProtocolTypes

private static Map<Integer,Integer> copyProtocolTypes(Session session,
                                                      ProgressReporter progress)
Copy from 'ProtocolTypes' table to 'ItemSubtypes' table. Fix "hard links" in 'Protocols' and 'PlateEventTypes' tables. Fix all "soft links" related to "PROTOCOLTYPE", so that they now use "ITEMSUBTYPE" instead.

Returns:
A Map with oldId -> newId for protocoltypes

copyHardwareTypes

private static Map<Integer,Integer> copyHardwareTypes(Session session,
                                                      ProgressReporter progress)
Copy from 'HardwareTypes' table to 'ItemSubtypes' table. Fix "hard links" in 'Hardware' table. Fix all "soft links" related to "HARDWARETYPE", so that they now use "ITEMSUBTYPE" instead.

Returns:
A Map with oldId -> newId for hardwaretypes

copyFileTypes

private static Map<Integer,Integer> copyFileTypes(Session session,
                                                  ProgressReporter progress)
Copy from 'FileTypes' table to 'ItemSubtypes' table. Fix "hard links" in 'Files', 'MimeTypes' and 'DataFileTypes' tables. Fix all "soft links" related to "FILETYPE", so that they now use "ITEMSUBTYPE" instead.

Returns:
A Map with oldId -> newId for file types

copySoftwareTypes

private static Map<Integer,Integer> copySoftwareTypes(Session session,
                                                      ProgressReporter progress)
Copy from 'SoftwareTypes' table to 'ItemSubtypes' table. Fix "hard links" in 'Software' table. Fix all "soft links" related to "SOFTWARETYPE", so that they now use "ITEMSUBTYPE" instead.

Returns:
A Map with oldId -> newId for softwaretypes

fixPlatformFileTypes

private static void fixPlatformFileTypes(Session session)
Set PlatformFileTypes.allow_multiple to false for all with a null value


fixBioMaterialParents

private static void fixBioMaterialParents(Session session,
                                          ProgressReporter progress)
Copy from 'BioMaterialEventSources' to 'BioMaterialEventSources2' table. Set the parent type property on all biomaterials.


fixProjectDefaultItems

private static void fixProjectDefaultItems(Session session,
                                           ProgressReporter progress)
Copy project default items from 'AnyToAny' to 'ItemParameterValues'.


fixSoftLinks

private static void fixSoftLinks(Session session,
                                 int oldType,
                                 int newType,
                                 String oldDataClass,
                                 String newDataClass,
                                 Map<Integer,Integer> idMap,
                                 Map<Integer,Integer> annotationSetMap,
                                 ProgressReporter progress)
Fix all "soft links" in the BASE database. Soft links are links that are an item_type + item_id pair (or a class name + id)

Parameters:
oldType - The old item type code
newType - The new item type code (must be different from the old or the update may be incorrect)
idMap - Map with old -> new id values (null or empty is accepted)
annotationSetMap - Map with new item id -> annotation set id (null or empty is accepted)

ensureUnique

private static String ensureUnique(String name,
                                   Set<String> names)
Ensure that the given name is unique among the set of names. If the name doesn't exists in the set it is added to it and returned unmodified. If the name already exists we try to append (2), (3), ... and so on until an unused name is found.

Parameters:
name - The original name
names - The set of already used names
Returns:
A unique name

3.2.1: 2012-12-13