-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move some boilerplate exception-throwing into a utility class in core
Signed-off-by: Gavin King <gavin@hibernate.org>
- Loading branch information
Showing
6 changed files
with
82 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
hibernate-core/src/main/java/org/hibernate/exception/spi/Exceptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.exception.spi; | ||
|
||
import org.hibernate.Incubating; | ||
import org.hibernate.ObjectNotFoundException; | ||
|
||
/** | ||
* Utility methods used by Hibernate Processor. | ||
* | ||
* @author Gavin King | ||
* | ||
* @since 6.5 | ||
*/ | ||
@Incubating | ||
public class Exceptions { | ||
public static <E> E require(E entity, String entityName, Object id) { | ||
if ( entity == null ) { | ||
throw new ObjectNotFoundException( entityName, id ); | ||
} | ||
else { | ||
return entity; | ||
} | ||
} | ||
|
||
public static void require(Object argument, String parameterName) { | ||
if ( argument == null ) { | ||
throw new IllegalArgumentException("Null " + parameterName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters