Search in sources :

Example 1 with NonUniqueResultException

use of jakarta.nosql.NonUniqueResultException in project jnosql-diana by eclipse.

the class DefaultDocumentPreparedStatement method getSingleResult.

@Override
public Optional<DocumentEntity> getSingleResult() {
    Stream<DocumentEntity> entities = getResult();
    final Iterator<DocumentEntity> iterator = entities.iterator();
    if (!iterator.hasNext()) {
        return Optional.empty();
    }
    final DocumentEntity next = iterator.next();
    if (!iterator.hasNext()) {
        return Optional.of(next);
    }
    throw new NonUniqueResultException("The select returns more than one entity, select: " + query);
}
Also used : NonUniqueResultException(jakarta.nosql.NonUniqueResultException) DocumentEntity(jakarta.nosql.document.DocumentEntity)

Example 2 with NonUniqueResultException

use of jakarta.nosql.NonUniqueResultException in project jnosql-diana by eclipse.

the class DefaultKeyValuePreparedStatement method getSingleResult.

@Override
public Optional<Value> getSingleResult() {
    Stream<Value> entities = getResult();
    final Iterator<Value> iterator = entities.iterator();
    if (!iterator.hasNext()) {
        return Optional.empty();
    }
    final Value next = iterator.next();
    if (!iterator.hasNext()) {
        return Optional.of(next);
    }
    throw new NonUniqueResultException("The select returns more than one entity, select: " + query);
}
Also used : NonUniqueResultException(jakarta.nosql.NonUniqueResultException) Value(jakarta.nosql.Value)

Example 3 with NonUniqueResultException

use of jakarta.nosql.NonUniqueResultException in project jnosql-diana by eclipse.

the class DefaultColumnPreparedStatement method getSingleResult.

@Override
public Optional<ColumnEntity> getSingleResult() {
    Stream<ColumnEntity> entities = getResult();
    final Iterator<ColumnEntity> iterator = entities.iterator();
    if (!iterator.hasNext()) {
        return Optional.empty();
    }
    final ColumnEntity next = iterator.next();
    if (!iterator.hasNext()) {
        return Optional.of(next);
    }
    throw new NonUniqueResultException("The select returns more than one entity, select: " + query);
}
Also used : NonUniqueResultException(jakarta.nosql.NonUniqueResultException) ColumnEntity(jakarta.nosql.column.ColumnEntity)

Example 4 with NonUniqueResultException

use of jakarta.nosql.NonUniqueResultException in project jnosql-diana by eclipse.

the class DefaultVertexTraversal method getSingleResult.

@Override
public <T> Optional<T> getSingleResult() {
    final Stream<T> stream = getResult();
    final Iterator<T> iterator = stream.iterator();
    if (!iterator.hasNext()) {
        return Optional.empty();
    }
    final T entity = iterator.next();
    if (!iterator.hasNext()) {
        return Optional.of(entity);
    }
    throw new NonUniqueResultException("The Vertex traversal query returns more than one result");
}
Also used : NonUniqueResultException(jakarta.nosql.NonUniqueResultException) T(org.apache.tinkerpop.gremlin.structure.T)

Aggregations

NonUniqueResultException (jakarta.nosql.NonUniqueResultException)4 Value (jakarta.nosql.Value)1 ColumnEntity (jakarta.nosql.column.ColumnEntity)1 DocumentEntity (jakarta.nosql.document.DocumentEntity)1 T (org.apache.tinkerpop.gremlin.structure.T)1