All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.speedment.runtime.core.ApplicationBuilder Maven / Gradle / Ivy

/**
 *
 * Copyright (c) 2006-2016, Speedment, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); You may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.speedment.runtime.core;

import com.speedment.common.injector.InjectBundle;
import com.speedment.common.injector.Injector;
import com.speedment.common.injector.annotation.ExecuteBefore;
import com.speedment.common.injector.annotation.Inject;
import com.speedment.runtime.config.Document;
import com.speedment.runtime.config.trait.HasEnabled;
import com.speedment.runtime.core.internal.DefaultApplicationBuilder;
import com.speedment.runtime.core.internal.DefaultApplicationMetadata;
import com.speedment.runtime.core.internal.EmptyApplicationMetadata;
import com.speedment.runtime.core.manager.Manager;

import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * Builder class for producing new {@link Speedment} instances.
 *
 * @param       application that is built
 * @param   the type of this builder
 *
 * @author  Emil Forslund
 * @since   3.0.0
 */
public interface ApplicationBuilder> {
    
    /**
     * The type of logging to change the settings for.
     */
    enum LogType {
        
        /**
         * Logging related to querying the data source.
         */
        STREAM, 
        
        /**
         * Logging related to persisting new entities into the data source.
         */
        PERSIST, 
        
        /**
         * Logging related to updating existing entities in the data source.
         */
        UPDATE, 
        
        /**
         * Logging related to removing entities from the data source.
         */
        REMOVE, 
        
        /**
         * Logging related to configurating the application platform, dependency 
         * injection, component configuration etc.
         */
        APPLICATION_BUILDER
    }

    /**
     * Configures a parameter for the named {@link Document} of a certain class.
     * The consumer will then be applied after the configuration has been read
     * and after the System properties have been applied.
     *
     * @param        the type of {@link Document} that is to be used
     * @param type      the class of the type of {@link Document} that is to be used
     * @param name      the fully qualified name of the {@link Document}.
     * @param consumer  the consumer to apply
     * @return          this instance
     */
    default  BUILDER with(Class type, String name, Consumer consumer) {
        return with(type, name, (app, t) -> consumer.accept(t));
    }

    /**
     * Configures a parameter for the named {@link Document} of a certain class.
     * The consumer will then be applied after the configuration has been read
     * and after the System properties have been applied.
     *
     * @param        the type of {@link Document} that is to be used
     * @param type      the class of the type of {@link Document} that is to be used
     * @param name      the fully qualified name of the {@link Document}.
     * @param consumer  the consumer to apply
     * @return          this instance
     */
     BUILDER with(Class type, String name, BiConsumer consumer);

    /**
     * Configures a parameter for all {@link Document} of a certain class. The
     * consumer will then be applied after the configuration has been read and
     * after the System properties have been applied.
     *
     * @param        the type of {@link Document} that is to be used
     * @param type      the class of the type of {@link Document} that is to be used
     * @param consumer  the consumer to apply
     * @return          this instance
     */
    default  BUILDER with(Class type, Consumer consumer) {
        return with(type, (app, t) -> consumer.accept(t));
    }

    /**
     * Configures a parameter for all {@link Document} of a certain class. The
     * consumer will then be applied after the configuration has been read and
     * after the System properties have been applied.
     *
     * @param        the type of {@link Document} that is to be used
     * @param type      the class of the type of {@link Document} that is to be used
     * @param consumer  the consumer to apply
     * @return          this instance
     */
     BUILDER with(Class type, BiConsumer consumer);

    /**
     * Sets a config parameter that will be set automatically in all instances
     * created during initialization. This parameter can override settings in
     * the settings file.
     *
     * @param key    the key to set
     * @param value  the new value
     * @return       this instance
     */
    BUILDER withParam(String key, String value);

    /**
     * Configures a password for all dbmses in this project. The password will
     * then be applied after the configuration has been read and after the
     * System properties have been applied.
     * 

* This will not be saved in any configuration files! * * @param password to use for all dbms:es in this project * @return this instance */ BUILDER withPassword(char[] password); /** * Configures a password for the named dbms. The password will then be * applied after the configuration has been read and after the System * properties have been applied. *

* This will not be saved in any configuration files! * * @param dbmsName the name of the dbms * @param password to use for the named dbms * @return this instance */ BUILDER withPassword(String dbmsName, char[] password); /** * Configures a password for all dbmses in this project. The password will * then be applied after the configuration has been read and after the * System properties have been applied. *

* This will not be saved in any configuration files! * * @param password to use for all dbms:es in this project * @return this instance */ BUILDER withPassword(String password); /** * Configures a password for the named dbms. The password will then be * applied after the configuration has been read and after the System * properties have been applied. *

* This will not be saved in any configuration files! * * @param dbmsName the name of the dbms * @param password to use for the named dbms * @return this instance */ BUILDER withPassword(String dbmsName, String password); /** * Configures a username for all dbmses in this project. The username will * then be applied after the configuration has been read and after the * System properties have been applied. * * @param username to use for all dbms:es in this project * @return this instance */ BUILDER withUsername(String username); /** * Configures a username for the named dbms. The username will then be * applied after the configuration has been read and after the System * properties have been applied. * * @param dbmsName the name of the dbms * @param username to use for the named dbms * @return this instance */ BUILDER withUsername(String dbmsName, String username); /** * Configures an IP-address for all dbmses in this project. The IP-address * will then be applied after the configuration has been read and after the * System properties have been applied. * * @param ipAddress to use for all dbms:es in this project * @return this instance */ BUILDER withIpAddress(String ipAddress); /** * Configures an IP-address for the named dbms. The IP-address will then be * applied after the configuration has been read and after the System * properties have been applied. * * @param dbmsName the name of the dbms * @param ipAddress to use for the named dbms. * @return this instance */ BUILDER withIpAddress(String dbmsName, String ipAddress); /** * Configures a port for all dbmses in this project. The port will then be * applied after the configuration has been read and after the System * properties have been applied. * * @param port to use for all dbms:es in this project * @return this instance */ BUILDER withPort(int port); /** * Configures a port for the named dbms. The port will then be applied after * the configuration has been read and after the System properties have been * applied. * * @param dbmsName the name of the dbms * @param port to use for the named dbms * @return this instance */ BUILDER withPort(String dbmsName, int port); /** * Configures a new schema name for all schemas in this project. The new * schema name will then be applied after the configuration has been read * and after the System properties have been applied. *

* This method is useful for multi-tenant projects where there are several * identical schemas separated only by their names. * * @param schemaName to use for all schemas this project * @return this instance */ BUILDER withSchema(String schemaName); /** * Configures a new schema name for the named old schema name. The new * schema name will then be applied after the configuration has been read * and after the System properties have been applied. *

* This method is useful for multi-tenant projects where there are several * identical schemas separated only by their names. * * @param oldSchemaName the current name of a schema * @param schemaName to use for the named schema * @return this instance */ BUILDER withSchema(String oldSchemaName, String schemaName); /** * Configures a connection URL for all dbmses in this project. The new * connection URL will then be applied after the configuration has been read * and after the System properties have been applied. If the connectionUrl * is set to {@code null}, the connection URL will be calculated using the * dbmses' default connection URL generator (e.g. using ipAddress, port, * etc). *

* * @param connectionUrl to use for all dbms this project or null * @return this instance */ BUILDER withConnectionUrl(String connectionUrl); /** * Configures a connection URL for the named dbms in this project. The new * connection URL will then be applied after the configuration has been read * and after the System properties have been applied. If the connectionUrl * is set to {@code null}, the connection URL will be calculated using the * dbmses' default connection URL generator (e.g. using ipAddress, port, * etc). * * @param dbmsName the name of the dbms * @param connectionUrl to use for the named dbms or null * @return this instance */ BUILDER withConnectionUrl(String dbmsName, String connectionUrl); /** * Sets that the initial database check shall be skipped upon build(). * * @return this instance */ BUILDER withSkipCheckDatabaseConnectivity(); /** * Sets that the initial validation of the configuration shall be skipped * upon build(). Useful for testing. * * * @return this instance */ BUILDER withSkipValidateRuntimeConfig(); /** * Sets that the logo printout shall be skipped upon build(). * * * @return this instance */ BUILDER withSkipLogoPrintout(); /** * Adds a custom manager. * * @param the manager type * @param managerImplType the manager implementation class * @return this instance */ > BUILDER withManager(Class managerImplType); /** * Adds a custom component implementation class. The specified class will be * instantiated using its default constructor and fields annotated with * {@link Inject} will be dependency injected. Methods annotated with * {@link ExecuteBefore} will also be executed as part of the application * configuration phase. * * @param componentClass the implementation class * @return this instance */ BUILDER withComponent(Class componentClass); /** * Adds a custom component implementation class. The specified class will be * instantiated using its default constructor and fields annotated with * {@link Inject} will be dependency injected. Methods annotated with * {@link ExecuteBefore} will also be executed as part of the application * configuration phase. * * @param key the key to store it under * @param componentClass the implementation class * @return this instance */ BUILDER withComponent(String key, Class componentClass); /** * Adds a custom bundle of dependency injectable implementation classes. *

* The specified classes will be instantiated using its default constructor * and fields annotated with {@link Inject} will be dependency injected. * Methods annotated with {@link ExecuteBefore} will also be executed as * part of the application configuration phase. * * @param bundleClass to use when adding injectables * @return this instance */ BUILDER withBundle(Class bundleClass); /** * Adds a logging configuration to the application. * * @param logType to turn on * @return this instance */ BUILDER withLogging(LogType logType); /** * Builds this application. This is expected to be the last method called on * this object. * * @return the built application */ APP build(); /** * Creates and returns a new empty {@code ApplicationBuilder}. * * @param ApplicationBuilder type * @return a new empty ApplicationBuilder */ @SuppressWarnings("unchecked") static > BUILDER empty() { return (BUILDER) new DefaultApplicationBuilder(EmptyApplicationMetadata.class); } /** * Creates and returns a new standard ApplicationBuilder. The configuration * is read from a JSON file. * * @param ApplicationBuilder type * @return a new standard ApplicationBuilder */ @SuppressWarnings("unchecked") static > BUILDER standard() { return (BUILDER) new DefaultApplicationBuilder(DefaultApplicationMetadata.class); } /** * Creates and returns a new ApplicationBuilder configured with the given * ApplicationMetadata class. * * @param ApplicationBuilder type * @param applicationMetadataclass with configuration * * @return a new ApplicationBuilder configured with the given * ApplicationMetadata class */ @SuppressWarnings("unchecked") static > BUILDER create(Class applicationMetadataclass) { return (BUILDER) new DefaultApplicationBuilder(applicationMetadataclass); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy