public String getSqlString() {
    StringBuilder statementBuilder = new StringBuilder();
    if (selectedIds.isPresent() || !whereConstraints.isEmpty()) {
      statementBuilder.append("WHERE (");

      statementBuilder.append(getIdSetSqlCondition());
      if (selectedIds.isPresent() && !whereConstraints.isEmpty()) {
        statementBuilder.append(" AND ");
      }
      statementBuilder.append(getWhereSqlCriteria());
      statementBuilder.append(") ");
    }
    return statementBuilder.toString();
  }