1
1
/*
2
- * Copyright 2017-2019 the original author or authors.
2
+ * Copyright 2017-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
18
18
19
19
import io .r2dbc .postgresql .api .PostgresqlStatement ;
20
20
import io .r2dbc .postgresql .client .Binding ;
21
- import io .r2dbc .postgresql .client .Client ;
22
21
import io .r2dbc .postgresql .client .ExtendedQueryMessageFlow ;
23
22
import io .r2dbc .postgresql .client .PortalNameSupplier ;
24
- import io .r2dbc .postgresql .codec .Codecs ;
25
23
import io .r2dbc .postgresql .message .backend .BackendMessage ;
26
24
import io .r2dbc .postgresql .message .backend .BindComplete ;
27
25
import io .r2dbc .postgresql .message .backend .CloseComplete ;
@@ -48,9 +46,7 @@ final class ExtendedQueryPostgresqlStatement implements PostgresqlStatement {
48
46
49
47
private final Bindings bindings ;
50
48
51
- private final Client client ;
52
-
53
- private final Codecs codecs ;
49
+ private final ConnectionContext context ;
54
50
55
51
private final boolean forceBinary ;
56
52
@@ -62,9 +58,9 @@ final class ExtendedQueryPostgresqlStatement implements PostgresqlStatement {
62
58
63
59
private String [] generatedColumns ;
64
60
65
- ExtendedQueryPostgresqlStatement (Client client , Codecs codecs , PortalNameSupplier portalNameSupplier , String sql , StatementCache statementCache , boolean forceBinary ) {
66
- this . client = Assert . requireNonNull ( client , "client must not be null" );
67
- this .codecs = Assert .requireNonNull (codecs , "codecs must not be null" );
61
+ ExtendedQueryPostgresqlStatement (ConnectionContext context , PortalNameSupplier portalNameSupplier , String sql , StatementCache statementCache ,
62
+ boolean forceBinary ) {
63
+ this .context = Assert .requireNonNull (context , "context must not be null" );
68
64
this .portalNameSupplier = Assert .requireNonNull (portalNameSupplier , "portalNameSupplier must not be null" );
69
65
this .sql = Assert .requireNonNull (sql , "sql must not be null" );
70
66
this .statementCache = Assert .requireNonNull (statementCache , "statementCache must not be null" );
@@ -91,7 +87,7 @@ public ExtendedQueryPostgresqlStatement bind(String identifier, Object value) {
91
87
public ExtendedQueryPostgresqlStatement bind (int index , Object value ) {
92
88
Assert .requireNonNull (value , "value must not be null" );
93
89
94
- this .bindings .getCurrent ().add (index , this .codecs .encode (value ));
90
+ this .bindings .getCurrent ().add (index , this .context . getCodecs () .encode (value ));
95
91
96
92
return this ;
97
93
}
@@ -110,7 +106,7 @@ public ExtendedQueryPostgresqlStatement bindNull(String identifier, Class<?> typ
110
106
public ExtendedQueryPostgresqlStatement bindNull (int index , Class <?> type ) {
111
107
Assert .requireNonNull (type , "type must not be null" );
112
108
113
- this .bindings .getCurrent ().add (index , this .codecs .encodeNull (type ));
109
+ this .bindings .getCurrent ().add (index , this .context . getCodecs () .encodeNull (type ));
114
110
return this ;
115
111
}
116
112
@@ -143,8 +139,7 @@ public ExtendedQueryPostgresqlStatement returnGeneratedValues(String... columns)
143
139
public String toString () {
144
140
return "ExtendedQueryPostgresqlStatement{" +
145
141
"bindings=" + this .bindings +
146
- ", client=" + this .client +
147
- ", codecs=" + this .codecs +
142
+ ", context=" + this .context +
148
143
", forceBinary=" + this .forceBinary +
149
144
", portalNameSupplier=" + this .portalNameSupplier +
150
145
", sql='" + this .sql + '\'' +
@@ -183,10 +178,10 @@ private Flux<io.r2dbc.postgresql.api.PostgresqlResult> execute(String sql) {
183
178
ExceptionFactory factory = ExceptionFactory .withSql (sql );
184
179
return this .statementCache .getName (this .bindings .first (), sql )
185
180
.flatMapMany (name -> ExtendedQueryMessageFlow
186
- .execute (Flux .fromIterable (this .bindings .bindings ), this .client , this .portalNameSupplier , name , sql , this .forceBinary ))
181
+ .execute (Flux .fromIterable (this .bindings .bindings ), this .context . getClient () , this .portalNameSupplier , name , sql , this .forceBinary ))
187
182
.filter (RESULT_FRAME_FILTER )
188
183
.windowUntil (CloseComplete .class ::isInstance )
189
- .map (messages -> PostgresqlResult .toResult (this .codecs , messages , factory ));
184
+ .map (messages -> PostgresqlResult .toResult (this .context , messages , factory ));
190
185
}
191
186
192
187
private int getIndex (String identifier ) {
0 commit comments