Package ome.util

Class SqlAction.Impl

  • All Implemented Interfaces:
    SqlAction
    Direct Known Subclasses:
    PostgresSqlAction
    Enclosing interface:
    SqlAction

    public abstract static class SqlAction.Impl
    extends java.lang.Object
    implements SqlAction
    Base implementation which can be used
    • Field Detail

      • log

        protected final org.slf4j.Logger log
    • Constructor Detail

      • Impl

        public Impl()
    • Method Detail

      • _jdbc

        protected abstract org.springframework.jdbc.core.JdbcTemplate _jdbc()
      • _namedJdbc

        protected abstract org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate _namedJdbc()
      • _lookup

        protected abstract java.lang.String _lookup​(java.lang.String key)
      • printThrowable

        protected java.lang.String printThrowable​(java.lang.Throwable t)
      • createInsertTrigger

        public void createInsertTrigger​(java.lang.String name,
                                        java.lang.String table,
                                        java.lang.String procedure)
        Description copied from interface: SqlAction
        Creates an insert trigger of the given name, for the given table, with the given procedure. No error handling is performed.
        Specified by:
        createInsertTrigger in interface SqlAction
      • rewriteHql

        public java.lang.String rewriteHql​(java.lang.String query,
                                           java.lang.String key,
                                           java.lang.Object value)
        Description copied from interface: SqlAction
        Allows the specific database implementations a chance to modify queries.
        Specified by:
        rewriteHql in interface SqlAction
        Parameters:
        query - String query (non-null) which is in effect.
        key - Key of the argument e.g. (:ids)
        value - value which has been passed in for that parameter.
        Returns:
        Returns a query replacement.
        See Also:
        ticket 3697
      • createIdsTempTable

        public java.lang.String createIdsTempTable​(java.util.Collection<java.lang.Long> ids)
        Description copied from interface: SqlAction
        Creates a temporary table filled with the given ids and returns its name. The table is only available for the period if the transaction.
        Specified by:
        createIdsTempTable in interface SqlAction
      • closeNodeSessions

        public int closeNodeSessions​(java.lang.String uuid)
        Specified by:
        closeNodeSessions in interface SqlAction
      • closeNode

        public int closeNode​(java.lang.String uuid)
        Specified by:
        closeNode in interface SqlAction
      • setUserPassword

        public boolean setUserPassword​(java.lang.Long experimenterID,
                                       java.lang.String password)
        Specified by:
        setUserPassword in interface SqlAction
      • changeGroupPermissions

        public int changeGroupPermissions​(java.lang.Long id,
                                          java.lang.Long internal)
        Specified by:
        changeGroupPermissions in interface SqlAction
      • changeTablePermissionsForGroup

        public int changeTablePermissionsForGroup​(java.lang.String table,
                                                  java.lang.Long id,
                                                  java.lang.Long internal)
        Specified by:
        changeTablePermissionsForGroup in interface SqlAction
      • setPermissionsBit

        public boolean setPermissionsBit​(java.lang.String table,
                                         long id,
                                         int bit)
        Description copied from interface: SqlAction
        Sets the given permissions bit to 1. Note: Actually sets the bit to 1 in the value stored in the database, does not adopt the inverse convention associated with permissions flags.
        Specified by:
        setPermissionsBit in interface SqlAction
        Parameters:
        table - the table in which to find the row
        id - the value of the table's id column that identifies the row to update
        bit - the bit number to set to 1, counting from 0 as the least significant bit
        Returns:
        if the row was found in the table, regardless of the given bit's previous value
      • clearPermissionsBit

        public boolean clearPermissionsBit​(java.lang.String table,
                                           long id,
                                           int bit)
        Description copied from interface: SqlAction
        Sets the given permissions bit to 0. Note: Actually sets the bit to 0 in the value stored in the database, does not adopt the inverse convention associated with permissions flags.
        Specified by:
        clearPermissionsBit in interface SqlAction
        Parameters:
        table - the table in which to find the row
        id - the value of the table's id column that identifies the row to update
        bit - the bit number to set to 0, counting from 0 as the least significant bit
        Returns:
        if the row was found in the table, regardless of the given bit's previous value
      • setRoles

        public void setRoles​(long rootUserId,
                             long guestUserId,
                             long systemGroupId,
                             long userGroupId,
                             long guestGroupId)
        Description copied from interface: SqlAction
        Note the roles in the database.
        Specified by:
        setRoles in interface SqlAction
        Parameters:
        rootUserId - the root user's ID
        guestUserId - the guest user's ID
        systemGroupId - the system group's ID
        userGroupId - the user group's ID
        guestGroupId - the guest group's ID
      • findOldAdminPrivileges

        public java.util.Collection<java.lang.Long> findOldAdminPrivileges()
        Description copied from interface: SqlAction
        Find the completed transactions among the current light administrator privileges.
        Specified by:
        findOldAdminPrivileges in interface SqlAction
        Returns:
        the transaction IDs
      • deleteOldAdminPrivileges

        public void deleteOldAdminPrivileges​(java.util.Collection<java.lang.Long> transactionIds)
        Description copied from interface: SqlAction
        Delete the current light administrator privileges for the given transactions.
        Specified by:
        deleteOldAdminPrivileges in interface SqlAction
        Parameters:
        transactionIds - the transaction IDs to delete
      • deleteCurrentAdminPrivileges

        public void deleteCurrentAdminPrivileges()
        Description copied from interface: SqlAction
        Delete the current light administrator privileges for the current transaction.
        Specified by:
        deleteCurrentAdminPrivileges in interface SqlAction
      • insertCurrentAdminPrivileges

        public void insertCurrentAdminPrivileges​(java.lang.Iterable<AdminPrivilege> privileges)
        Description copied from interface: SqlAction
        Insert the current light administrator privileges for the current transaction.
        Specified by:
        insertCurrentAdminPrivileges in interface SqlAction
        Parameters:
        privileges - some light administrator privileges
      • addMimetypes

        protected java.lang.String addMimetypes​(java.util.Collection<java.lang.String> mimetypes,
                                                org.springframework.jdbc.core.namedparam.MapSqlParameterSource params)
        Returns the "and_mimetype" clause which must be appended to a given query. Note: the rest of the SQL statement to which this clause is appended must use named SQL parameters otherwise "Can't infer the SQL type to use" will be raised.
        Parameters:
        mimetypes - If null, then "" will be returned.
        params - sql parameter source to be passed to JDBC methods.
        Returns:
        Possibly empty String, but never null.
      • findRepoFile

        public java.lang.Long findRepoFile​(java.lang.String uuid,
                                           java.lang.String dirname,
                                           java.lang.String basename,
                                           java.util.Set<java.lang.String> mimetypes)
        Description copied from interface: SqlAction
        Lookup the id of an OriginalFile in a given repository or return null if none is found.
        Specified by:
        findRepoFile in interface SqlAction
        Parameters:
        uuid - The UUID of the repository (originalfile.sha1)
        dirname - the full directory path minus the file name.
        basename - i.e. the filename without any directory path
        mimetypes - if null, then no mimetype query fragement will be added.
        Returns:
        null if no OriginalFile is found, otherwise the id.
      • findRepoFiles

        public java.util.Map<java.lang.String,​java.lang.Long> findRepoFiles​(java.lang.String uuid,
                                                                                  java.lang.String dirname,
                                                                                  java.util.List<java.lang.String> basenames,
                                                                                  java.util.Set<java.lang.String> mimetypes)
        Description copied from interface: SqlAction
        Like SqlAction.findRepoFile(String, String, String, Set), but queries in bulk and returns a map for the found IDs.
        Specified by:
        findRepoFiles in interface SqlAction
      • repoScriptCount

        public int repoScriptCount​(java.lang.String uuid,
                                   java.util.Set<java.lang.String> mimetypes)
        Specified by:
        repoScriptCount in interface SqlAction
        Parameters:
        uuid - repository identifier
        mimetypes - file mimetypes to check; if null, all files;
      • isFileInRepo

        public int isFileInRepo​(java.lang.String uuid,
                                long id,
                                java.util.Set<java.lang.String> mimetypes)
        Specified by:
        isFileInRepo in interface SqlAction
        Parameters:
        uuid - Repository identifier
        id - file identifier
        mimetypes - Set of mimetypes to check; if null, all files.
      • fileIdsInDb

        public java.util.List<java.lang.Long> fileIdsInDb​(java.lang.String uuid,
                                                          java.util.Set<java.lang.String> mimetypes)
        Description copied from interface: SqlAction
        Return all IDs matching the given mimetypes, or all IDs if mimetypes is null.
        Specified by:
        fileIdsInDb in interface SqlAction
      • filterFileIdsByRepo

        public java.util.List<java.lang.Long> filterFileIdsByRepo​(java.lang.String uuid,
                                                                  java.util.List<java.lang.Long> fileIds)
        Description copied from interface: SqlAction
        Find the original file IDs among those given that are in the given repository.
        Specified by:
        filterFileIdsByRepo in interface SqlAction
        Parameters:
        uuid - a repository UUID
        fileIds - IDs of original files
        Returns:
        those IDs among those given whose original files are in the given repository
      • findRepoFiles

        public java.util.List<java.lang.Long> findRepoFiles​(java.lang.String uuid,
                                                            java.lang.String dirname)
        Description copied from interface: SqlAction
        Return a list of original file ids that all have a path value matching the passed dirname in the given repository.
        Specified by:
        findRepoFiles in interface SqlAction
        Returns:
        possibly empty list of ids.
      • findRepoRootPath

        public java.lang.String findRepoRootPath​(java.lang.String uuid)
        Description copied from interface: SqlAction
        Find the path of the repository root.
        Specified by:
        findRepoRootPath in interface SqlAction
        Parameters:
        uuid - a repository UUID
        Returns:
        the repository root
      • findRepoFilePath

        public java.lang.String findRepoFilePath​(java.lang.String uuid,
                                                 long id)
        Specified by:
        findRepoFilePath in interface SqlAction
      • nextPixelsDataLogForRepo

        public java.util.List<long[]> nextPixelsDataLogForRepo​(java.lang.String repo,
                                                               long lastEventId,
                                                               int rows)
        Description copied from interface: SqlAction
        Returns arrays of longs for the following SQL return values: experimenter, eventlog, entityid as pixels, rownumber The oldest N eventlogs with action = "PIXELDATA" and entitytype = "ome.model.core.Pixels" is found per user and returned. Multiple eventlogs are returned per user in order to support multi-threading. Duplicate pixel ids are stripped.
        Specified by:
        nextPixelsDataLogForRepo in interface SqlAction
      • getGroupPermissions

        public long getGroupPermissions​(long groupId)
        Description copied from interface: SqlAction
        Returns the permissions for the given group id.
        Specified by:
        getGroupPermissions in interface SqlAction
      • getGroupIds

        public java.util.Map<java.lang.String,​java.lang.Long> getGroupIds​(java.util.Collection<java.lang.String> names)
        Specified by:
        getGroupIds in interface SqlAction
      • getPasswordHash

        public java.lang.String getPasswordHash​(java.lang.Long experimenterID)
        Specified by:
        getPasswordHash in interface SqlAction
      • getUserId

        public java.lang.Long getUserId​(java.lang.String userName)
        Description copied from interface: SqlAction
        Get the user's ID
        Specified by:
        getUserId in interface SqlAction
        Parameters:
        userName - the user's name
        Returns:
        their ID, or null if they cannot be found
      • getUserPrettyNameByOmeName

        public java.lang.String getUserPrettyNameByOmeName​(java.lang.String userName)
        Description copied from interface: SqlAction
        Load the pretty name for the given user.
        Specified by:
        getUserPrettyNameByOmeName in interface SqlAction
        Parameters:
        userName - a user's OME name
        Returns:
        the user's name for presentation, may be null if their OME name does not exist
      • getUserEmailByOmeName

        public java.lang.String getUserEmailByOmeName​(java.lang.String userName)
        Description copied from interface: SqlAction
        Load the email address for the given user.
        Specified by:
        getUserEmailByOmeName in interface SqlAction
        Parameters:
        userName - a user's OME name
        Returns:
        the user's email address, may be null if they have none or their OME name does not exist
      • getUserEmailsByGroup

        public java.util.Collection<java.lang.String> getUserEmailsByGroup​(long groupId)
        Description copied from interface: SqlAction
        Load all the non-empty email addresses for users in a given group.
        Specified by:
        getUserEmailsByGroup in interface SqlAction
        Returns:
        a non-null Collection of non-empty user email addresses.
      • getUsername

        public java.lang.String getUsername​(long userId)
        Description copied from interface: SqlAction
        Get the user's name
        Specified by:
        getUsername in interface SqlAction
        Parameters:
        userId - the user's ID
        Returns:
        their name, or null if they cannot be found
      • getLdapExperimenters

        public java.util.List<java.lang.Long> getLdapExperimenters()
        Description copied from interface: SqlAction
        Gets the experimenters who have the ldap attribute enabled.
        Specified by:
        getLdapExperimenters in interface SqlAction
        Returns:
        a list of user IDs.
      • isLdapExperimenter

        public boolean isLdapExperimenter​(java.lang.Long id)
        Description copied from interface: SqlAction
        Checks whether the specified experimenter ID has the ldap flag set.
        Specified by:
        isLdapExperimenter in interface SqlAction
        Parameters:
        id - The experimenter ID.
        Returns:
        true if the experimenter is an LDAP user; false otherwise.
      • getUserGroups

        public java.util.List<java.lang.String> getUserGroups​(java.lang.String userName)
        Specified by:
        getUserGroups in interface SqlAction
      • fileRepo

        public java.lang.String fileRepo​(long fileId)
        Specified by:
        fileRepo in interface SqlAction
      • scriptRepo

        public java.lang.String scriptRepo​(long fileId,
                                           java.util.Set<java.lang.String> mimetypes)
        Description copied from interface: SqlAction
        Similar to SqlAction.fileRepo(long), but only returns values for files which are also scripts. Null may be returned
        Specified by:
        scriptRepo in interface SqlAction
        mimetypes - null implies all files are checked
      • configValue

        public java.lang.String configValue​(java.lang.String key)
        Specified by:
        configValue in interface SqlAction
      • delConfigValue

        public int delConfigValue​(java.lang.String key)
        Specified by:
        delConfigValue in interface SqlAction
      • updateOrInsertConfigValue

        public int updateOrInsertConfigValue​(java.lang.String name,
                                             java.lang.String value)
        Specified by:
        updateOrInsertConfigValue in interface SqlAction
      • getEventLogPercent

        public float getEventLogPercent​(java.lang.String key)
        Description copied from interface: SqlAction
        Returns the percent (e.g. 0-100%) as calculated by the number of rows represented as completed by the configuration table row of this key divided by the total number of rows in the event log. Since this method executes 2 counts over the event log table, it can take a significant amount of time.
        Specified by:
        getEventLogPercent in interface SqlAction
        Parameters:
        key - PersistentEventLogLoader key for lookup in the configuration table
        Returns:
        float value between 0 and 100 of the percent completed
      • getEventLogPartitions

        public java.util.List<java.lang.Object[]> getEventLogPartitions​(java.util.Collection<java.lang.String> types,
                                                                        java.util.Collection<java.lang.String> actions,
                                                                        long offset,
                                                                        long limit)
        Description copied from interface: SqlAction
        Loads up to "limit" event logs using partioning so that only the last event log of a particular (type, id) pair is returned. The contents of the object array are:
        1. the id of the event log (Long)
        2. the entity type of the event log (String)
        3. the entity id of the event log (Long)
        4. the action of the event log (String)
        5. the number of skipped event logs (Integer)
        Specified by:
        getEventLogPartitions in interface SqlAction
        Parameters:
        types - Collection of entityType strings which should be queried
        actions - Collection of ACTION strings which should be queried
        offset - Offset to the row which should be queried first
        limit - Maximum number of rows (after partionting) which should be returned.
      • setCurrentEventLog

        public void setCurrentEventLog​(long id,
                                       java.lang.String key)
        Specified by:
        setCurrentEventLog in interface SqlAction
      • delCurrentEventLog

        public void delCurrentEventLog​(java.lang.String key)
        Specified by:
        delCurrentEventLog in interface SqlAction
      • refreshEventLogFromUpdatedAnnotations

        public void refreshEventLogFromUpdatedAnnotations()
        Description copied from interface: SqlAction
        Convert the _reindexing_required table to REINDEX entries in the event log.
        Specified by:
        refreshEventLogFromUpdatedAnnotations in interface SqlAction
      • hasUnicodeUnits

        public boolean hasUnicodeUnits()
        Specified by:
        hasUnicodeUnits in interface SqlAction
        Returns:
        if the database's type system contains correctly encoded units of measure
      • addMessageWithinDbPatchStart

        public void addMessageWithinDbPatchStart​(java.lang.String version,
                                                 int patch,
                                                 java.lang.String message)
        Description copied from interface: SqlAction
        Add a unique message to the DB patch table within the current patch. This method marks the start of the corresponding DB adjustment process.
        Specified by:
        addMessageWithinDbPatchStart in interface SqlAction
        Parameters:
        version - the version of the current DB
        patch - the patch of the current DB
        message - the new message to note
      • addMessageWithinDbPatchEnd

        public void addMessageWithinDbPatchEnd​(java.lang.String version,
                                               int patch,
                                               java.lang.String message)
        Description copied from interface: SqlAction
        Add a unique message to the DB patch table within the current patch. This method marks the end of the corresponding DB adjustment process.
        Specified by:
        addMessageWithinDbPatchEnd in interface SqlAction
        Parameters:
        version - the version of the current DB
        patch - the patch of the current DB
        message - the new message to note
      • getShareData

        public java.util.Map<java.lang.Long,​byte[]> getShareData​(java.util.List<java.lang.Long> ids)
        Description copied from interface: SqlAction
        Returns a map of Share ID to Share data blob.
        Specified by:
        getShareData in interface SqlAction
        Parameters:
        ids - IDs of Shares for which data blobs are to be returned.
        Returns:
        map of ID to data blob.