Class QueryExecutionInfoFormatter
java.lang.Object
io.r2dbc.proxy.support.QueryExecutionInfoFormatter
- All Implemented Interfaces:
Function<QueryExecutionInfo, String>
public class QueryExecutionInfoFormatter
extends Object
implements Function<QueryExecutionInfo, String>
Convert
QueryExecutionInfo
to String
.
Sample usage:
// convert all info
QueryExecutionInfoFormatter formatter = QueryExecutionInfoFormatter.showAll();
String str = formatter.format(queryExecutionInfo);
// customize conversion
QueryExecutionInfoFormatter formatter = new QueryExecutionInfoFormatter();
formatter.addConsumer((execInfo, sb) -> {
sb.append("MY-QUERY-EXECUTION="); // add prefix
};
formatter.newLine(); // new line
formatter.showSuccess();
formatter.addConsumer((execInfo, sb) -> {
// custom conversion
sb.append("MY-ID=" + executionInfo.getConnectionInfo().getConnectionId());
});
formatter.showQuery();
// convert it
String str = formatter.format(queryExecutionInfo);
- Author:
- Tadaya Tsuyukubo
-
Field Summary
FieldsModifier and TypeFieldDescriptionDefault implementation for formatting bindings.Default implementation for formatting bound value.Default implementation for formattingParameter
value.Default implementation for formatting actual value of bound value.Default implementation for formatting bindings by index.Default implementation for formatting bindings by name. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddConsumer
(BiConsumer<QueryExecutionInfo, StringBuilder> consumer) apply
(QueryExecutionInfo executionInfo) boundValue
(BiConsumer<BoundValue, StringBuilder> onBoundValue) Set a consumer for convertingBoundValue
.Set a delimiter between each consumerformat
(QueryExecutionInfo executionInfo) Convert the givenQueryExecutionInfo
toString
using registered consumers.indexBindings
(BiConsumer<SortedSet<Binding>, StringBuilder> onIndexBindings) namedBindings
(BiConsumer<SortedSet<Binding>, StringBuilder> onNamedBindings) newLine()
Change the linestatic QueryExecutionInfoFormatter
showAll()
Create aQueryExecutionInfoFormatter
which writes out all attributes onQueryExecutionInfo
.Show batch size with default format.Show bindings with default format.Show binding size with default format.Show connection information with default format.Show query with default format.Show query success with default format.Show thread information with default format.showTime()
Show query execution duration with default format.Show transaction information with default format.showType()
Show statement type(batch or statement) with default format.
-
Field Details
-
onBoundValue
Default implementation for formatting bound value. -
onBoundValueRaw
Default implementation for formatting actual value of bound value.Example: "100", "Foo", "<clob>".
-
onBoundValueParameter
Default implementation for formattingParameter
value.Example: "null(in,INTEGER)", "Foo(out,String)".
-
onIndexBindings
Default implementation for formatting bindings by index. generate comma separated values. "val1,val2,val3" -
onNamedBindings
Default implementation for formatting bindings by name. Generate comma separated key-values pair string. "key1=val1,key2=val2,key3=val3" -
onBindings
Default implementation for formatting bindings.
-
-
Constructor Details
-
QueryExecutionInfoFormatter
public QueryExecutionInfoFormatter()
-
-
Method Details
-
showAll
Create aQueryExecutionInfoFormatter
which writes out all attributes onQueryExecutionInfo
.- Returns:
- a formatter
-
addConsumer
public QueryExecutionInfoFormatter addConsumer(BiConsumer<QueryExecutionInfo, StringBuilder> consumer) - Parameters:
consumer
- aBiConsumer
that takes aQueryExecutionInfo
and write to theStringBuilder
.- Returns:
- this formatter
- Throws:
IllegalArgumentException
- ifconsumer
isnull
-
format
Convert the givenQueryExecutionInfo
toString
using registered consumers.- Parameters:
executionInfo
- input- Returns:
- formatted sting
- Throws:
IllegalArgumentException
- ifexecutionInfo
isnull
-
apply
- Specified by:
apply
in interfaceFunction<QueryExecutionInfo, String>
-
delimiter
Set a delimiter between each consumer- Parameters:
delimiter
- delimiter- Returns:
- formatter
- Throws:
IllegalArgumentException
- ifdelimiter
isnull
-
showThread
Show thread information with default format.- Returns:
- formatter
-
showConnection
Show connection information with default format.- Returns:
- formatter
-
showTransaction
Show transaction information with default format.- Returns:
- formatter
-
showSuccess
Show query success with default format.- Returns:
- formatter
-
showTime
Show query execution duration with default format.- Returns:
- formatter
-
showType
Show statement type(batch or statement) with default format.- Returns:
- formatter
-
showBatchSize
Show batch size with default format. i.e. Number of the calls ofBatch.add(String)
}.- Returns:
- formatter
-
showBindingsSize
Show binding size with default format. i.e. Number of the calls ofStatement.add()
}.- Returns:
- formatter
-
showQuery
-
showBindings
Show bindings with default format.- Returns:
- formatter
-
newLine
-
boundValue
Set a consumer for convertingBoundValue
.- Parameters:
onBoundValue
- bi-consumer for binding value- Returns:
- formatter
- Throws:
IllegalArgumentException
- ifonBoundValue
isnull
-
indexBindings
public QueryExecutionInfoFormatter indexBindings(BiConsumer<SortedSet<Binding>, StringBuilder> onIndexBindings) - Parameters:
onIndexBindings
- bi-consumer for index-bindings- Returns:
- formatter
- Throws:
IllegalArgumentException
- ifonIndexBindings
isnull
-
namedBindings
public QueryExecutionInfoFormatter namedBindings(BiConsumer<SortedSet<Binding>, StringBuilder> onNamedBindings) - Parameters:
onNamedBindings
- bi-consumer for named-bindings- Returns:
- formatter
- Throws:
IllegalArgumentException
- ifonNamedBindings
isnull
-