io.micronaut.core.util.ArgumentUtils Java Examples
The following examples show how to use
io.micronaut.core.util.ArgumentUtils.
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: SqlResultEntityTypeMapper.java From micronaut-data with Apache License 2.0 | 6 votes |
/** * 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 #2
Source File: AbstractSqlRepositoryOperations.java From micronaut-data with Apache License 2.0 | 6 votes |
@NonNull @Override public final <T> RuntimePersistentEntity<T> getEntity(@NonNull Class<T> type) { ArgumentUtils.requireNonNull("type", type); RuntimePersistentEntity<T> entity = entities.get(type); if (entity == null) { entity = new RuntimePersistentEntity<T>(type) { @Override protected RuntimePersistentEntity<T> getEntity(Class<T> type) { return AbstractSqlRepositoryOperations.this.getEntity(type); } }; entities.put(type, entity); } return entity; }
Example #3
Source File: SpringJdbcTransactionOperations.java From micronaut-data with Apache License 2.0 | 6 votes |
@Override public <R> R execute(@NonNull TransactionDefinition definition, @NonNull TransactionCallback<Connection, R> callback) { ArgumentUtils.requireNonNull("callback", callback); ArgumentUtils.requireNonNull("definition", definition); final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setReadOnly(definition.isReadOnly()); def.setIsolationLevel(definition.getIsolationLevel().getCode()); def.setPropagationBehavior(definition.getPropagationBehavior().ordinal()); def.setName(definition.getName()); final Duration timeout = definition.getTimeout(); if (!timeout.isNegative()) { def.setTimeout((int) timeout.getSeconds()); } TransactionTemplate template = new TransactionTemplate(transactionManager, def); return template.execute(status -> { try { return callback.call(new JdbcTransactionStatus(status)); } catch (RuntimeException | Error ex) { throw ex; } catch (Exception e) { throw new UndeclaredThrowableException(e, "TransactionCallback threw undeclared checked exception"); } } ); }
Example #4
Source File: NamingStrategy.java From micronaut-data with Apache License 2.0 | 6 votes |
/** * Return the mapped name for the given property. * @param property The property * @return The mapped name */ default @NonNull String mappedName(@NonNull PersistentProperty property) { ArgumentUtils.requireNonNull("property", property); Supplier<String> defaultNameSupplier = () -> mappedName(property.getName()); if (property instanceof Association) { Association association = (Association) property; if (association.isForeignKey()) { return mappedName(association.getOwner().getDecapitalizedName() + association.getAssociatedEntity().getSimpleName()); } else { switch (association.getKind()) { case ONE_TO_ONE: case MANY_TO_ONE: return property.getAnnotationMetadata().stringValue(MappedProperty.class) .orElseGet(() -> mappedName(property.getName() + getForeignKeySuffix())); default: return property.getAnnotationMetadata().stringValue(MappedProperty.class) .orElseGet(defaultNameSupplier); } } } else { return property.getAnnotationMetadata().stringValue(MappedProperty.class) .map(s -> StringUtils.isEmpty(s) ? defaultNameSupplier.get() : s) .orElseGet(defaultNameSupplier); } }
Example #5
Source File: GrpcEmbeddedServer.java From micronaut-grpc with Apache License 2.0 | 6 votes |
/** * Default constructor. * @param applicationContext The application context * @param applicationConfiguration The application configuration * @param grpcServerConfiguration The GRPC server configuration * @param serverBuilder The server builder * @param eventPublisher The event publisher * @param computeInstanceMetadataResolver The computed instance metadata * @param metadataContributors The metadata contributors */ @Internal GrpcEmbeddedServer( @Nonnull ApplicationContext applicationContext, @Nonnull ApplicationConfiguration applicationConfiguration, @Nonnull GrpcServerConfiguration grpcServerConfiguration, @Nonnull ServerBuilder<?> serverBuilder, @Nonnull ApplicationEventPublisher eventPublisher, @Nullable ComputeInstanceMetadataResolver computeInstanceMetadataResolver, @Nullable List<ServiceInstanceMetadataContributor> metadataContributors) { ArgumentUtils.requireNonNull("applicationContext", applicationContext); ArgumentUtils.requireNonNull("applicationConfiguration", applicationConfiguration); ArgumentUtils.requireNonNull("grpcServerConfiguration", grpcServerConfiguration); this.applicationContext = applicationContext; this.configuration = applicationConfiguration; this.grpcConfiguration = grpcServerConfiguration; this.eventPublisher = eventPublisher; this.server = serverBuilder.build(); this.computeInstanceMetadataResolver = computeInstanceMetadataResolver; this.metadataContributors = metadataContributors; }
Example #6
Source File: MicronautLambdaContainerHandler.java From micronaut-aws with Apache License 2.0 | 6 votes |
/** * constructor. * * @param lambdaContainerEnvironment The container environment * @param applicationContextBuilder The context builder * @throws ContainerInitializationException if the container couldn't be started */ private MicronautLambdaContainerHandler( LambdaContainerState lambdaContainerEnvironment, ApplicationContextBuilder applicationContextBuilder) throws ContainerInitializationException { super( AwsProxyRequest.class, AwsProxyResponse.class, new MicronautRequestReader(lambdaContainerEnvironment), new MicronautResponseWriter(lambdaContainerEnvironment), new AwsProxySecurityContextWriter(), new MicronautAwsProxyExceptionHandler(lambdaContainerEnvironment) ); ArgumentUtils.requireNonNull("applicationContextBuilder", applicationContextBuilder); this.lambdaContainerEnvironment = lambdaContainerEnvironment; this.applicationContextBuilder = applicationContextBuilder; initialize(); }
Example #7
Source File: SpringHibernateTransactionOperations.java From micronaut-data with Apache License 2.0 | 6 votes |
@Override public <R> R execute(@NonNull TransactionDefinition definition, @NonNull TransactionCallback<Connection, R> callback) { ArgumentUtils.requireNonNull("callback", callback); ArgumentUtils.requireNonNull("definition", definition); final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setReadOnly(definition.isReadOnly()); def.setIsolationLevel(definition.getIsolationLevel().getCode()); def.setPropagationBehavior(definition.getPropagationBehavior().ordinal()); def.setName(definition.getName()); final Duration timeout = definition.getTimeout(); if (!timeout.isNegative()) { def.setTimeout((int) timeout.getSeconds()); } TransactionTemplate template = new TransactionTemplate(transactionManager, def); return template.execute(status -> { try { return callback.call(new JpaTransactionStatus(status)); } catch (RuntimeException | Error ex) { throw ex; } catch (Exception e) { throw new UndeclaredThrowableException(e, "TransactionCallback threw undeclared checked exception"); } } ); }
Example #8
Source File: GrpcEmbeddedServer.java From micronaut-grpc with Apache License 2.0 | 6 votes |
/** * Default constructor. * @param applicationContext The application context * @param applicationConfiguration The application configuration * @param grpcServerConfiguration The GRPC server configuration * @param serverBuilder The server builder * @param eventPublisher The event publisher * @param computeInstanceMetadataResolver The computed instance metadata * @param metadataContributors The metadata contributors */ @Internal GrpcEmbeddedServer( @Nonnull ApplicationContext applicationContext, @Nonnull ApplicationConfiguration applicationConfiguration, @Nonnull GrpcServerConfiguration grpcServerConfiguration, @Nonnull ServerBuilder<?> serverBuilder, @Nonnull ApplicationEventPublisher eventPublisher, @Nullable ComputeInstanceMetadataResolver computeInstanceMetadataResolver, @Nullable List<ServiceInstanceMetadataContributor> metadataContributors) { ArgumentUtils.requireNonNull("applicationContext", applicationContext); ArgumentUtils.requireNonNull("applicationConfiguration", applicationConfiguration); ArgumentUtils.requireNonNull("grpcServerConfiguration", grpcServerConfiguration); this.applicationContext = applicationContext; this.configuration = applicationConfiguration; this.grpcConfiguration = grpcServerConfiguration; this.eventPublisher = eventPublisher; this.server = serverBuilder.build(); this.computeInstanceMetadataResolver = computeInstanceMetadataResolver; this.metadataContributors = metadataContributors; }
Example #9
Source File: MicronautBeanFactory.java From micronaut-spring with Apache License 2.0 | 6 votes |
@Override public @Nonnull <T> T getBean(@Nonnull Class<T> requiredType) throws BeansException { ArgumentUtils.requireNonNull("requiredType", requiredType); if (beanExcludes.contains(requiredType)) { throw new NoSuchBeanDefinitionException(requiredType); } // unfortunate hack try { final String[] beanNamesForType = super.getBeanNamesForType(requiredType, false, false); if (ArrayUtils.isNotEmpty(beanNamesForType)) { return getBean(beanNamesForType[0], requiredType); } else { return beanContext.getBean(requiredType); } } catch (NoSuchBeanException e) { throw new NoSuchBeanDefinitionException(requiredType, e.getMessage()); } }
Example #10
Source File: DefaultJdbcRepositoryOperations.java From micronaut-data with Apache License 2.0 | 5 votes |
@NonNull @Override public <R> R prepareStatement(@NonNull String sql, @NonNull PreparedStatementCallback<R> callback) { ArgumentUtils.requireNonNull("sql", sql); ArgumentUtils.requireNonNull("callback", callback); if (QUERY_LOG.isDebugEnabled()) { QUERY_LOG.debug("Executing Query: {}", sql); } try { return callback.call(transactionOperations.getConnection().prepareStatement(sql)); } catch (SQLException e) { throw new DataAccessException("Error preparing SQL statement: " + e.getMessage(), e); } }
Example #11
Source File: ExecutorAsyncOperations.java From micronaut-data with Apache License 2.0 | 5 votes |
/** * Default constructor. * * @param operations The target operations * @param executor The executor to use. */ public ExecutorAsyncOperations(@NonNull RepositoryOperations operations, @NonNull Executor executor) { ArgumentUtils.requireNonNull("operations", operations); ArgumentUtils.requireNonNull("executor", executor); this.datastore = operations; this.executor = executor; }
Example #12
Source File: DefaultJdbcRepositoryOperations.java From micronaut-data with Apache License 2.0 | 5 votes |
/** * Default constructor. * * @param dataSourceName The data source name * @param dataSource The datasource * @param transactionOperations The JDBC operations for the data source * @param executorService The executor service * @param beanContext The bean context * @param codecs The codecs * @param dateTimeProvider The dateTimeProvider */ protected DefaultJdbcRepositoryOperations(@Parameter String dataSourceName, DataSource dataSource, @Parameter TransactionOperations<Connection> transactionOperations, @Named("io") @Nullable ExecutorService executorService, BeanContext beanContext, List<MediaTypeCodec> codecs, @NonNull DateTimeProvider dateTimeProvider) { super( new ColumnNameResultSetReader(), new ColumnIndexResultSetReader(), new JdbcQueryStatement(), codecs, dateTimeProvider ); ArgumentUtils.requireNonNull("dataSource", dataSource); ArgumentUtils.requireNonNull("transactionOperations", transactionOperations); this.dataSource = dataSource; this.transactionOperations = transactionOperations; this.executorService = executorService; Collection<BeanDefinition<GenericRepository>> beanDefinitions = beanContext.getBeanDefinitions(GenericRepository.class, Qualifiers.byStereotype(Repository.class)); for (BeanDefinition<GenericRepository> beanDefinition : beanDefinitions) { String targetDs = beanDefinition.stringValue(Repository.class).orElse("default"); if (targetDs.equalsIgnoreCase(dataSourceName)) { Dialect dialect = beanDefinition.enumValue(JdbcRepository.class, "dialect", Dialect.class).orElseGet(() -> beanDefinition.enumValue(JdbcRepository.class, "dialectName", Dialect.class).orElse(Dialect.ANSI)); dialects.put(beanDefinition.getBeanType(), dialect); QueryBuilder qb = queryBuilders.get(dialect); if (qb == null) { queryBuilders.put(dialect, new SqlQueryBuilder(dialect)); } } } }
Example #13
Source File: NamingStrategy.java From micronaut-data with Apache License 2.0 | 5 votes |
/** * Return the mapped name for the given entity. * @param entity The entity * @return The mapped name */ default @NonNull String mappedName(@NonNull PersistentEntity entity) { ArgumentUtils.requireNonNull("entity", entity); return entity.getAnnotationMetadata().stringValue(MappedEntity.class) .filter(StringUtils::isNotEmpty) .orElseGet(() -> mappedName(entity.getSimpleName())); }
Example #14
Source File: DTOMapper.java From micronaut-data with Apache License 2.0 | 5 votes |
/** * 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 #15
Source File: DefaultJdbcRepositoryOperations.java From micronaut-data with Apache License 2.0 | 5 votes |
@NonNull @Override public <T> Stream<T> entityStream(@NonNull ResultSet resultSet, @Nullable String prefix, @NonNull Class<T> rootEntity) { ArgumentUtils.requireNonNull("resultSet", resultSet); ArgumentUtils.requireNonNull("rootEntity", rootEntity); TypeMapper<ResultSet, T> mapper = new SqlResultEntityTypeMapper<>(prefix, getEntity(rootEntity), columnNameResultSetReader, jsonCodec); Iterable<T> iterable = () -> new Iterator<T>() { boolean nextCalled = false; @Override public boolean hasNext() { try { if (!nextCalled) { nextCalled = true; return resultSet.next(); } else { return nextCalled; } } catch (SQLException e) { throw new DataAccessException("Error retrieving next JDBC result: " + e.getMessage(), e); } } @Override public T next() { nextCalled = false; return mapper.map(resultSet, rootEntity); } }; return StreamSupport.stream(iterable.spliterator(), false); }
Example #16
Source File: QueryResult.java From micronaut-data with Apache License 2.0 | 5 votes |
/** * Creates a new encoded query. * @param query The query * @param parameters The parameters * @param parameterTypes The parameter types * @param additionalRequiredParameters Names of the additional required parameters to execute the query * @return The query */ static @NonNull QueryResult of( @NonNull String query, @Nullable Map<String, String> parameters, @Nullable Map<String, DataType> parameterTypes, @Nullable Set<String> additionalRequiredParameters) { ArgumentUtils.requireNonNull("query", query); return new QueryResult() { @NonNull @Override public String getQuery() { return query; } @NonNull @Override public Map<String, String> getParameters() { return parameters != null ? Collections.unmodifiableMap(parameters) : Collections.emptyMap(); } @NonNull @Override public Map<String, DataType> getParameterTypes() { return parameterTypes != null ? Collections.unmodifiableMap(parameterTypes) : Collections.emptyMap(); } @Override public Set<String> getAdditionalRequiredParameters() { return additionalRequiredParameters != null ? additionalRequiredParameters : Collections.emptySet(); } }; }
Example #17
Source File: AbstractSqlLikeQueryBuilder.java From micronaut-data with Apache License 2.0 | 5 votes |
@Override public QueryResult buildQuery(@NonNull AnnotationMetadata annotationMetadata, @NonNull QueryModel query) { ArgumentUtils.requireNonNull("annotationMetadata", annotationMetadata); ArgumentUtils.requireNonNull("query", query); QueryState queryState = newQueryState(query, true); Collection<JoinPath> joinPaths = query.getJoinPaths(); for (JoinPath joinPath : joinPaths) { queryState.applyJoin(joinPath); } StringBuilder select = new StringBuilder(SELECT_CLAUSE); buildSelectClause(query, queryState, select); queryState.getQuery().insert(0, select.toString()); QueryModel.Junction criteria = query.getCriteria(); Map<String, String> parameters = null; if (!criteria.isEmpty() || annotationMetadata.hasStereotype(WhereSpecifications.class) || queryState.getEntity().getAnnotationMetadata().hasStereotype(WhereSpecifications.class)) { parameters = buildWhereClause(annotationMetadata, criteria, queryState); } appendOrder(query, queryState); return QueryResult.of( queryState.getQuery().toString(), parameters, queryState.getParameterTypes(), queryState.getAdditionalRequiredParameters() ); }
Example #18
Source File: Sort.java From micronaut-data with Apache License 2.0 | 5 votes |
/** * Constructs an order for the given property with the given direction. * @param property The property * @param direction The direction * @param ignoreCase Whether to ignore case */ @JsonCreator public Order( @JsonProperty("property") @NonNull String property, @JsonProperty("direction") @NonNull Direction direction, @JsonProperty("ignoreCase") boolean ignoreCase) { ArgumentUtils.requireNonNull("direction", direction); ArgumentUtils.requireNonNull("property", property); this.direction = direction; this.property = property; this.ignoreCase = ignoreCase; }
Example #19
Source File: HibernateJpaOperations.java From micronaut-data with Apache License 2.0 | 5 votes |
/** * Default constructor. * * @param sessionFactory The session factory * @param transactionOperations The transaction operations * @param executorService The executor service for I/O tasks to use */ protected HibernateJpaOperations( @NonNull SessionFactory sessionFactory, @NonNull @Parameter TransactionOperations<Connection> transactionOperations, @Named("io") @Nullable ExecutorService executorService) { ArgumentUtils.requireNonNull("sessionFactory", sessionFactory); this.sessionFactory = sessionFactory; this.transactionOperations = transactionOperations; this.executorService = executorService; }
Example #20
Source File: DefaultQuery.java From micronaut-data with Apache License 2.0 | 5 votes |
/** * Adds the specified criterion instance to the query. * * @param criterion The criterion instance */ @Override public @NonNull QueryModel add(@NonNull QueryModel.Criterion criterion) { ArgumentUtils.requireNonNull("criterion", criterion); QueryModel.Junction currentJunction = criteria; add(currentJunction, criterion); return this; }
Example #21
Source File: SpringJdbcTransactionOperations.java From micronaut-data with Apache License 2.0 | 5 votes |
@Override public <R> R executeRead(@NonNull TransactionCallback<Connection, R> callback) { ArgumentUtils.requireNonNull("callback", callback); return readTransactionTemplate.execute(status -> { try { return callback.call(new JdbcTransactionStatus(status)); } catch (RuntimeException | Error ex) { throw ex; } catch (Exception e) { throw new UndeclaredThrowableException(e, "TransactionCallback threw undeclared checked exception"); } } ); }
Example #22
Source File: SpringJdbcTransactionOperations.java From micronaut-data with Apache License 2.0 | 5 votes |
@Override public <R> R executeWrite(@NonNull TransactionCallback<Connection, R> callback) { ArgumentUtils.requireNonNull("callback", callback); return writeTransactionTemplate.execute(status -> { try { return callback.call(new JdbcTransactionStatus(status)); } catch (RuntimeException | Error ex) { throw ex; } catch (Exception e) { throw new UndeclaredThrowableException(e, "TransactionCallback threw undeclared checked exception"); } } ); }
Example #23
Source File: SpringHibernateTransactionOperations.java From micronaut-data with Apache License 2.0 | 5 votes |
@Override public <R> R executeRead(@NonNull TransactionCallback<Connection, R> callback) { ArgumentUtils.requireNonNull("callback", callback); return readTransactionTemplate.execute(status -> { try { return callback.call(new JpaTransactionStatus(status)); } catch (RuntimeException | Error ex) { throw ex; } catch (Exception e) { throw new UndeclaredThrowableException(e, "TransactionCallback threw undeclared checked exception"); } } ); }
Example #24
Source File: KafkaConsumerProcessor.java From micronaut-kafka with Apache License 2.0 | 5 votes |
@Nonnull @Override public <K, V> Consumer<K, V> getConsumer(@Nonnull String id) { ArgumentUtils.requireNonNull("id", id); final Consumer consumer = consumers.get(id); if (consumer == null) { throw new IllegalArgumentException("No consumer found for ID: " + id); } return consumer; }
Example #25
Source File: SpringHibernateTransactionOperations.java From micronaut-data with Apache License 2.0 | 5 votes |
@Override public <R> R executeWrite(@NonNull TransactionCallback<Connection, R> callback) { ArgumentUtils.requireNonNull("callback", callback); return writeTransactionTemplate.execute(status -> { try { return callback.call(new JpaTransactionStatus(status)); } catch (RuntimeException | Error ex) { throw ex; } catch (Exception e) { throw new UndeclaredThrowableException(e, "TransactionCallback threw undeclared checked exception"); } } ); }
Example #26
Source File: MicronautAwsProxyResponse.java From micronaut-aws with Apache License 2.0 | 5 votes |
@Override public MutableHttpHeaders add(CharSequence header, CharSequence value) { ArgumentUtils.requireNonNull("header", header); ArgumentUtils.requireNonNull("value", value); multiValueHeaders.add(header.toString(), value.toString()); return this; }
Example #27
Source File: GoogleMultiValueMap.java From micronaut-gcp with Apache License 2.0 | 5 votes |
@Nullable @Override public String get(CharSequence name) { ArgumentUtils.requireNonNull("name", name); final List<String> values = map.get(name.toString()); if (values != null) { final Iterator<String> i = values.iterator(); if (i.hasNext()) { return i.next(); } } return null; }
Example #28
Source File: GoogleFunctionHttpResponse.java From micronaut-gcp with Apache License 2.0 | 5 votes |
@Override public MutableHttpHeaders add(CharSequence header, CharSequence value) { ArgumentUtils.requireNonNull("header", header); if (value != null) { response.appendHeader(header.toString(), value.toString()); } else { response.getHeaders().remove(header.toString()); } return this; }
Example #29
Source File: MicronautBeanFactoryConfiguration.java From micronaut-spring with Apache License 2.0 | 4 votes |
/** * The bean types to exclude from being exposed by Spring's {@link org.springframework.beans.factory.BeanFactory} interface. * @param beanExcludes The bean types */ public void setBeanExcludes(@Nonnull List<Class<?>> beanExcludes) { ArgumentUtils.requireNonNull("beanExcludes", beanExcludes); this.beanExcludes = beanExcludes; }
Example #30
Source File: GoogleFunctionHttpRequest.java From micronaut-gcp with Apache License 2.0 | 4 votes |
@Override public Optional<String> getFirst(CharSequence name) { ArgumentUtils.requireNonNull("name", name); return googleRequest.getFirstQueryParameter(name.toString()); }