Java Code Examples for edu.umd.cs.findbugs.annotations.Nullable

The following examples show how to use edu.umd.cs.findbugs.annotations.Nullable. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Resume the given transaction. Delegates to the {@code doResume}
 * template method first, then resuming transaction synchronization.
 * @param transaction the current transaction object
 * @param resourcesHolder the object that holds suspended resources,
 * as returned by {@code suspend} (or {@code null} to just
 * resume synchronizations, if any)
 * @see #doResume
 * @see #suspend
 * @throws TransactionException Thrown if an error occurs resuming the transaction
 */
protected final void resume(@Nullable Object transaction, @Nullable SuspendedResourcesHolder resourcesHolder)
        throws TransactionException {

    if (resourcesHolder != null) {
        Object suspendedResources = resourcesHolder.suspendedResources;
        if (suspendedResources != null) {
            doResume(transaction, suspendedResources);
        }
        List<TransactionSynchronization> suspendedSynchronizations = resourcesHolder.suspendedSynchronizations;
        if (suspendedSynchronizations != null) {
            TransactionSynchronizationManager.setActualTransactionActive(resourcesHolder.wasActive);
            TransactionSynchronizationManager.setCurrentTransactionIsolationLevel(resourcesHolder.isolationLevel);
            TransactionSynchronizationManager.setCurrentTransactionReadOnly(resourcesHolder.readOnly);
            TransactionSynchronizationManager.setCurrentTransactionName(resourcesHolder.name);
            doResumeSynchronization(suspendedSynchronizations);
        }
    }
}
 
Example 2
Source Project: micronaut-aws   Source File: Ssml.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param text text to be wrapped in the prosody tag
 * @param rate Rate of Speech
 * @param pitch Tone (pitch) of the speech
 * @param volume Volume of the Speech
 * @return SSML Builder
 */
public Ssml prosody(@Nonnull String text,
                    @Nullable ProsodyRate rate,
                    @Nullable ProsodyPitch pitch,
                    @Nullable ProsodyVolume volume) {
    StringBuffer sb = new StringBuffer();
    Map<String, String> attributes = new HashMap<>();

    if (rate != null) {
        attributes.put(RATE, rate.toString());
    }
    if (pitch != null) {
        attributes.put(PITCH, pitch.toString());
    }
    if (volume != null) {
        attributes.put(VOLUME, volume.toString());
    }
    sb.append(openTag(TAG_PROSODY, attributes));
    sb.append(text);
    sb.append(closeTag(TAG_PROSODY));
    result.append(sb);
    return this;
}
 
Example 3
Source Project: micronaut-aws   Source File: Ssml.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param text text to be wrapped in a say as tag
 * @param interpretAs Indicate alexa how to interpret text
 * @param interpretAsDateFormat Format to be used when interpret-as is set to date.
 * @return SSML Builder
 */
public Ssml sayAs(@Nonnull String text,
                  @NonNull InterpretAs interpretAs,
                  @Nullable InterpretAsDateFormat interpretAsDateFormat) {
    Map<String, String> attributes = new HashMap<>();
    attributes.put(INTERPRET_AS, interpretAs.toString());
    if (interpretAsDateFormat != null) {
        attributes.put(FORMAT, interpretAsDateFormat.toString());
    }
    StringBuffer sb = new StringBuffer();
    sb.append(openTag(TAG_SAY_AS, attributes));
    sb.append(text);
    sb.append(closeTag(TAG_SAY_AS));
    result.append(sb);
    return this;
}
 
Example 4
/**
 *
 * @param handlerResponse Handler response object
 * @return If the handlerResponseType and the responseType are identical just returns the supplied object. However,
 * if the response type is of type {@link APIGatewayProxyResponseEvent} it attempts to serialized the handler response
 * as a JSON String and set it in the response body. If the object cannot be serialized, a 400 response is returned
 */
@Nullable
protected ResponseType createResponse(HandlerResponseType handlerResponse) {
    if (handlerResponseType == responseType) {
        logn(LogLevel.TRACE, "HandlerResponseType and ResponseType are identical");
        return (ResponseType) handlerResponse;

    } else if (responseType == APIGatewayProxyResponseEvent.class) {
        logn(LogLevel.TRACE, "response type is APIGatewayProxyResponseEvent");
        String json = serializeAsJsonString(handlerResponse);
        if (json != null) {
            return (ResponseType) respond(HttpStatus.OK, json, MediaType.APPLICATION_JSON);
        }
        return (ResponseType) respond(HttpStatus.BAD_REQUEST,
                "Could not serialize " + handlerResponse.toString() + " as json",
                MediaType.TEXT_PLAIN);
    }
    return null;
}
 
Example 5
/**
 * Actually check the value of the resource that is bound for the given key.
 */
@Nullable
private static Object doGetResource(Object actualKey) {
    Map<Object, Object> map = RESOURCES.get();
    if (map == null) {
        return null;
    }
    Object value = map.get(actualKey);
    // Transparently remove ResourceHolder that was marked as void...
    if (value instanceof ResourceHolder && ((ResourceHolder) value).isVoid()) {
        map.remove(actualKey);
        // Remove entire ThreadLocal if empty...
        if (map.isEmpty()) {
            RESOURCES.remove();
        }
        value = null;
    }
    return value;
}
 
Example 6
Source Project: micronaut-data   Source File: SourcePersistentEntity.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public SourcePersistentProperty getPropertyByName(String name) {
    if (StringUtils.isNotEmpty(name)) {
        final PropertyElement prop = beanProperties.get(name);
        if (prop != null) {
            if (prop.hasStereotype(Relation.class)) {
                if (isEmbedded(prop)) {
                    return new SourceEmbedded(this, prop, entityResolver);
                } else {
                    return new SourceAssociation(this, prop, entityResolver);
                }
            } else {
                return new SourcePersistentProperty(this, prop);
            }
        }
    }
    return null;
}
 
Example 7
Source Project: micronaut-data   Source File: SqlResultEntityTypeMapper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructor used to customize the join paths.
 * @param entity The entity
 * @param resultReader The result reader
 * @param joinPaths The join paths
 */
private SqlResultEntityTypeMapper(
        @NonNull RuntimePersistentEntity<R> entity,
        @NonNull ResultReader<RS, String> resultReader,
        @Nullable Set<JoinPath> joinPaths,
        String startingPrefix,
        @Nullable MediaTypeCodec jsonCodec) {
    ArgumentUtils.requireNonNull("entity", entity);
    ArgumentUtils.requireNonNull("resultReader", resultReader);
    this.entity = entity;
    this.jsonCodec = jsonCodec;
    this.resultReader = resultReader;
    if (CollectionUtils.isNotEmpty(joinPaths)) {
        this.joinPaths = new HashMap<>(joinPaths.size());
        for (JoinPath joinPath : joinPaths) {
            this.joinPaths.put(joinPath.getPath(), joinPath);
        }
    } else {
        this.joinPaths = Collections.emptyMap();
    }
    this.startingPrefix = startingPrefix;
}
 
Example 8
Source Project: micronaut-data   Source File: SqlResultEntityTypeMapper.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Object read(@NonNull RS resultSet, @NonNull Argument<?> argument) {
    RuntimePersistentProperty<R> property = entity.getPropertyByName(argument.getName());
    DataType dataType;
    String columnName;
    if (property == null) {
        dataType = argument.getAnnotationMetadata()
                .enumValue(TypeDef.class, "type", DataType.class)
                .orElseGet(() -> DataType.forType(argument.getType()));
        columnName = argument.getName();
    } else {
        dataType = property.getDataType();
        columnName = property.getPersistedName();
    }

    return resultReader.readDynamic(
            resultSet,
            columnName,
            dataType
    );
}
 
Example 9
Source Project: micronaut-data   Source File: AbstractPatternBasedMethod.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param matchContext The match context
 * @return The resolved {@link DataInterceptor} or {@literal null}.
 */
@Nullable
protected Class<? extends DataInterceptor> resolveFindInterceptor(@NonNull MethodMatchContext matchContext) {
    ClassElement returnType = matchContext.getReturnType();

    if (isPage(matchContext, returnType)) {
        return FindPageInterceptor.class;
    } else if (isSlice(matchContext, returnType)) {
        return FindSliceInterceptor.class;
    } else if (returnType.isAssignable(Iterable.class)) {
        return FindAllInterceptor.class;
    } else if (returnType.isAssignable(Stream.class)) {
        return FindStreamInterceptor.class;
    } else if (returnType.isAssignable(Optional.class)) {
        return FindOptionalInterceptor.class;
    } else if (returnType.isAssignable(Publisher.class)) {
        return FindAllReactiveInterceptor.class;
    }
    return null;
}
 
Example 10
Source Project: micronaut-aws   Source File: AWSLambdaConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param endpointConfiguration The {@link AwsClientBuilder#getEndpoint()}
 */
@Inject
public void setEndpointConfiguration(@Nullable AwsClientBuilder.EndpointConfiguration endpointConfiguration) {
    if (endpointConfiguration != null) {
        builder.setEndpointConfiguration(endpointConfiguration);
    }
}
 
Example 11
Source Project: micronaut-aws   Source File: MicronautAwsProxyResponse.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public String get(CharSequence name) {
    if (StringUtils.isNotEmpty(name)) {
        return multiValueHeaders.getFirst(name.toString());
    }
    return null;
}
 
Example 12
Source Project: micronaut-data   Source File: ColumnNameResultSetReader.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public String readString(ResultSet resultSet, String name) {
    try {
        return resultSet.getString(name);
    } catch (SQLException e) {
        throw exceptionForColumn(name, e);
    }
}
 
Example 13
Source Project: micronaut-data   Source File: DTOMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Object read(@NonNull S object, @NonNull Argument<?> argument) {
    RuntimePersistentProperty<T> pp = persistentEntity.getPropertyByName(argument.getName());
    if (pp == null) {
        DataType type = argument.getAnnotationMetadata()
                .enumValue(TypeDef.class, "type", DataType.class)
                .orElseGet(() -> DataType.forType(argument.getType()));
        return read(object, argument.getName(), type);
    } else {
        return read(object, pp);
    }
}
 
Example 14
/**
 * Actually invoke the {@code afterCommit} methods of the
 * given Spring TransactionSynchronization objects.
 * @param synchronizations a List of TransactionSynchronization objects
 * @see TransactionSynchronization#afterCommit()
 */
public static void invokeAfterCommit(@Nullable List<TransactionSynchronization> synchronizations) {
    if (synchronizations != null) {
        for (TransactionSynchronization synchronization : synchronizations) {
            synchronization.afterCommit();
        }
    }
}
 
Example 15
/**
 *
 * @param args Command Line Args
 * @return if {@link AbstractMicronautLambdaRuntime#createHandler(String...)} or {@link AbstractMicronautLambdaRuntime#createRequestStreamHandler(String...)} are implemented, it returns the handler returned by those methods. If they are not, it attempts to instantiate the class
 * referenced by the environment variable {@link ReservedRuntimeEnvironmentVariables#HANDLER} via Introspection. Otherwise, it returns {@code null}.
 */
@Nullable
protected Object createHandler(String... args) {
    RequestHandler<HandlerRequestType, HandlerResponseType> requestHandler = createRequestHandler(args);
    if (requestHandler != null) {
        return requestHandler;
    }
    RequestStreamHandler requestStreamHandler = createRequestStreamHandler(args);
    if (requestStreamHandler != null) {
        return requestStreamHandler;
    }
    return createEnvironmentHandler();
}
 
Example 16
Source Project: micronaut-data   Source File: SaveAllMethod.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public MethodMatchInfo buildMatchInfo(@NonNull MethodMatchContext matchContext) {
    // default doesn't build a query and query construction left to runtime
    // this is fine for JPA, for SQL we need to build an insert
    Class<? extends DataInterceptor> interceptor;
    ClassElement returnType = matchContext.getReturnType();
    if (TypeUtils.isFutureType(returnType)) {
        interceptor = SaveAllAsyncInterceptor.class;
    } else if (TypeUtils.isReactiveType(returnType)) {
        interceptor = SaveAllReactiveInterceptor.class;
    } else {
        interceptor = SaveAllInterceptor.class;
    }

    if (matchContext.supportsImplicitQueries()) {
        return new MethodMatchInfo(
                null,
                null,
                getInterceptorElement(matchContext, interceptor),
                MethodMatchInfo.OperationType.INSERT
        );
    } else {
        return new MethodMatchInfo(
                null,
                QueryModel.from(matchContext.getRootEntity()),
                getInterceptorElement(matchContext, interceptor),
                MethodMatchInfo.OperationType.INSERT
        );
    }
}
 
Example 17
Source Project: micronaut-data   Source File: ExistsByFinder.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
protected MethodMatchInfo buildInfo(
        @NonNull MethodMatchContext matchContext,
        @NonNull ClassElement queryResultType,
        @Nullable QueryModel query) {
    Class<? extends DataInterceptor> interceptor = ExistsByInterceptor.class;
    ClassElement returnType = matchContext.getReturnType();
    if (TypeUtils.isFutureType(returnType)) {
        interceptor = ExistsByAsyncInterceptor.class;
        returnType = returnType.getGenericType().getFirstTypeArgument().orElse(returnType);
    } else if (TypeUtils.isReactiveType(returnType)) {
        interceptor = ExistsByReactiveInterceptor.class;
        returnType = returnType.getGenericType().getFirstTypeArgument().orElse(returnType);
    }
    if (query == null) {
        query = matchContext.supportsImplicitQueries() ? query : QueryModel.from(matchContext.getRootEntity());
    }
    if (query != null) {
        query.projections().id();
    }
    return new MethodMatchInfo(
            returnType,
            query,
            getInterceptorElement(matchContext, interceptor)
    );
}
 
Example 18
/**
 * Create a new TransactionStatus for the given arguments,
 * also initializing transaction synchronization as appropriate.
 * @see #newTransactionStatus
 * @see #prepareTransactionStatus
 * @param definition The definition
 * @param transaction The transaction object
 * @param newTransaction Is this is a new transaction
 * @param newSynchronization Is this a new synchronization
 * @param debug Is debug enabled
 * @param suspendedResources Any suspended resources
 * @return The status
 */
protected final DefaultTransactionStatus prepareTransactionStatus(
        TransactionDefinition definition,
        @Nullable Object transaction,
        boolean newTransaction,
        boolean newSynchronization,
        boolean debug,
        @Nullable Object suspendedResources) {

    DefaultTransactionStatus status = newTransactionStatus(
            definition, transaction, newTransaction, newSynchronization, debug, suspendedResources);
    prepareSynchronization(status, definition);
    return status;
}
 
Example 19
/**
 * Create a new HibernateTransactionManager instance.
 * @param sessionFactory the SessionFactory to manage transactions for
 * @param dataSource The data source associated with the session factory
 * @param entityInterceptor The configured entity interceptor
 */
public HibernateTransactionManager(
        SessionFactory sessionFactory,
        @Parameter DataSource dataSource,
        @Nullable Interceptor entityInterceptor) {
    this.sessionFactory = sessionFactory;
    if (dataSource instanceof DelegatingDataSource) {
        dataSource = ((DelegatingDataSource) dataSource).getTargetDataSource();
    }
    this.dataSource = dataSource;
    this.entityInterceptor = entityInterceptor;
}
 
Example 20
Source Project: micronaut-data   Source File: MethodMatchInfo.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a method info.
 * @param resultType The result type
 * @param query The query
 * @param interceptor The interceptor type to execute at runtime
 * @param dto indicate that this is a DTO query
 */
public MethodMatchInfo(
        @Nullable TypedElement resultType,
        @Nullable QueryModel query,
        @Nullable ClassElement interceptor,
        boolean dto) {
    this(resultType, query, interceptor, OperationType.QUERY);
    this.dto = dto;
}
 
Example 21
Source Project: micronaut-data   Source File: MethodMatchInfo.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a method info.
 * @param resultType The result type, can be null for void etc.
 * @param query The query, can be null for interceptors that don't execute queries.
 * @param interceptor The interceptor type to execute at runtime
 * @param operationType The operation type
 * @param updateProperties the update properties
 */
public MethodMatchInfo(
        @Nullable TypedElement resultType,
        @Nullable QueryModel query,
        @Nullable ClassElement interceptor,
        @NonNull OperationType operationType,
        String... updateProperties) {
    this.query = query;
    this.interceptor = interceptor;
    this.operationType = operationType;
    this.resultType = resultType;
    this.updateProperties = updateProperties;
}
 
Example 22
Source Project: micronaut-data   Source File: DefaultPageable.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Default constructor.
 *
 * @param page The page
 * @param size The size
 * @param sort The sort
 */
@Creator
DefaultPageable(int page, int size, @Nullable Sort sort) {
    if (page < 0) {
        throw new IllegalArgumentException("Page index cannot be negative");
    }
    if (size < 1) {
        throw new IllegalArgumentException("Max size cannot be less than 1");
    }
    this.max = size;
    this.number = page;
    this.sort = sort == null ? Sort.unsorted() : sort;
}
 
Example 23
Source Project: micronaut-data   Source File: CountMethod.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
protected MethodMatchInfo buildInfo(@NonNull MethodMatchContext matchContext, @NonNull ClassElement queryResultType, @Nullable QueryModel query) {
    return buildCountInfo(
            matchContext, query
    );
}
 
Example 24
Source Project: micronaut-data   Source File: DTOMapper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Default constructor.
 * @param persistentEntity The entity
 * @param resultReader The result reader
 * @param jsonCodec The JSON codec
 */
public DTOMapper(
        RuntimePersistentEntity<T> persistentEntity,
        ResultReader<S, String> resultReader,
        @Nullable MediaTypeCodec jsonCodec) {
    ArgumentUtils.requireNonNull("persistentEntity", persistentEntity);
    ArgumentUtils.requireNonNull("resultReader", resultReader);
    this.persistentEntity = persistentEntity;
    this.resultReader = resultReader;
    this.jsonCodec = jsonCodec;
}
 
Example 25
Source Project: micronaut-data   Source File: SaveEntityMethod.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public MethodMatchInfo buildMatchInfo(@NonNull MethodMatchContext matchContext) {
    VisitorContext visitorContext = matchContext.getVisitorContext();
    ParameterElement[] parameters = matchContext.getParameters();
    if (ArrayUtils.isNotEmpty(parameters)) {
        if (Arrays.stream(parameters).anyMatch(p -> p.getGenericType().hasAnnotation(MappedEntity.class))) {
            ClassElement returnType = matchContext.getReturnType();
            Class<? extends DataInterceptor> interceptor = pickSaveInterceptor(returnType);
            if (TypeUtils.isReactiveOrFuture(returnType)) {
                returnType = returnType.getGenericType().getFirstTypeArgument().orElse(returnType);
            }

            if (matchContext.supportsImplicitQueries()) {
                return new MethodMatchInfo(returnType, null, getInterceptorElement(matchContext, interceptor), MethodMatchInfo.OperationType.INSERT);
            } else {
                return new MethodMatchInfo(returnType,
                        QueryModel.from(matchContext.getRootEntity()),
                        getInterceptorElement(matchContext, interceptor),
                        MethodMatchInfo.OperationType.INSERT
                );
            }
        }
    }
    visitorContext.fail(
            "Cannot implement save method for specified arguments and return type",
            matchContext.getMethodElement()
    );
    return null;
}
 
Example 26
Source Project: micronaut-data   Source File: FindSliceByMethod.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
protected MethodMatchInfo buildInfo(MethodMatchContext matchContext, @NonNull ClassElement queryResultType, @Nullable QueryModel query) {
    if (!matchContext.hasParameterInRole(TypeRole.PAGEABLE)) {
        matchContext.fail("Method must accept an argument that is a Pageable");
        return null;
    } else {
        return super.buildInfo(matchContext, queryResultType, query);
    }
}
 
Example 27
Source Project: micronaut-data   Source File: CountByMethod.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Builds count info.
 * @param matchContext The match context
 * @param query The query
 * @return The method info
 */
MethodMatchInfo buildCountInfo(@NonNull MethodMatchContext matchContext, @Nullable QueryModel query) {
    Class<? extends DataInterceptor> interceptor = CountInterceptor.class;
    ClassElement returnType = matchContext.getReturnType();
    if (TypeUtils.isFutureType(returnType)) {
        interceptor = CountAsyncInterceptor.class;
        returnType = returnType.getGenericType().getFirstTypeArgument().orElse(returnType);
    } else if (TypeUtils.isReactiveType(returnType)) {
        interceptor = CountReactiveInterceptor.class;
        returnType = returnType.getGenericType().getFirstTypeArgument().orElse(returnType);
    }
    if (query != null) {
        ProjectionList projections = query.projections();
        projections.count();
        return new MethodMatchInfo(
                returnType,
                query,
                getInterceptorElement(matchContext, interceptor)
        );
    } else {
        return new MethodMatchInfo(
                returnType,
                matchContext.supportsImplicitQueries() ? null : QueryModel.from(matchContext.getRootEntity()),
                getInterceptorElement(matchContext, interceptor)
        );
    }
}
 
Example 28
Source Project: micronaut-data   Source File: ResultReader.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Read a value dynamically using the result set and the given name and data type.
 * @param resultSet The result set
 * @param index The name
 * @param dataType The data type
 * @return The value, can be null
 * @throws DataAccessException if the value cannot be read
 */
default @Nullable Object readDynamic(
        @NonNull RS resultSet,
        @NonNull IDX index,
        @NonNull DataType dataType) {
    switch (dataType) {
        case STRING:
        case UUID:
        case JSON:
            return readString(resultSet, index);
        case LONG:
            return readLong(resultSet, index);
        case INTEGER:
            return readInt(resultSet, index);
        case BOOLEAN:
            return readBoolean(resultSet, index);
        case BYTE:
            return readByte(resultSet, index);
        case TIMESTAMP:
            return readTimestamp(resultSet, index);
        case DATE:
            return readDate(resultSet, index);
        case CHARACTER:
            return readChar(resultSet, index);
        case FLOAT:
            return readFloat(resultSet, index);
        case SHORT:
            return readShort(resultSet, index);
        case DOUBLE:
            return readDouble(resultSet, index);
        case BYTE_ARRAY:
            return readBytes(resultSet, index);
        case BIGDECIMAL:
            return readBigDecimal(resultSet, index);
        case OBJECT:
        default:
            return getRequiredValue(resultSet, index, Object.class);
    }
}
 
Example 29
Source Project: micronaut-data   Source File: FindOneSpecificationMethod.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public MethodMatchInfo buildMatchInfo(@NonNull MethodMatchContext matchContext) {
    final ClassElement interceptorElement = getInterceptorElement(matchContext,
            "io.micronaut.data.spring.jpa.intercept.FindOneSpecificationInterceptor");
    return new MethodMatchInfo(
            matchContext.getReturnType(),
            null,
            interceptorElement
    );
}
 
Example 30
Source Project: micronaut-data   Source File: DataIntroductionAdvice.java    License: Apache License 2.0 5 votes vote down vote up
private @NonNull
DataInterceptor<Object, Object> findInterceptor(
        @Nullable String dataSourceName,
        @NonNull Class<?> operationsType,
        @NonNull Class<?> interceptorType) {
    DataInterceptor interceptor;
    if (!RepositoryOperations.class.isAssignableFrom(operationsType)) {
        throw new IllegalArgumentException("Repository type must be an instance of RepositoryOperations!");
    }

    RepositoryOperations datastore;
    try {
        if (dataSourceName != null) {
            Qualifier qualifier = Qualifiers.byName(dataSourceName);
            datastore = (RepositoryOperations) beanLocator.getBean(operationsType, qualifier);
        } else {
            datastore = (RepositoryOperations) beanLocator.getBean(operationsType);
        }
    } catch (NoSuchBeanException e) {
        throw new ConfigurationException("No backing RepositoryOperations configured for repository. Check your configuration and try again", e);
    }
    BeanIntrospection<Object> introspection = BeanIntrospector.SHARED.findIntrospections(ref -> interceptorType.isAssignableFrom(ref.getBeanType())).stream().findFirst().orElseThrow(() ->
            new DataAccessException("No Data interceptor found for type: " + interceptorType)
    );
    if (introspection.getConstructorArguments().length == 0) {
        interceptor = (DataInterceptor) introspection.instantiate();
    } else {
        interceptor = (DataInterceptor) introspection.instantiate(datastore);
    }
    return interceptor;
}