GeezerVison is showing github.com — NonUniqueResultException · jamesagada/objectbox-java@4ee5178
File tree
Expand file treeCollapse file tree
Open diff view settings
objectbox-java/src/main/java/io/objectbox tests/objectbox-java-test/src/test/java/io/objectbox/query
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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 | +} |
Collapse file
Copy file name to clipboardExpand all lines: objectbox-java/src/main/java/io/objectbox/query/Query.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -169,7 +169,7 @@ private void ensureNoComparator() { |
169 | 169 | /** |
170 | 170 | * Find the unique Object matching the query. |
171 | 171 | * |
172 | | - * @throws io.objectbox.exception.DbException if result was not unique |
| 172 | + * @throws io.objectbox.exception.NonUniqueResultException if result was not unique |
173 | 173 | */ |
174 | 174 | @Nullable |
175 | 175 | public T findUnique() { |
|
Collapse file
Copy file name to clipboardExpand all lines: tests/objectbox-java-test/src/test/java/io/objectbox/query/QueryTest.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
33 | 33 | import io.objectbox.TestEntity; |
34 | 34 | import io.objectbox.TestEntity_; |
35 | 35 | import io.objectbox.TxCallback; |
36 | | -import io.objectbox.exception.DbException; |
37 | 36 | import io.objectbox.exception.DbExceptionListener; |
| 37 | +import io.objectbox.exception.NonUniqueResultException; |
38 | 38 | import io.objectbox.query.QueryBuilder.StringOrder; |
39 | 39 | import io.objectbox.relation.MyObjectBox; |
40 | 40 | import io.objectbox.relation.Order; |
@@ -720,7 +720,7 @@ public void onDbException(Exception e) { |
720 | 720 | try { |
721 | 721 | query.findUnique(); |
722 | 722 | fail("Should have thrown"); |
723 | | - } catch (DbException e) { |
| 723 | + } catch (NonUniqueResultException e) { |
724 | 724 | assertSame(e, exs[0]); |
725 | 725 | } |
726 | 726 | } |
|