Package org.apache.tajo.catalog

Source Code of org.apache.tajo.catalog.IndexDesc

/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you 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 org.apache.tajo.catalog;

import com.google.common.base.Objects;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.tajo.catalog.proto.CatalogProtos.IndexDescProto;
import org.apache.tajo.catalog.proto.CatalogProtos.IndexMethod;
import org.apache.tajo.common.ProtoObject;

public class IndexDesc implements ProtoObject<IndexDescProto>, Cloneable {
  private IndexDescProto.Builder builder;
 
  private String name; // required
  private String tableId; // required
  private Column column; // required
  private IndexMethod indexMethod; // required
  private boolean isUnique = false; // optional [default = false]
  private boolean isClustered = false; // optional [default = false]
  private boolean isAscending = false; // optional [default = false]
 
  public IndexDesc() {
    this.builder = IndexDescProto.newBuilder();
  }
 
  public IndexDesc(String name, String tableId, Column column, IndexMethod type,
      boolean isUnique, boolean isClustered, boolean isAscending) {
    this();
    this.name = name.toLowerCase();
    this.tableId = tableId.toLowerCase();
    this.column = column;
    this.indexMethod = type;
    this.isUnique = isUnique;
    this.isClustered = isClustered;
    this.isAscending = isAscending;
  }
 
  public IndexDesc(IndexDescProto proto) {
    this(proto.getName(), proto.getTableId(), new Column(proto.getColumn()),
        proto.getIndexMethod(), proto.getIsUnique(), proto.getIsClustered(), proto.getIsAscending());
  }
 
  public String getName() {
    return name;
  }
 
  public String getTableId() {
    return tableId;
  }
 
  public Column getColumn() {
    return column;
  }
 
  public IndexMethod getIndexMethod() {
    return this.indexMethod;
  }
 
  public boolean isClustered() {
    return this.isClustered;
  }
 
  public boolean isUnique() {
    return this.isUnique;
  }
 
  public boolean isAscending() {
    return this.isAscending;
  }

  @Override
  public IndexDescProto getProto() {
    if (builder == null) {
      builder = IndexDescProto.newBuilder();
    }
    builder.setName(this.name);
    builder.setTableId(this.tableId);
    builder.setColumn(this.column.getProto());
    builder.setIndexMethod(indexMethod);
    builder.setIsUnique(this.isUnique);
    builder.setIsClustered(this.isClustered);
    builder.setIsAscending(this.isAscending);

    return builder.build();
  }
 
  public boolean equals(Object obj) {
    if (obj instanceof IndexDesc) {
      IndexDesc other = (IndexDesc) obj;
      return getName().equals(other.getName())
          && getTableId().equals(other.getTableId())
          && getColumn().equals(other.getColumn())
          && getIndexMethod().equals(other.getIndexMethod())
          && isUnique() == other.isUnique()
          && isClustered() == other.isClustered()
          && isAscending() == other.isAscending();
    } else {
      return false;
    }
  }
 
  public int hashCode() {
    return Objects.hashCode(getName(), getTableId(), getColumn(),
        getIndexMethod(), isUnique(), isClustered(), isAscending());
  }
 
  public Object clone() throws CloneNotSupportedException {
    IndexDesc desc = (IndexDesc) super.clone();
    desc.name = name;
    desc.tableId = tableId;
    desc.column = (Column) column.clone();
    desc.indexMethod = indexMethod;
    desc.isUnique = isUnique;
    desc.isClustered = isClustered;
    desc.isAscending = isAscending;
    return desc;
  }
 
  public String toString() {
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    return gson.toJson(this);
  }
}
TOP

Related Classes of org.apache.tajo.catalog.IndexDesc

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.