private static <T> Object getObject(List<T> entities, Method method) { if (entities.isEmpty()) { return null; } if (entities.size() == 1) { return entities.get(0); } throw new NonUniqueResultException("No unique result to the method: " + method); }
private static <T> Object getObject(List<T> entities, Method method) { if (entities.isEmpty()) { return null; } if (entities.size() == 1) { return entities.get(0); } throw new NonUniqueResultException("No unique result to the method: " + method); }
private static <T> Object getObject(List<T> entities, Method method) { if (entities.isEmpty()) { return null; } if (entities.size() == 1) { return entities.get(0); } throw new NonUniqueResultException("No unique result to the method: " + method); }
@Override public <T> Optional<T> singleResult(String query) { List<T> entities = query(query); if (entities.isEmpty()) { return Optional.empty(); } if (entities.size() == 1) { return Optional.ofNullable(entities.get(0)); } throw new NonUniqueResultException("No unique result found to the query: " + query); }
@Override public Optional<DocumentEntity> getSingleResult() { List<DocumentEntity> entities = getResultList(); if (entities.isEmpty()) { return Optional.empty(); } if (entities.size() == 1) { return Optional.of(entities.get(0)); } throw new NonUniqueResultException("The select returns more than one entity, select: " + query); }
@Override public <T> Optional<T> singleResult(String query) { List<T> entities = query(query); if (entities.isEmpty()) { return Optional.empty(); } if (entities.size() == 1) { return Optional.ofNullable(entities.get(0)); } throw new NonUniqueResultException("No unique result found to the query: " + query); }
@Override public Optional<ColumnEntity> getSingleResult() { List<ColumnEntity> entities = getResultList(); if (entities.isEmpty()) { return Optional.empty(); } if (entities.size() == 1) { return Optional.of(entities.get(0)); } throw new NonUniqueResultException("The select returns more than one entity, select: " + query); }
@Override public Optional<Value> getSingleResult() { List<Value> entities = getResultList(); if (entities.isEmpty()) { return Optional.empty(); } if (entities.size() == 1) { return Optional.of(entities.get(0)); } throw new NonUniqueResultException("The select returns more than one entity, select: " + query); }
@Override public <T> Optional<T> getSingleResult(String query, Class<T> entityClass) { List<T> result = query(query, entityClass); if (result.isEmpty()) { return Optional.empty(); } if (result.size() == 1) { return Optional.ofNullable(result.get(0)); } throw new NonUniqueResultException("No Unique result found to the query: " + query); }
public void getSingleResult(Consumer<Optional<DocumentEntity>> callBack) { Objects.requireNonNull(callBack, "callBack is required"); getResultList(entities -> { if (entities.isEmpty()) { callBack.accept(Optional.empty()); return; } if (entities.size() == 1) { callBack.accept(Optional.of(entities.get(0))); return; } throw new NonUniqueResultException("The select returns more than one entity, select: " + query); }); }
public void getSingleResult(Consumer<Optional<ColumnEntity>> callBack) { Objects.requireNonNull(callBack, "callBack is required"); getResultList(entities -> { if (entities.isEmpty()) { callBack.accept(Optional.empty()); return; } if (entities.size() == 1) { callBack.accept(Optional.of(entities.get(0))); return; } throw new NonUniqueResultException("The select returns more than one entity, select: " + query); }); }
/** * Returns a single entity from select * * @param query - select to figure out entities * @return an entity on {@link Optional} or {@link Optional#empty()} when the result is not found. * @throws NonUniqueResultException when the result has more than 1 entity * @throws NullPointerException when select is null * @throws UnsupportedOperationException if the implementation does not support any operation that a query has. */ default Optional<ColumnEntity> singleResult(ColumnQuery query) { List<ColumnEntity> entities = select(query); if (entities.isEmpty()) { return Optional.empty(); } if (entities.size() == 1) { return Optional.of(entities.get(0)); } throw new NonUniqueResultException("The select returns more than one entity, select: " + query); }
/** * Returns a single entity from query * * @param query - query to figure out entities * @param <T> the instance type * @return an entity on {@link Optional} or {@link Optional#empty()} when the result is not found. * @throws NonUniqueResultException when the result has more than 1 entity * @throws NullPointerException when query is null */ default <T> Optional<T> singleResult(DocumentQuery query) { List<T> entities = select(query); if (entities.isEmpty()) { return Optional.empty(); } if (entities.size() == 1) { return Optional.of(entities.get(0)); } throw new NonUniqueResultException("The query returns more than one entity, query: " + query); }
/** * Returns a single entity from query * * @param query - query to figure out entities * @param <T> the instance type * @return an entity on {@link Optional} or {@link Optional#empty()} when the result is not found. * @throws NonUniqueResultException when the result has more than 1 entity * @throws NullPointerException when query is null */ default <T> Optional<T> singleResult(ColumnQuery query) { List<T> entities = select(query); if (entities.isEmpty()) { return Optional.empty(); } if (entities.size() == 1) { return Optional.of(entities.get(0)); } throw new NonUniqueResultException("The query returns more than one entity, query: " + query); }
/** * Returns a single entity from select * * @param query - select to figure out entities * @param callBack the callback * @throws NonUniqueResultException when the result has more than 1 entity * @throws NullPointerException when select is null * @throws UnsupportedOperationException if the implementation does not support any operation that a query has. */ default void singleResult(ColumnQuery query, Consumer<Optional<ColumnEntity>> callBack) { select(query, entities -> { if (entities.isEmpty()) { callBack.accept(Optional.empty()); return; } else if (entities.size() == 1) { callBack.accept(Optional.of(entities.get(0))); return; } throw new NonUniqueResultException("The select returns more than one entity, select: " + query); }); }
/** * Returns a single entity from select * * @param query - select to figure out entities * @return an entity on {@link Optional} or {@link Optional#empty()} when the result is not found. * @throws NonUniqueResultException when the result has more than 1 entity * @throws NullPointerException when select is null * @throws UnsupportedOperationException if the implementation does not support any operation that a query has. */ default Optional<DocumentEntity> singleResult(DocumentQuery query) { List<DocumentEntity> entities = select(query); if (entities.isEmpty()) { return Optional.empty(); } if (entities.size() == 1) { return Optional.of(entities.get(0)); } throw new NonUniqueResultException("The select returns more than one entity, select: " + query); }
/** * Returns a single entity from select * * @param query - select to figure out entities * @param callBack the callback * @throws NonUniqueResultException when the result has more than 1 entity * @throws NullPointerException when select is null * @throws UnsupportedOperationException if the implementation does not support any operation that a query has. */ default void singleResult(DocumentQuery query, Consumer<Optional<DocumentEntity>> callBack) { select(query, entities -> { if (entities.isEmpty()) { callBack.accept(Optional.empty()); return; } else if (entities.size() == 1) { callBack.accept(Optional.of(entities.get(0))); return; } throw new NonUniqueResultException("The select returns more than one entity, select: " + query); }); }
/** * Execute a query to consume an unique result * * @param query the query * @param callBack the callback * @param <T> the type * @throws org.jnosql.diana.api.ExecuteAsyncQueryException when there is a async error * @throws UnsupportedOperationException when the database does not have support to insert asynchronous * @throws NullPointerException when either query or callback are null * @throws NonUniqueResultException when it returns more than one result */ default <T> void singleResult(DocumentQuery query, Consumer<Optional<T>> callBack) { requireNonNull(callBack, "callBack is required"); Consumer<List<T>> singleCallBack = entities -> { if (entities.isEmpty()) { callBack.accept(Optional.empty()); } else if (entities.size() == 1) { callBack.accept(Optional.of(entities.get(0))); } else { throw new NonUniqueResultException("The query returns more than one entity, query: " + query); } }; select(query, singleCallBack); } }
/** * Execute a query to consume an unique result * * @param query the query * @param callback the callback * @param <T> the type * @throws org.jnosql.diana.api.ExecuteAsyncQueryException when there is a async error * @throws UnsupportedOperationException when the database does not have support to insert asynchronous * @throws NullPointerException when either query or callback are null * @throws NonUniqueResultException when it returns more than one result */ default <T> void singleResult(ColumnQuery query, Consumer<Optional<T>> callback) { requireNonNull(callback, "callback is required"); Consumer<List<T>> singleCallBack = entities -> { if (entities.isEmpty()) { callback.accept(Optional.empty()); } else if (entities.size() == 1) { callback.accept(Optional.of(entities.get(0))); } else { throw new NonUniqueResultException("The query returns more than one entity, query: " + query); } }; select(query, singleCallBack); } }