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

schemacrawler.crawl.MutableCrawlInfo Maven / Gradle / Ivy

/*
========================================================================
SchemaCrawler
http://www.schemacrawler.com
Copyright (c) 2000-2020, Sualeh Fatehi .
All rights reserved.
------------------------------------------------------------------------

SchemaCrawler 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.

SchemaCrawler and the accompanying materials are made available under
the terms of the Eclipse Public License v1.0, GNU General Public License
v3 or GNU Lesser General Public License v3.

You may elect to redistribute this code under any of these licenses.

The Eclipse Public License is available at:
http://www.eclipse.org/legal/epl-v10.html

The GNU General Public License v3 and the GNU Lesser General Public
License v3 are available at:
http://www.gnu.org/licenses/

========================================================================
*/

package schemacrawler.crawl;


import static java.time.ZoneOffset.UTC;
import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE;
import static java.time.format.DateTimeFormatter.ISO_LOCAL_TIME;
import static java.util.Objects.requireNonNull;

import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.util.UUID;

import schemacrawler.BaseProductVersion;
import schemacrawler.JvmSystemInfo;
import schemacrawler.OperatingSystemInfo;
import schemacrawler.ProductVersion;
import schemacrawler.SchemaCrawlerInfo;
import schemacrawler.schema.CrawlInfo;
import schemacrawler.schema.DatabaseInfo;
import schemacrawler.schema.JdbcDriverInfo;

/**
 * SchemaCrawler crawl information.
 *
 * @author Sualeh Fatehi [email protected]
 */
final class MutableCrawlInfo
  implements CrawlInfo
{

  private static final long serialVersionUID = 5982990326485881993L;

  public static final DateTimeFormatter DATE_TIME_FORMATTER;

  static
  {
    DATE_TIME_FORMATTER = new DateTimeFormatterBuilder()
      .append(ISO_LOCAL_DATE)
      .appendLiteral(' ')
      .append(ISO_LOCAL_TIME)
      .toFormatter();
  }

  private final Instant crawlTimestamp;
  private final ProductVersion jvmVersion;
  private final ProductVersion operatingSystemVersion;
  private final UUID runId;
  private final ProductVersion schemaCrawlerVersion;
  private ProductVersion databaseVersion;
  private ProductVersion jdbcDriverVersion;

  MutableCrawlInfo()
  {
    schemaCrawlerVersion = new SchemaCrawlerInfo();
    operatingSystemVersion = new OperatingSystemInfo();
    jvmVersion = new JvmSystemInfo();

    crawlTimestamp = Instant.now();
    runId = UUID.randomUUID();
  }

  @Override
  public String getCrawlTimestamp()
  {
    final ZonedDateTime dateTime = ZonedDateTime.ofInstant(crawlTimestamp, UTC);
    return DATE_TIME_FORMATTER.format(dateTime);
  }

  @Override
  public Instant getCrawlTimestampInstant()
  {
    return crawlTimestamp;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public ProductVersion getDatabaseVersion()
  {
    return databaseVersion;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public ProductVersion getJdbcDriverVersion()
  {
    return jdbcDriverVersion;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public ProductVersion getJvmVersion()
  {
    return jvmVersion;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public ProductVersion getOperatingSystemVersion()
  {
    return operatingSystemVersion;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public String getRunId()
  {
    return runId.toString();
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public ProductVersion getSchemaCrawlerVersion()
  {
    return schemaCrawlerVersion;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public String toString()
  {
    final StringBuilder info = new StringBuilder(1024);
    info
      .append("-- generated by: ")
      .append(schemaCrawlerVersion)
      .append(System.lineSeparator());
    info
      .append("-- generated on: ")
      .append(getCrawlTimestamp())
      .append(System.lineSeparator());
    info
      .append("-- database: ")
      .append(databaseVersion)
      .append(System.lineSeparator());
    info
      .append("-- driver: ")
      .append(jdbcDriverVersion)
      .append(System.lineSeparator());
    info
      .append("-- operating system: ")
      .append(operatingSystemVersion)
      .append(System.lineSeparator());
    info
      .append("-- JVM system: ")
      .append(jvmVersion)
      .append(System.lineSeparator());

    return info.toString();
  }

  void setDatabaseInfo(final JdbcDriverInfo jdbcDriverInfo,
                       final DatabaseInfo databaseInfo)
  {
    requireNonNull(jdbcDriverInfo, "No JDBC driver information provided");
    this.jdbcDriverVersion = new BaseProductVersion(jdbcDriverInfo);

    requireNonNull(databaseInfo, "No database information provided");
    this.databaseVersion = new BaseProductVersion(databaseInfo);
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy