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

io.trino.plugin.hive.metastore.file.DatabaseMetadata Maven / Gradle / Ivy

There is a newer version: 468
Show newest version
/*
 * 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 io.trino.plugin.hive.metastore.file;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableMap;
import io.trino.metastore.Database;
import io.trino.spi.security.PrincipalType;

import java.util.Map;
import java.util.Optional;

import static java.util.Objects.requireNonNull;

public class DatabaseMetadata
{
    private final Optional writerVersion;
    private final Optional location;
    private final Optional ownerName;
    private final Optional ownerType;
    private final Map parameters;

    @JsonCreator
    public DatabaseMetadata(
            @JsonProperty("writerVersion") Optional writerVersion,
            @JsonProperty("location") Optional location,
            @JsonProperty("ownerName") Optional ownerName,
            @JsonProperty("ownerType") Optional ownerType,
            @JsonProperty("parameters") Map parameters)
    {
        this.writerVersion = requireNonNull(writerVersion, "writerVersion is null");
        this.location = requireNonNull(location, "location is null");
        this.ownerName = requireNonNull(ownerName, "ownerName is null");
        this.ownerType = requireNonNull(ownerType, "ownerType is null");
        this.parameters = ImmutableMap.copyOf(requireNonNull(parameters, "parameters is null"));
    }

    public DatabaseMetadata(String currentVersion, Database database)
    {
        this.writerVersion = Optional.of(requireNonNull(currentVersion, "currentVersion is null"));
        this.location = database.getLocation();
        this.ownerName = database.getOwnerName();
        this.ownerType = database.getOwnerType();
        this.parameters = database.getParameters();
    }

    @JsonProperty
    public Optional getWriterVersion()
    {
        return writerVersion;
    }

    @JsonProperty
    public Optional getLocation()
    {
        return location;
    }

    @JsonProperty
    public Optional getOwnerName()
    {
        return ownerName;
    }

    @JsonProperty
    public Optional getOwnerType()
    {
        return ownerType;
    }

    @JsonProperty
    public Map getParameters()
    {
        return parameters;
    }

    public Database toDatabase(String databaseName, String databaseMetadataDirectory)
    {
        return Database.builder()
                .setDatabaseName(databaseName)
                .setLocation(Optional.of(location.orElse(databaseMetadataDirectory)))
                .setOwnerName(ownerName)
                .setOwnerType(ownerType)
                .setParameters(parameters)
                .build();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy