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

com.huaweicloud.dws.client.model.TableName Maven / Gradle / Ivy

There is a newer version: 2.0.0-r0
Show newest version
package com.huaweicloud.dws.client.model;

import com.huaweicloud.dws.client.exception.InvalidException;
import com.huaweicloud.dws.client.util.IdentifierUtil;

import java.io.Serializable;
import java.util.Objects;

/**
 * @ProjectName: dws-connector
 * @ClassName: TableNmae
 * @Description: 表名
 * @Date: 2022/12/22 11:28
 * @Version: 1.0
 */
public class TableName implements Serializable {
    public static final String DEFAULT_SCHEMA_NAME = "public";
    public static final String SPLIT = "\\.";

    /**
     * 表schema
     */
    private final String schemaName;

    /**
     * 不包含schema的表明
     */
    private final String tableName;

    /**
     * 包含schema的全名称
     */
    private final String fullName;

    private TableName(String schemaName, String tableName, String fullName) {
        this.schemaName = schemaName;
        this.tableName = tableName;
        this.fullName = fullName;
    }

    public String getSchemaName() {
        return schemaName;
    }

    public String getTableName() {
        return tableName;
    }

    public String getFullName() {
        return fullName;
    }


    public static TableName valueOf(String name) throws InvalidException {
        if (name == null || name.isEmpty()) {
            throw new InvalidException(name);
        }
        String[] tmp = name.split(SPLIT);
        String schema = DEFAULT_SCHEMA_NAME;
        String table = name;
        switch (tmp.length) {
            case 1:
                break;
            case 2:
                schema = tmp[0];
                table = tmp[1];
                break;
            default:
                throw new InvalidException(name);
        }
        return new TableName(schema, table, String.format("%s.%s", IdentifierUtil.quoteIdentifier(schema), IdentifierUtil.quoteIdentifier(table)));
    }

    @Override
    public String toString() {
        return "TableName{" +
                "schemaName='" + schemaName + '\'' +
                ", tableName='" + tableName + '\'' +
                ", fullName='" + fullName + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        TableName tableName1 = (TableName) o;
        return Objects.equals(schemaName, tableName1.schemaName)
                && Objects.equals(tableName, tableName1.tableName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(schemaName, tableName);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy