Instruction:
作为 Java 安全专家，检测此代码中的安全漏洞：
## 内容1
### 文件路径：
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java
### 代码内容：
package org.hisp.dhis.common;

import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.hisp.dhis.attribute.Attribute;
import org.hisp.dhis.attribute.AttributeValue;
import org.hisp.dhis.translation.Translation;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserInfo;

/**
 * @author Lars Helge Overland
 */
public interface IdentifiableObjectManager
{
    String ID = IdentifiableObjectManager.class.getName();

    void save( IdentifiableObject object );

    void save( IdentifiableObject object, boolean clearSharing );

    void save( List<IdentifiableObject> objects );

    void update( IdentifiableObject object );

    void update( IdentifiableObject object, User user );

    void update( List<IdentifiableObject> objects );

    void update( List<IdentifiableObject> objects, User user );

    void delete( IdentifiableObject object );

    void delete( IdentifiableObject object, User user );

    <T extends IdentifiableObject> T get( String uid );

    <T extends IdentifiableObject> T get( Class<T> clazz, long id );

    <T extends IdentifiableObject> T get( Class<T> clazz, String uid );

    <T extends IdentifiableObject> boolean exists( Class<T> clazz, String uid );

    <T extends IdentifiableObject> T get( Collection<Class<? extends IdentifiableObject>> classes, String uid );

    <T extends IdentifiableObject> T get( Collection<Class<? extends IdentifiableObject>> classes, IdScheme idScheme,
        String value );

    <T extends IdentifiableObject> T getByCode( Class<T> clazz, String code );

    <T extends IdentifiableObject> List<T> getByCode( Class<T> clazz, Collection<String> codes );

    <T extends IdentifiableObject> T getByName( Class<T> clazz, String name );

    <T extends IdentifiableObject> T getByUniqueAttributeValue( Class<T> clazz, Attribute attribute, String value );

    <T extends IdentifiableObject> T getByUniqueAttributeValue( Class<T> clazz, Attribute attribute, String value,
        UserInfo userInfo );

    <T extends IdentifiableObject> T search( Class<T> clazz, String query );

    <T extends IdentifiableObject> List<T> filter( Class<T> clazz, String query );

    <T extends IdentifiableObject> List<T> getAll( Class<T> clazz );

    <T extends IdentifiableObject> List<T> getDataWriteAll( Class<T> clazz );

    <T extends IdentifiableObject> List<T> getDataReadAll( Class<T> clazz );

    <T extends IdentifiableObject> List<T> getAllSorted( Class<T> clazz );

    <T extends IdentifiableObject> List<T> getAllByAttributes( Class<T> klass, List<Attribute> attributes );

    <T extends IdentifiableObject> List<AttributeValue> getAllValuesByAttributes( Class<T> klass,
        List<Attribute> attributes );

    <T extends IdentifiableObject> long countAllValuesByAttributes( Class<T> klass, List<Attribute> attributes );

    <T extends IdentifiableObject> List<T> getByUid( Class<T> clazz, Collection<String> uids );

    <T extends IdentifiableObject> List<T> getById( Class<T> clazz, Collection<Long> ids );

    <T extends IdentifiableObject> List<T> getOrdered( Class<T> clazz, IdScheme idScheme, Collection<String> values );

    <T extends IdentifiableObject> List<T> getByUidOrdered( Class<T> clazz, List<String> uids );

    <T extends IdentifiableObject> List<T> getLikeName( Class<T> clazz, String name );

    <T extends IdentifiableObject> List<T> getLikeName( Class<T> clazz, String name, boolean caseSensitive );

    <T extends IdentifiableObject> List<T> getBetweenSorted( Class<T> clazz, int first, int max );

    <T extends IdentifiableObject> List<T> getBetweenLikeName( Class<T> clazz, Set<String> words, int first, int max );

    <T extends IdentifiableObject> Date getLastUpdated( Class<T> clazz );

    <T extends IdentifiableObject> Map<String, T> getIdMap( Class<T> clazz, IdentifiableProperty property );

    <T extends IdentifiableObject> Map<String, T> getIdMap( Class<T> clazz, IdScheme idScheme );

    <T extends IdentifiableObject> Map<String, T> getIdMapNoAcl( Class<T> clazz, IdentifiableProperty property );

    <T extends IdentifiableObject> Map<String, T> getIdMapNoAcl( Class<T> clazz, IdScheme idScheme );

    <T extends IdentifiableObject> List<T> getObjects( Class<T> clazz, IdentifiableProperty property,
        Collection<String> identifiers );

    <T extends IdentifiableObject> List<T> getObjects( Class<T> clazz, Collection<Long> identifiers );

    <T extends IdentifiableObject> T getObject( Class<T> clazz, IdentifiableProperty property, String value );

    <T extends IdentifiableObject> T getObject( Class<T> clazz, IdScheme idScheme, String value );

    IdentifiableObject getObject( String uid, String simpleClassName );

    IdentifiableObject getObject( long id, String simpleClassName );

    <T extends IdentifiableObject> int getCount( Class<T> clazz );

    <T extends IdentifiableObject> int getCountByCreated( Class<T> clazz, Date created );

    <T extends IdentifiableObject> int getCountByLastUpdated( Class<T> clazz, Date lastUpdated );

    <T extends DimensionalObject> List<T> getDataDimensions( Class<T> clazz );

    <T extends DimensionalObject> List<T> getDataDimensionsNoAcl( Class<T> clazz );

    void refresh( Object object );

    void flush();

    void clear();

    void evict( Object object );

    <T extends IdentifiableObject> List<T> getByAttributeAndValue( Class<T> klass, Attribute attribute, String value );

    <T extends IdentifiableObject> boolean isAttributeValueUnique( Class<? extends IdentifiableObject> klass, T object,
        AttributeValue attributeValue );

    <T extends IdentifiableObject> boolean isAttributeValueUnique( Class<? extends IdentifiableObject> klass, T object,
        Attribute attribute, String value );

    List<? extends IdentifiableObject> getAllByAttributeAndValues( Class<? extends IdentifiableObject> klass,
        Attribute attribute, List<String> values );

    Map<Class<? extends IdentifiableObject>, IdentifiableObject> getDefaults();

    void updateTranslations( IdentifiableObject persistedObject, Set<Translation> translations );

    <T extends IdentifiableObject> List<T> get( Class<T> clazz, Collection<String> uids );

    <T extends IdentifiableObject> List<T> getNoAcl( Class<T> clazz, Collection<String> uids );

    boolean isDefault( IdentifiableObject object );

    List<String> getUidsCreatedBefore( Class<? extends IdentifiableObject> klass, Date date );

    /**
     * Remove given UserGroup UID from all sharing records in database
     */
    void removeUserGroupFromSharing( String userGroupUid );

    // -------------------------------------------------------------------------
    // NO ACL
    // -------------------------------------------------------------------------

    <T extends IdentifiableObject> T getNoAcl( Class<T> clazz, String uid );

    <T extends IdentifiableObject> void updateNoAcl( T object );

    <T extends IdentifiableObject> List<T> getAllNoAcl( Class<T> clazz );
}

## 内容2
### 文件路径：
dhis-2/dhis-api/src/main/java/org/hisp/dhis/feedback/ErrorCode.java
### 代码内容：
package org.hisp.dhis.feedback;

/**
 * @author Morten Olav Hansen <mortenoh@gmail.com>
 */
public enum ErrorCode
{
    /* General */
    E1000( "API query must be specified" ),
    E1001( "API query contains an illegal string" ),
    E1002( "API version is invalid" ),

    /* Basic metadata */
    E1100( "Data element not found or not accessible: `{0}`" ),
    E1101( "Period is invalid: `{0}`" ),
    E1102( "Organisation unit not found or not accessible: `{0}`" ),
    E1103( "Category option combo not found or not accessible: `{0}`" ),
    E1104( "Attribute option combo not found or not accessible: `{0}`" ),
    E1105( "Data set not found or not accessible: `{0}`" ),
    E1106( "There are duplicate translation record for property `{0}` and locale `{1}`" ),
    E1107( "Object type `{0}` is not translatable." ),

    /* Data */
    E2000( "Query parameters cannot be null" ),
    E2001( "At least one data element, data set or data element group must be specified" ),
    E2002( "At least one period, start/end dates, last updated or last updated duration must be specified" ),
    E2003( "Both periods and start/end date cannot be specified" ),
    E2004( "Start date must be before end date" ),
    E2005( "Duration is not valid: `{0}`" ),
    E2006( "At least one organisation unit or organisation unit group must be specified" ),
    E2007( "Organisation unit children cannot be included for organisation unit groups" ),
    E2008( "At least one organisation unit must be specified when children are included" ),
    E2009( "Limit cannot be less than zero: `{0}`" ),
    E2010( "User is not allowed to read data for data set: `{0}`" ),
    E2011( "User is not allowed to read data for attribute option combo: `{0}`" ),
    E2012( "User is not allowed to view org unit: `{0}`" ),
    E2013( "At least one data set must be specified" ),
    E2014( "Unable to parse filter `{0}`" ),
    E2015( "Unable to parse order param: `{0}`" ),
    E2016( "Unable to parse element `{0}` on filter `{1}`. The values available are: {2}" ),
    E2017( "Data set is locked" ),
    E2018( "Category option combo is required but not specified" ),
    E2019( "Organisation unit is closed for the selected period: `{0}`" ),
    E2020( "Organisation unit is not in the hierarchy of the current user: `{0}`" ),
    E2021( "Data set: `{0}` does not contain data element: `{1}`" ),
    E2022( "Period: `{0}` is after latest open future period: `{1}` for data element: `{2}`" ),
    E2023( "Period: `{0}` is before start date: {1} for attribute option: `{2}`" ),
    E2024( "Period: `{0}` is after start date: {1} for attribute option: `{2}`" ),
    E2025( "Period: `{0}` is not open for data set: `{1}`" ),
    E2026( "File resource already assigned or linked to a data value" ),
    E2027( "File resource is invalid: `{0}`" ),
    E2028( "Comment is invalid: `{0}`" ),
    E2029( "Data value is not a valid option of the data element option set: `{0}`" ),
    E2030( "Data value must match data element value type: `{0}`" ),
    E2031( "User does not have write access to category option combo: `{0}`" ),
    E2032( "Data value does not exist" ),
    E2033( "Follow-up must be specified" ),
    E2034( "Filter not supported: `{0}`" ),
    E2035( "Operator not supported: `{0}`" ),
    E2036( "Combination not supported: `{0}`" ),
    E2037( "Order not supported: `{0}`" ),

    /* Outlier detection */
    E2200( "At least one data element must be specified" ),
    E2201( "Start date and end date must be specified" ),
    E2202( "Start date must be before end date" ),
    E2203( "At least one organisation unit must be specified" ),
    E2204( "Threshold must be a positive number" ),
    E2205( "Max results must be a positive number" ),
    E2206( "Max results exceeds the allowed max limit: `{0}`" ),
    E2207( "Data start date must be before data end date" ),
    E2208( "Non-numeric data values encountered during outlier value detection" ),

    /* Security */
    E3000( "User `{0}` is not allowed to create objects of type {1}." ),
    E3001( "User `{0}` is not allowed to update object `{1}`." ),
    E3002( "User `{0}` is not allowed to delete object `{1}`." ),
    E3003( "User `{0}` is not allowed to grant users access to user role `{1}`." ),
    E3004( "User `{0}` is not allowed to grant users access to user groups." ),
    E3005( "User `{0}` is not allowed to grant users access to user group `{1}`." ),
    E3006( "User `{0}` is not allowed to externalize objects of type `{1}`." ),
    E3008( "User `{0}` is not allowed to make public objects of type `{1}`." ),
    E3009( "User `{0}` is not allowed to make private objects of type `{1}`." ),
    E3010( "Invalid access string `{0}`." ),
    E3011(
        "Data sharing is not enabled for type `{0}`, but one or more access strings contains data sharing read or write." ),
    E3012( "User `{0}` does not have read access for object `{1}`." ),
    E3013( "Sharing settings of system default metadata object of type `{0}` cannot be modified." ),
    E3014( "You do not have manage access to this object." ),
    E3015( "Invalid public access string: `{0}`" ),
    E3016( "Data sharing is not enabled for this object" ),
    E3017( "Invalid user group access string: `{0}`" ),
    E3018( "Invalid user access string: `{0}`" ),

    /* Metadata Validation */
    E4000( "Missing required property `{0}`." ),
    E4001( "Maximum length of property `{0}`is {1}, but given length was {2}." ),
    E4002( "Allowed length range for property `{0}` is [{1} to {2}], but given length was {3}." ),
    E4003( "Property `{0}` requires a valid email address, was given `{1}`." ),
    E4004( "Property `{0}` requires a valid URL, was given `{1}`." ),
    E4005( "Property `{0}` requires a valid password, was given `{1}`." ),
    E4006( "Property `{0}` requires a valid HEX color, was given `{1}`." ),
    E4007( "Allowed size range for collection property `{0}` is [{1} to {2}], but size given was {3}." ),
    E4008( "Allowed range for numeric property `{0}` is [{1} to {2}], but number given was {3}." ),
    E4009( "Attribute `{0}` is unique, and value `{1}` already exist." ),
    E4010( "Attribute `{0}` is not supported for type `{1}`." ),
    E4011( "Attribute `{0}` is required, but no value was found." ),
    E4012( "Attribute `{0}` contains elements of different period type than the data set it was added to" ),
    E4013( "Invalid Closing date `{0}`, must be after Opening date `{1}`" ),
    E4014( "Invalid UID `{0}` for property `{1}`" ),
    E4015( "Property `{0}` refers to an object that does not exist, could not find `{1}`" ),
    E4016( "Object referenced by the `{0}` property is already associated with another object, value: `{1}`" ),
    E4017( "RenderingType `{0}` is not supported for ValueType `{1}`" ),
    E4018( "Property `{0}` must be set when property `{1}` is `{2}`" ),
    E4019( "Failed to parse pattern `{0}`. {1}" ),
    E4020( "The value `{0}` does not conform to the attribute pattern `{1}`" ),
    E4021( "ID-pattern is required to have 1 generated segment (RANDOM or SEQUENTIAL)." ),
    E4022( "Pattern `{0}` does not conform to the value type `{1}`." ),
    E4023( "Property `{0}` can not be set when property `{1}` is `{2}`. " ),
    E4024( "Property `{0}` must be set when property `{1}` is `{2}`. " ),
    E4025( "Properties `{0}` and `{1}` are mutually exclusive and cannot be used together." ),
    E4026( "One of the properties `{0}` and `{1}` is required when property `{2}` is `{3}`." ),
    E4027( "Value `{0}` is not a valid for property `{1}`" ),
    E4028( "Option set `{0}` already contains option `{1}`" ),
    E4029( "Job parameters cannot be null for job type: {0}" ),
    E4030( "Object could not be deleted because it is associated with another object: {0}" ),

    E4032( "A program rule variable with name `{0}` and program uid `{1}` already exists" ),
    E4033( "For program rule variable with name `{0}` following keywords are forbidden : and , or , not" ),
    E4053( "Program stage `{0}` must reference a program." ),

    /* SQL views */
    E4300( "SQL query is null" ),
    E4301( "SQL query must be a select query" ),
    E4302( "SQL query can only contain a single semi-colon at the end of the query" ),
    E4303( "Variables contain null key" ),
    E4304( "Variables contain null value" ),
    E4305( "Variable params are invalid: `{0}`" ),
    E4306( "Variables are invalid: `{0}`" ),
    E4307( "SQL query contains variables not provided in request: `{0}`" ),
    E4308( "Criteria params are invalid: `{0}`" ),
    E4309( "Criteria values are invalid: `{0}`" ),
    E4310( "SQL query contains references to protected tables" ),
    E4311( "SQL query contains illegal keywords" ),
    E4312( "Current user is not authorised to read data from SQL view: `{0}`" ),
    E4313( "SQL query contains variable names that are invalid: `{0}`" ),

    /* Preheat */
    E5000(
        "Found matching object for given reference, but import mode is CREATE. Identifier was {0}, and object was {1}." ),
    E5001( "No matching object for given reference. Identifier was {0}, and object was {1}." ),
    E5002( "Invalid reference {0} on object {1} for association `{2}`." ),
    E5003( "Property `{0}` with value `{1}` on object {2} already exists on object {3}." ),
    E5004( "Id `{0}` for type `{1}` exists on more than 1 object in the payload, removing all but the first found." ),
    E5005( "Properties `{0}` in objects `{1}` must be unique within the payload" ),

    /* Metadata import */
    E6000( "Program `{0}` has more than one Program Instances" ),
    E6001(
        "ProgramStage `{0}` has invalid next event scheduling property `{1}`. This property need to be data element of value type date and belong the program stage." ),

    /* File resource */
    E6100( "Filename not present" ),
    E6101( "File type not allowed" ),

    /* Users */
    E6200( "Feedback message recipients user group not defined" ),

    /* Scheduling */
    E7000(
        "Failed to add/update job configuration, another job of the same job type is already scheduled with this cron expression: `{0}`" ),
    E7002( "Failed to add/update job configuration, UID does not exist" ),
    E7003(
        "Failed to add/update job configuration, only interval can be configured for non configurable job type: `{0}`" ),
    E7004(
        "Failed to add/update job configuration, cron expression must be not null for job with scheduling type CRON: `{0}`" ),
    E7005( "Failed to add/update job configuration, cron expression is invalid: `{0}` " ),
    E7006( "Failed to execute job `{0}`." ),
    E7007(
        "Failed to add/update job configuration - Delay must be not null for jobs with scheduling type FIXED_DELAY: `{0}`" ),
    E7010( "Failed to validate job runtime - `{0}`" ),

    /* Aggregate analytics */
    E7100( "Query parameters cannot be null" ),
    E7101( "At least one dimension must be specified" ),
    E7102( "At least one data dimension item or data element group set dimension item must be specified" ),
    E7103( "Dimensions cannot be specified as dimension and filter simultaneously: `{0}`" ),
    E7104( "At least one period as dimension or filter, or start and dates, must be specified" ),
    E7105( "Periods and start and end dates cannot be specified simultaneously" ),
    E7106( "Start date cannot be after end date" ),
    E7107( "Start and end dates cannot be specified for reporting rates" ),
    E7108( "Only a single indicator can be specified as filter" ),
    E7109( "Only a single reporting rate can be specified as filter" ),
    E7110( "Category option combos cannot be specified as filter" ),
    E7111( "Dimensions cannot be specified more than once: `{0}`" ),
    E7112( "Reporting rates can only be specified together with dimensions of type: `{0}`" ),
    E7113( "Assigned categories cannot be specified when data elements are not specified" ),
    E7114( "Assigned categories can only be specified together with data elements, not indicators or reporting rates" ),
    E7115( "Data elements must be of a value and aggregation type that allow aggregation: `{0}`" ),
    E7116( "Indicator expressions cannot contain cyclic references: `{0}`" ),
    E7117( "A data dimension 'dx' must be specified when output format is DATA_VALUE_SET" ),
    E7118( "A period dimension 'pe' must be specified when output format is DATA_VALUE_SET" ),
    E7119( "An organisation unit dimension 'ou' must be specified when output format is DATA_VALUE_SET" ),
    E7120( "User: `{0}` is not allowed to view org unit: `{1}`" ),
    E7121( "User: `{0}` is not allowed to read data for `{1}`: `{2}`" ),
    E7122( "Data approval level does not exist: `{0}`" ),
    E7123( "Current user is constrained by a dimension but has access to no dimension items: `{0}`" ),
    E7124( "Dimension is present in query without any valid dimension options: `{0}`" ),
    E7125( "Dimension identifier does not reference any dimension: `{0}`" ),
    E7126( "Column must be present as dimension in query: `{0}`" ),
    E7127( "Row must be present as dimension in query: `{0}`" ),
    E7128( "Query result set exceeded max limit: `{0}`" ),
    E7129( "Program is specified but does not exist: `{0}`" ),
    E7130( "Program stage is specified but does not exist: `{0}`" ),
    E7131( "Query failed, likely because the query timed out" ),
    E7132( "An indicator expression caused division by zero operation" ),
    E7133( "Query cannot be executed, possibly because of invalid types or invalid operation" ),

    /* Event analytics */
    E7200( "At least one organisation unit must be specified" ),
    E7201( "Dimensions cannot be specified more than once: `{0}`" ),
    E7202( "Query items cannot be specified more than once: `{0}`" ),
    E7203( "Value dimension cannot also be specified as an item or item filter" ),
    E7204( "Value dimension or aggregate data must be specified when aggregation type is specified" ),
    E7205( "Start and end date or at least one period must be specified" ),
    E7206( "Start date is after end date: `{0}`, `{1}`" ),
    E7207( "Page number must be a positive number: `{0}`" ),
    E7208( "Page size must be zero or a positive number: `{0}`" ),
    E7209( "Limit is larger than max limit: `{0}`, `{1}`" ),
    E7210( "Time field is invalid: `{0}`" ),
    E7211( "Org unit field is invalid: `{0}`" ),
    E7212( "Cluster size must be a positive number: `{0}`" ),
    E7213( "Bbox is invalid, must be on format: 'min-lng,min-lat,max-lng,max-lat': `{0}`" ),
    E7214( "Cluster field must be specified when bbox or cluster size are specified" ),
    E7215( "Query item cannot specify both legend set and option set: `{0}`" ),
    E7216( "Query item must be aggregateable when used in aggregate query: `{0}`" ),
    E7217( "User is not allowed to view event analytics data: `{0}`" ),
    E7218( "Spatial database support is not enabled" ),
    E7219( "Data element must be of value type coordinate or org unit in order to be used as coordinate field: `{0}`" ),
    E7220( "Attribute must be of value type coordinate or org unit in order to be used as coordinate field: `{0}`" ),
    E7221( "Coordinate field is invalid: `{0}`" ),
    E7222( "Query item or filter is invalid: `{0}`" ),
    E7223( "Value does not refer to a data element or attribute which are numeric and part of the program: `{0}`" ),
    E7224( "Item identifier does not reference any data element, attribute or indicator part of the program: `{0}`" ),
    E7225( "Program stage is mandatory for data element dimensions in enrollment analytics queries: `{0}`" ),
    E7226( "Dimension is not a valid query item: `{0}`" ),
    E7227( "Relationship entity type not supported: `{0}`" ),

    /* Org unit analytics */
    E7300( "At least one organisation unit must be specified" ),
    E7301( "At least one organisation unit group set must be specified" ),

    /* Debug analytics */
    E7400( "Debug query must contain at least one data element, one period and one organisation unit" ),

    /* Validation Results API */
    E7500( "Organisation unit does not exist: `{0}`" ),
    E7501( "Validation rule does not exist: `{0}`" ),
    E7502( "Filter for period is not valid: `{0}`" ),
    E7503( "Filter for created date period is not valid: `{0}`" );

    private String message;

    ErrorCode( String message )
    {
        this.message = message;
    }

    public String getMessage()
    {
        return message;
    }
}

## 内容3
### 文件路径：
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/association/ProgramOrganisationUnitAssociationsQueryBuilder.java
### 代码内容：
package org.hisp.dhis.association;

import static java.util.stream.Collectors.joining;
import static org.hisp.dhis.hibernate.jsonb.type.JsonbFunctions.CHECK_USER_ACCESS;
import static org.hisp.dhis.hibernate.jsonb.type.JsonbFunctions.CHECK_USER_GROUPS_ACCESS;
import static org.hisp.dhis.hibernate.jsonb.type.JsonbFunctions.EXTRACT_PATH_TEXT;
import static org.hisp.dhis.hibernate.jsonb.type.JsonbFunctions.HAS_USER_GROUP_IDS;
import static org.hisp.dhis.hibernate.jsonb.type.JsonbFunctions.HAS_USER_ID;
import static org.hisp.dhis.security.acl.AclService.LIKE_READ_METADATA;

import java.util.Arrays;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Stream;

import lombok.RequiredArgsConstructor;

import org.hisp.dhis.commons.collection.CollectionUtils;
import org.hisp.dhis.user.CurrentUserGroupInfo;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ProgramOrganisationUnitAssociationsQueryBuilder
{

    private final CurrentUserService currentUserService;

    private static final String SHARING_OUTER_QUERY_BEGIN = "select " +
        "    prg.uid, " +
        "    prg.agg_ou_uid " +
        "from (";

    private static final String SHARING_OUTER_QUERY_END = ") as prg";

    private static final String INNER_SQL_QUERY = "select " +
        "    pr.uid, " +
        "    pr.sharing, " +
        "    array_agg(ou.uid) agg_ou_uid " +
        "from program pr " +
        "    left join program_organisationunits po on pr.programid = po.programid " +
        "    left join organisationunit ou on po.organisationunitid = ou.organisationunitid " +
        "where";

    private static final String INNER_QUERY_GROUPING_BY = "group by pr.uid, pr.sharing";

    public String buildSqlQuery( Set<String> programUids, Set<String> userOrgUnitPaths, User currentUser )
    {
        Stream<String> queryParts = Stream.of(
            SHARING_OUTER_QUERY_BEGIN,
            innerQueryProvider( programUids, userOrgUnitPaths, currentUser ),
            SHARING_OUTER_QUERY_END );

        if ( nonSuperUser( currentUser ) )
        {
            queryParts = Stream.concat(
                queryParts,
                Stream.of(
                    "where",
                    getSharingConditions( LIKE_READ_METADATA ) ) );
        }
        return queryParts.collect( joining( " " ) );
    }

    public String buildSqlQueryForRawAssociation( Set<String> uids )
    {
        Stream<String> queryParts = Stream.of(
            SHARING_OUTER_QUERY_BEGIN,
            innerQueryProvider( uids, null, null ),
            SHARING_OUTER_QUERY_END );

        return queryParts.collect( joining( " " ) );
    }

    private String innerQueryProvider( Set<String> programUids, Set<String> userOrgUnitPaths, User currentUser )
    {
        Stream<String> queryParts = Stream.of(
            INNER_SQL_QUERY,
            getProgramUidsFilter( programUids ) );

        if ( nonSuperUser( currentUser ) )
        {
            queryParts = Stream.concat( queryParts,
                Stream.of(
                    "and",
                    getUserOrgUnitPathsFilter( userOrgUnitPaths ) ) );
        }

        queryParts = Stream.concat( queryParts, Stream.of( INNER_QUERY_GROUPING_BY ) );

        return queryParts.collect( joining( " " ) );
    }

    private String getSharingConditions( String access )
    {
        CurrentUserGroupInfo currentUserGroupInfo = currentUserService.getCurrentUserGroupsInfo();
        return String.join( " or ",
            getOwnerCondition( currentUserGroupInfo ),
            getPublicSharingCondition( access ),
            getUserGroupAccessCondition( currentUserGroupInfo, access ),
            getUserAccessCondition( currentUserGroupInfo, access ) );
    }

    private String getOwnerCondition( CurrentUserGroupInfo currentUserGroupInfo )
    {
        return String.join( " or ",
            jsonbFunction( EXTRACT_PATH_TEXT, "owner" ) + " = " + withQuotes( currentUserGroupInfo.getUserUID() ),
            jsonbFunction( EXTRACT_PATH_TEXT, "owner" ) + " is null" );
    }

    private String getPublicSharingCondition( String access )
    {
        return String.join( " or ",
            jsonbFunction( EXTRACT_PATH_TEXT, "public" ) + " like " + withQuotes( access ),
            jsonbFunction( EXTRACT_PATH_TEXT, "public" ) + " is null" );
    }

    private String getUserAccessCondition( CurrentUserGroupInfo currentUserGroupInfo, String access )
    {
        String userUid = currentUserGroupInfo.getUserUID();
        return Stream.of(
            jsonbFunction( HAS_USER_ID, userUid ),
            jsonbFunction( CHECK_USER_ACCESS, userUid, access ) )
            .collect( joining( " and ", "(", ")" ) );
    }

    private String getUserGroupAccessCondition( CurrentUserGroupInfo currentUserGroupInfo, String access )
    {
        if ( CollectionUtils.isEmpty( currentUserGroupInfo.getUserGroupUIDs() ) )
        {
            return "1=0";
        }
        String groupUids = "{" + String.join( ",", currentUserGroupInfo.getUserGroupUIDs() ) + "}";
        return Stream.of(
            jsonbFunction( HAS_USER_GROUP_IDS, groupUids ),
            jsonbFunction( CHECK_USER_GROUPS_ACCESS, access, groupUids ) )
            .collect( joining( " and ", "(", ")" ) );
    }

    private String jsonbFunction( String functionName, String... params )
    {
        return String.join( "",
            functionName,
            "(",
            String.join( ",", "prg.sharing",
                Arrays.stream( params )
                    .map( this::withQuotes )
                    .collect( joining( "," ) ) ),
            ")" );
    }

    private boolean nonSuperUser( User currentUser )
    {
        return Objects.nonNull( currentUser ) && !currentUser.isSuper();
    }

    private String getProgramUidsFilter( Set<String> programUids )
    {
        return "pr.uid in (" +
            programUids.stream()
                .map( this::withQuotes )
                .collect( joining( "," ) )
            + ")";
    }

    private String withQuotes( String programUid )
    {
        return String.join( "", "'", programUid, "'" );
    }

    private String getUserOrgUnitPathsFilter( Set<String> userOrgUnitPaths )
    {
        return Stream.concat(
            Stream.of( "ou.organisationUnitId is null" ),
            userOrgUnitPaths.stream()
                .map( userOrgUnitPath -> "ou.path like '" + userOrgUnitPath + "%'" ) )
            .collect( joining( " or ", "(", ")" ) );
    }

}

## 内容4
### 文件路径：
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java
### 代码内容：
package org.hisp.dhis.common;

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hisp.dhis.attribute.Attribute;
import org.hisp.dhis.attribute.AttributeValue;
import org.hisp.dhis.cache.Cache;
import org.hisp.dhis.cache.CacheProvider;
import org.hisp.dhis.category.Category;
import org.hisp.dhis.category.CategoryCombo;
import org.hisp.dhis.category.CategoryOption;
import org.hisp.dhis.category.CategoryOptionCombo;
import org.hisp.dhis.chart.Chart;
import org.hisp.dhis.common.exception.InvalidIdentifierReferenceException;
import org.hisp.dhis.hibernate.HibernateProxyUtils;
import org.hisp.dhis.reporttable.ReportTable;
import org.hisp.dhis.schema.Schema;
import org.hisp.dhis.schema.SchemaService;
import org.hisp.dhis.translation.Translation;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserCredentials;
import org.hisp.dhis.user.UserGroup;
import org.hisp.dhis.user.UserInfo;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.google.api.client.util.Lists;
import com.google.common.collect.ImmutableMap;

/**
 * Note that it is required for nameable object stores to have concrete
 * implementation classes, not rely on the HibernateIdentifiableObjectStore
 * class, in order to be injected as nameable object stores.
 *
 * @author Lars Helge Overland
 */
@Slf4j
@Component( "org.hisp.dhis.common.IdentifiableObjectManager" )
public class DefaultIdentifiableObjectManager
    implements IdentifiableObjectManager
{
    public static final String DEFAULT = "default";

    /**
     * Cache for default category objects. Disabled during test phase.
     */
    private final Cache<IdentifiableObject> defaultObjectCache;

    private final Set<IdentifiableObjectStore<? extends IdentifiableObject>> identifiableObjectStores;

    private final Set<GenericDimensionalObjectStore<? extends DimensionalObject>> dimensionalObjectStores;

    private final SessionFactory sessionFactory;

    private final CurrentUserService currentUserService;

    protected final SchemaService schemaService;

    private Map<Class<? extends IdentifiableObject>, IdentifiableObjectStore<? extends IdentifiableObject>> identifiableObjectStoreMap;

    private Map<Class<? extends DimensionalObject>, GenericDimensionalObjectStore<? extends DimensionalObject>> dimensionalObjectStoreMap;

    public DefaultIdentifiableObjectManager(
        Set<IdentifiableObjectStore<? extends IdentifiableObject>> identifiableObjectStores,
        Set<GenericDimensionalObjectStore<? extends DimensionalObject>> dimensionalObjectStores,
        SessionFactory sessionFactory, CurrentUserService currentUserService, SchemaService schemaService,
        CacheProvider cacheProvider )
    {
        checkNotNull( identifiableObjectStores );
        checkNotNull( dimensionalObjectStores );
        checkNotNull( sessionFactory );
        checkNotNull( currentUserService );
        checkNotNull( schemaService );
        checkNotNull( cacheProvider );

        this.identifiableObjectStores = identifiableObjectStores;
        this.dimensionalObjectStores = dimensionalObjectStores;
        this.sessionFactory = sessionFactory;
        this.currentUserService = currentUserService;
        this.schemaService = schemaService;
        this.defaultObjectCache = cacheProvider.createDefaultObjectCache();

        removeNonSupportedStores();
    }

    /**
     * This method removes identifiable stores that should not be supported
     * anymore. Some objects are still in usage in very specific places, but
     * should no longer be backed by any store. Their stores are still usage
     * directly in a few limited places, but they should not be used broadly or
     * be part of the core set of endpoints exposed.
     */
    private void removeNonSupportedStores()
    {
        identifiableObjectStores
            .removeIf( store -> store.getClazz() == Chart.class || store.getClazz() == ReportTable.class );
    }

    // --------------------------------------------------------------------------
    // IdentifiableObjectManager implementation
    // --------------------------------------------------------------------------

    @Override
    @Transactional
    public void save( IdentifiableObject object )
    {
        save( object, true );
    }

    @Override
    @Transactional
    @SuppressWarnings( "unchecked" )
    public void save( IdentifiableObject object, boolean clearSharing )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore(
            HibernateProxyUtils.getRealClass( object ) );

        if ( store != null )
        {
            store.save( object, clearSharing );
        }
    }

    @Override
    @Transactional
    public void save( List<IdentifiableObject> objects )
    {
        objects.forEach( o -> save( o, true ) );
    }

    @Override
    @Transactional
    public void update( IdentifiableObject object )
    {
        update( object, currentUserService.getCurrentUser() );
    }

    @Override
    @Transactional
    @SuppressWarnings( "unchecked" )
    public void update( IdentifiableObject object, User user )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore(
            HibernateProxyUtils.getRealClass( object ) );

        if ( store != null )
        {
            store.update( object, user );
        }
    }

    @Override
    @Transactional
    public void update( List<IdentifiableObject> objects )
    {
        update( objects, currentUserService.getCurrentUser() );
    }

    @Override
    @Transactional
    public void update( List<IdentifiableObject> objects, User user )
    {
        if ( objects == null || objects.isEmpty() )
        {
            return;
        }

        for ( IdentifiableObject object : objects )
        {
            update( object, user );
        }
    }

    @Override
    @Transactional
    public void updateTranslations( IdentifiableObject persistedObject, Set<Translation> translations )
    {
        Session session = sessionFactory.getCurrentSession();

        BaseIdentifiableObject translatedObject = (BaseIdentifiableObject) persistedObject;

        translatedObject.setTranslations(
            translations.stream()
                .filter( t -> !StringUtils.isEmpty( t.getValue() ) )
                .collect( Collectors.toSet() ) );

        translatedObject.setLastUpdated( new Date() );
        translatedObject.setLastUpdatedBy( currentUserService.getCurrentUser() );

        session.update( translatedObject );
    }

    @Override
    @Transactional
    public void delete( IdentifiableObject object )
    {
        delete( object, currentUserService.getCurrentUser() );
    }

    @Override
    @Transactional
    @SuppressWarnings( "unchecked" )
    public void delete( IdentifiableObject object, User user )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore(
            HibernateProxyUtils.getRealClass( object ) );

        if ( store != null )
        {
            store.delete( object, user );
        }
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> T get( String uid )
    {
        for ( IdentifiableObjectStore<? extends IdentifiableObject> store : identifiableObjectStores )
        {
            T object = (T) store.getByUid( uid );

            if ( object != null )
            {
                return object;
            }
        }

        return null;
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> T get( Class<T> clazz, long id )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return null;
        }

        return (T) store.get( id );
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> T get( Class<T> clazz, String uid )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return null;
        }

        return (T) store.getByUid( uid );
    }

    @Override
    @Transactional( readOnly = true )
    public <T extends IdentifiableObject> boolean exists( Class<T> clazz, String uid )
    {
        return get( clazz, uid ) != null;
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> T get( Collection<Class<? extends IdentifiableObject>> classes, String uid )
    {
        for ( Class<? extends IdentifiableObject> clazz : classes )
        {
            T object = (T) get( clazz, uid );

            if ( object != null )
            {
                return object;
            }
        }

        return null;
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> T get( Collection<Class<? extends IdentifiableObject>> classes,
        IdScheme idScheme, String identifier )
    {
        for ( Class<? extends IdentifiableObject> clazz : classes )
        {
            T object = (T) getObject( clazz, idScheme, identifier );

            if ( object != null )
            {
                return object;
            }
        }

        return null;
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> get( Class<T> clazz, Collection<String> uids )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return null;
        }

        return (List<T>) store.getByUid( uids );
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getNoAcl( Class<T> clazz, Collection<String> uids )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return null;
        }

        return (List<T>) store.getByUidNoAcl( uids );
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> T getByCode( Class<T> clazz, String code )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return null;
        }

        return (T) store.getByCode( code );
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> T getByName( Class<T> clazz, String name )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return null;
        }

        return (T) store.getByName( name );
    }

    @Override
    @Transactional( readOnly = true )
    public <T extends IdentifiableObject> T getByUniqueAttributeValue( Class<T> clazz, Attribute attribute,
        String value )
    {
        return getByUniqueAttributeValue( clazz, attribute, value, currentUserService.getCurrentUserInfo() );
    }

    @SuppressWarnings( "unchecked" )
    @Override
    @Transactional( readOnly = true )
    public <T extends IdentifiableObject> T getByUniqueAttributeValue( Class<T> clazz, Attribute attribute,
        String value, UserInfo userInfo )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return null;
        }

        return (T) store.getByUniqueAttributeValue( attribute, value, userInfo );
    }

    @Override
    @Transactional( readOnly = true )
    public <T extends IdentifiableObject> T search( Class<T> clazz, String query )
    {
        T object = get( clazz, query );

        if ( object == null )
        {
            object = getByCode( clazz, query );
        }

        if ( object == null )
        {
            object = getByName( clazz, query );
        }

        return object;
    }

    @Override
    @Transactional( readOnly = true )
    public <T extends IdentifiableObject> List<T> filter( Class<T> clazz, String query )
    {
        Set<T> uniqueObjects = new HashSet<>();

        T uidObject = get( clazz, query );

        if ( uidObject != null )
        {
            uniqueObjects.add( uidObject );
        }

        T codeObject = getByCode( clazz, query );

        if ( codeObject != null )
        {
            uniqueObjects.add( codeObject );
        }

        uniqueObjects.addAll( getLikeName( clazz, query, false ) );

        List<T> objects = new ArrayList<>( uniqueObjects );

        Collections.sort( objects );

        return objects;
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getAll( Class<T> clazz )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        return (List<T>) store.getAll();
    }

    @Override
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getDataWriteAll( Class<T> clazz )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        return (List<T>) store.getDataWriteAll();
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getDataReadAll( Class<T> clazz )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        return (List<T>) store.getDataReadAll();
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getAllSorted( Class<T> clazz )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        return (List<T>) store.getAllOrderedName();
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getAllByAttributes( Class<T> klass, List<Attribute> attributes )
    {
        Schema schema = schemaService.getDynamicSchema( klass );

        if ( schema == null || !schema.havePersistedProperty( "attributeValues" ) || attributes.isEmpty() )
        {
            return new ArrayList<>();
        }

        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( klass );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        return (List<T>) store.getAllByAttributes( attributes );
    }

    @Override
    @Transactional( readOnly = true )
    public <T extends IdentifiableObject> List<AttributeValue> getAllValuesByAttributes( Class<T> klass,
        List<Attribute> attributes )
    {
        Schema schema = schemaService.getDynamicSchema( klass );

        if ( schema == null || !schema.havePersistedProperty( "attributeValues" ) || attributes.isEmpty() )
        {
            return new ArrayList<>();
        }

        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( klass );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        return store.getAllValuesByAttributes( attributes );
    }

    @Override
    public <T extends IdentifiableObject> long countAllValuesByAttributes( Class<T> klass, List<Attribute> attributes )
    {
        Schema schema = schemaService.getDynamicSchema( klass );

        if ( schema == null || !schema.havePersistedProperty( "attributeValues" ) || attributes.isEmpty() )
        {
            return 0;
        }

        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( klass );

        if ( store == null )
        {
            return 0;
        }

        return store.countAllValuesByAttributes( attributes );
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getByUid( Class<T> clazz, Collection<String> uids )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        return (List<T>) store.getByUid( uids );
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getById( Class<T> clazz, Collection<Long> ids )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return null;
        }

        return (List<T>) store.getById( ids );
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getByCode( Class<T> clazz, Collection<String> codes )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        return (List<T>) store.getByCode( codes );
    }

    @Override
    @Transactional( readOnly = true )
    public <T extends IdentifiableObject> List<T> getOrdered( Class<T> clazz, IdScheme idScheme,
        Collection<String> values )
    {
        if ( values == null )
        {
            return new ArrayList<>();
        }

        List<T> list = new ArrayList<>();

        for ( String value : values )
        {
            T object = getObject( clazz, idScheme, value );

            if ( object != null )
            {
                list.add( object );
            }
        }

        return list;
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getByUidOrdered( Class<T> clazz, List<String> uids )
    {
        IdentifiableObjectStore<T> store = (IdentifiableObjectStore<T>) getIdentifiableObjectStore( clazz );

        if ( store == null || uids == null )
        {
            return new ArrayList<>();
        }

        List<T> list = new ArrayList<>();

        for ( String uid : uids )
        {
            T object = store.getByUid( uid );

            if ( object != null )
            {
                list.add( object );
            }
        }

        return list;
    }

    @Override
    @Transactional
    public <T extends IdentifiableObject> int getCount( Class<T> clazz )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store != null )
        {
            return store.getCount();
        }

        return 0;
    }

    @Override
    @Transactional( readOnly = true )
    public <T extends IdentifiableObject> int getCountByCreated( Class<T> clazz, Date created )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store != null )
        {
            return store.getCountGeCreated( created );
        }

        return 0;
    }

    @Override
    @Transactional( readOnly = true )
    public <T extends IdentifiableObject> int getCountByLastUpdated( Class<T> clazz, Date lastUpdated )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store != null )
        {
            return store.getCountGeLastUpdated( lastUpdated );
        }

        return 0;
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getLikeName( Class<T> clazz, String name )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        return (List<T>) store.getAllLikeName( name );
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getLikeName( Class<T> clazz, String name, boolean caseSensitive )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        return (List<T>) store.getAllLikeName( name, caseSensitive );
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getBetweenSorted( Class<T> clazz, int first, int max )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        return (List<T>) store.getAllOrderedName( first, max );
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getBetweenLikeName( Class<T> clazz, Set<String> words, int first,
        int max )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        return (List<T>) store.getAllLikeName( words, first, max );
    }

    @Override
    @Transactional( readOnly = true )
    public <T extends IdentifiableObject> Date getLastUpdated( Class<T> clazz )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return null;
        }

        return store.getLastUpdated();
    }

    @Override
    @Transactional( readOnly = true )
    public <T extends IdentifiableObject> Map<String, T> getIdMap( Class<T> clazz, IdentifiableProperty property )
    {
        return getIdMap( clazz, IdScheme.from( property ) );
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> Map<String, T> getIdMap( Class<T> clazz, IdScheme idScheme )
    {
        IdentifiableObjectStore<T> store = (IdentifiableObjectStore<T>) getIdentifiableObjectStore( clazz );

        Map<String, T> map = new HashMap<>();

        if ( store == null )
        {
            return map;
        }

        List<T> objects = store.getAll();

        return IdentifiableObjectUtils.getIdMap( objects, idScheme );
    }

    @Override
    @Transactional( readOnly = true )
    public <T extends IdentifiableObject> Map<String, T> getIdMapNoAcl( Class<T> clazz, IdentifiableProperty property )
    {
        return getIdMapNoAcl( clazz, IdScheme.from( property ) );
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> Map<String, T> getIdMapNoAcl( Class<T> clazz, IdScheme idScheme )
    {
        IdentifiableObjectStore<T> store = (IdentifiableObjectStore<T>) getIdentifiableObjectStore( clazz );

        Map<String, T> map = new HashMap<>();

        if ( store == null )
        {
            return map;
        }

        List<T> objects = store.getAllNoAcl();

        return IdentifiableObjectUtils.getIdMap( objects, idScheme );
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getObjects( Class<T> clazz, IdentifiableProperty property,
        Collection<String> identifiers )
    {
        IdentifiableObjectStore<T> store = (IdentifiableObjectStore<T>) getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        if ( identifiers != null && !identifiers.isEmpty() )
        {
            if ( property == null || IdentifiableProperty.UID.equals( property ) )
            {
                return store.getByUid( identifiers );
            }
            else if ( IdentifiableProperty.CODE.equals( property ) )
            {
                return store.getByCode( identifiers );
            }
            else if ( IdentifiableProperty.NAME.equals( property ) )
            {
                return store.getByName( identifiers );
            }

            throw new InvalidIdentifierReferenceException(
                "Invalid identifiable property / class combination: " + property );
        }

        return new ArrayList<>();
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getObjects( Class<T> clazz, Collection<Long> identifiers )
    {
        IdentifiableObjectStore<T> store = (IdentifiableObjectStore<T>) getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        return store.getById( identifiers );
    }

    @Override
    @Transactional( readOnly = true )
    public <T extends IdentifiableObject> T getObject( Class<T> clazz, IdentifiableProperty property, String value )
    {
        return getObject( clazz, IdScheme.from( property ), value );
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> T getObject( Class<T> clazz, IdScheme idScheme, String value )
    {
        IdentifiableObjectStore<T> store = (IdentifiableObjectStore<T>) getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return null;
        }

        if ( !StringUtils.isEmpty( value ) )
        {
            if ( idScheme.isNull() || idScheme.is( IdentifiableProperty.UID ) )
            {
                return store.getByUid( value );
            }
            else if ( idScheme.is( IdentifiableProperty.CODE ) )
            {
                return store.getByCode( value );
            }
            else if ( idScheme.is( IdentifiableProperty.NAME ) )
            {
                return store.getByName( value );
            }
            else if ( idScheme.is( IdentifiableProperty.ATTRIBUTE ) )
            {
                Attribute attribute = get( Attribute.class, idScheme.getAttribute() );
                return store.getByUniqueAttributeValue( attribute, value );
            }
            else if ( idScheme.is( IdentifiableProperty.ID ) )
            {
                if ( Integer.valueOf( value ) > 0 )
                {
                    return store.get( Integer.valueOf( value ) );
                }
            }

            throw new InvalidIdentifierReferenceException(
                "Invalid identifiable property / class combination: " + idScheme );
        }

        return null;
    }

    @Override
    @Transactional( readOnly = true )
    public IdentifiableObject getObject( String uid, String simpleClassName )
    {
        for ( IdentifiableObjectStore<? extends IdentifiableObject> objectStore : identifiableObjectStores )
        {
            if ( simpleClassName.equals( objectStore.getClazz().getSimpleName() ) )
            {
                return objectStore.getByUid( uid );
            }
        }

        return null;
    }

    @Override
    @Transactional( readOnly = true )
    public IdentifiableObject getObject( long id, String simpleClassName )
    {
        for ( IdentifiableObjectStore<? extends IdentifiableObject> objectStore : identifiableObjectStores )
        {
            if ( simpleClassName.equals( objectStore.getClazz().getSimpleName() ) )
            {
                return objectStore.get( id );
            }
        }

        return null;
    }

    @Override
    @Transactional
    public void refresh( Object object )
    {
        sessionFactory.getCurrentSession().refresh( object );
    }

    @Override
    @Transactional
    public void flush()
    {
        sessionFactory.getCurrentSession().flush();
    }

    @Override
    @Transactional
    public void clear()
    {
        sessionFactory.getCurrentSession().clear();
    }

    @Override
    @Transactional
    public void evict( Object object )
    {
        sessionFactory.getCurrentSession().evict( object );
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> T getNoAcl( Class<T> clazz, String uid )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return null;
        }

        return (T) store.getByUidNoAcl( uid );
    }

    @Override
    @Transactional
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> void updateNoAcl( T object )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore(
            HibernateProxyUtils.getRealClass( object ) );

        if ( store != null )
        {
            store.updateNoAcl( object );
        }
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getAllNoAcl( Class<T> clazz )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        return (List<T>) store.getAllNoAcl();
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends DimensionalObject> List<T> getDataDimensions( Class<T> clazz )
    {
        GenericDimensionalObjectStore<DimensionalObject> store = getDimensionalObjectStore( clazz );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        return (List<T>) store.getByDataDimension( true );
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends DimensionalObject> List<T> getDataDimensionsNoAcl( Class<T> clazz )
    {
        GenericDimensionalObjectStore<DimensionalObject> store = getDimensionalObjectStore( clazz );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        return (List<T>) store.getByDataDimensionNoAcl( true );
    }

    @Override
    @Transactional( readOnly = true )
    @SuppressWarnings( "unchecked" )
    public <T extends IdentifiableObject> List<T> getByAttributeAndValue( Class<T> klass, Attribute attribute,
        String value )
    {
        Schema schema = schemaService.getDynamicSchema( klass );

        if ( schema == null || !schema.havePersistedProperty( "attributeValues" ) )
        {
            return null;
        }

        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( klass );

        if ( store == null )
        {
            return null;
        }

        return (List<T>) store.getByAttributeAndValue( attribute, value );
    }

    @Override
    @Transactional( readOnly = true )
    public <T extends IdentifiableObject> boolean isAttributeValueUnique( Class<? extends IdentifiableObject> klass,
        T object, AttributeValue attributeValue )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( klass );
        return store != null && store.isAttributeValueUnique( object, attributeValue );
    }

    @Override
    @Transactional( readOnly = true )
    public <T extends IdentifiableObject> boolean isAttributeValueUnique( Class<? extends IdentifiableObject> klass,
        T object, Attribute attribute, String value )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( klass );
        return store != null && store.isAttributeValueUnique( object, attribute, value );
    }

    @Override
    @Transactional( readOnly = true )
    public List<? extends IdentifiableObject> getAllByAttributeAndValues( Class<? extends IdentifiableObject> klass,
        Attribute attribute, List<String> values )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( klass );
        return store != null ? store.getAllByAttributeAndValues( attribute, values ) : Lists.newArrayList();
    }

    @Override
    public Map<Class<? extends IdentifiableObject>, IdentifiableObject> getDefaults()
    {
        Optional<IdentifiableObject> categoryObjects = defaultObjectCache.get( Category.class.getName(),
            key -> HibernateProxyUtils.unproxy( getByName( Category.class, DEFAULT ) ) );
        Optional<IdentifiableObject> categoryComboObjects = defaultObjectCache.get( CategoryCombo.class.getName(),
            key -> HibernateProxyUtils.unproxy( getByName( CategoryCombo.class, DEFAULT ) ) );
        Optional<IdentifiableObject> categoryOptionObjects = defaultObjectCache.get( CategoryOption.class.getName(),
            key -> HibernateProxyUtils.unproxy( getByName( CategoryOption.class, DEFAULT ) ) );
        Optional<IdentifiableObject> categoryOptionCombo = defaultObjectCache.get(
            CategoryOptionCombo.class.getName(),
            key -> HibernateProxyUtils.unproxy( getByName( CategoryOptionCombo.class, DEFAULT ) ) );

        return new ImmutableMap.Builder<Class<? extends IdentifiableObject>, IdentifiableObject>()
            .put( Category.class, Objects.requireNonNull( categoryObjects.orElse( null ) ) )
            .put( CategoryCombo.class, Objects.requireNonNull( categoryComboObjects.orElse( null ) ) )
            .put( CategoryOption.class, Objects.requireNonNull( categoryOptionObjects.orElse( null ) ) )
            .put( CategoryOptionCombo.class, Objects.requireNonNull( categoryOptionCombo.orElse( null ) ) )
            .build();
    }

    @Override
    @Transactional( readOnly = true )
    public List<String> getUidsCreatedBefore( Class<? extends IdentifiableObject> klass, Date date )
    {
        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( klass );

        if ( store == null )
        {
            return new ArrayList<>();
        }

        return store.getUidsCreatedBefore( date );
    }

    // --------------------------------------------------------------------------
    // Supportive methods
    // --------------------------------------------------------------------------

    @Override
    @Transactional( readOnly = true )
    public boolean isDefault( IdentifiableObject object )
    {
        Map<Class<? extends IdentifiableObject>, IdentifiableObject> defaults = getDefaults();

        if ( object == null )
        {
            return false;
        }

        Class<?> realClass = HibernateProxyUtils.getRealClass( object );

        if ( !defaults.containsKey( realClass ) )
        {
            return false;
        }

        IdentifiableObject defaultObject = defaults.get( realClass );

        return defaultObject != null && defaultObject.getUid().equals( object.getUid() );
    }

    @Override
    @Transactional
    public void removeUserGroupFromSharing( String userGroupUid )
    {
        List<Schema> schemas = schemaService.getSchemas().stream().filter( s -> s.isShareable() ).collect(
            Collectors.toList() );

        IdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( UserGroup.class );
        schemas.forEach( schema -> store.removeUserGroupFromSharing( userGroupUid, schema.getTableName() ) );
    }

    @SuppressWarnings( "unchecked" )
    private <T extends IdentifiableObject> IdentifiableObjectStore<IdentifiableObject> getIdentifiableObjectStore(
        Class<T> clazz )
    {
        initMaps();

        IdentifiableObjectStore<? extends IdentifiableObject> store = identifiableObjectStoreMap.get( clazz );

        if ( store == null )
        {
            store = identifiableObjectStoreMap.get( clazz.getSuperclass() );

            if ( store == null && !UserCredentials.class.isAssignableFrom( clazz ) )
            {
                log.debug( "No IdentifiableObjectStore found for class: " + clazz );
            }
        }

        return (IdentifiableObjectStore<IdentifiableObject>) store;
    }

    @SuppressWarnings( "unchecked" )
    private <T extends DimensionalObject> GenericDimensionalObjectStore<DimensionalObject> getDimensionalObjectStore(
        Class<T> clazz )
    {
        initMaps();

        GenericDimensionalObjectStore<? extends DimensionalObject> store = dimensionalObjectStoreMap.get( clazz );

        if ( store == null )
        {
            store = dimensionalObjectStoreMap.get( clazz.getSuperclass() );

            if ( store == null )
            {
                log.debug( "No DimensionalObjectStore found for class: " + clazz );
            }
        }

        return (GenericDimensionalObjectStore<DimensionalObject>) store;
    }

    private void initMaps()
    {
        if ( identifiableObjectStoreMap != null )
        {
            return; // Already initialized
        }

        identifiableObjectStoreMap = new HashMap<>();

        for ( IdentifiableObjectStore<? extends IdentifiableObject> store : identifiableObjectStores )
        {
            identifiableObjectStoreMap.put( store.getClazz(), store );
        }

        dimensionalObjectStoreMap = new HashMap<>();

        for ( GenericDimensionalObjectStore<? extends DimensionalObject> store : dimensionalObjectStores )
        {
            dimensionalObjectStoreMap.put( store.getClazz(), store );
        }
    }
}

## 内容5
### 文件路径：
dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/commons/collection/CollectionUtils.java
### 代码内容：
package org.hisp.dhis.commons.collection;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;

/**
 * Utility methods for operations on various collections.
 *
 * @author Morten Olav Hansen
 */
public class CollectionUtils
{
    public static final String[] STRING_ARR = new String[0];

    /**
     * Returns the intersection of the given Collections.
     *
     * @param c1 the first Collection.
     * @param c2 the second Collection.
     * @param <T> the type.
     * @return the intersection of the Collections.
     */
    public static <T> Collection<T> intersection( Collection<T> c1, Collection<T> c2 )
    {
        Set<T> set1 = new HashSet<>( c1 );
        set1.retainAll( new HashSet<>( c2 ) );
        return set1;
    }

    /**
     * Searches for and returns the first string which starts with the given
     * prefix. Removes the match from the collection.
     *
     * @param collection the collection.
     * @param prefix the string prefix.
     * @return a string, or null if no matches.
     */
    public static String popStartsWith( Collection<String> collection, String prefix )
    {
        Iterator<String> iterator = collection.iterator();

        while ( iterator.hasNext() )
        {
            String element = iterator.next();

            if ( element != null && element.startsWith( prefix ) )
            {
                iterator.remove();
                return element;
            }
        }

        return null;
    }

    /**
     * Applies the given consumer to each item in the given collection after
     * filtering out null items.
     *
     * @param collection the collection.
     * @param consumer the consumer.
     */
    public static <E> void nullSafeForEach( Collection<E> collection, Consumer<E> consumer )
    {
        collection.stream()
            .filter( Objects::nonNull )
            .forEach( consumer );
    }

    /**
     * Returns an empty set if the given set is null, if not returns the set.
     *
     * @param set the set.
     * @return a non-null set.
     */
    public static <T> Set<T> emptyIfNull( Set<T> set )
    {
        return set != null ? set : new HashSet<>();
    }

    /**
     * Adds all items not already present in the target collection
     *
     * @param collection collection to add items to.
     * @param items collection of items to add.
     */
    public static <E> void addAllUnique( Collection<E> collection, Collection<E> items )
    {
        items.stream()
            .filter( item -> !collection.contains( item ) )
            .forEach( item -> collection.add( item ) );
    }

    public static boolean isEmpty( Collection collection )
    {
        return collection == null || collection.isEmpty();
    }
}

## 内容6
### 文件路径：
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/SqlUtils.java
### 代码内容：
package org.hisp.dhis.system.util;

import java.sql.Array;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Set;

import org.springframework.util.Assert;

import com.google.common.collect.Sets;

/**
 * Utilities for SQL operations, compatible with PostgreSQL and H2 database
 * platforms.
 *
 * @author Lars Helge Overland
 */
public class SqlUtils
{
    public static final String QUOTE = "\"";

    public static final String SEPARATOR = ".";

    public static final String OPTION_SEP = ".";

    /**
     * Quotes the given relation (typically a column). Quotes part of the given
     * relation are encoded (replaced by double quotes that is).
     *
     * @param relation the relation (typically a column).
     * @return the quoted relation.
     */
    public static String quote( String relation )
    {
        String rel = relation.replaceAll( QUOTE, (QUOTE + QUOTE) );

        return QUOTE + rel + QUOTE;
    }

    /**
     * Quotes and qualifies the given relation (typically a column). Quotes part
     * of the given relation are encoded (replaced by double quotes that is).
     * The column name is qualified by the given alias.
     *
     * @param relation the relation (typically a column).
     * @param alias the alias.
     * @return the quoted relation.
     */
    public static String quote( String alias, String relation )
    {
        Assert.notNull( alias, "Alias must be specified" );

        return alias + SEPARATOR + quote( relation );
    }

    /**
     * Returns a string set for the given result set and column. Assumes that
     * the SQL type is an array of text values.
     *
     * @param rs the result set.
     * @param columnLabel the column label.
     * @return a string set.
     */
    public static Set<String> getArrayAsSet( ResultSet rs, String columnLabel )
        throws SQLException
    {
        Array sqlArray = rs.getArray( columnLabel );
        String[] array = (String[]) sqlArray.getArray();
        return Sets.newHashSet( array );
    }

    /**
     * Cast the given value to numeric (cast(X as numeric).
     *
     * @param value the value.
     * @return a string with the numeric cast statement.
     */
    public static String castToNumber( String value )
    {
        return "cast (" + value + " as numeric)";
    }

    public static String lower( String value )
    {
        return "lower(" + value + ")";
    }

}