18
18
19
19
import io .r2dbc .postgresql .api .PostgresqlStatement ;
20
20
import io .r2dbc .postgresql .client .Binding ;
21
+ import io .r2dbc .postgresql .client .ConnectionContext ;
21
22
import io .r2dbc .postgresql .client .ExtendedQueryMessageFlow ;
22
23
import io .r2dbc .postgresql .message .backend .BackendMessage ;
23
24
import io .r2dbc .postgresql .message .backend .BindComplete ;
31
32
import java .util .Arrays ;
32
33
import java .util .HashSet ;
33
34
import java .util .List ;
34
- import java .util .Objects ;
35
35
import java .util .Set ;
36
36
import java .util .function .Predicate ;
37
37
import java .util .regex .Matcher ;
@@ -49,19 +49,22 @@ final class ExtendedQueryPostgresqlStatement implements PostgresqlStatement {
49
49
50
50
private final Bindings bindings ;
51
51
52
- private final ConnectionResources context ;
52
+ private final ConnectionResources resources ;
53
+
54
+ private final ConnectionContext connectionContext ;
53
55
54
56
private final String sql ;
55
57
56
58
private int fetchSize ;
57
59
58
60
private String [] generatedColumns ;
59
61
60
- ExtendedQueryPostgresqlStatement (ConnectionResources context , String sql ) {
61
- this .context = Assert .requireNonNull (context , "context must not be null" );
62
+ ExtendedQueryPostgresqlStatement (ConnectionResources resources , String sql ) {
63
+ this .resources = Assert .requireNonNull (resources , "context must not be null" );
64
+ this .connectionContext = resources .getClient ().getContext ();
62
65
this .sql = Assert .requireNonNull (sql , "sql must not be null" );
63
66
this .bindings = new Bindings (expectedSize (sql ));
64
- fetchSize (this .context .getConfiguration ().getFetchSize (sql ));
67
+ fetchSize (this .resources .getConfiguration ().getFetchSize (sql ));
65
68
}
66
69
67
70
@ Override
@@ -75,16 +78,16 @@ public ExtendedQueryPostgresqlStatement bind(String identifier, Object value) {
75
78
Assert .requireNonNull (identifier , "identifier must not be null" );
76
79
Assert .requireType (identifier , String .class , "identifier must be a String" );
77
80
78
- BindingLogger .logBinding ( identifier , Objects . toString ( value ) );
81
+ BindingLogger .logBind ( this . connectionContext , identifier , value );
79
82
return bind (getIndex (identifier ), value );
80
83
}
81
84
82
85
@ Override
83
86
public ExtendedQueryPostgresqlStatement bind (int index , Object value ) {
84
87
Assert .requireNonNull (value , "value must not be null" );
85
88
86
- BindingLogger .logBinding ( index , Objects . toString ( value ) );
87
- this .bindings .getCurrent ().add (index , this .context .getCodecs ().encode (value ));
89
+ BindingLogger .logBind ( this . connectionContext , index , value );
90
+ this .bindings .getCurrent ().add (index , this .resources .getCodecs ().encode (value ));
88
91
89
92
return this ;
90
93
}
@@ -95,7 +98,7 @@ public ExtendedQueryPostgresqlStatement bindNull(String identifier, Class<?> typ
95
98
Assert .requireType (identifier , String .class , "identifier must be a String" );
96
99
Assert .requireNonNull (type , "type must not be null" );
97
100
98
- BindingLogger .logBinding ( identifier , "null of type " + type . getName () );
101
+ BindingLogger .logBindNull ( this . connectionContext , identifier , type );
99
102
bindNull (getIndex (identifier ), type );
100
103
return this ;
101
104
}
@@ -104,8 +107,8 @@ public ExtendedQueryPostgresqlStatement bindNull(String identifier, Class<?> typ
104
107
public ExtendedQueryPostgresqlStatement bindNull (int index , Class <?> type ) {
105
108
Assert .requireNonNull (type , "type must not be null" );
106
109
107
- BindingLogger .logBinding ( index , "null of type " + type . getName () );
108
- this .bindings .getCurrent ().add (index , this .context .getCodecs ().encodeNull (type ));
110
+ BindingLogger .logBindNull ( this . connectionContext , index , type );
111
+ this .bindings .getCurrent ().add (index , this .resources .getCodecs ().encodeNull (type ));
109
112
return this ;
110
113
}
111
114
@@ -145,7 +148,7 @@ public ExtendedQueryPostgresqlStatement fetchSize(int rows) {
145
148
public String toString () {
146
149
return "ExtendedQueryPostgresqlStatement{" +
147
150
"bindings=" + this .bindings +
148
- ", context=" + this .context +
151
+ ", context=" + this .resources +
149
152
", sql='" + this .sql + '\'' +
150
153
", generatedColumns=" + Arrays .toString (this .generatedColumns ) +
151
154
'}' ;
@@ -179,9 +182,9 @@ private Flux<io.r2dbc.postgresql.api.PostgresqlResult> execute(String sql) {
179
182
this .bindings .finish ();
180
183
181
184
ExceptionFactory factory = ExceptionFactory .withSql (sql );
182
- return this .context .getStatementCache ().getName (this .bindings .first (), sql )
185
+ return this .resources .getStatementCache ().getName (this .bindings .first (), sql )
183
186
.flatMapMany (name -> Flux .fromIterable (this .bindings .bindings ).map (binding -> {
184
- return createPostgresqlResult (sql , factory , name , binding , this .context , this .fetchSize );
187
+ return createPostgresqlResult (sql , factory , name , binding , this .resources , this .fetchSize );
185
188
}))
186
189
.cast (io .r2dbc .postgresql .api .PostgresqlResult .class );
187
190
}
0 commit comments