1818
1919import io .r2dbc .postgresql .api .PostgresqlStatement ;
2020import io .r2dbc .postgresql .client .Binding ;
21+ import io .r2dbc .postgresql .client .ConnectionContext ;
2122import io .r2dbc .postgresql .client .ExtendedQueryMessageFlow ;
2223import io .r2dbc .postgresql .message .backend .BackendMessage ;
2324import io .r2dbc .postgresql .message .backend .BindComplete ;
3132import java .util .Arrays ;
3233import java .util .HashSet ;
3334import java .util .List ;
34- import java .util .Objects ;
3535import java .util .Set ;
3636import java .util .function .Predicate ;
3737import java .util .regex .Matcher ;
@@ -49,19 +49,22 @@ final class ExtendedQueryPostgresqlStatement implements PostgresqlStatement {
4949
5050 private final Bindings bindings ;
5151
52- private final ConnectionResources context ;
52+ private final ConnectionResources resources ;
53+
54+ private final ConnectionContext connectionContext ;
5355
5456 private final String sql ;
5557
5658 private int fetchSize ;
5759
5860 private String [] generatedColumns ;
5961
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 ();
6265 this .sql = Assert .requireNonNull (sql , "sql must not be null" );
6366 this .bindings = new Bindings (expectedSize (sql ));
64- fetchSize (this .context .getConfiguration ().getFetchSize (sql ));
67+ fetchSize (this .resources .getConfiguration ().getFetchSize (sql ));
6568 }
6669
6770 @ Override
@@ -75,16 +78,16 @@ public ExtendedQueryPostgresqlStatement bind(String identifier, Object value) {
7578 Assert .requireNonNull (identifier , "identifier must not be null" );
7679 Assert .requireType (identifier , String .class , "identifier must be a String" );
7780
78- BindingLogger .logBinding ( identifier , Objects . toString ( value ) );
81+ BindingLogger .logBind ( this . connectionContext , identifier , value );
7982 return bind (getIndex (identifier ), value );
8083 }
8184
8285 @ Override
8386 public ExtendedQueryPostgresqlStatement bind (int index , Object value ) {
8487 Assert .requireNonNull (value , "value must not be null" );
8588
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 ));
8891
8992 return this ;
9093 }
@@ -95,7 +98,7 @@ public ExtendedQueryPostgresqlStatement bindNull(String identifier, Class<?> typ
9598 Assert .requireType (identifier , String .class , "identifier must be a String" );
9699 Assert .requireNonNull (type , "type must not be null" );
97100
98- BindingLogger .logBinding ( identifier , "null of type " + type . getName () );
101+ BindingLogger .logBindNull ( this . connectionContext , identifier , type );
99102 bindNull (getIndex (identifier ), type );
100103 return this ;
101104 }
@@ -104,8 +107,8 @@ public ExtendedQueryPostgresqlStatement bindNull(String identifier, Class<?> typ
104107 public ExtendedQueryPostgresqlStatement bindNull (int index , Class <?> type ) {
105108 Assert .requireNonNull (type , "type must not be null" );
106109
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 ));
109112 return this ;
110113 }
111114
@@ -145,7 +148,7 @@ public ExtendedQueryPostgresqlStatement fetchSize(int rows) {
145148 public String toString () {
146149 return "ExtendedQueryPostgresqlStatement{" +
147150 "bindings=" + this .bindings +
148- ", context=" + this .context +
151+ ", context=" + this .resources +
149152 ", sql='" + this .sql + '\'' +
150153 ", generatedColumns=" + Arrays .toString (this .generatedColumns ) +
151154 '}' ;
@@ -179,9 +182,9 @@ private Flux<io.r2dbc.postgresql.api.PostgresqlResult> execute(String sql) {
179182 this .bindings .finish ();
180183
181184 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 )
183186 .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 );
185188 }))
186189 .cast (io .r2dbc .postgresql .api .PostgresqlResult .class );
187190 }
0 commit comments