Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ protected static <T> RowTransformer<T> determineRowTransformer(
if ( queryOptions.getTupleTransformer() != null ) {
return makeRowTransformerTupleTransformerAdapter( sqm, queryOptions );
}
else if ( resultClass == null ) {
else if ( resultClass == null || resultClass == Object.class ) {
return RowTransformerStandardImpl.instance();
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public abstract class AbstractSqmSelectQuery<T>
implements SqmSelectQuery<T> {
private final Map<String, SqmCteStatement<?>> cteStatements;
private SqmQueryPart<T> sqmQueryPart;
private Class<T> resultType;
private final Class<T> resultType;

public AbstractSqmSelectQuery(Class<T> resultType, NodeBuilder builder) {
this( new SqmQuerySpec<>( builder ), resultType, builder );
Expand Down Expand Up @@ -204,8 +204,12 @@ public Class<T> getResultType() {
return resultType;
}

/**
* @deprecated Don't use this method. It has no effect.
*/
@Deprecated(forRemoval = true)
protected void setResultType(Class<T> resultType) {
this.resultType = resultType;
// No-op
}

@Override
Expand Down Expand Up @@ -412,7 +416,6 @@ protected Selection<? extends T> getResultSelection(Selection<?>[] selections) {
break;
}
default: {
setResultType( (Class<T>) Object[].class );
resultSelection = ( Selection<? extends T> ) nodeBuilder().array( selections );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ public SqmSelectStatement<T> copy(SqmCopyContext context) {
if ( existing != null ) {
return existing;
}
return createCopy( context, getResultType() );
}

private <X> SqmSelectStatement<X> createCopy(SqmCopyContext context, Class<X> resultType) {
final Set<SqmParameter<?>> parameters;
if ( this.parameters == null ) {
parameters = null;
Expand All @@ -129,17 +133,19 @@ public SqmSelectStatement<T> copy(SqmCopyContext context) {
parameters.add( parameter.copy( context ) );
}
}
final SqmSelectStatement<T> statement = context.registerCopy(
//noinspection unchecked
final SqmSelectStatement<X> statement = (SqmSelectStatement<X>) context.registerCopy(
this,
new SqmSelectStatement<>(
nodeBuilder(),
copyCteStatements( context ),
getResultType(),
resultType,
getQuerySource(),
parameters
)
);
statement.setQueryPart( getQueryPart().copy( context ) );
//noinspection unchecked
statement.setQueryPart( (SqmQueryPart<X>) getQueryPart().copy( context ) );
return statement;
}

Expand Down Expand Up @@ -266,9 +272,6 @@ public SqmSelectStatement<T> select(Selection<? extends T> selection) {
checkSelectionIsJpaCompliant( selection );
}
getQuerySpec().setSelection( (JpaSelection<T>) selection );
if ( getResultType() == Object.class ) {
setResultType( (Class<T>) selection.getJavaType() );
}
return this;
}

Expand Down Expand Up @@ -313,7 +316,6 @@ private Selection<? extends T> getResultSelection(List<?> selectionList) {
return (Selection<? extends T>) selectionList.get( 0 );
}
default: {
setResultType( (Class<T>) Object[].class );
return (Selection<? extends T>) nodeBuilder().array( selections );
}
}
Expand Down Expand Up @@ -461,14 +463,14 @@ private void validateComplianceFetchOffset() {

@Override
public SqmSelectStatement<Long> createCountQuery() {
final SqmSelectStatement<?> copy = copy( noParamCopyContext() );
final SqmQuerySpec<?> querySpec = copy.getQuerySpec();
final SqmSelectStatement<?> copy = createCopy( noParamCopyContext(), Object.class );
final SqmQueryPart<?> queryPart = copy.getQueryPart();
final SqmQuerySpec<?> querySpec;
//TODO: detect queries with no 'group by', but aggregate functions
// in 'select' list (we don't even need to hit the database to
// know they return exactly one row)
if ( queryPart.isSimpleQueryPart()
&& !querySpec.isDistinct()
&& !( querySpec = (SqmQuerySpec<?>) queryPart ).isDistinct()
&& querySpec.getGroupingExpressions().isEmpty() ) {
for ( SqmRoot<?> root : querySpec.getRootList() ) {
root.removeLeftFetchJoins();
Expand All @@ -478,24 +480,21 @@ public SqmSelectStatement<Long> createCountQuery() {
querySpec.setOrderByClause( null );
}

@SuppressWarnings("unchecked")
final SqmSelectStatement<Long> statement = (SqmSelectStatement<Long>) copy;
statement.setResultType( Long.class );
return statement;
return (SqmSelectStatement<Long>) copy;
}
else {
final JpaSelection<?> selection = querySpec.getSelection();
final JpaSelection<?> selection = queryPart.getFirstQuerySpec().getSelection();
if ( selection.isCompoundSelection() ) {
char c = 'a';
for ( JpaSelection<?> item: selection.getSelectionItems() ) {
item.alias( Character.toString(++c) + '_' );
for ( JpaSelection<?> item : selection.getSelectionItems() ) {
item.alias( Character.toString( ++c ) + '_' );
}
}
else {
selection.alias("a_");
selection.alias( "a_" );
}
final SqmSubQuery<?> subquery = new SqmSubQuery<>( copy, queryPart, null, nodeBuilder() );
final SqmSelectStatement<Long> query = nodeBuilder().createQuery(Long.class);
final SqmSelectStatement<Long> query = nodeBuilder().createQuery( Long.class );
query.from( subquery );
query.select( nodeBuilder().count() );
return query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ public SqmSubQuery<T> multiselect(List<Selection<?>> selectionList) {
break;
}
default: {
setResultType( (Class<T>) Object[].class );
resultSelection = ( Selection<? extends T> ) nodeBuilder().array( selections );
}
}
Expand Down Expand Up @@ -609,9 +608,6 @@ public SqmExpressible<T> getNodeType() {
public void applyInferableType(SqmExpressible<?> type) {
//noinspection unchecked
expressibleType = (SqmExpressible<T>) type;
if ( expressibleType != null && expressibleType.getExpressibleJavaType() != null ) {
setResultType( expressibleType.getExpressibleJavaType().getJavaTypeClass() );
}
}

private void applyInferableType(Class<T> type) {
Expand Down