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

The following examples show how to use edu.umd.cs.findbugs.annotations.NonNull. 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
Source Project: micronaut-data   Source File: HibernateJpaOperations.java    License: 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 Project: micronaut-data   Source File: SourceAssociation.java    License: 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
@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 4
Source Project: micronaut-data   Source File: AbstractQueryInterceptor.java    License: 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 5
Source Project: gitlab-branch-source-plugin   Source File: GitLabSCMSource.java    License: 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 6
/**
 * 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 7
Source Project: micronaut-data   Source File: HibernateJpaOperations.java    License: 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 8
Source Project: micronaut-data   Source File: ProjectionMethodExpression.java    License: 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 9
/**
 * 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 10
Source Project: micronaut-data   Source File: HibernateJpaOperations.java    License: 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 11
Source Project: micronaut-data   Source File: CountSpecificationMethod.java    License: 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 12
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 13
Source Project: micronaut-data   Source File: ExecutorReactiveOperations.java    License: 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 14
Source Project: micronaut-data   Source File: DefaultQuery.java    License: 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 15
Source Project: micronaut-data   Source File: ListPageMethod.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;
    }
    return super.buildInfo(matchContext, queryResultType, query);
}
 
Example 16
Source Project: micronaut-data   Source File: DefaultQuery.java    License: 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 17
Source Project: micronaut-data   Source File: JdbcQueryStatement.java    License: 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 18
/**
 * 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 19
Source Project: micronaut-data   Source File: JdbcQueryStatement.java    License: 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 20
/**
 * {@inheritDoc}
 */
@Override
public String descriptionFor(@NonNull SCMNavigator navigator) {
    return description();
}
 
Example 21
Source Project: micronaut-data   Source File: QueryModel.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
QueryModel not(@NonNull Criteria other);
 
Example 22
@Override
@NonNull
public final Propagation getPropagationBehavior() {
    return this.propagationBehavior;
}
 
Example 23
MergeWithGitSCMExtension(@NonNull String baseName, @CheckForNull String baseHash) {
    super(baseName, baseHash);
}
 
Example 24
Source Project: micronaut-data   Source File: OneToManyMapper.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public String getName() {
    return "javax.persistence.OneToMany";
}
 
Example 25
Source Project: micronaut-data   Source File: DefaultQuery.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public DefaultQuery sizeGt(@NonNull String propertyName, @NonNull QueryParameter size) {
    criteria.add(Restrictions.sizeGt(propertyName, size));
    return this;
}
 
Example 26
Source Project: gitlab-branch-source-plugin   Source File: GitLabLink.java    License: MIT License 4 votes vote down vote up
@NonNull
public String getUrl() {
    return url;
}
 
Example 27
@NonNull
protected abstract Map<SCMHead, SCMRevision> headsFor(GitLabSCMSource source);
 
Example 28
Source Project: micronaut-data   Source File: UpdateEntityMethod.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public MethodMatchInfo buildMatchInfo(@NonNull MethodMatchContext matchContext) {
    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.UPDATE
                );
            } else {
                final SourcePersistentEntity rootEntity = matchContext.getRootEntity();
                final String idName;
                final SourcePersistentProperty identity = rootEntity.getIdentity();
                if (identity != null) {
                    idName = identity.getName();
                } else {
                    idName = TypeRole.ID;
                }
                final QueryModel queryModel = QueryModel.from(rootEntity)
                        .idEq(new QueryParameter(idName));
                String[] updateProperties = rootEntity.getPersistentProperties()
                        .stream().filter(p ->
                                !((p instanceof Association) && ((Association) p).isForeignKey()) &&
                                        p.booleanValue(AutoPopulated.class, "updateable").orElse(true)
                        )
                        .map(PersistentProperty::getName)
                        .toArray(String[]::new);
                if (ArrayUtils.isEmpty(updateProperties)) {
                    return new MethodMatchInfo(
                            returnType,
                            null,
                            getInterceptorElement(matchContext, interceptor),
                            MethodMatchInfo.OperationType.UPDATE
                    );
                } else {
                    return new MethodMatchInfo(
                            returnType,
                            queryModel,
                            getInterceptorElement(matchContext, interceptor),
                            MethodMatchInfo.OperationType.UPDATE,
                            updateProperties
                    );
                }

            }
        }
    }
    matchContext.fail("Cannot implement update method for specified arguments and return type");
    return null;
}
 
Example 29
Source Project: micronaut-data   Source File: QueryModel.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
QueryModel geProperty(@NonNull String propertyName, @NonNull String otherPropertyName);
 
Example 30
Source Project: micronaut-data   Source File: NamingStrategies.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public String mappedName(@NonNull String name) {
    return name;
}