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

com.torodb.backend.tables.SemanticTable Maven / Gradle / Ivy

There is a newer version: 0.50.3
Show newest version
/*
 * ToroDB
 * Copyright © 2014 8Kdata Technology (www.8kdata.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see .
 */

package com.torodb.backend.tables;

import com.torodb.core.exceptions.InvalidDatabaseException;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.jooq.Field;
import org.jooq.Record;
import org.jooq.Schema;
import org.jooq.Table;
import org.jooq.impl.TableImpl;

@SuppressFBWarnings(
    value = "HE_HASHCODE_NO_EQUALS",
    justification =
    "Equals comparation is done in TableImpl class, which compares schema, name and fields"
)
public abstract class SemanticTable extends TableImpl {

  private static final long serialVersionUID = 1;

  public SemanticTable(String name, Schema schema, Table aliased, Field[] parameters,
      String comment) {
    super(name, schema, aliased, parameters, comment);
  }

  public SemanticTable(String name, Schema schema, Table aliased, Field[] parameters) {
    super(name, schema, aliased, parameters);
  }

  public SemanticTable(String name, Schema schema, Table aliased) {
    super(name, schema, aliased);
  }

  public SemanticTable(String name, Schema schema) {
    super(name, schema);
  }

  public SemanticTable(String name) {
    super(name);
  }

  public boolean checkSemanticallyEquals(Table table) throws InvalidDatabaseException {
    if (!table.getName().equals(getName())) {
      throw new InvalidDatabaseException("It was expected that "
          + "the table " + table + " was the " + getName() + " table, "
          + "but they are not semantically equals");
    }
    if (table.getSchema() == null || !getSchema().getName().equals(table.getSchema().getName())) {
      throw new InvalidDatabaseException("It was expected that "
          + "the table " + table + " was the " + getName() + " table, "
          + "but they are not semantically equals");
    }
    if (table.fields().length != fields().length) {
      throw new InvalidDatabaseException("It was expected that "
          + "the table " + table + " was the " + getName() + " table, "
          + "but they are not semantically equals");
    }
    for (Field field : fields()) {
      boolean fieldFound = false;
      for (Field tableField : table.fields()) {
        if (field.getName().equals(tableField.getName())) {
          fieldFound = true;
          break;
        }
      }

      if (!fieldFound) {
        throw new InvalidDatabaseException("It was expected that "
            + "the table " + table + " was the " + getName() + " table, "
            + "but they are not semantically equals");
      }
    }
    return true;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy