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

com.speedment.runtime.config.Dbms Maven / Gradle / Ivy

Go to download

A Speedment bundle that shades all dependencies into one jar. This is useful when deploying an application on a server.

The newest version!
/*
 *
 * Copyright (c) 2006-2019, 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.config;

import com.speedment.runtime.config.exception.SpeedmentConfigException;
import com.speedment.runtime.config.internal.DbmsImpl;
import com.speedment.runtime.config.mutator.DbmsMutator;
import com.speedment.runtime.config.mutator.DocumentMutator;
import com.speedment.runtime.config.trait.HasAlias;
import com.speedment.runtime.config.trait.HasChildren;
import com.speedment.runtime.config.trait.HasDeepCopy;
import com.speedment.runtime.config.trait.HasEnabled;
import com.speedment.runtime.config.trait.HasId;
import com.speedment.runtime.config.trait.HasMainInterface;
import com.speedment.runtime.config.trait.HasMutator;
import com.speedment.runtime.config.trait.HasName;
import com.speedment.runtime.config.trait.HasParent;
import com.speedment.runtime.config.util.DocumentUtil;

import java.nio.file.Paths;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.stream.Stream;

/**
 * A typed {@link Document} that represents a dbms instance in the database. A
 * {@code Dbms} is located inside a {@link Project} and can have multiple 
 * {@link Schema Schemas} as children.
 * 
 * @author  Emil Forslund
 * @since   2.0.0
 */

public interface Dbms extends 
        Document,
        HasParent,
        HasEnabled,
        HasDeepCopy,
        HasId,        
        HasName,
        HasChildren,
        HasAlias,
        HasMainInterface,
        HasMutator> {

    /**
     * Returns the type name of the {@code DbmsType} of this {@code Dbms}. This
     * will be the fully qualified class name of the {@code DbmsType} 
     * implementing class.
     * 
     * @return  the type name
     */
    default String getTypeName() {
        return getAsString(DbmsUtil.TYPE_NAME).orElseThrow(() -> new SpeedmentConfigException(
            "Every " + Dbms.class.getSimpleName() + 
            " document is required to have the '" + 
            DbmsUtil.TYPE_NAME + "' attribute."
        ));
    }
    
    /**
     * Returns the address of the database host if it is specified. The address
     * could be an ip-address or a hostname. If no address is specified,
     * {@code empty} will be returned.
     *
     * @return the address of the host or {@code empty}
     */
    default Optional getIpAddress() {
        return getAsString(DbmsUtil.IP_ADDRESS);
    }
    
    /**
     * Returns the port number of the database on the database host. If no port
     * is specified, {@code empty} is returned.
     *
     * @return the port of the database or {@code empty}
     */
    default OptionalInt getPort() {
        return getAsInt(DbmsUtil.PORT);
    }

    /**
     * Returns the local path to the file where the data of this Dbms is stored.
     * The file name should be parsable using {@link Paths#get}. This property
     * is optional and not even supported in most database systems.
     *
     * @return the local path to the data file
     */
    default Optional getLocalPath() {
        return getAsString(DbmsUtil.LOCAL_PATH);
    }
    
    /**
     * Returns the explicit connection URL to use for this {@code Dbms} if the
     * user has specified one, or an empty {@code Optional} if one should be
     * generated automatically by the {@code DbmsType}.
     * 
     * @return  the explicit connection URL to use for this {@code Dbms}
     */
    default Optional getConnectionUrl() {
        return getAsString(DbmsUtil.CONNECTION_URL);
    }
    
    /**
     * Returns the database username to use when connecting to the dbms. If no
     * username is specified, {@code empty} is returned.
     *
     * @return the database username or {@code empty}
     */
    default Optional getUsername() {
        return getAsString(DbmsUtil.USERNAME);
    }
    
    /**
     * Creates a stream of schemas located in this document.
     * 
     * @return  schemas
     */
    Stream schemas();

    @Override
    default Class mainInterface() {
        return Dbms.class;
    }  
    
    @Override
    default DbmsMutator mutator() {
        return DocumentMutator.of(this);
    }

    @Override
    default Dbms deepCopy() {
        return DocumentUtil.deepCopy(this, DbmsImpl::new);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy