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

com.github.jinahya.database.metadata.bind.Function Maven / Gradle / Ivy

package com.github.jinahya.database.metadata.bind;

/*-
 * #%L
 * database-metadata-bind
 * %%
 * Copyright (C) 2011 - 2019 Jinahya, Inc.
 * %%
 * 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.
 * #L%
 */

import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

import java.sql.DatabaseMetaData;
import java.util.Comparator;
import java.util.Optional;

import static java.util.Comparator.naturalOrder;
import static java.util.Comparator.nullsFirst;

/**
 * A class for binding the results of
 * {@link DatabaseMetaData#getFunctions(java.lang.String, java.lang.String, java.lang.String)} method.
 *
 * @author Jin Kwon <jinahya_at_gmail.com>
 * @see Context#getFunctions(String, String, String)
 */
@_ParentOf(FunctionColumn.class)
@Setter
@Getter
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SuperBuilder(toBuilder = true)
public class Function extends AbstractMetadataType {

    private static final long serialVersionUID = -3318947900237453301L;

    static final Comparator CASE_INSENSITIVE_ORDER =
            Comparator.comparing(Function::getSchemaId, SchemaId.CASE_INSENSITIVE_ORDER)
                    .thenComparing(Function::getFunctionName, nullsFirst(String.CASE_INSENSITIVE_ORDER))
                    .thenComparing(Function::getSpecificName, nullsFirst(String.CASE_INSENSITIVE_ORDER));

    static final Comparator LEXICOGRAPHIC_ORDER =
            Comparator.comparing(Function::getSchemaId, SchemaId.LEXICOGRAPHIC_ORDER)
                    .thenComparing(Function::getFunctionName, nullsFirst(naturalOrder()))
                    .thenComparing(Function::getSpecificName, nullsFirst(naturalOrder()));

    public static final String COLUMN_LABEL_FUNCTION_CAT = "FUNCTION_CAT";

    public static final String PROPERTY_NAME_FUNCTION_CAT = "functionCat";

    public static final String COLUMN_LABEL_FUNCTION_SCHEM = "FUNCTION_SCHEM";

    public static final String PROPERTY_NAME_FUNCTION_SCHEM = "functionSchem";

    public static final String COLUMN_LABEL_FUNCTION_TYPE = "FUNCTION_TYPE";

    public static final String PROPERTY_NAME_FUNCTION_TYPE = "functionType";

    // ------------------------------------------------------------------------------------------------------ functionId
    FunctionId getFunctionId() {
        if (functionId == null) {
            functionId = FunctionId.of(
                    getFunctionCatNonNull(),
                    getFunctionSchemNonNull(),
                    getSpecificName()
            );
        }
        return functionId;
    }

    private SchemaId getSchemaId() {
        return getFunctionId().getSchemaId();
    }

    // ----------------------------------------------------------------------------------------------------- functionCat
    String getFunctionCatNonNull() {
        return Optional.ofNullable(getFunctionCat()).orElse(Catalog.COLUMN_VALUE_TABLE_CAT_EMPTY);
    }

    public void setFunctionCat(final String functionCat) {
        this.functionCat = functionCat;
        functionId = null;
    }

    // --------------------------------------------------------------------------------------------------- functionSchem
    String getFunctionSchemNonNull() {
        return Optional.ofNullable(getFunctionSchem()).orElse(Schema.COLUMN_VALUE_TABLE_SCHEM_EMPTY);
    }

    public void setFunctionSchem(final String functionSchem) {
        this.functionSchem = functionSchem;
        functionId = null;
    }

    // ---------------------------------------------------------------------------------------------------- specificName
    public void setSpecificName(final String specificName) {
        this.specificName = specificName;
        functionId = null;
    }

    // -----------------------------------------------------------------------------------------------------------------
    @Setter(AccessLevel.NONE)
    @Getter(AccessLevel.NONE)
    @EqualsAndHashCode.Exclude
    @ToString.Exclude
    private transient FunctionId functionId;

    // -----------------------------------------------------------------------------------------------------------------
    @_NullableBySpecification
    @_ColumnLabel(COLUMN_LABEL_FUNCTION_CAT)
    private String functionCat;

    @_NullableBySpecification
    @_ColumnLabel(COLUMN_LABEL_FUNCTION_SCHEM)
    private String functionSchem;

    @_ColumnLabel("FUNCTION_NAME")
    @EqualsAndHashCode.Exclude
    private String functionName;

    @_NullableByVendor("PostgreSQL")
    @_ColumnLabel("REMARKS")
    private String remarks;

    @_ColumnLabel("FUNCTION_TYPE")
    private int functionType;

    @_ColumnLabel("SPECIFIC_NAME")
    private String specificName;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy