Esempio n. 1
0
  @Override
  public void setConnection(final DatabaseConnection conn) {
    LogFactory.getLogger()
        .debug("Connected to " + conn.getConnectionUserName() + "@" + conn.getURL());
    this.connection = conn;
    try {
      boolean autoCommit = conn.getAutoCommit();
      if (autoCommit == getAutoCommitMode()) {
        // Don't adjust the auto-commit mode if it's already what the database wants it to be.
        LogFactory.getLogger()
            .debug("Not adjusting the auto commit mode; it is already " + autoCommit);
      } else {
        // Store the previous auto-commit mode, because the connection needs to be restored to it
        // when this
        // AbstractDatabase type is closed. This is important for systems which use connection
        // pools.
        previousAutoCommit = autoCommit;

        LogFactory.getLogger()
            .debug("Setting auto commit to " + getAutoCommitMode() + " from " + autoCommit);
        connection.setAutoCommit(getAutoCommitMode());
      }
    } catch (DatabaseException e) {
      LogFactory.getLogger()
          .warning("Cannot set auto commit to " + getAutoCommitMode() + " on connection");
    }

    this.connection.attached(this);
  }
Esempio n. 2
0
 /**
  * Default implementation, just look for "local" IPs. If the database returns a null URL we return
  * false since we don't know it's safe to run the update.
  *
  * @throws liquibase.exception.DatabaseException
  */
 @Override
 public boolean isSafeToRunUpdate() throws DatabaseException {
   DatabaseConnection connection = getConnection();
   if (connection == null) {
     return true;
   }
   String url = connection.getURL();
   if (url == null) {
     return false;
   }
   return (url.contains("localhost")) || (url.contains("127.0.0.1"));
 }
Esempio n. 3
0
  @Override
  public void close() throws DatabaseException {
    DatabaseConnection connection = getConnection();
    if (connection != null) {
      if (previousAutoCommit != null) {
        try {
          connection.setAutoCommit(previousAutoCommit);
        } catch (DatabaseException e) {
          LogFactory.getLogger()
              .warning("Failed to restore the auto commit to " + previousAutoCommit);

          throw e;
        }
      }
      connection.close();
    }
    ExecutorService.getInstance().clearExecutor(this);
  }
Esempio n. 4
0
 @Override
 public int getDatabaseMinorVersion() throws DatabaseException {
   if (connection == null) {
     return -1;
   }
   try {
     return connection.getDatabaseMinorVersion();
   } catch (DatabaseException e) {
     throw new DatabaseException(e);
   }
 }
Esempio n. 5
0
  @Override
  public String getDatabaseProductVersion() throws DatabaseException {
    if (connection == null) {
      return null;
    }

    try {
      return connection.getDatabaseProductVersion();
    } catch (DatabaseException e) {
      throw new DatabaseException(e);
    }
  }
Esempio n. 6
0
  /** Returns the name of the database product according to the underlying database. */
  @Override
  public String getDatabaseProductName() {
    if (connection == null) {
      return getDefaultDatabaseProductName();
    }

    try {
      return connection.getDatabaseProductName();
    } catch (DatabaseException e) {
      throw new RuntimeException("Cannot get database name");
    }
  }
Esempio n. 7
0
  @Override
  public boolean equals(final Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    AbstractJdbcDatabase that = (AbstractJdbcDatabase) o;

    if (connection == null) {
      if (that.connection == null) {
        return this == that;
      } else {
        return false;
      }
    } else {
      return connection.equals(that.connection);
    }
  }
Esempio n. 8
0
 protected String getConnectionCatalogName() throws DatabaseException {
   return connection.getCatalog();
 }
Esempio n. 9
0
 @Override
 public int hashCode() {
   return (connection != null ? connection.hashCode() : super.hashCode());
 }