Java Code Examples for io.micronaut.core.util.StringUtils

The following examples show how to use io.micronaut.core.util.StringUtils. 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-aws   Source File: EC2ServiceInstance.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Container to hold AWS EC2 Instance info.
 * @param id if of the instance
 * @param uri uri to access this instance
 */
public EC2ServiceInstance(String id, URI uri) {
    this.id = id;

    String userInfo = uri.getUserInfo();
    if (StringUtils.isNotEmpty(userInfo)) {
        try {
            this.uri = new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment());
            this.metadata = ConvertibleValues.of(Collections.singletonMap(
                HttpHeaders.AUTHORIZATION_INFO, userInfo
            ));
        } catch (URISyntaxException e) {
            throw new IllegalStateException("ServiceInstance URI is invalid: " + e.getMessage(), e);
        }
    } else {
        this.uri = uri;
    }
}
 
Example 2
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 3
Source Project: micronaut-data   Source File: ProjectionMethodExpression.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected ProjectionMethodExpression initProjection(@NonNull MethodMatchContext matchContext, String remaining) {
    if (StringUtils.isEmpty(remaining)) {
        this.expectedType = matchContext.getRootEntity().getType();
        return this;
    } else {
        this.property = NameUtils.decapitalize(remaining);
        SourcePersistentProperty pp = matchContext.getRootEntity().getPropertyByName(property);
        if (pp == null || pp.getType() == null) {
            matchContext.fail("Cannot project on non-existent property " + property);
            return null;
        }
        this.expectedType = pp.getType();
        return this;
    }
}
 
Example 4
Source Project: micronaut-data   Source File: ProjectionMethodExpression.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected ProjectionMethodExpression initProjection(@NonNull MethodMatchContext matchContext, String remaining) {
    if (StringUtils.isEmpty(remaining)) {
        matchContext.fail(getClass().getSimpleName() + " projection requires a property name");
        return null;
    } else {

        this.property = NameUtils.decapitalize(remaining);
        this.persistentProperty = (SourcePersistentProperty) matchContext.getRootEntity().getPropertyByPath(property).orElse(null);
        if (persistentProperty == null || persistentProperty.getType() == null) {
            matchContext.fail("Cannot project on non-existent property " + property);
            return null;
        }
        this.expectedType = resolveExpectedType(matchContext, persistentProperty.getType());
        return this;
    }
}
 
Example 5
Source Project: micronaut-data   Source File: NamingStrategy.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 6
Source Project: micronaut-graphql   Source File: GraphQLWsMessageHandler.java    License: Apache License 2.0 6 votes vote down vote up
private Publisher<GraphQLWsResponse> startOperation(GraphQLWsRequest request, WebSocketSession session) {
    if (request.getId() == null) {
        LOG.warn("GraphQL operation id is required with type start");
        return Flowable.just(new GraphQLWsResponse(GQL_ERROR));
    }

    if (state.operationExists(request, session)) {
        LOG.info("Already subscribed to operation {} in session {}", request.getId(), session.getId());
        return Flowable.empty();
    }

    GraphQLRequestBody payload = request.getPayload();
    if (payload == null || StringUtils.isEmpty(payload.getQuery())) {
        LOG.info("Payload was null or query empty for operation {} in session {}", request.getId(),
                 session.getId());
        return Flowable.just(new GraphQLWsResponse(GQL_ERROR, request.getId()));
    }

    return executeRequest(request.getId(), payload, session);
}
 
Example 7
Source Project: micronaut-spring   Source File: MicronautBeanFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public @Nonnull
String[] getBeanNamesForType(Class<?> type, boolean includeNonSingletons, boolean allowEagerInit) {
    // ignore certain common cases
    if (type == null || Object.class == type || List.class == type || beanExcludes.contains(type)) {
        return StringUtils.EMPTY_STRING_ARRAY;
    }
    String[] names = beanNamesForTypeCache.get(type);
    if (names == null) {
        final String[] superResult = MicronautBeanFactory.super.getBeanNamesForType(type, includeNonSingletons, allowEagerInit);
        if (ArrayUtils.isNotEmpty(superResult)) {
            names = superResult;
        } else {
            final Collection<? extends BeanDefinition<?>> beanDefinitions = beanContext.getBeanDefinitions(type);
            names = beansToNames(beanDefinitions);
        }
        beanNamesForTypeCache.put(type, names);
    }
    return names;
}
 
Example 8
Source Project: micronaut-spring   Source File: BeanAnnotationMapper.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    List<AnnotationValue<?>> newAnnotations = new ArrayList<>(3);
    final AnnotationValueBuilder<Bean> beanAnn = AnnotationValue.builder(Bean.class);

    final Optional<String> destroyMethod = annotation.get("destroyMethod", String.class);
    destroyMethod.ifPresent(s -> beanAnn.member("preDestroy", s));
    newAnnotations.add(beanAnn.build());
    newAnnotations.add(AnnotationValue.builder(DefaultScope.class)
            .value(Singleton.class)
            .build());
    final String beanName = annotation.getValue(String.class).orElse(annotation.get("name", String.class).orElse(null));

    if (StringUtils.isNotEmpty(beanName)) {
        newAnnotations.add(AnnotationValue.builder(Named.class).value(beanName).build());
    }

    return newAnnotations;
}
 
Example 9
Source Project: micronaut-gcp   Source File: GoogleMethodRouteBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected UriRoute buildBeanRoute(String httpMethodName, HttpMethod httpMethod, String uri, BeanDefinition<?> beanDefinition, ExecutableMethod<?, ?> method) {
    String cp = contextPathProvider.getContextPath();
    if (cp != null) {
        uri = StringUtils.prependUri(cp, uri);
    }
    return super.buildBeanRoute(httpMethodName, httpMethod, uri, beanDefinition, method);
}
 
Example 10
Source Project: micronaut-aws   Source File: MicronautAwsProxyRequest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Default constructor.
 *
 * @param path            The path
 * @param awsProxyRequest The underlying request
 * @param securityContext The {@link SecurityContext}
 * @param lambdaContext   The lambda context
 * @param config          The container configuration
 */
MicronautAwsProxyRequest(
        String path,
        AwsProxyRequest awsProxyRequest,
        SecurityContext securityContext,
        Context lambdaContext,
        ContainerConfig config) {
    this.config = config;
    this.awsProxyRequest = awsProxyRequest;
    this.path = path;
    final String httpMethod = awsProxyRequest.getHttpMethod();
    this.httpMethod = StringUtils.isNotEmpty(httpMethod) ? HttpMethod.valueOf(httpMethod) : HttpMethod.GET;
    final Headers multiValueHeaders = awsProxyRequest.getMultiValueHeaders();
    this.headers = multiValueHeaders != null ? new AwsHeaders() : new SimpleHttpHeaders(ConversionService.SHARED);
    final MultiValuedTreeMap<String, String> params = awsProxyRequest.getMultiValueQueryStringParameters();
    this.parameters = params != null ? new AwsParameters() : new SimpleHttpParameters(ConversionService.SHARED);

    final AwsProxyRequestContext requestContext = awsProxyRequest.getRequestContext();
    setAttribute(API_GATEWAY_CONTEXT_PROPERTY, requestContext);
    setAttribute(API_GATEWAY_STAGE_VARS_PROPERTY, awsProxyRequest.getStageVariables());
    setAttribute(API_GATEWAY_EVENT_PROPERTY, awsProxyRequest);
    if (requestContext != null) {
        setAttribute(ALB_CONTEXT_PROPERTY, requestContext.getElb());
    }
    setAttribute(LAMBDA_CONTEXT_PROPERTY, lambdaContext);
    setAttribute(JAX_SECURITY_CONTEXT_PROPERTY, config);
    if (securityContext != null && requestContext != null) {
        setAttribute("micronaut.AUTHENTICATION", securityContext.getUserPrincipal());
    }
}
 
Example 11
Source Project: micronaut-aws   Source File: MicronautAwsProxyRequest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getAll(CharSequence name) {
    if (StringUtils.isNotEmpty(name)) {
        final List<String> strings = params.get(name.toString());
        if (CollectionUtils.isNotEmpty(strings)) {
            return strings.stream().map(v -> decodeValue(name, v)).collect(Collectors.toList());
        }
    }
    return Collections.emptyList();
}
 
Example 12
Source Project: micronaut-aws   Source File: MicronautAwsProxyRequest.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public String get(CharSequence name) {
    if (StringUtils.isNotEmpty(name)) {
        final String v = params.getFirst(name.toString());
        if (v != null) {
            return decodeValue(name, v);
        }
        return v;
    }
    return null;
}
 
Example 13
Source Project: micronaut-aws   Source File: MicronautAwsProxyRequest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getAll(CharSequence name) {
    if (StringUtils.isNotEmpty(name)) {
        final List<String> strings = multiValueHeaders.get(name.toString());
        if (CollectionUtils.isNotEmpty(strings)) {
            return strings;
        }
    }
    return Collections.emptyList();
}
 
Example 14
Source Project: micronaut-aws   Source File: MicronautAwsProxyRequest.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 15
Source Project: micronaut-aws   Source File: MicronautAwsProxyResponse.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getAll(CharSequence name) {
    if (StringUtils.isNotEmpty(name)) {
        return multiValueHeaders.get(name.toString());
    }
    return Collections.emptyList();
}
 
Example 16
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 17
Source Project: micronaut-aws   Source File: AnnotatedRequestHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
default boolean canHandle(HandlerInput handlerInput) {
    final Class<? extends AnnotatedRequestHandler> type = getClass();
    final String annotationMetadata = type.getPackage().getName() + ".$" + type.getSimpleName() + "DefinitionClass";
    final AnnotationMetadata metadata = ClassUtils.forName(annotationMetadata, type.getClassLoader()).flatMap(aClass -> {
        final Object o = InstantiationUtils.tryInstantiate(aClass).orElse(null);
        if (o instanceof AnnotationMetadataProvider) {
            return Optional.of(((AnnotationMetadataProvider) o).getAnnotationMetadata());
        }
        return Optional.empty();
    }).orElse(AnnotationMetadata.EMPTY_METADATA);
    final String[] names = metadata.getValue(IntentHandler.class, String[].class).orElse(StringUtils.EMPTY_STRING_ARRAY);
    return Arrays.stream(names).anyMatch(n -> handlerInput.matches(intentName(n)));
}
 
Example 18
/**
 * Get the X-Ray tracing header from the Lambda-Runtime-Trace-Id header in the API response.
 * Set the _X_AMZN_TRACE_ID environment variable with the same value for the X-Ray SDK to use.
 * @param headers next API Response HTTP Headers
 */
@SuppressWarnings("EmptyBlock")
protected void propagateTraceId(HttpHeaders headers) {
    String traceId = headers.get(LambdaRuntimeInvocationResponseHeaders.LAMBDA_RUNTIME_TRACE_ID);
    logn(LogLevel.DEBUG, "Trace id: " + traceId + "\n");
    if (StringUtils.isNotEmpty(traceId)) {
        //TODO Set Env.variable _X_AMZN_TRACE_ID with value traceId
    }
}
 
Example 19
private URL lookupRuntimeApiEndpoint() throws MalformedURLException {
    final String runtimeApiEndpoint = getEnv(ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_RUNTIME_API);
    if (StringUtils.isEmpty(runtimeApiEndpoint)) {
        throw new IllegalStateException("Missing " + ReservedRuntimeEnvironmentVariables.AWS_LAMBDA_RUNTIME_API + " environment variable. Custom runtime can only be run within AWS Lambda environment.");
    }
    return new URL("http://" + runtimeApiEndpoint);
}
 
Example 20
Source Project: micronaut-grpc   Source File: GrpcNameResolverFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * A GRPC name resolver factory that integrates with Micronaut's discovery client.
 * @param discoveryClient The discovery client
 * @param serviceInstanceLists The service instance list
 * @return The name resolver
 */
@Singleton
@Requires(beans = DiscoveryClient.class)
@Requires(property = ENABLED, value = StringUtils.TRUE, defaultValue = StringUtils.FALSE)
protected NameResolver.Factory nameResolverFactory(
        DiscoveryClient discoveryClient,
        List<ServiceInstanceList> serviceInstanceLists) {
    return new GrpcNameResolverProvider(discoveryClient, serviceInstanceLists);
}
 
Example 21
Source Project: micronaut-grpc   Source File: GrpcChannelScope.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <T> T get(
        BeanResolutionContext resolutionContext,
        BeanDefinition<T> beanDefinition,
        BeanIdentifier identifier,
        Provider<T> provider) {
    BeanResolutionContext.Segment segment = resolutionContext.getPath().currentSegment().orElseThrow(() ->
            new IllegalStateException("@GrpcChannel used in invalid location")
    );
    Argument argument = segment.getArgument();
    String value = argument.getAnnotationMetadata().getValue(GrpcChannel.class, String.class).orElse(null);
    if (StringUtils.isEmpty(value)) {
        throw new DependencyInjectionException(resolutionContext, argument, "No value specified to @GrpcChannel annotation");
    }
    if (!Channel.class.isAssignableFrom(argument.getType())) {
        throw new DependencyInjectionException(resolutionContext, argument, "@GrpcChannel used on type that is not a Channel");
    }

    if ("grpc-server".equalsIgnoreCase(value)) {
        return (T) applicationContext.getBean(ManagedChannel.class, Qualifiers.byName("grpc-server"));
    }

    if (!(provider instanceof ParametrizedProvider)) {
        throw new DependencyInjectionException(resolutionContext, argument, "GrpcChannelScope called with invalid bean provider");
    }
    value = applicationContext.resolveRequiredPlaceholders(value);
    String finalValue = value;
    return (T) channels.computeIfAbsent(new ChannelKey(identifier, value), channelKey ->
            (ManagedChannel) ((ParametrizedProvider<T>) provider).get(finalValue)
    );
}
 
Example 22
Source Project: micronaut-sql   Source File: PgClientFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a connection pool to the database configured with the
 * {@link PgClientConfiguration}.
 * @return A pool of connections.
 */
private PgPool createClient() {
    PgClientConfiguration configuration = this.connectionConfiguration;
    String connectionUri = configuration.getUri();
    if (StringUtils.isNotEmpty(connectionUri)) {
        return PgPool.pool(connectionUri, configuration.poolOptions);
    } else {
        return PgPool.pool(configuration.connectOptions, configuration.poolOptions);
    }
}
 
Example 23
Source Project: micronaut-sql   Source File: PgClientFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a connection pool to the database configured with the {@link PgClientConfiguration }.
 * @param vertx The Vertx instance.
 * @return A pool of connections.
 */
private PgPool createClient(Vertx vertx) {
    PgClientConfiguration configuration = this.connectionConfiguration;
    String connectionUri = configuration.getUri();
    if (StringUtils.isNotEmpty(connectionUri)) {
        return PgPool.pool(vertx, connectionUri, configuration.poolOptions);
    } else {
        return PgPool.pool(vertx, configuration.connectOptions, configuration.poolOptions);
    }
}
 
Example 24
Source Project: micronaut-sql   Source File: CalculatedSettings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Determines the driver class name based on the configured value. If not
 * configured, determine the driver class name based on the URL. If the
 * URL is not configured, look for an embedded database driver on the
 * classpath.
 *
 * @return The calculated driver class name
 */
public String getDriverClassName() {
    final String driverClassName = basicJdbcConfiguration.getConfiguredDriverClassName();
    if (calculatedDriverClassName == null || StringUtils.hasText(driverClassName)) {
        if (StringUtils.hasText(driverClassName)) {
            if (!driverClassIsPresent(driverClassName)) {
                throw new ConfigurationException(String.format("Error configuring data source '%s'. The driver class '%s' was not found on the classpath", basicJdbcConfiguration.getName(), driverClassName));
            }
            calculatedDriverClassName = driverClassName;
        } else {
            final String url = basicJdbcConfiguration.getUrl();
            if (StringUtils.hasText(url)) {
                JdbcDatabaseManager.findDatabase(url).ifPresent(db ->
                    calculatedDriverClassName = db.getDriverClassName());
            }

            if (!StringUtils.hasText(calculatedDriverClassName) && embeddedDatabaseConnection.isPresent()) {
                calculatedDriverClassName = this.embeddedDatabaseConnection.get().getDriverClassName();
            }

            if (!StringUtils.hasText(calculatedDriverClassName)) {
                throw new ConfigurationException(String.format("Error configuring data source '%s'. No driver class name specified", basicJdbcConfiguration.getName()));
            }
        }
    }

    return calculatedDriverClassName;
}
 
Example 25
Source Project: micronaut-sql   Source File: CalculatedSettings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Determines the URL based on the configured value. If the URL is
 * not configured, search for an embedded database driver on the
 * classpath and retrieve a default URL for it.
 *
 * @return The calculated URL
 */
public String getUrl() {
    final String url = basicJdbcConfiguration.getConfiguredUrl();
    if (calculatedUrl == null || StringUtils.hasText(url)) {
        calculatedUrl = url;
        if (!StringUtils.hasText(calculatedUrl) && embeddedDatabaseConnection.isPresent()) {
            calculatedUrl = embeddedDatabaseConnection.get().getUrl(basicJdbcConfiguration.getName());
        }
        if (!StringUtils.hasText(calculatedUrl)) {
            throw new ConfigurationException(String.format("Error configuring data source '%s'. No URL specified", basicJdbcConfiguration.getName()));
        }
    }

    return calculatedUrl;
}
 
Example 26
Source Project: micronaut-sql   Source File: CalculatedSettings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Determines the username based on the configured value. If the
 * username is not configured and an embedded database driver is
 * on the classpath, return 'sa'.
 *
 * @return The calculated username
 */
public String getUsername() {
    final String username = basicJdbcConfiguration.getConfiguredUsername();
    if (calculatedUsername == null || StringUtils.hasText(username)) {
        calculatedUsername = username;
        if (!StringUtils.hasText(calculatedUsername) && JdbcDatabaseManager.isEmbedded(basicJdbcConfiguration.getDriverClassName())) {
            calculatedUsername = "sa";
        }
    }

    return calculatedUsername;
}
 
Example 27
Source Project: micronaut-sql   Source File: CalculatedSettings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Determines the password based on the configured value. If the
 * password is not configured and an embedded database driver is
 * on the classpath, return an empty string.
 *
 * @return The calculated password
 */
public String getPassword() {
    final String password = basicJdbcConfiguration.getConfiguredPassword();
    if (calculatedPassword == null || StringUtils.hasText(password)) {
        calculatedPassword = password;
        if (!StringUtils.hasText(calculatedPassword) && JdbcDatabaseManager.isEmbedded(basicJdbcConfiguration.getDriverClassName())) {
            calculatedPassword = "";
        }
    }

    return calculatedPassword;
}
 
Example 28
Source Project: micronaut-sql   Source File: CalculatedSettings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Determines the validation query based on the configured value. If the
 * validation query is not configured, search pre-defined databases for
 * a match based on the URL. If a match is found, return the defined
 * validation query for that database.
 *
 * @return The calculated validation query
 */
public String getValidationQuery() {
    final String validationQuery = basicJdbcConfiguration.getConfiguredValidationQuery();
    if (calculatedValidationQuery == null || StringUtils.hasText(validationQuery)) {
        calculatedValidationQuery = validationQuery;
        if (!StringUtils.hasText(calculatedValidationQuery)) {
            JdbcDatabaseManager.findDatabase(getUrl()).ifPresent(db ->
                calculatedValidationQuery = db.getValidationQuery());
        }
    }

    return calculatedValidationQuery;
}
 
Example 29
Source Project: micronaut-sql   Source File: JdbcDatabaseManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Searches defined database where the URL prefix matches one of the prefixes defined in a {@link JdbcDatabase}.
 * The prefix is determined by:
 * <p>
 * jdbc:<prefix>:...
 *
 * @param jdbcUrl The connection URL
 * @return An optional {@link JdbcDatabase}
 */
@SuppressWarnings("MagicNumber")
public static Optional<JdbcDatabase> findDatabase(String jdbcUrl) {
    if (StringUtils.isNotEmpty(jdbcUrl)) {
        if (!jdbcUrl.startsWith("jdbc")) {
            throw new IllegalArgumentException("Invalid JDBC URL [" + jdbcUrl + "]. JDBC URLs must start with 'jdbc'.");
        }
        String partialUrl = jdbcUrl.substring(5);
        String prefix = partialUrl.substring(0, partialUrl.indexOf(':')).toLowerCase();

        return databases.stream().filter(db -> db.containsPrefix(prefix)).findFirst();
    }
    return Optional.empty();
}
 
Example 30
Source Project: micronaut-sql   Source File: MySQLClientFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a connection pool to the database configured with the
 * {@link MySQLClientConfiguration}.
 * @return A pool of connections.
 */
private MySQLPool createClient() {
    MySQLClientConfiguration configuration = this.connectionConfiguration;
    String connectionUri = configuration.getUri();
    if (StringUtils.isNotEmpty(connectionUri)) {
        return MySQLPool.pool(connectionUri, configuration.poolOptions);
    } else {
        return MySQLPool.pool(configuration.connectOptions, configuration.poolOptions);
    }
}