edu.umd.cs.findbugs.annotations.NonNull Java Examples

The following examples show how to use edu.umd.cs.findbugs.annotations.NonNull. 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
Source File: HibernateJpaOperations.java    From micronaut-data with Apache License 2.0 6 votes vote down vote up
private <T> void bindCriteriaSort(CriteriaQuery<T> criteriaQuery, Root<?> root, CriteriaBuilder builder, @NonNull Sort sort) {
    List<Order> orders = new ArrayList<>();
    for (Sort.Order order : sort.getOrderBy()) {
        Path<String> path = root.get(order.getProperty());
        Expression expression = order.isIgnoreCase() ? builder.lower(path) : path;
        switch (order.getDirection()) {

            case DESC:
                orders.add(builder.desc(expression));
                continue;
            default:
            case ASC:
                orders.add(builder.asc(expression));
        }
    }
    criteriaQuery.orderBy(orders);
}
 
Example #2
Source File: SourceAssociation.java    From micronaut-data with Apache License 2.0 6 votes vote down vote up
@Override
@NonNull
public PersistentEntity getAssociatedEntity() {
    ClassElement type = getType();
    switch (getKind()) {
        case ONE_TO_MANY:
        case MANY_TO_MANY:
            ClassElement classElement = type.getFirstTypeArgument().orElse(null);
            if (classElement  != null) {
                return entityResolver.apply(classElement);
            } else {
                throw new MappingException("Collection association [" + getName() + "] of entity [" + getOwner().getName() + "] is not a collection type with a generic type argument that specifies another entity type to associate");
            }
        default:
            return entityResolver.apply(type);
    }
}
 
Example #3
Source File: GitLabSCMSourceRequest.java    From gitlab-branch-source-plugin with MIT License 5 votes vote down vote up
/**
 * Returns the {@link ChangeRequestCheckoutStrategy} to create for merge requests of the
 * specified type.
 *
 * @param fork {@code true} to return strategies for the fork merge requests, {@code false} for
 * origin merge requests.
 * @return the {@link ChangeRequestCheckoutStrategy} to create for each merge request.
 */
@NonNull
public final Set<ChangeRequestCheckoutStrategy> getMRStrategies(boolean fork) {
    if (fork) {
        return fetchForkMRs ? getForkMRStrategies()
            : Collections.<ChangeRequestCheckoutStrategy>emptySet();
    }
    return fetchOriginMRs ? getOriginMRStrategies()
        : Collections.<ChangeRequestCheckoutStrategy>emptySet();
}
 
Example #4
Source File: GitLabSCMSource.java    From gitlab-branch-source-plugin with MIT License 5 votes vote down vote up
@NonNull
@Override
protected SCMHeadCategory[] createCategories() {
    return new SCMHeadCategory[] {
            new UncategorizedSCMHeadCategory(Messages._GitLabSCMSource_UncategorizedCategory()),
            new ChangeRequestSCMHeadCategory(Messages._GitLabSCMSource_ChangeRequestCategory()),
            new TagSCMHeadCategory(Messages._GitLabSCMSource_TagCategory()) };
}
 
Example #5
Source File: AbstractQueryInterceptor.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
/**
 * Return whether the metadata indicates the instance is nullable.
 * @param metadata The metadata
 * @return True if it is nullable
 */
protected boolean isNullable(@NonNull AnnotationMetadata metadata) {
    return metadata
            .getDeclaredAnnotationNames()
            .stream()
            .anyMatch(n -> NameUtils.getSimpleName(n).equalsIgnoreCase("nullable"));
}
 
Example #6
Source File: JdbcQueryStatement.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public QueryStatement<PreparedStatement, Integer> setBytes(PreparedStatement statement, Integer name, byte[] bytes) {
    try {
        statement.setBytes(name, bytes);
    } catch (SQLException e) {
        throw newDataAccessException(e);
    }
    return this;
}
 
Example #7
Source File: JdbcQueryStatement.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public QueryStatement<PreparedStatement, Integer> setBoolean(PreparedStatement statement, Integer name, boolean bool) {
    try {
        statement.setBoolean(name, bool);
    } catch (SQLException e) {
        throw newDataAccessException(e);
    }
    return this;
}
 
Example #8
Source File: ConfigDrivenWorkflowBranchProjectFactory.java    From config-driven-pipeline-plugin with MIT License 5 votes vote down vote up
@Override protected SCMSourceCriteria getSCMSourceCriteria(SCMSource source) {
    return new SCMSourceCriteria() {
        @Override public boolean isHead(@NonNull SCMSourceCriteria.Probe probe, @NonNull TaskListener listener) throws IOException {
            SCMProbeStat stat = probe.stat(scriptPath);
            switch (stat.getType()) {
                case NONEXISTENT:
                    if (stat.getAlternativePath() != null) {
                        listener.getLogger().format("      ‘%s’ not found (but found ‘%s’, search is case sensitive)%n", scriptPath, stat.getAlternativePath());
                    } else {
                        listener.getLogger().format("      ‘%s’ not found%n", scriptPath);
                    }
                    return false;
                case DIRECTORY:
                    listener.getLogger().format("      ‘%s’ found but is a directory not a file%n", scriptPath);
                    return false;
                default:
                    listener.getLogger().format("      ‘%s’ found%n", scriptPath);
                    return true;

            }
        }

        @Override
        public int hashCode() {
            return getClass().hashCode();
        }

        @Override
        public boolean equals(Object obj) {
            return getClass().isInstance(obj);
        }
    };
}
 
Example #9
Source File: DefaultQuery.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
/**
 * Used to restrict a property to be null.
 *
 * @param property The property name
 */
@Override
public @NonNull
DefaultQuery isNull(@NonNull String property) {
    criteria.add(Restrictions.isNull(property));
    return this;
}
 
Example #10
Source File: PersonalAccessTokenImpl.java    From gitlab-branch-source-plugin with MIT License 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param scope the credentials scope.
 * @param id the credentials id.
 * @param description the description of the token.
 * @param token the token itself (will be passed through {@link Secret#fromString(String)})
 */
@DataBoundConstructor
public PersonalAccessTokenImpl(
    @CheckForNull CredentialsScope scope,
    @CheckForNull String id,
    @CheckForNull String description,
    @NonNull String token) {
    super(scope, id, description);
    this.token = Secret.fromString(token);
}
 
Example #11
Source File: HibernateJpaOperations.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public <T> T update(@NonNull UpdateOperation<T> operation) {
    return transactionOperations.executeWrite(status -> {
        T entity = operation.getEntity();
        EntityManager session = sessionFactory.getCurrentSession();
        entity = session.merge(entity);
        flushIfNecessary(session, operation.getAnnotationMetadata());
        return entity;
    });
}
 
Example #12
Source File: ProjectionMethodExpression.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(@NonNull MethodMatchContext matchContext, @NonNull QueryModel query) {
    query.projections().property(property);
    if (persistentProperty instanceof Association && !query.getJoinPath(property).isPresent()) {
        query.join((Association) persistentProperty);
    }
}
 
Example #13
Source File: ListPageMethod.java    From micronaut-data with 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;
    }
    return super.buildInfo(matchContext, queryResultType, query);
}
 
Example #14
Source File: OriginMergeRequestDiscoveryTrait.java    From gitlab-branch-source-plugin with MIT License 5 votes vote down vote up
/**
 * Returns the strategies.
 *
 * @return the strategies.
 */
@NonNull
public Set<ChangeRequestCheckoutStrategy> getStrategies() {
    switch (strategyId) {
        case 1:
            return EnumSet.of(ChangeRequestCheckoutStrategy.MERGE);
        case 2:
            return EnumSet.of(ChangeRequestCheckoutStrategy.HEAD);
        case 3:
            return EnumSet
                .of(ChangeRequestCheckoutStrategy.HEAD, ChangeRequestCheckoutStrategy.MERGE);
        default:
            return EnumSet.noneOf(ChangeRequestCheckoutStrategy.class);
    }
}
 
Example #15
Source File: DefaultQuery.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
/**
 * Used to restrict a property to be not null.
 *
 * @param property The property name
 */
@Override
public @NonNull
DefaultQuery isNotNull(@NonNull String property) {
    criteria.add(Restrictions.isNotNull(property));
    return this;
}
 
Example #16
Source File: HibernateJpaOperations.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
private <T> void bindPageable(Query<T> q, @NonNull Pageable pageable) {
    if (pageable == Pageable.UNPAGED) {
        // no pagination
        return;
    }

    int max = pageable.getSize();
    if (max > 0) {
        q.setMaxResults(max);
    }
    long offset = pageable.getOffset();
    if (offset > 0) {
        q.setFirstResult((int) offset);
    }
}
 
Example #17
Source File: ExecutorReactiveOperations.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public <T> Publisher<T> findAll(PagedQuery<T> pagedQuery) {
    return Flowable.fromPublisher(Publishers.fromCompletableFuture(() ->
            asyncOperations.findAll(pagedQuery)
    )).flatMap(Flowable::fromIterable);
}
 
Example #18
Source File: ExistsByFinder.java    From micronaut-data with 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 #19
Source File: CountSpecificationMethod.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isMethodMatch(@NonNull MethodElement methodElement, @NonNull MatchContext matchContext) {

    final VisitorContext visitorContext = matchContext.getVisitorContext();
    ClassElement returnType = matchContext.getReturnType();

    return super.isMethodMatch(methodElement, matchContext) &&
            (returnType.isPrimitive() || returnType.isAssignable(Number.class)) &&
            visitorContext.getClassElement("io.micronaut.data.spring.jpa.intercept.CountSpecificationInterceptor").isPresent() &&
            visitorContext.getClassElement("org.springframework.data.jpa.domain.Specification").isPresent() &&
            isFirstParameterJpaSpecification(methodElement);
}
 
Example #20
Source File: JpaRepository.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
List<E> findAll();
 
Example #21
Source File: SpringCreatedDateMapper.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public String getName() {
    return "org.springframework.data.annotation.CreatedDate";
}
 
Example #22
Source File: DefaultQuery.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public PersistentEntity getPersistentEntity() {
    return entity;
}
 
Example #23
Source File: DefaultQuery.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public DefaultQuery ltProperty(@NonNull String propertyName, @NonNull String otherPropertyName) {
    criteria.add(Restrictions.ltProperty(propertyName, otherPropertyName));
    return this;
}
 
Example #24
Source File: OriginMergeRequestDiscoveryTrait.java    From gitlab-branch-source-plugin with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@NonNull
@Override
public String getDisplayName() {
    return Messages.OriginMergeRequestDiscoveryTrait_authorityDisplayName();
}
 
Example #25
Source File: QueryModel.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
QueryModel allEq(@NonNull Map<String, QueryParameter> propertyValues);
 
Example #26
Source File: DefaultJdbcRepositoryOperations.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
@Override
public <T> Optional<Number> deleteAll(@NonNull BatchOperation<T> operation) {
    throw new UnsupportedOperationException("The deleteAll method via batch is unsupported. Execute the SQL update directly");
}
 
Example #27
Source File: RuntimePersistentEntity.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public String getName() {
    return introspection.getBeanType().getName();
}
 
Example #28
Source File: QueryModel.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
QueryModel sizeGt(@NonNull String propertyName, @NonNull QueryParameter size);
 
Example #29
Source File: GitLabProjectSCMEvent.java    From gitlab-branch-source-plugin with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public String descriptionFor(@NonNull SCMNavigator navigator) {
    return description();
}
 
Example #30
Source File: TransactionalInterceptor.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
/**
 * @return The transaction manager
 */
@NonNull
public SynchronousTransactionManager getTransactionManager() {
    return this.transactionManager;
}