-
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.
experiment with allowing single-item auto-instantiation
- Loading branch information
Showing
19 changed files
with
367 additions
and
110 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
57 changes: 57 additions & 0 deletions
57
...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,57 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* @author Gavin King | ||
*/ | ||
public class RowTransformerCheckingImpl<R> implements RowTransformer<R> { | ||
|
||
private final Class<R> type; | ||
private final Class<?> objectType; | ||
|
||
private static final Map<Class<?>,Class<?>> WRAPPERS | ||
= Map.of( | ||
boolean.class, Boolean.class, | ||
int.class, Integer.class, | ||
long.class, Long.class, | ||
short.class, Short.class, | ||
byte.class, Byte.class, | ||
float.class, Float.class, | ||
double.class, Double.class, | ||
char.class, Character.class | ||
); | ||
|
||
public RowTransformerCheckingImpl(Class<R> type) { | ||
this.type = type; | ||
objectType = WRAPPERS.getOrDefault(type, type); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public R transformRow(Object[] row) { | ||
final Object result = row[0]; | ||
if ( result == null || objectType.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.