Skip to content

Commit 4ee5178

Browse files
committed
NonUniqueResultException
1 parent 5504c71 commit 4ee5178

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2018 ObjectBox Ltd. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.objectbox.exception;
18+
19+
/** Throw if {@link io.objectbox.query.Query#findUnique()} returns more than one result. */
20+
public class NonUniqueResultException extends DbException {
21+
public NonUniqueResultException(String message) {
22+
super(message);
23+
}
24+
}

objectbox-java/src/main/java/io/objectbox/query/Query.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ private void ensureNoComparator() {
169169
/**
170170
* Find the unique Object matching the query.
171171
*
172-
* @throws io.objectbox.exception.DbException if result was not unique
172+
* @throws io.objectbox.exception.NonUniqueResultException if result was not unique
173173
*/
174174
@Nullable
175175
public T findUnique() {

tests/objectbox-java-test/src/test/java/io/objectbox/query/QueryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import io.objectbox.TestEntity;
3434
import io.objectbox.TestEntity_;
3535
import io.objectbox.TxCallback;
36-
import io.objectbox.exception.DbException;
3736
import io.objectbox.exception.DbExceptionListener;
37+
import io.objectbox.exception.NonUniqueResultException;
3838
import io.objectbox.query.QueryBuilder.StringOrder;
3939
import io.objectbox.relation.MyObjectBox;
4040
import io.objectbox.relation.Order;
@@ -720,7 +720,7 @@ public void onDbException(Exception e) {
720720
try {
721721
query.findUnique();
722722
fail("Should have thrown");
723-
} catch (DbException e) {
723+
} catch (NonUniqueResultException e) {
724724
assertSame(e, exs[0]);
725725
}
726726
}

0 commit comments

Comments
 (0)