use of com.querydsl.core.NonUniqueResultException in project querydsl by querydsl.
the class AbstractLuceneQuery method oneResult.
@Nullable
private T oneResult(boolean unique) {
try {
int maxDoc = maxDoc();
if (maxDoc == 0) {
return null;
}
final ScoreDoc[] scoreDocs = searcher.search(createQuery(), getFilter(), maxDoc).scoreDocs;
int index = 0;
QueryModifiers modifiers = queryMixin.getMetadata().getModifiers();
Long offset = modifiers.getOffset();
if (offset != null) {
index = offset.intValue();
}
Long limit = modifiers.getLimit();
if (unique && (limit == null ? scoreDocs.length - index > 1 : limit > 1 && scoreDocs.length > 1)) {
throw new NonUniqueResultException("Unique result requested, but " + scoreDocs.length + " found.");
} else if (scoreDocs.length > index) {
Document document;
if (fieldSelector != null) {
document = searcher.doc(scoreDocs[index].doc, fieldSelector);
} else {
document = searcher.doc(scoreDocs[index].doc);
}
return transformer.apply(document);
} else {
return null;
}
} catch (IOException | IllegalArgumentException e) {
throw new QueryException(e);
}
}
use of com.querydsl.core.NonUniqueResultException in project querydsl by querydsl.
the class AbstractLuceneQuery method oneResult.
@Nullable
private T oneResult(boolean unique) {
try {
int maxDoc = maxDoc();
if (maxDoc == 0) {
return null;
}
final ScoreDoc[] scoreDocs = searcher.search(createQuery(), getFilter(), maxDoc, Sort.INDEXORDER, false, false).scoreDocs;
int index = 0;
QueryModifiers modifiers = queryMixin.getMetadata().getModifiers();
Long offset = modifiers.getOffset();
if (offset != null) {
index = offset.intValue();
}
Long limit = modifiers.getLimit();
if (unique && (limit == null ? scoreDocs.length - index > 1 : limit > 1 && scoreDocs.length > 1)) {
throw new NonUniqueResultException("Unique result requested, but " + scoreDocs.length + " found.");
} else if (scoreDocs.length > index) {
Document document;
if (fieldsToLoad != null) {
document = searcher.doc(scoreDocs[index].doc, fieldsToLoad);
} else {
document = searcher.doc(scoreDocs[index].doc);
}
return transformer.apply(document);
} else {
return null;
}
} catch (IOException | IllegalArgumentException e) {
throw new QueryException(e);
}
}
use of com.querydsl.core.NonUniqueResultException in project querydsl by querydsl.
the class AbstractHibernateQuery method fetchOne.
@SuppressWarnings("unchecked")
@Override
public T fetchOne() throws NonUniqueResultException {
try {
QueryModifiers modifiers = getMetadata().getModifiers();
Query query = createQuery(modifiers, false);
try {
return (T) query.uniqueResult();
} catch (org.hibernate.NonUniqueResultException e) {
throw new NonUniqueResultException(e);
}
} finally {
reset();
}
}
use of com.querydsl.core.NonUniqueResultException in project querydsl by querydsl.
the class AbstractLuceneQuery method oneResult.
@Nullable
private T oneResult(boolean unique) {
try {
int maxDoc = maxDoc();
if (maxDoc == 0) {
return null;
}
final ScoreDoc[] scoreDocs = searcher.search(createQuery(), maxDoc, Sort.INDEXORDER, false, false).scoreDocs;
int index = 0;
QueryModifiers modifiers = queryMixin.getMetadata().getModifiers();
Long offset = modifiers.getOffset();
if (offset != null) {
index = offset.intValue();
}
Long limit = modifiers.getLimit();
if (unique && (limit == null ? scoreDocs.length - index > 1 : limit > 1 && scoreDocs.length > 1)) {
throw new NonUniqueResultException("Unique result requested, but " + scoreDocs.length + " found.");
} else if (scoreDocs.length > index) {
Document document;
if (fieldsToLoad != null) {
document = searcher.doc(scoreDocs[index].doc, fieldsToLoad);
} else {
document = searcher.doc(scoreDocs[index].doc);
}
return transformer.apply(document);
} else {
return null;
}
} catch (IOException | IllegalArgumentException e) {
throw new QueryException(e);
}
}
Aggregations