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

com.pingcap.tikv.meta.TiDBInfo Maven / Gradle / Ivy

There is a newer version: 3.2.3
Show newest version
/*
 * Copyright 2017 PingCAP, 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,
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.pingcap.tikv.meta;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;
import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
public class TiDBInfo implements Serializable {
  private final long id;
  private final String name;
  private final String charset;
  private final String collate;
  private final List tables;
  private final SchemaState schemaState;

  @JsonCreator
  public TiDBInfo(
      @JsonProperty("id") long id,
      @JsonProperty("db_name") CIStr name,
      @JsonProperty("charset") String charset,
      @JsonProperty("collate") String collate,
      @JsonProperty("-") List tables,
      @JsonProperty("state") int schemaState) {
    this.id = id;
    this.name = name.getL();
    this.charset = charset;
    this.collate = collate;
    this.tables = tables;
    this.schemaState = SchemaState.fromValue(schemaState);
  }

  private TiDBInfo(
      long id,
      String name,
      String charset,
      String collate,
      List tables,
      SchemaState schemaState) {
    this.id = id;
    this.name = name;
    this.charset = charset;
    this.collate = collate;
    this.tables = tables;
    this.schemaState = schemaState;
  }

  public TiDBInfo rename(String newName) {
    return new TiDBInfo(id, newName, charset, collate, tables, schemaState);
  }

  public long getId() {
    return id;
  }

  public String getName() {
    return name;
  }

  public String getCharset() {
    return charset;
  }

  public String getCollate() {
    return collate;
  }

  public List getTables() {
    return tables;
  }

  SchemaState getSchemaState() {
    return schemaState;
  }

  @Override
  public boolean equals(Object other) {
    if (other == this) {
      return true;
    }
    if (!(other instanceof TiDBInfo)) {
      return false;
    }
    TiDBInfo otherDB = (TiDBInfo) other;
    return otherDB.getId() == getId() && otherDB.getName().equals(getName());
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = prime + Long.hashCode(getId());
    return result * prime + getName().hashCode();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy