io.micronaut.context.annotation.Parameter Java Examples

The following examples show how to use io.micronaut.context.annotation.Parameter. 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: KafkaProducerFactory.java    From micronaut-kafka with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new {@link KafkaProducer} for the given configuration.
 *
 * @param producerConfiguration The producer configuration
 * @param <K> The key type
 * @param <V> The value type
 * @return The consumer
 */
@Prototype
public <K, V> KafkaProducer<K, V> createProducer(@Parameter AbstractKafkaProducerConfiguration<K, V> producerConfiguration) {
    Optional<Serializer<K>> keySerializer = producerConfiguration.getKeySerializer();
    Optional<Serializer<V>> valueSerializer = producerConfiguration.getValueSerializer();

    Properties config = producerConfiguration.getConfig();
    if (keySerializer.isPresent() && valueSerializer.isPresent()) {
        Serializer<K> ks = keySerializer.get();
        Serializer<V> vs = valueSerializer.get();
        return new KafkaProducer<>(
                config,
                ks,
                vs
        );
    } else if (keySerializer.isPresent() || valueSerializer.isPresent()) {
        throw new ConfigurationException("Both the [keySerializer] and [valueSerializer] must be set when setting either");
    } else {
        return new KafkaProducer<>(
                config
        );
    }
}
 
Example #2
Source File: KafkaProducerConfiguration.java    From micronaut-kafka with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs the default producer configuration.
 *
 * @param producerName The name of the producer
 * @param defaultConfiguration The default Kafka configuration
 * @param environment The environment
 */
public KafkaProducerConfiguration(
        @Parameter String producerName,
        KafkaDefaultConfiguration defaultConfiguration,
        Environment environment) {
    super(new Properties());
    Properties config = getConfig();
    config.putAll(defaultConfiguration.getConfig());
    String propertyKey = PREFIX + '.' + NameUtils.hyphenate(producerName, true);
    if (environment.containsProperties(propertyKey)) {
        config.putAll(
                environment.getProperties(propertyKey, StringConvention.RAW)
        );
    }

}
 
Example #3
Source File: KafkaConsumerFactory.java    From micronaut-kafka with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new {@link KafkaConsumer} for the given configuration.
 *
 * @param consumerConfiguration The consumer configuration
 * @param <K> The key type
 * @param <V> The value type
 * @return The consumer
 */
@Prototype
public <K, V> KafkaConsumer<K, V> createConsumer(
        @Parameter AbstractKafkaConsumerConfiguration<K, V> consumerConfiguration) {

    Optional<Deserializer<K>> keyDeserializer = consumerConfiguration.getKeyDeserializer();
    Optional<Deserializer<V>> valueDeserializer = consumerConfiguration.getValueDeserializer();
    Properties config = consumerConfiguration.getConfig();

    if (keyDeserializer.isPresent() && valueDeserializer.isPresent()) {
        return new KafkaConsumer<>(
                config,
                keyDeserializer.get(),
                valueDeserializer.get()
        );
    } else if (keyDeserializer.isPresent() || valueDeserializer.isPresent()) {
        throw new ConfigurationException("Both the [keyDeserializer] and [valueDeserializer] must be set when setting either");
    } else {
        return new KafkaConsumer<>(
                config
        );
    }

}
 
Example #4
Source File: GrpcNamedManagedChannelConfiguration.java    From micronaut-grpc with Apache License 2.0 5 votes vote down vote up
/**
 * Default constructor.
 * @param name The name
 * @param env The environment
 * @param executorService The executor service
 */
public GrpcNamedManagedChannelConfiguration(
        @Parameter String name,
        Environment env,
        ExecutorService executorService) {
    super(name, env, executorService);
}
 
Example #5
Source File: StandardSkillFactory.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
/**
 * @param alexaSkillConfiguration Alexa Skill Configuration
 * @return An Alexa Skill using the {@link AlexaSkillBuilder} and the {@link SkillBuilderProvider} bean.
 */
@EachBean(AlexaSkillConfiguration.class)
public Skill createSkill(@Parameter AlexaSkillConfiguration alexaSkillConfiguration) {
    AlexaSkill alexaSkill = alexaSkillBuilder.buildSkill(skillBuilderProvider.getSkillBuilder(), alexaSkillConfiguration);
    if (alexaSkill instanceof Skill) {
        return ((Skill) alexaSkill);
    }
    return null;
}
 
Example #6
Source File: GrpcManagedChannelFactory.java    From micronaut-grpc with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a managed channel for the given target.
 * @param target The target
 * @return The channel
 */
@Bean
@Primary
protected ManagedChannel managedChannel(@Parameter String target) {
    final NettyChannelBuilder nettyChannelBuilder = beanContext.createBean(NettyChannelBuilder.class, target);
    return nettyChannelBuilder.build();
}
 
Example #7
Source File: GrpcManagedChannelFactory.java    From micronaut-grpc with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a managed channel for the given target.
 * @param target The target
 * @return The channel
 */
@Bean
@Primary
protected ManagedChannel managedChannel(@Parameter String target) {
    final NettyChannelBuilder nettyChannelBuilder = beanContext.createBean(NettyChannelBuilder.class, target);
    return nettyChannelBuilder.build();
}
 
Example #8
Source File: GrpcNamedManagedChannelConfiguration.java    From micronaut-grpc with Apache License 2.0 5 votes vote down vote up
/**
 * Default constructor.
 * @param name The name
 * @param env The environment
 * @param executorService The executor service
 */
public GrpcNamedManagedChannelConfiguration(
        @Parameter String name,
        Environment env,
        ExecutorService executorService) {
    super(name, env, executorService);
}
 
Example #9
Source File: HibernateJpaOperations.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #10
Source File: DefaultJdbcRepositoryOperations.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #11
Source File: HibernateTransactionManager.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #12
Source File: KafkaStreamsConfiguration.java    From micronaut-kafka with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a new {@link KafkaStreamsConfiguration} for the given defaults.
 *
 * @param streamName The stream name
 * @param defaultConfiguration The default configuration
 * @param applicationConfiguration The application configuration
 * @param environment The environment
 */
public KafkaStreamsConfiguration(
        @Parameter String streamName,
        KafkaDefaultConfiguration defaultConfiguration,
        ApplicationConfiguration applicationConfiguration,
        Environment environment) {
    super(defaultConfiguration);
    Properties config = getConfig();
    String propertyKey = PREFIX + '.' + NameUtils.hyphenate(streamName, true);
    config.putAll(environment.getProperty(propertyKey, Properties.class).orElseGet(Properties::new));
    init(applicationConfiguration, environment, config);
}
 
Example #13
Source File: KafkaConsumerConfiguration.java    From micronaut-kafka with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a new {@link KafkaConsumerConfiguration} for the given defaults.
 *
 * @param consumerName The name of the consumer
 * @param defaultConfiguration The default configuration
 * @param environment The environment
 */
public KafkaConsumerConfiguration(
        @Parameter String consumerName,
        KafkaDefaultConfiguration defaultConfiguration,
        Environment environment) {
    super(new Properties());
    Properties config = getConfig();
    config.putAll(defaultConfiguration.getConfig());
    String propertyKey = PREFIX + '.' + NameUtils.hyphenate(consumerName, true);
    if (environment.containsProperties(propertyKey)) {
        config.putAll(
                environment.getProperties(propertyKey, StringConvention.RAW)
        );
    }
}
 
Example #14
Source File: AWSInvokeRequestDefinition.java    From micronaut-aws with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor.
 * @param name configured name from a property
 */
public AWSInvokeRequestDefinition(@Parameter String name) {
    this.invokeRequest = new InvokeRequest();
    this.invokeRequest.setFunctionName(name);
}
 
Example #15
Source File: UpdateMethod.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public MethodMatchInfo buildMatchInfo(
        @NonNull MethodMatchContext matchContext) {
    ParameterElement[] parameters = matchContext.getMethodElement().getParameters();
    List<ParameterElement> remainingParameters = Arrays.stream(parameters)
            .filter(p -> !p.hasAnnotation(Id.class))
            .collect(Collectors.toList());

    ParameterElement idParameter = Arrays.stream(parameters).filter(p -> p.hasAnnotation(Id.class)).findFirst()
            .orElse(null);
    if (idParameter == null) {
        matchContext.fail("ID required for update method, but not specified");
        return null;
    }

    SourcePersistentEntity entity = matchContext.getRootEntity();

    SourcePersistentProperty identity = entity.getIdentity();
    if (identity == null) {
        matchContext.fail("Cannot update by ID for entity that has no ID");
        return null;
    } else {
        String idType = TypeUtils.getTypeName(identity.getType());
        String idParameterType = TypeUtils.getTypeName(idParameter.getType());
        if (!idType.equals(idParameterType)) {
            matchContext.fail("ID type of method [" + idParameterType + "] does not match ID type of entity: " + idType);
        }
    }


    QueryModel query = QueryModel.from(entity);
    query.idEq(new QueryParameter(idParameter.getName()));
    List<String> properiesToUpdate = new ArrayList<>(remainingParameters.size());
    for (ParameterElement parameter : remainingParameters) {
        String name = parameter.stringValue(Parameter.class).orElse(parameter.getName());
        SourcePersistentProperty prop = entity.getPropertyByName(name);
        if (prop == null) {
            matchContext.fail("Cannot update non-existent property: " + name);
            return null;
        } else {
            if (prop.isGenerated()) {
                matchContext.fail("Cannot update a generated property: " + name);
                return null;
            } else {
                properiesToUpdate.add(name);
            }
        }
    }

    Element element = matchContext.getParametersInRole().get(TypeRole.LAST_UPDATED_PROPERTY);
    if (element instanceof PropertyElement) {
        properiesToUpdate.add(element.getName());
    }

    ClassElement returnType = matchContext.getReturnType();
    Class<? extends DataInterceptor> interceptor = pickUpdateInterceptor(returnType);
    if (TypeUtils.isReactiveOrFuture(returnType)) {
        returnType = returnType.getGenericType().getFirstTypeArgument().orElse(returnType);
    }
    MethodMatchInfo info = new MethodMatchInfo(
            returnType,
            query,
            getInterceptorElement(matchContext, interceptor),
            MethodMatchInfo.OperationType.UPDATE,
            properiesToUpdate.toArray(new String[0])
    );

    info.addParameterRole(
            TypeRole.ID,
            idParameter.getName()
    );
    return info;
}
 
Example #16
Source File: RepositoryTypeElementVisitor.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
private void parameterBindingToIndex(
        AnnotationValueBuilder<DataMethod> annotationBuilder,
        ParameterElement[] parameters,
        Map<String, String> finalParameterBinding,
        MethodMatchContext methodMatchContext,
        boolean includeNames,
        String... members) {
    List<String> parameterNames = Arrays.stream(parameters).map(parameterElement ->
            parameterElement.stringValue(Parameter.class).orElse(parameterElement.getName())).collect(Collectors.toList()
    );
    int len = finalParameterBinding.size();
    String[] parameterPaths = new String[len];
    String[] nameIndex = new String[len];
    AtomicInteger ai = new AtomicInteger(0);
    int[] parameterIndices = finalParameterBinding.entrySet().stream().map(entry -> {
        String parameterName = entry.getValue();
        int pathIndex = ai.getAndIncrement();
        parameterPaths[pathIndex] = "";
        nameIndex[pathIndex] = entry.getKey();
        int i = parameterNames.indexOf(parameterName);
        if (i > -1) {
            return i;
        } else {
            int j = parameterName.indexOf('.');
            if (j > -1) {
                String prop = parameterName.substring(0, j);
                int paramIndex = parameterNames.indexOf(prop);
                parameterPaths[pathIndex] = paramIndex + "." + parameterName.substring(j + 1);
                return -1;
            } else {
                // -1 indicates special handling for parameters in roles etc.
                Map<String, Element> parametersInRole = methodMatchContext.getParametersInRole();
                for (Map.Entry<String, Element> roleEntry : parametersInRole.entrySet()) {
                    Element element = roleEntry.getValue();
                    if (element instanceof PropertyElement) {
                        String name = element.getName();
                        if (name.equals(parameterName)) {
                            parameterPaths[pathIndex] = name;
                            break;
                        }
                    }
                }
                return -1;
            }

        }
    }).mapToInt(i -> i).toArray();
    for (String member : members) {
        annotationBuilder.member(member, parameterIndices);
        annotationBuilder.member(member + "Paths", parameterPaths);
        if (includeNames) {
            annotationBuilder.member(member + "Names", nameIndex);
        }
    }


}
 
Example #17
Source File: AbstractQueryInterceptor.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
private <RT> void storeInParameterValues(
        MethodInvocationContext<T, R> context,
        StoredQuery<?, RT> storedQuery,
        Map<String, Object> namedValues,
        Object index,
        String argument,
        Map parameterValues) {
    if (namedValues.containsKey(argument)) {
        parameterValues.put(index, namedValues.get(argument));
    } else {
        String v = storedQuery.getLastUpdatedProperty();
        if (v != null && v.equals(argument)) {

            Class<?> rootEntity = storedQuery.getRootEntity();
            Class<?> lastUpdatedType = getLastUpdatedType(rootEntity, v);
            if (lastUpdatedType == null) {
                throw new IllegalStateException("Could not establish last updated time for entity: " + rootEntity);
            }
            Object timestamp = ConversionService.SHARED.convert(OffsetDateTime.now(), lastUpdatedType).orElse(null);
            if (timestamp == null) {
                throw new IllegalStateException("Unsupported date type: " + lastUpdatedType);
            }
            parameterValues.put(index, timestamp);
        } else {
            int i = argument.indexOf('.');
            if (i > -1) {
                String argumentName = argument.substring(0, i);
                Object o = namedValues.get(argumentName);
                if (o != null) {
                    try {
                        BeanWrapper<Object> wrapper = BeanWrapper.getWrapper(o);
                        String prop = argument.substring(i + 1);
                        Object val = wrapper.getRequiredProperty(prop, Object.class);
                        parameterValues.put(index, val);
                    } catch (IntrospectionException e) {
                        throw new DataAccessException("Embedded value [" + o + "] should be annotated with introspected");
                    }
                }
            } else {
                Optional<Argument> named = Arrays.stream(context.getArguments())
                        .filter(arg -> {
                            String n = arg.getAnnotationMetadata().stringValue(Parameter.class).orElse(arg.getName());
                            return n.equals(argument);
                        })
                        .findFirst();
                if (named.isPresent()) {
                    parameterValues.put(index, namedValues.get(named.get().getName()));
                } else {
                    throw new IllegalArgumentException("Missing query arguments: " + argument);
                }
            }
        }


    }
}
 
Example #18
Source File: FlywayConfigurationProperties.java    From micronaut-flyway with Apache License 2.0 4 votes vote down vote up
/**
 * @param name The name qualifier.
 */
public FlywayConfigurationProperties(@Parameter String name) {
    this.nameQualifier = name;
}
 
Example #19
Source File: UpdateByMethod.java    From micronaut-data with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
protected MethodMatchInfo buildInfo(
        MethodMatchContext matchContext,
        @NonNull ClassElement queryResultType,
        @Nullable QueryModel query) {
    if (query == null) {
        matchContext.fail("Cannot implement batch update operation that doesn't perform a query");
        return null;
    }
    if (CollectionUtils.isNotEmpty(query.getProjections())) {
        matchContext.fail("Projections are not supported on batch updates");
        return null;
    }
    String[] updateProperties;
    if (!(query instanceof RawQuery)) {

        List<QueryModel.Criterion> criterionList = query.getCriteria().getCriteria();
        if (CollectionUtils.isEmpty(criterionList)) {
            matchContext.fail("Cannot implement batch update operation that doesn't perform a query");
            return null;
        }
        Set<String> queryParameters = new HashSet<>();
        for (QueryModel.Criterion criterion : criterionList) {
            if (criterion instanceof QueryModel.PropertyCriterion) {
                QueryModel.PropertyCriterion pc = (QueryModel.PropertyCriterion) criterion;
                Object v = pc.getValue();
                if (v instanceof QueryParameter) {
                    queryParameters.add(((QueryParameter) v).getName());
                }
            }
        }
        List<Element> updateParameters = Arrays.stream(matchContext.getParameters()).filter(p -> !queryParameters.contains(p.getName()))
                .collect(Collectors.toList());
        if (CollectionUtils.isEmpty(updateParameters)) {
            matchContext.fail("At least one parameter required to update");
            return null;
        }
        Element element = matchContext.getParametersInRole().get(TypeRole.LAST_UPDATED_PROPERTY);
        if (element instanceof PropertyElement) {
            updateParameters.add(element);
        }
        SourcePersistentEntity entity = matchContext.getRootEntity();
        updateProperties = new String[updateParameters.size()];
        for (int i = 0; i < updateProperties.length; i++) {
            Element parameter = updateParameters.get(i);
            String parameterName = parameter.stringValue(Parameter.class).orElse(parameter.getName());
            Optional<String> path = entity.getPath(parameterName);
            if (path.isPresent()) {
                updateProperties[i] = path.get();
            } else {
                matchContext.fail("Cannot perform batch update for non-existent property: " + parameterName);
                return null;
            }
        }
    } else {
        updateProperties = StringUtils.EMPTY_STRING_ARRAY;
    }
    return new MethodMatchInfo(
            queryResultType,
            query,
            getInterceptorElement(matchContext, UpdateMethod.pickUpdateInterceptor(matchContext.getReturnType())),
            MethodMatchInfo.OperationType.UPDATE,
            updateProperties
    );
}
 
Example #20
Source File: DatasourceConfiguration.java    From micronaut-sql with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor.
 * @param name name that comes from properties
 */
public DatasourceConfiguration(@Parameter String name) throws SQLException {
    super();
    this.name = name;
    this.calculatedSettings = new CalculatedSettings(this);
}
 
Example #21
Source File: StandardSkillFactory.java    From micronaut-aws with Apache License 2.0 4 votes vote down vote up
/**
 * @param alexaSkillConfiguration Alexa Skill Configuration
 * @return An Alexa Skill using the {@link AlexaSkillBuilder} and the {@link SkillBuilderProvider} bean.
 */
@EachBean(AlexaSkillConfiguration.class)
public AlexaSkill createStandardAlexaSkill(@Parameter AlexaSkillConfiguration alexaSkillConfiguration) {
    return alexaSkillBuilder.buildSkill(skillBuilderProvider.getSkillBuilder(), alexaSkillConfiguration);
}
 
Example #22
Source File: AlexaSkillConfigurationProperties.java    From micronaut-aws with Apache License 2.0 4 votes vote down vote up
/**
 * @param name The name of the configuration
 */
public AlexaSkillConfigurationProperties(@Parameter String name) {
    this.name = name;
}
 
Example #23
Source File: DatasourceConfiguration.java    From micronaut-sql with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor.
 * @param name name that comes from properties
 */
public DatasourceConfiguration(@Parameter String name) {
    super();
    this.name = name;
    this.calculatedSettings = new CalculatedSettings(this);
}
 
Example #24
Source File: DatasourceConfiguration.java    From micronaut-sql with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor.
 * @param name name that comes from properties
 */
public DatasourceConfiguration(@Parameter String name) {
    super();
    this.setName(name);
    this.calculatedSettings = new CalculatedSettings(this);
}
 
Example #25
Source File: DatasourceConfiguration.java    From micronaut-sql with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor.
 * @param name name configured from properties
 */
public DatasourceConfiguration(@Parameter String name) {
    super();
    this.name = name;
    this.calculatedSettings = new CalculatedSettings(this);
}
 
Example #26
Source File: JooqConfigurationFactory.java    From micronaut-sql with Apache License 2.0 4 votes vote down vote up
/**
 * Creates jOOQ {@link Configuration}.
 * It will configure it with available jOOQ provider beans with the same qualifier.
 *
 * @param name                   The data source name
 * @param dataSource             The {@link DataSource}
 * @param transactionProvider    The transaction provider
 * @param settings               The settings
 * @param executorProvider       The executor provider
 * @param recordMapperProvider   The record mapper provider
 * @param recordUnmapperProvider The record unmapper provider
 * @param metaProvider           The metadata provider
 * @param ctx                    The {@link ApplicationContext}
 * @return A {@link Configuration}
 */
@EachBean(DataSource.class)
public Configuration jooqConfiguration(
        @Parameter String name,
        DataSource dataSource,
        @Parameter @Nullable TransactionProvider transactionProvider,
        @Parameter @Nullable Settings settings,
        @Parameter @Nullable ExecutorProvider executorProvider,
        @Parameter @Nullable RecordMapperProvider recordMapperProvider,
        @Parameter @Nullable RecordUnmapperProvider recordUnmapperProvider,
        @Parameter @Nullable MetaProvider metaProvider,
        ApplicationContext ctx
) {
    DefaultConfiguration configuration = new DefaultConfiguration();

    JooqConfigurationProperties properties = ctx.findBean(JooqConfigurationProperties.class, Qualifiers.byName(name))
            .orElseGet(JooqConfigurationProperties::new);
    DataSourceResolver dataSourceResolver = ctx.findBean(DataSourceResolver.class).orElse(DataSourceResolver.DEFAULT);
    configuration.setSQLDialect(properties.determineSqlDialect(dataSourceResolver.resolve(dataSource)));

    configuration.setDataSource(dataSource);
    if (transactionProvider != null) {
        configuration.setTransactionProvider(transactionProvider);
    }
    if (settings != null) {
        configuration.setSettings(settings);
    }
    if (executorProvider != null) {
        configuration.setExecutorProvider(executorProvider);
    }
    if (recordMapperProvider != null) {
        configuration.setRecordMapperProvider(recordMapperProvider);
    }
    if (recordUnmapperProvider != null) {
        configuration.setRecordUnmapperProvider(recordUnmapperProvider);
    }
    if (metaProvider != null) {
        configuration.setMetaProvider(metaProvider);
    }
    configuration.setExecuteListenerProvider(ctx.getBeansOfType(ExecuteListenerProvider.class, Qualifiers.byName(name))
            .toArray(new ExecuteListenerProvider[0]));
    configuration.setRecordListenerProvider(ctx.getBeansOfType(RecordListenerProvider.class, Qualifiers.byName(name))
            .toArray(new RecordListenerProvider[0]));
    configuration.setVisitListenerProvider(ctx.getBeansOfType(VisitListenerProvider.class, Qualifiers.byName(name))
            .toArray(new VisitListenerProvider[0]));
    configuration.setTransactionListenerProvider(ctx.getBeansOfType(TransactionListenerProvider.class, Qualifiers.byName(name))
            .toArray(new TransactionListenerProvider[0]));
    configuration.setDiagnosticsListenerProvider(ctx.getBeansOfType(DiagnosticsListenerProvider.class, Qualifiers.byName(name))
            .toArray(new DiagnosticsListenerProvider[0]));

    return configuration;
}
 
Example #27
Source File: JsonSerde.java    From micronaut-kafka with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs a new instance for the given arguments.
 *
 * @param objectSerializer The {@link JacksonObjectSerializer}
 * @param type The target type
 */
@Inject
public JsonSerde(JacksonObjectSerializer objectSerializer, @Parameter Class<T> type) {
    this.objectSerializer = objectSerializer;
    this.type = type;
}
 
Example #28
Source File: DataJdbcConfiguration.java    From micronaut-data with Apache License 2.0 2 votes vote down vote up
/**
 * The configuration.
 * @param name The configuration name
 */
public DataJdbcConfiguration(@Parameter String name) {
    this.name = name;
}
 
Example #29
Source File: PersonReactiveRepository.java    From micronaut-data with Apache License 2.0 votes vote down vote up
Completable updatePerson(@Id Long id, @Parameter("name") String name); 
Example #30
Source File: AuthorRepository.java    From micronaut-data with Apache License 2.0 votes vote down vote up
void updateNickname(@Id Long id, @Parameter("nickName") @Nullable String nickName);