Skip to content

Commit 3d14d1b

Browse files
committed
minor cleanups in QueryBinder
1 parent 33fec62 commit 3d14d1b

File tree

3 files changed

+50
-69
lines changed

3 files changed

+50
-69
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ public static void bindDefaults(MetadataBuildingContext context) {
159159
@SuppressWarnings("unchecked")
160160
List<SqlResultSetMapping> mappings = ( List<SqlResultSetMapping> ) defaults.get( SqlResultSetMapping.class );
161161
if ( mappings != null ) {
162-
for ( SqlResultSetMapping ann : mappings ) {
163-
QueryBinder.bindSqlResultSetMapping( ann, context, true );
162+
for ( SqlResultSetMapping annotation : mappings ) {
163+
QueryBinder.bindSqlResultSetMapping( annotation, context, true );
164164
}
165165
}
166166
}
@@ -262,12 +262,11 @@ private static void bindNamedJpaQueries(XAnnotatedElement annotatedElement, Meta
262262
false
263263
);
264264

265-
final SqlResultSetMappings ann = annotatedElement.getAnnotation( SqlResultSetMappings.class );
266-
if ( ann != null ) {
267-
for ( SqlResultSetMapping current : ann.value() ) {
268-
QueryBinder.bindSqlResultSetMapping( current, context, false );
269-
}
270-
}
265+
QueryBinder.bindSqlResultSetMappings(
266+
annotatedElement.getAnnotation( SqlResultSetMappings.class ),
267+
context,
268+
false
269+
);
271270

272271
QueryBinder.bindQuery(
273272
annotatedElement.getAnnotation( NamedQuery.class ),

hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java

Lines changed: 42 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,11 @@ public static NamedProcedureCallDefinition createStoredProcedure(
223223
if ( !sqlString.startsWith( "{" ) || !sqlString.endsWith( "}" ) ) {
224224
throw exceptionProducer.get();
225225
}
226-
final JdbcCall jdbcCall = parseJdbcCall(
227-
sqlString,
228-
exceptionProducer
229-
);
226+
final JdbcCall jdbcCall = parseJdbcCall( sqlString, exceptionProducer );
230227

231-
AnnotationDescriptor ann = new AnnotationDescriptor( NamedStoredProcedureQuery.class );
232-
ann.setValue( "name", builder.getName() );
233-
ann.setValue( "procedureName", jdbcCall.callableName );
228+
AnnotationDescriptor descriptor = new AnnotationDescriptor( NamedStoredProcedureQuery.class );
229+
descriptor.setValue( "name", builder.getName() );
230+
descriptor.setValue( "procedureName", jdbcCall.callableName );
234231

235232
for ( String parameterName : jdbcCall.parameters ) {
236233
AnnotationDescriptor parameterDescriptor = new AnnotationDescriptor( StoredProcedureParameter.class );
@@ -249,20 +246,20 @@ public static NamedProcedureCallDefinition createStoredProcedure(
249246
}
250247
storedProcedureParameters.add( AnnotationFactory.create( parameterDescriptor ) );
251248
}
252-
ann.setValue(
249+
descriptor.setValue(
253250
"parameters",
254251
storedProcedureParameters.toArray( new StoredProcedureParameter[storedProcedureParameters.size()] )
255252
);
256253

257254
if ( builder.getResultSetMappingName() != null ) {
258-
ann.setValue( "resultSetMappings", new String[]{ builder.getResultSetMappingName() } );
255+
descriptor.setValue( "resultSetMappings", new String[]{ builder.getResultSetMappingName() } );
259256
}
260257
else {
261-
ann.setValue( "resultSetMappings", new String[0] );
258+
descriptor.setValue( "resultSetMappings", new String[0] );
262259
}
263260

264261
if ( builder.getResultSetMappingClassName() != null ) {
265-
ann.setValue(
262+
descriptor.setValue(
266263
"resultClasses",
267264
new Class[] {
268265
context.getBootstrapContext()
@@ -271,7 +268,7 @@ public static NamedProcedureCallDefinition createStoredProcedure(
271268
);
272269
}
273270
else {
274-
ann.setValue( "resultClasses", new Class[0] );
271+
descriptor.setValue( "resultClasses", new Class[0] );
275272
}
276273

277274
if ( builder.getQuerySpaces() != null ) {
@@ -289,9 +286,9 @@ public static NamedProcedureCallDefinition createStoredProcedure(
289286
queryHints.add( AnnotationFactory.create( hintDescriptor2 ) );
290287
}
291288

292-
ann.setValue( "hints", queryHints.toArray( new QueryHint[queryHints.size()] ) );
289+
descriptor.setValue( "hints", queryHints.toArray( new QueryHint[queryHints.size()] ) );
293290

294-
return new NamedProcedureCallDefinitionImpl( AnnotationFactory.create( ann ) );
291+
return new NamedProcedureCallDefinitionImpl( AnnotationFactory.create( descriptor ) );
295292
}
296293

297294
public static void bindQueries(NamedQueries namedQueries, MetadataBuildingContext context, boolean isDefault) {
@@ -368,27 +365,20 @@ private static CacheMode getCacheMode(org.hibernate.annotations.NamedNativeQuery
368365
}
369366

370367
private static FlushMode getFlushMode(FlushModeType flushModeType) {
371-
FlushMode flushMode;
372368
switch ( flushModeType ) {
373369
case ALWAYS:
374-
flushMode = FlushMode.ALWAYS;
375-
break;
370+
return FlushMode.ALWAYS;
376371
case AUTO:
377-
flushMode = FlushMode.AUTO;
378-
break;
372+
return FlushMode.AUTO;
379373
case COMMIT:
380-
flushMode = FlushMode.COMMIT;
381-
break;
374+
return FlushMode.COMMIT;
382375
case MANUAL:
383-
flushMode = FlushMode.MANUAL;
384-
break;
376+
return FlushMode.MANUAL;
385377
case PERSISTENCE_CONTEXT:
386-
flushMode = null;
387-
break;
378+
return null;
388379
default:
389-
throw new AssertionFailure( "Unknown flushModeType: " + flushModeType );
380+
throw new AssertionFailure( "Unknown FlushModeType: " + flushModeType );
390381
}
391-
return flushMode;
392382
}
393383

394384
private static CacheMode getCacheMode(CacheModeType cacheModeType) {
@@ -410,60 +400,52 @@ private static CacheMode getCacheMode(CacheModeType cacheModeType) {
410400

411401

412402
public static void bindQueries(
413-
org.hibernate.annotations.NamedQueries queriesAnn,
403+
org.hibernate.annotations.NamedQueries namedQueries,
414404
MetadataBuildingContext context) {
415-
if ( queriesAnn == null ) {
416-
return;
417-
}
418-
419-
for (org.hibernate.annotations.NamedQuery q : queriesAnn.value()) {
420-
bindQuery( q, context );
405+
if ( namedQueries != null ) {
406+
for (org.hibernate.annotations.NamedQuery namedQuery : namedQueries.value()) {
407+
bindQuery( namedQuery, context );
408+
}
421409
}
422410
}
423411

424412
public static void bindNamedStoredProcedureQuery(
425-
NamedStoredProcedureQuery annotation,
413+
NamedStoredProcedureQuery namedStoredProcedureQuery,
426414
MetadataBuildingContext context,
427415
boolean isDefault) {
428-
if ( annotation == null ) {
429-
return;
430-
}
431-
432-
if ( annotation.name().isEmpty() ) {
433-
throw new AnnotationException( "Class or package level '@NamedStoredProcedureQuery' annotation must specify a 'name'" );
434-
}
435-
436-
final NamedProcedureCallDefinitionImpl def = new NamedProcedureCallDefinitionImpl( annotation );
416+
if ( namedStoredProcedureQuery != null ) {
417+
if ( namedStoredProcedureQuery.name().isEmpty() ) {
418+
throw new AnnotationException( "Class or package level '@NamedStoredProcedureQuery' annotation must specify a 'name'" );
419+
}
437420

438-
if ( isDefault ) {
439-
context.getMetadataCollector().addDefaultNamedProcedureCall( def );
440-
}
441-
else {
442-
context.getMetadataCollector().addNamedProcedureCallDefinition( def );
421+
final NamedProcedureCallDefinitionImpl definition = new NamedProcedureCallDefinitionImpl( namedStoredProcedureQuery );
422+
if ( isDefault ) {
423+
context.getMetadataCollector().addDefaultNamedProcedureCall( definition );
424+
}
425+
else {
426+
context.getMetadataCollector().addNamedProcedureCallDefinition( definition );
427+
}
428+
LOG.debugf( "Bound named stored procedure query : %s => %s", definition.getRegistrationName(), definition.getProcedureName() );
443429
}
444-
LOG.debugf( "Bound named stored procedure query : %s => %s", def.getRegistrationName(), def.getProcedureName() );
445430
}
446431

447432
public static void bindSqlResultSetMappings(
448-
SqlResultSetMappings ann,
433+
SqlResultSetMappings resultSetMappings,
449434
MetadataBuildingContext context,
450435
boolean isDefault) {
451-
if ( ann == null ) {
452-
return;
453-
}
454-
455-
for (SqlResultSetMapping rs : ann.value()) {
456-
//no need to handle inSecondPass
457-
context.getMetadataCollector().addSecondPass( new ResultSetMappingSecondPass( rs, context, true ) );
436+
if ( resultSetMappings != null ) {
437+
for ( SqlResultSetMapping resultSetMapping : resultSetMappings.value() ) {
438+
bindSqlResultSetMapping( resultSetMapping, context, isDefault );
439+
}
458440
}
459441
}
460442

461443
public static void bindSqlResultSetMapping(
462-
SqlResultSetMapping ann,
444+
SqlResultSetMapping resultSetMapping,
463445
MetadataBuildingContext context,
464446
boolean isDefault) {
465447
//no need to handle inSecondPass
466-
context.getMetadataCollector().addSecondPass( new ResultSetMappingSecondPass( ann, context, isDefault ) );
448+
context.getMetadataCollector().addSecondPass( new ResultSetMappingSecondPass( resultSetMapping, context, isDefault ) );
467449
}
468450

469451
private static class JdbcCall {

hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryHintDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public LockOptions determineLockOptions(NamedQuery namedQueryAnnotation) {
154154
final Integer lockTimeoutHint = specLockTimeout();
155155
final Boolean followOnLocking = getBooleanWrapper( HibernateHints.HINT_FOLLOW_ON_LOCKING );
156156

157-
return determineLockOptions(lockModeType, lockTimeoutHint, followOnLocking);
157+
return determineLockOptions( lockModeType, lockTimeoutHint, followOnLocking );
158158
}
159159

160160
private Integer specLockTimeout() {

0 commit comments

Comments
 (0)