HHH-10405: <return> elements of <sql-query> are not handled properly when building metadata - Refactoring
This commit is contained in:
parent
9e89826f8f
commit
3d237f67ba
|
@ -6,14 +6,11 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.boot.model.source.internal.hbm;
|
package org.hibernate.boot.model.source.internal.hbm;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import javax.xml.bind.JAXBElement;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBElement;
|
|
||||||
|
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.boot.jaxb.hbm.internal.ImplicitResultSetMappingDefinition;
|
import org.hibernate.boot.jaxb.hbm.internal.ImplicitResultSetMappingDefinition;
|
||||||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNamedNativeQueryType;
|
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmNamedNativeQueryType;
|
||||||
|
@ -170,32 +167,18 @@ public class NamedQueryBinder {
|
||||||
|
|
||||||
final ImplicitResultSetMappingDefinition implicitResultSetMappingDefinition = implicitResultSetMappingBuilder.build();
|
final ImplicitResultSetMappingDefinition implicitResultSetMappingDefinition = implicitResultSetMappingBuilder.build();
|
||||||
builder.setResultSetRef( implicitResultSetMappingDefinition.getName() );
|
builder.setResultSetRef( implicitResultSetMappingDefinition.getName() );
|
||||||
|
|
||||||
context.getMetadataCollector().addSecondPass(
|
context.getMetadataCollector().addSecondPass(
|
||||||
new SecondPass() {
|
new SecondPass() {
|
||||||
@Override
|
@Override
|
||||||
public void doSecondPass(Map persistentClasses) throws MappingException {
|
public void doSecondPass(Map persistentClasses) throws MappingException {
|
||||||
ResultSetMappingDefinition resultSetMappingDefinition =
|
final ResultSetMappingDefinition resultSetMappingDefinition =
|
||||||
ResultSetMappingBinder.bind(implicitResultSetMappingDefinition, context);
|
ResultSetMappingBinder.bind( implicitResultSetMappingDefinition, context );
|
||||||
context.getMetadataCollector().addResultSetMapping(resultSetMappingDefinition);
|
context.getMetadataCollector().addResultSetMapping( resultSetMappingDefinition );
|
||||||
NativeSQLQueryReturn[] newQueryReturns = resultSetMappingDefinition.getQueryReturns();
|
NativeSQLQueryReturn[] newQueryReturns = resultSetMappingDefinition.getQueryReturns();
|
||||||
if (newQueryReturns != null && newQueryReturns.length > 0) {
|
final NamedSQLQueryDefinition queryDefinition =
|
||||||
List<NativeSQLQueryReturn> queryReturnList =
|
context.getMetadataCollector().getNamedNativeQueryDefinition( queryName );
|
||||||
new ArrayList<NativeSQLQueryReturn>();
|
if ( queryDefinition != null ) {
|
||||||
NamedSQLQueryDefinition queryDefinition =
|
queryDefinition.addQueryReturns( newQueryReturns );
|
||||||
context.getMetadataCollector().getNamedNativeQueryDefinition(queryName);
|
|
||||||
NativeSQLQueryReturn[] existingQueryReturns = queryDefinition.getQueryReturns();
|
|
||||||
if (existingQueryReturns != null && existingQueryReturns.length > 0) {
|
|
||||||
for (NativeSQLQueryReturn queryReturn : existingQueryReturns) {
|
|
||||||
queryReturnList.add(queryReturn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (NativeSQLQueryReturn queryReturn : newQueryReturns) {
|
|
||||||
queryReturnList.add(queryReturn);
|
|
||||||
}
|
|
||||||
NativeSQLQueryReturn[] allQueryReturns =
|
|
||||||
queryReturnList.toArray(new NativeSQLQueryReturn[queryReturnList.size()]);
|
|
||||||
queryDefinition.setQueryReturns(allQueryReturns);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.engine.spi;
|
package org.hibernate.engine.spi;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -223,7 +224,25 @@ public class NamedSQLQueryDefinition extends NamedQueryDefinition {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setQueryReturns(NativeSQLQueryReturn[] queryReturns) {
|
public void addQueryReturns(NativeSQLQueryReturn[] queryReturnsToAdd) {
|
||||||
this.queryReturns = queryReturns;
|
if ( queryReturnsToAdd != null && queryReturnsToAdd.length > 0 ) {
|
||||||
|
int initialQueryReturnsLength = 0;
|
||||||
|
if ( this.queryReturns != null ) {
|
||||||
|
initialQueryReturnsLength = this.queryReturns.length;
|
||||||
|
}
|
||||||
|
NativeSQLQueryReturn[] allQueryReturns = new NativeSQLQueryReturn[initialQueryReturnsLength + queryReturnsToAdd.length];
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for ( i = 0; i < initialQueryReturnsLength; i++ ) {
|
||||||
|
allQueryReturns[i] = this.queryReturns[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( int j = 0; j < queryReturnsToAdd.length; j++ ) {
|
||||||
|
allQueryReturns[i] = queryReturnsToAdd[j];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.queryReturns = allQueryReturns;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue