HHH-8560 - Add (trace/debug) logging of SQL ResultSet mapping info
This commit is contained in:
parent
1a621666e1
commit
0d7854a15d
|
@ -27,6 +27,8 @@ import java.io.Serializable;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn;
|
||||
|
||||
/**
|
||||
|
@ -74,4 +76,25 @@ public class ResultSetMappingDefinition implements Serializable {
|
|||
return queryReturns.toArray( new NativeSQLQueryReturn[queryReturns.size()] );
|
||||
}
|
||||
|
||||
public String traceLoggableFormat() {
|
||||
final StringBuilder buffer = new StringBuilder()
|
||||
.append( "ResultSetMappingDefinition[\n" )
|
||||
.append( " name=" ).append( name ).append( "\n" )
|
||||
.append( " returns=[\n" );
|
||||
|
||||
for ( NativeSQLQueryReturn rtn : queryReturns ) {
|
||||
rtn.traceLog(
|
||||
new NativeSQLQueryReturn.TraceLogger() {
|
||||
@Override
|
||||
public void writeLine(String traceLine) {
|
||||
buffer.append( " " + traceLine + "\n" );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
buffer.append( " ]\n" ).append( "]" );
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,4 +46,25 @@ public class NativeSQLQueryConstructorReturn implements NativeSQLQueryReturn {
|
|||
public NativeSQLQueryScalarReturn[] getColumnReturns() {
|
||||
return columnReturns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceLog(final TraceLogger logger) {
|
||||
logger.writeLine( "Constructor[" );
|
||||
logger.writeLine( " targetClass=" + targetClass + "," );
|
||||
logger.writeLine( " columns=[" );
|
||||
|
||||
TraceLogger nestedLogger = new TraceLogger() {
|
||||
@Override
|
||||
public void writeLine(String traceLine) {
|
||||
logger.writeLine( " " + traceLine );
|
||||
}
|
||||
};
|
||||
|
||||
for ( NativeSQLQueryScalarReturn columnReturn : columnReturns ) {
|
||||
columnReturn.traceLog( nestedLogger );
|
||||
}
|
||||
|
||||
logger.writeLine( " ]" );
|
||||
logger.writeLine( "]" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,4 +123,20 @@ public abstract class NativeSQLQueryNonScalarReturn implements NativeSQLQueryRet
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceLog(TraceLogger logger) {
|
||||
if ( NativeSQLQueryRootReturn.class.isInstance( this ) ) {
|
||||
logger.writeLine( "Entity(...)" );
|
||||
}
|
||||
else if ( NativeSQLQueryCollectionReturn.class.isInstance( this ) ) {
|
||||
logger.writeLine( "Collection(...)" );
|
||||
}
|
||||
else if ( NativeSQLQueryJoinReturn.class.isInstance( this ) ) {
|
||||
logger.writeLine( "Join(...)" );
|
||||
}
|
||||
else {
|
||||
logger.writeLine( getClass().getName() + "(...)" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,4 +33,9 @@ package org.hibernate.engine.query.spi.sql;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface NativeSQLQueryReturn {
|
||||
public static interface TraceLogger {
|
||||
public void writeLine(String traceLine);
|
||||
}
|
||||
|
||||
public void traceLog(TraceLogger logger);
|
||||
}
|
||||
|
|
|
@ -79,4 +79,12 @@ public class NativeSQLQueryScalarReturn implements NativeSQLQueryReturn {
|
|||
result = 31 * result + ( columnAlias != null ? columnAlias.hashCode() : 0 );
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traceLog(TraceLogger logger) {
|
||||
logger.writeLine( "Scalar[" );
|
||||
logger.writeLine( " columnAlias=" + columnAlias + "," );
|
||||
logger.writeLine( " type=" + ( type == null ? "<unknown>" : type.getName() ) + "," );
|
||||
logger.writeLine( "]" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ package org.hibernate.procedure.internal;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.engine.ResultSetMappingDefinition;
|
||||
|
@ -43,6 +45,8 @@ import org.hibernate.procedure.UnknownSqlResultSetMappingException;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Util {
|
||||
private static final Logger log = Logger.getLogger( Util.class );
|
||||
|
||||
private Util() {
|
||||
}
|
||||
|
||||
|
@ -128,11 +132,14 @@ public class Util {
|
|||
*/
|
||||
public static void resolveResultSetMappings(ResultSetMappingResolutionContext context, String... resultSetMappingNames) {
|
||||
for ( String resultSetMappingName : resultSetMappingNames ) {
|
||||
log.tracef( "Starting attempt resolve named result-set-mapping : %s", resultSetMappingName );
|
||||
final ResultSetMappingDefinition mapping = context.findResultSetMapping( resultSetMappingName );
|
||||
if ( mapping == null ) {
|
||||
throw new UnknownSqlResultSetMappingException( "Unknown SqlResultSetMapping [" + resultSetMappingName + "]" );
|
||||
}
|
||||
|
||||
log.tracef( "Found result-set-mapping : %s", mapping.traceLoggableFormat() );
|
||||
|
||||
context.addQueryReturns( mapping.getQueryReturns() );
|
||||
|
||||
final SQLQueryReturnProcessor processor =
|
||||
|
|
Loading…
Reference in New Issue