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

org.postgresql.jdbc.FieldMetadata Maven / Gradle / Ivy

There is a newer version: 5.0.0.9.pg
Show newest version
/*
 * Copyright (c) 2016, PostgreSQL Global Development Group
 * See the LICENSE file in the project root for more information.
 */

package io.mogdb.jdbc;

import io.mogdb.util.CanEstimateSize;

/**
 * This is an internal class to hold field metadata info like table name, column name, etc.
 * This class is not meant to be used outside of pgjdbc.
 */
public class FieldMetadata implements CanEstimateSize {
  public static class Key {
    final int tableOid;
    final int positionInTable;

    Key(int tableOid, int positionInTable) {
      this.positionInTable = positionInTable;
      this.tableOid = tableOid;
    }

    @Override
    public boolean equals(Object o) {
      if (this == o) {
        return true;
      }
      if (o == null || getClass() != o.getClass()) {
        return false;
      }

      Key key = (Key) o;

      if (tableOid != key.tableOid) {
        return false;
      }
      return positionInTable == key.positionInTable;
    }

    @Override
    public int hashCode() {
      int result = tableOid;
      result = 31 * result + positionInTable;
      return result;
    }

    @Override
    public String toString() {
      return "Key{"
          + "tableOid=" + tableOid
          + ", positionInTable=" + positionInTable
          + '}';
    }
  }

  final String columnName;
  final String tableName;
  final String schemaName;
  final int nullable;
  final boolean autoIncrement;
  final int clientLogicOriginalMod;

  public FieldMetadata(String columnName) {
    this(columnName, "", "", PgResultSetMetaData.columnNullableUnknown, false, 0);
  }

  FieldMetadata(String columnName, String tableName, String schemaName, int nullable,
      boolean autoIncrement, int clientLogicOriginalMod) {
    this.columnName = columnName;
    this.tableName = tableName;
    this.schemaName = schemaName;
    this.nullable = nullable;
    this.autoIncrement = autoIncrement;
    this.clientLogicOriginalMod = clientLogicOriginalMod;
  }

  public long getSize() {
    return columnName.length() * 2
        + tableName.length() * 2
        + schemaName.length() * 2
        + 4L
        + 1L
        + 4L; //for clientLogic data
  }

  @Override
  public String toString() {
    return "FieldMetadata{"
        + "columnName='" + columnName + '\''
        + ", tableName='" + tableName + '\''
        + ", schemaName='" + schemaName + '\''
        + ", nullable=" + nullable
        + ", autoIncrement=" + autoIncrement
        + '}';
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy