public void prepareDataSource()

in wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/MariadbDriverHelper.java [46:116]


  public void prepareDataSource(
      final @NonNull DataSource dataSource,
      final @NonNull String protocol,
      final @NonNull HostSpec hostSpec,
      final @NonNull Properties props) throws SQLException {

    if (dataSource instanceof MariaDbDataSource) {
      final MariaDbDataSource mariaDbDataSource = (MariaDbDataSource) dataSource;

      mariaDbDataSource.setUser(PropertyDefinition.USER.getString(props));
      mariaDbDataSource.setPassword(PropertyDefinition.PASSWORD.getString(props));

      final String loginTimeoutValue = props.getProperty(LOGIN_TIMEOUT, null);
      if (loginTimeoutValue != null) {
        mariaDbDataSource.setLoginTimeout(Integer.parseInt(loginTimeoutValue));
        props.remove(LOGIN_TIMEOUT);
      }

      Integer loginTimeout = PropertyUtils.getIntegerPropertyValue(props, PropertyDefinition.LOGIN_TIMEOUT);
      if (loginTimeout != null) {
        mariaDbDataSource.setLoginTimeout((int) TimeUnit.MILLISECONDS.toSeconds(loginTimeout));
      }

      // keep unknown properties (the ones that don't belong to AWS Wrapper Driver)
      // and include them to connect URL.
      PropertyDefinition.removeAllExcept(props,
          PropertyDefinition.DATABASE.name,
          PropertyDefinition.TCP_KEEP_ALIVE.name,
          PropertyDefinition.CONNECT_TIMEOUT.name,
          PropertyDefinition.SOCKET_TIMEOUT.name);

      String finalUrl = buildUrl(protocol, hostSpec, props);
      LOGGER.finest(() -> "Connecting to " + finalUrl);
      mariaDbDataSource.setUrl(finalUrl);

    } else if (dataSource instanceof MariaDbPoolDataSource) {

      final MariaDbPoolDataSource mariaDbPoolDataSource = (MariaDbPoolDataSource) dataSource;

      mariaDbPoolDataSource.setUser(PropertyDefinition.USER.getString(props));
      mariaDbPoolDataSource.setPassword(PropertyDefinition.PASSWORD.getString(props));

      final String loginTimeoutValue = props.getProperty(LOGIN_TIMEOUT, null);
      if (loginTimeoutValue != null) {
        mariaDbPoolDataSource.setLoginTimeout(Integer.parseInt(loginTimeoutValue));
        props.remove(LOGIN_TIMEOUT);
      }

      Integer loginTimeout = PropertyUtils.getIntegerPropertyValue(props, PropertyDefinition.LOGIN_TIMEOUT);
      if (loginTimeout != null) {
        mariaDbPoolDataSource.setLoginTimeout((int) TimeUnit.MILLISECONDS.toSeconds(loginTimeout));
      }

      // keep unknown properties (the ones that don't belong to AWS Wrapper Driver)
      // and include them to connect URL.
      PropertyDefinition.removeAllExcept(props,
          PropertyDefinition.DATABASE.name,
          PropertyDefinition.TCP_KEEP_ALIVE.name,
          PropertyDefinition.CONNECT_TIMEOUT.name,
          PropertyDefinition.SOCKET_TIMEOUT.name);

      String finalUrl = buildUrl(protocol, hostSpec, props);
      LOGGER.finest(() -> "Connecting to " + finalUrl);
      mariaDbPoolDataSource.setUrl(finalUrl);

    } else {
      throw new SQLException(Messages.get(
          "TargetDriverDialectManager.unexpectedClass",
          new Object[] { DS_CLASS_NAME + ", " + DS_CP_CLASS_NAME, dataSource.getClass().getName() }));
    }
  }