Finds a unique result from database, using given {@link RowMapper} to convert the row.

@throws NonUniqueResultException if there is more then one row
@throws EmptyResultException if there are no rows
162588
public <T> T findUnique(@NotNull RowMapper<T> mapper, @NotNull @SQL String sql, Object... args) {
        return findUnique(mapper, SqlQuery.query(sql, args));
    }
779057
private static Row row(List<StatementResult> results) {
		Row row = results.get( 0 ).getData().get( 0 );
		return row;
	}
1149846
public boolean next() throws SQLException {
        boolean result = queryResult.next();
        orderValues = result ? getOrderValues() : Collections.<Comparable<?>>emptyList();
        return result;
    }
922940
@FFDCIgnore({ EntityNotFoundException.class, Exception.class })
    private String getUniqueNameByUniqueId(String uniqueId, boolean isAllowOperationIfReposDown, Set<String> failureRepositoryIds) throws WIMException {
        final String METHODNAME = "getUniqueNameByUniqueId";
        String uniqueName = null;

        boolean found = false;
        int i = 0;
        Root temp = new Root();
        Entity entity = new Entity();
        IdentifierType id = new IdentifierType();
        id.setExternalId(uniqueId);
        entity.setIdentifier(id);
        temp.getEntities().add(entity);

        List<String> repositoryIds = repositoryManager.getRepoIds();
        while (i < repositoryIds.size() && !found) {
            try {
                Root returnedRoot = repositoryManager.getRepository(repositoryIds.get(i)).get(temp);
                if (returnedRoot != null) {
                    List<Entity> pes = returnedRoot.getEntities();
                    if (pes != null) {
                        Entity ent = pes.get(0);
                        if (ent != null) {
                            IdentifierType entityId = ent.getIdentifier();
                            if (entityId != null) {
                                uniqueName = entityId.getUniqueName();
                                found = true;
                            }
                        }
                    }
                }
            } catch (EntityNotFoundException e) {
                // Move on to the next repository
                i++;
            } catch (Exception e) {
                if (!isAllowOperationIfReposDown) {
                    if (e instanceof WIMException) {
                        throw (WIMException) e;
                    }
                    throw new WIMException(e);
                } else {
                    if (tc.isDebugEnabled())
                        Tr.debug(tc, METHODNAME + " IGNORE: exception [" + e.getMessage()
                                     + "] on repository [" + repositoryIds.get(i) + "]");
                    failureRepositoryIds.add(repositoryIds.get(i));

                    // Move on to the next repository
                    i++;
                }
            }
        }
        return uniqueName;
    }
1322951
public Result find(String rowKey, List<String> returnFields, QueryOptions options) throws IOException {
        Get get = new Get(rowKey.getBytes());
        
        if (returnFields != null) {
            for (String field : returnFields) {
                String[] parts = field.split(":");
                get.addColumn(parts[0].getBytes(), parts[1].getBytes());
            }
        } else {
            getReturnFields(get, options);
        }

        int maxVersions = (options != null) ? options.getInt("maxVersions", 0) : 0;
        if (maxVersions > 0) {
            get.setMaxVersions(maxVersions);
        }
        
        return table.get(get);
    }
956346
public T mapRow(ResultSet rs) throws SQLException {
    Map<String, Object> map = new HashMap<String, Object>();
    ResultSetMetaData metadata = rs.getMetaData();

    for (int i = 1; i <= metadata.getColumnCount(); ++i) {
      String label = metadata.getColumnLabel(i);

      final Object value;
      // calling getObject on a BLOB/CLOB produces weird results
      switch (metadata.getColumnType(i)) {
        case Types.BLOB:
          value = rs.getBytes(i);
          break;
        case Types.CLOB:
          value = rs.getString(i);
          break;
        default:
          value = rs.getObject(i);
      }

      // don't use table name extractor because we don't want aliased table name
      boolean overwrite = this.tableName != null && this.tableName.equals(metadata.getTableName(i));
      String tableName = TABLE_NAME_EXTRACTOR.getTableName(metadata, i);
      if (tableName != null && !tableName.isEmpty()) {
        String qualifiedName = tableName + "." + metadata.getColumnName(i);
        add(map, qualifiedName, value, overwrite);
      }

      add(map, label, value, overwrite);
    }

    return objectMapper.convertValue(map, type);
  }
228792
public Object firstRow() throws SQLException {
        List rows = rows();
        if (rows.isEmpty()) return null;
        return (rows.get(0));
    }
381151
public static <T> ExceptionalStream<T, SQLException> rows(final ResultSet resultSet,
            final Try.BiFunction<ResultSet, List<String>, T, SQLException> recordGetter) {
        N.checkArgNotNull(resultSet, "resultSet");
        N.checkArgNotNull(recordGetter, "recordGetter");

        final ExceptionalIterator<T, SQLException> iter = new ExceptionalIterator<T, SQLException>() {
            private List<String> columnLabels = null;
            private boolean hasNext;

            @Override
            public boolean hasNext() throws SQLException {
                if (hasNext == false) {
                    hasNext = resultSet.next();
                }

                return hasNext;
            }

            @Override
            public T next() throws SQLException {
                if (hasNext() == false) {
                    throw new NoSuchElementException();
                }

                hasNext = false;

                if (columnLabels == null) {
                    columnLabels = JdbcUtil.getColumnLabelList(resultSet);
                }

                return recordGetter.apply(resultSet, columnLabels);
            }

            @Override
            public void skip(long n) throws SQLException {
                N.checkArgNotNegative(n, "n");

                final long m = hasNext ? n - 1 : n;

                JdbcUtil.skip(resultSet, m);

                hasNext = false;
            }

            @Override
            public long count() throws SQLException {
                long cnt = 0;

                while (resultSet.next()) {
                    cnt++;
                }

                return cnt;
            }
        };

        return newStream(iter);
    }
1261422
function handleUniqueResult(results) {
      var res = [], flag = {};
      for (var i = 0; i<results.length; i++) {
        if (flag[results[i][self.displayProperty1]]) continue;
        flag[results[i][self.displayProperty1]] = true;
        res.push(results[i]);
      }
      return res;
    }
1249167
@Override
    public T findUniqueUsingQueryModel(QueryModel queryModel)
            throws NoSuchItemException, TooManyItemsException, JeppettoException {
        T result;

        try {
            if (accessControlContextProvider == null
                || accessControlHelper.annotationAllowsAccess(persistentClass, queryModel.getAccessControlContext(), AccessType.Read)) {
                // noinspection unchecked
                result = (T) buildCriteria(queryModel).uniqueResult();
            } else {
                // noinspection unchecked
                result = (T) createAccessControlledQuery(queryModel).uniqueResult();
            }
        } catch (NonUniqueObjectException e) {
            throw new TooManyItemsException(e.getMessage());
        } catch (HibernateException e) {
            throw new JeppettoException(e);
        }

        if (result == null) {
            throw new NoSuchItemException(persistentClass.getSimpleName(), queryModel.toString());
        }

        return result;
    }
613752
@Override
    public RowIterator findFirstRowNotNull(Session session,
                                           PersistentStore store) {

        readLock.lock();

        try {
            NodeAVL x = getAccessor(store);

            while (x != null) {
                boolean t = colTypes[0].compare(
                    null, x.getRow(store).getData()[colIndex[0]]) >= 0;

                if (t) {
                    NodeAVL r = x.getRight(store);

                    if (r == null) {
                        break;
                    }

                    x = r;
                } else {
                    NodeAVL l = x.getLeft(store);

                    if (l == null) {
                        break;
                    }

                    x = l;
                }
            }

            while (x != null) {
                Object colvalue = x.getRow(store).getData()[colIndex[0]];

                if (colvalue == null) {
                    x = next(store, x);
                } else {
                    break;
                }
            }

// MVCC
            while (session != null && x != null) {
                Row row = x.getRow(store);

                if (session.database.txManager.canRead(session, row)) {
                    break;
                }

                x = next(store, x);
            }

            return getIterator(session, store, x);
        } finally {
            readLock.unlock();
        }
    }
1180602
protected T getRowObject(int rowIndex) {
		int pageIndex = rowIndex - dataOffset;
		if (pageIndex >= 0 && pageIndex < data.size()) {
			return data.get(pageIndex);
		}
		return null;
	}
285772
public static <T> ExceptionalStream<T, SQLException> rows(final ResultSet resultSet, final int columnIndex) {
        N.checkArgNotNull(resultSet, "resultSet");
        N.checkArgNotNegative(columnIndex, "columnIndex");

        final ExceptionalIterator<T, SQLException> iter = new ExceptionalIterator<T, SQLException>() {
            private final int newColumnIndex = columnIndex + 1;
            private boolean hasNext = false;

            @Override
            public boolean hasNext() throws SQLException {
                if (hasNext == false) {
                    hasNext = resultSet.next();
                }

                return hasNext;
            }

            @Override
            public T next() throws SQLException {
                if (!hasNext()) {
                    throw new NoSuchElementException("No more rows");
                }

                final T next = (T) JdbcUtil.getColumnValue(resultSet, newColumnIndex);
                hasNext = false;
                return next;
            }

            @Override
            public void skip(long n) throws SQLException {
                N.checkArgNotNegative(n, "n");

                final long m = hasNext ? n - 1 : n;

                JdbcUtil.skip(resultSet, m);

                hasNext = false;
            }
        };

        return newStream(iter);
    }
899939
@Override
    public T findUniqueUsingQueryModel(QueryModel queryModel)
            throws NoSuchItemException, TooManyItemsException, JeppettoException {
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;

        try {
            connection = dataSource.getConnection();
            preparedStatement = buildPreparedStatement(connection, queryModel);
            resultSet = preparedStatement.executeQuery();

            if (!resultSet.next()) {
                throw new NoSuchItemException(entityClass.getSimpleName(), buildSelectString(queryModel));
            }

            T t = enhancer.newInstance();

            ((JDBCPersistable) t).populateObject(resultSet);

            if (resultSet.next()) {
                throw new TooManyItemsException(entityClass.getSimpleName(), buildSelectString(queryModel));
            }

            return t;
        } catch (SQLException e) {
            throw new JeppettoException(e);
        } finally {
            if (resultSet != null) { try { resultSet.close(); } catch (SQLException ignore) { } }
            if (preparedStatement != null) { try { preparedStatement.close(); } catch (SQLException ignore) { } }
            if (connection != null) { try { connection.close(); } catch (SQLException ignore) { } }
        }
    }
1075000
public <T> T queryForObject(String sql, RowMapper<T> rowMapper) throws SQLException  {
		return (T) query(sql, rowMapper);
	}
956446
protected void onValidateSingleResult(List results)
    {
        if (results == null || results.isEmpty())
        {
            log.error("No result found for {} ", kunderaQuery.getJPAQuery());
            throw new NoResultException("No result found!");
        }

        if (results.size() > 1)
        {
            log.error("Non unique results found for query {} ", kunderaQuery.getJPAQuery());
            throw new NonUniqueResultException("Containing more than one result!");
        }

    }
832271
@Override
    public Object getSingleResult()
    {
        // to fetch a single result form database.
        isSingleResult = true;
        List results = getResultList();
        isSingleResult = false;
        return onReturnResults(results);
    }