public void applyPristineSessionState()

in wrapper/src/main/java/software/amazon/jdbc/states/SessionStateServiceImpl.java [472:564]


  public void applyPristineSessionState(Connection connection) throws SQLException {
    if (!this.resetStateEnabledSetting()) {
      return;
    }

    ResetSessionStateOnCloseCallable callableCopy = Driver.getResetSessionStateOnCloseFunc();
    if (callableCopy != null) {
      final boolean isHandled = callableCopy.apply(sessionState, connection);
      if (isHandled) {
        // Custom function has handled session transfer
        return;
      }
    }

    if (this.copySessionState.autoCommit.canRestorePristine()) {
      try {
        //noinspection OptionalGetWithoutIsPresent
        connection.setAutoCommit(this.copySessionState.autoCommit.getPristineValue().get());
      } catch (final SQLException e) {
        // Ignore any exception
      }
    }

    if (this.copySessionState.readOnly.canRestorePristine()) {
      try {
        //noinspection OptionalGetWithoutIsPresent
        connection.setReadOnly(this.copySessionState.readOnly.getPristineValue().get());
      } catch (final SQLException e) {
        // Ignore any exception
      }
    }

    if (this.copySessionState.catalog.canRestorePristine()) {
      try {
        //noinspection OptionalGetWithoutIsPresent
        final String pristineCatalog = this.copySessionState.catalog.getPristineValue().get();
        if (!StringUtils.isNullOrEmpty(pristineCatalog)) {
          connection.setCatalog(pristineCatalog);
        }
      } catch (final SQLException e) {
        // Ignore any exception
      }
    }

    if (this.copySessionState.schema.canRestorePristine()) {
      try {
        //noinspection OptionalGetWithoutIsPresent
        connection.setSchema(this.copySessionState.schema.getPristineValue().get());
      } catch (final SQLException e) {
        // Ignore any exception
      }
    }

    if (this.copySessionState.holdability.canRestorePristine()) {
      try {
        //noinspection OptionalGetWithoutIsPresent
        connection.setHoldability(this.copySessionState.holdability.getPristineValue().get());
      } catch (final SQLException e) {
        // Ignore any exception
      }
    }

    if (this.copySessionState.transactionIsolation.canRestorePristine()) {
      try {
        //noinspection OptionalGetWithoutIsPresent,MagicConstant
        connection.setTransactionIsolation(
            this.copySessionState.transactionIsolation.getPristineValue().get());
      } catch (final SQLException e) {
        // Ignore any exception
      }
    }

    if (this.copySessionState.networkTimeout.canRestorePristine()) {
      try {
        final ExecutorService executorService = Executors.newSingleThreadExecutor();
        //noinspection OptionalGetWithoutIsPresent
        connection.setNetworkTimeout(executorService,
            this.copySessionState.networkTimeout.getPristineValue().get());
        executorService.shutdown();
      } catch (final SQLException e) {
        // Ignore any exception
      }
    }

    if (this.copySessionState.typeMap.canRestorePristine()) {
      try {
        //noinspection OptionalGetWithoutIsPresent
        connection.setTypeMap(this.copySessionState.typeMap.getPristineValue().get());
      } catch (final SQLException e) {
        // Ignore any exception
      }
    }
  }