From 1ce0bca17958e04d3f1070aefe86d3a7df305da2 Mon Sep 17 00:00:00 2001 From: Jan Schatteman Date: Thu, 6 Apr 2023 17:30:53 +0200 Subject: [PATCH] Remove some unnecessary code duplications in AbstractSelectionQuery and AbstractQuery Signed-off-by: Jan Schatteman --- .../hibernate/query/spi/AbstractQuery.java | 27 ++++++------------- .../query/spi/AbstractSelectionQuery.java | 9 +------ 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java index b0b0dfa79e..ed9870b7a2 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java @@ -130,27 +130,18 @@ public abstract class AbstractQuery @Override public int getMaxResults() { - getSession().checkOpen(); - return getQueryOptions().getLimit().getMaxRowsJpa(); + return super.getMaxResults(); } @Override public QueryImplementor setMaxResults(int maxResult) { - if ( maxResult < 0 ) { - throw new IllegalArgumentException( "max-results cannot be negative" ); - } - - getSession().checkOpen(); - - getQueryOptions().getLimit().setMaxRows( maxResult ); - + super.setMaxResults( maxResult ); return this; } @Override public int getFirstResult() { - getSession().checkOpen(); - return getQueryOptions().getLimit().getFirstRowJpa(); + return super.getFirstResult(); } @Override @@ -256,7 +247,7 @@ public abstract class AbstractQuery @Override public LockModeType getLockMode() { getSession().checkOpen( false ); - return LockModeTypeHelper.getLockModeType( getQueryOptions().getLockOptions().getLockMode() ); + return super.getLockMode(); } @Override @@ -274,18 +265,18 @@ public abstract class AbstractQuery @Override public QueryImplementor setLockMode(LockModeType lockModeType) { getSession().checkOpen(); - getQueryOptions().getLockOptions().setLockMode( LockModeTypeHelper.getLockMode( lockModeType ) ); + super.setHibernateLockMode( LockModeTypeHelper.getLockMode( lockModeType ) ); return this; } @Override public String getComment() { - return getQueryOptions().getComment(); + return super.getComment(); } @Override public QueryImplementor setComment(String comment) { - getQueryOptions().setComment( comment ); + super.setComment( comment ); return this; } @@ -365,8 +356,7 @@ public abstract class AbstractQuery @Override @SuppressWarnings( {"unchecked", "rawtypes"} ) public Set> getParameters() { - getSession().checkOpen( false ); - return (Set) getParameterMetadata().getRegistrations(); + return super.getParameters(); } @Override @@ -518,7 +508,6 @@ public abstract class AbstractQuery @Override public

QueryImplementor setParameterList(int position, Collection values, Class

javaTypeClass) { super.setParameterList( position, values, javaTypeClass ); - return this; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java index 7e4866c56a..b11e772720 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java @@ -541,14 +541,7 @@ public abstract class AbstractSelectionQuery @Override public SelectionQuery setMaxResults(int maxResult) { - if ( maxResult < 0 ) { - throw new IllegalArgumentException( "max-results cannot be negative" ); - } - - getSession().checkOpen(); - - getQueryOptions().getLimit().setMaxRows( maxResult ); - + super.applyMaxResults( maxResult ); return this; }