-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-17764 query result types and single-item selection lists
- allow single-item auto-instantiation - check the type of the selection item against the given result type
- Loading branch information
Showing
19 changed files
with
366 additions
and
111 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
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
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
41 changes: 41 additions & 0 deletions
41
...ate-core/src/main/java/org/hibernate/sql/results/internal/RowTransformerCheckingImpl.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,41 @@ | ||
/* | ||
* 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.sql.results.internal; | ||
|
||
import org.hibernate.TypeMismatchException; | ||
import org.hibernate.sql.results.spi.RowTransformer; | ||
|
||
/** | ||
* @author Gavin King | ||
*/ | ||
public class RowTransformerCheckingImpl<R> implements RowTransformer<R> { | ||
|
||
private final Class<R> type; | ||
|
||
public RowTransformerCheckingImpl(Class<R> type) { | ||
this.type = type; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public R transformRow(Object[] row) { | ||
final Object result = row[0]; | ||
if ( result == null || type.isInstance( result ) ) { | ||
return (R) result; | ||
} | ||
else { | ||
throw new TypeMismatchException( "Result type is '" + type.getSimpleName() | ||
+ "' but the query returned a '" + result.getClass().getSimpleName() + "'" ); | ||
} | ||
} | ||
|
||
@Override | ||
public int determineNumberOfResultElements(int rawElementCount) { | ||
return 1; | ||
} | ||
} |
Oops, something went wrong.