Skip to content

Commit 42a5a75

Browse files
JavaDoc reviewed
1 parent 1b4b896 commit 42a5a75

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+197
-164
lines changed

TODO.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Refactoring
2+
* Make futures completable through arbitrary executor.
3+
* Make maximum number of all variables private.
4+
* Review all round trips.
5+
6+
## Tests
7+
* Make tests for all round trips.
8+
* Review other test cases.

src/main/java/com/github/pgasync/ConnectionPool.java

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public interface ConnectionPool extends Db {
2828
/**
2929
* Gets a connection when available.
3030
* {@link Connection#close()} method will return the connection into this pool instead of closing it.
31+
*
32+
* @return {@link CompletableFuture} that is queued and completed when pool has an available connection.
3133
*/
3234
CompletableFuture<Connection> getConnection();
3335

src/main/java/com/github/pgasync/ConnectionPoolBuilder.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ public ConnectionPoolBuilder database(String database) {
6262
return this;
6363
}
6464

65-
public ConnectionPoolBuilder poolSize(int poolSize) {
66-
properties.maxConnections = poolSize;
65+
public ConnectionPoolBuilder maxConnections(int maxConnections) {
66+
properties.maxConnections = maxConnections;
67+
return this;
68+
}
69+
70+
public ConnectionPoolBuilder maxStatements(int maxStatements) {
71+
properties.maxStatements = maxStatements;
6772
return this;
6873
}
6974

src/main/java/com/github/pgasync/PreparedStatement.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public interface PreparedStatement {
1515

1616
/**
17-
* Fetches the whole row set and returns a {@link CompletableFuture} with an instance of {@link ResultSet}.
17+
* Fetches the whole row set and returns a {@link CompletableFuture} completed with an instance of {@link ResultSet}.
1818
* This future may be completed with an error. Use this method if you are sure, that all data, returned by the query can be placed into memory.
1919
*
2020
* @param params Array of query parameters values.
@@ -26,12 +26,19 @@ public interface PreparedStatement {
2626
* Fetches data rows from Postgres one by one. Use this method when you are unsure, that all data, returned by the query can be placed into memory.
2727
*
2828
* @param onColumns {@link Consumer} of parameters by name map. Gets called when bind/describe chain succeeded.
29-
* @param processor {@link Consumer} of single data row. Performs some processing of data.
29+
* @param processor {@link Consumer} of single data row. Performs transformation from {@link com.github.pgasync.impl.message.backend.DataRow} message
30+
* to {@link Row} implementation instance.
3031
* @param params Array of query parameters values.
31-
* @return CompletableFuture that completes when the whole process ends or when an error occurs. Future's value will indicate the number of affected rows by the query.
32+
* @return CompletableFuture that completes when the whole process ends or when an error occurs. Future's value will indicate the number of rows affected by the query.
3233
*/
3334
CompletableFuture<Integer> fetch(Consumer<Map<String, PgColumn>> onColumns, Consumer<Row> processor, Object... params);
3435

36+
/**
37+
* Closes this {@link PreparedStatement} and possibly frees resources. In case of pool statement it may be returned to a pool for future reuse.
38+
* @return CompletableFuture that is completed when the network process ends.
39+
* Network process may occur if returned statement has evicted some other statement from the pool in case of pooled statement.
40+
* Closing of such evicted statement is network activity, we should be aware of.
41+
*/
3542
CompletableFuture<Void> close();
3643

3744
}

src/main/java/com/github/pgasync/QueryExecutor.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,17 @@ default CompletableFuture<Collection<ResultSet>> completeScript(String sql) {
5656
*
5757
* @param onColumns Columns fetched callback consumer.
5858
* @param onRow A row fetched callback consumer.
59-
* @param onAffected An affected rows callback consumer. It is called when a particular {@link ResultSet} is completely fetched with its affected rows count. This callback should be used to create a {@link ResultSet} instance from already fetched columns, rows and affected rows count.
59+
* @param onAffected An affected rows callback consumer.
60+
* It is called when a particular {@link ResultSet} is completely fetched with its affected rows count.
61+
* This callback should be used to create a {@link ResultSet} instance from already fetched columns, rows and affected rows count.
6062
* @param sql Sql Script text.
6163
* @return CompletableFuture that is completed when the whole process of multiple {@link ResultSet}s fetching ends.
6264
*/
6365
CompletableFuture<Void> script(Consumer<Map<String, PgColumn>> onColumns, Consumer<Row> onRow, Consumer<Integer> onAffected, String sql);
6466

6567
/**
6668
* Sends single query with parameters. Uses extended query protocol of Postgres.
67-
* Accumulates fetched columns, rows and affected rows count into memory and transforms them into ResultSet when it is fetched.
69+
* Accumulates fetched columns, rows and affected rows count into memory and transforms them into a {@link ResultSet} when it is fetched.
6870
* Completes returned {@link CompletableFuture} when the whole process of {@link ResultSet} fetching ends.
6971
*
7072
* @param sql Sql query text with parameters substituted with ?.
@@ -88,7 +90,7 @@ default CompletableFuture<ResultSet> completeQuery(String sql, Object... params)
8890
* Sends single query with parameters. Uses extended query protocol of Postgres.
8991
* Unlike {@link #completeQuery(String, Object...)} doesn't accumulate columns, rows and affected rows counts into memory.
9092
* Instead it calls passed in consumers, when columns, or particular row is fetched from Postgres.
91-
* Completes returned {@link CompletableFuture} when the process of single {@link ResultSet}s fetching ends.
93+
* Completes returned {@link CompletableFuture} with affected rows count when the process of single {@link ResultSet}s fetching ends.
9294
*
9395
* @param onColumns Columns fetched callback consumer.
9496
* @param onRow A row fetched callback consumer.

src/main/java/com/github/pgasync/impl/PgConnection.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
package com.github.pgasync.impl;
1616

17-
import static com.github.pgasync.impl.message.b.RowDescription.ColumnDescription;
17+
import static com.github.pgasync.impl.message.backend.RowDescription.ColumnDescription;
1818

1919
import java.util.ArrayList;
2020
import java.util.LinkedHashMap;
@@ -34,17 +34,17 @@
3434
import com.github.pgasync.Row;
3535
import com.github.pgasync.Transaction;
3636
import com.github.pgasync.impl.conversion.DataConverter;
37-
import com.github.pgasync.impl.message.b.Authentication;
38-
import com.github.pgasync.impl.message.b.RowDescription;
39-
import com.github.pgasync.impl.message.f.Bind;
40-
import com.github.pgasync.impl.message.f.Close;
41-
import com.github.pgasync.impl.message.f.Describe;
42-
import com.github.pgasync.impl.message.f.Execute;
37+
import com.github.pgasync.impl.message.backend.Authentication;
38+
import com.github.pgasync.impl.message.backend.RowDescription;
39+
import com.github.pgasync.impl.message.frontend.Bind;
40+
import com.github.pgasync.impl.message.frontend.Close;
41+
import com.github.pgasync.impl.message.frontend.Describe;
42+
import com.github.pgasync.impl.message.frontend.Execute;
4343
import com.github.pgasync.impl.message.Message;
44-
import com.github.pgasync.impl.message.f.Parse;
45-
import com.github.pgasync.impl.message.f.PasswordMessage;
46-
import com.github.pgasync.impl.message.f.Query;
47-
import com.github.pgasync.impl.message.f.StartupMessage;
44+
import com.github.pgasync.impl.message.frontend.Parse;
45+
import com.github.pgasync.impl.message.frontend.PasswordMessage;
46+
import com.github.pgasync.impl.message.frontend.Query;
47+
import com.github.pgasync.impl.message.frontend.StartupMessage;
4848

4949
/**
5050
* A connection to Postgres backend. The postmaster forks a backend process for
@@ -290,7 +290,7 @@ public CompletableFuture<Integer> query(Consumer<Map<String, PgColumn>> onColumn
290290
}
291291

292292
/**
293-
* Nested Transaction using savepoints.
293+
* Nested transaction using savepoints.
294294
*/
295295
class PgConnectionNestedTransaction extends PgConnectionTransaction {
296296

src/main/java/com/github/pgasync/impl/PgConnectionPool.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
import java.util.function.Function;
3131

3232
/**
33-
* Pool for backend connections. {@link CompletableFuture}s are queued and completed when pool has an available
34-
* connection.
33+
* Pool for backend connections.
3534
*
3635
* @author Antti Laisi
3736
*/

src/main/java/com/github/pgasync/impl/PgProtocolStream.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
package com.github.pgasync.impl;
1616

1717
import com.github.pgasync.impl.message.Message;
18-
import com.github.pgasync.impl.message.b.CommandComplete;
19-
import com.github.pgasync.impl.message.b.DataRow;
20-
import com.github.pgasync.impl.message.b.RowDescription;
21-
import com.github.pgasync.impl.message.f.Execute;
22-
import com.github.pgasync.impl.message.f.PasswordMessage;
23-
import com.github.pgasync.impl.message.f.Query;
24-
import com.github.pgasync.impl.message.f.StartupMessage;
18+
import com.github.pgasync.impl.message.backend.CommandComplete;
19+
import com.github.pgasync.impl.message.backend.DataRow;
20+
import com.github.pgasync.impl.message.backend.RowDescription;
21+
import com.github.pgasync.impl.message.frontend.Execute;
22+
import com.github.pgasync.impl.message.frontend.PasswordMessage;
23+
import com.github.pgasync.impl.message.frontend.Query;
24+
import com.github.pgasync.impl.message.frontend.StartupMessage;
2525

2626
import java.util.concurrent.CompletableFuture;
2727
import java.util.function.Consumer;

src/main/java/com/github/pgasync/impl/PgRow.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import com.github.pgasync.Row;
1818
import com.github.pgasync.SqlException;
1919
import com.github.pgasync.impl.conversion.DataConverter;
20-
import com.github.pgasync.impl.message.b.DataRow;
20+
import com.github.pgasync.impl.message.backend.DataRow;
2121

2222
import java.math.BigDecimal;
2323
import java.math.BigInteger;

src/main/java/com/github/pgasync/impl/conversion/BooleanConversions.java

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* @author Antti Laisi
88
*/
99
public class BooleanConversions {
10-
;
1110

1211
static final byte[] TRUE = new byte[]{ 't' };
1312
static final byte[] FALSE = new byte[]{ 'f' };

src/main/java/com/github/pgasync/impl/conversion/DataConverter.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.sql.Time;
1010
import java.sql.Timestamp;
1111
import java.util.*;
12+
import java.util.function.Function;
13+
import java.util.stream.Collectors;
1214

1315
import static java.nio.charset.StandardCharsets.UTF_8;
1416

@@ -17,14 +19,15 @@
1719
*/
1820
public class DataConverter {
1921

20-
final Map<Class<?>, Converter<?>> typeToConverter = new HashMap<>();
22+
final Map<Class<?>, Converter<?>> typeToConverter;
2123

2224
public DataConverter(List<Converter<?>> converters) {
23-
converters.forEach(c -> typeToConverter.put(c.type(), c));
25+
typeToConverter = converters.stream()
26+
.collect(Collectors.toMap(Converter::type, Function.identity()));
2427
}
2528

2629
public DataConverter() {
27-
this(Collections.emptyList());
30+
this(List.of());
2831
}
2932

3033
public String toString(Oid oid, byte[] value) {

src/main/java/com/github/pgasync/impl/io/b/AuthenticationDecoder.java renamed to src/main/java/com/github/pgasync/impl/io/backend/AuthenticationDecoder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
* limitations under the License.
1313
*/
1414

15-
package com.github.pgasync.impl.io.b;
15+
package com.github.pgasync.impl.io.backend;
1616

1717
import com.github.pgasync.impl.io.Decoder;
18-
import com.github.pgasync.impl.message.b.Authentication;
18+
import com.github.pgasync.impl.message.backend.Authentication;
1919

2020
import java.nio.ByteBuffer;
2121

src/main/java/com/github/pgasync/impl/io/b/BindCompleteDecoder.java renamed to src/main/java/com/github/pgasync/impl/io/backend/BindCompleteDecoder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
* limitations under the License.
1313
*/
1414

15-
package com.github.pgasync.impl.io.b;
15+
package com.github.pgasync.impl.io.backend;
1616

1717
import com.github.pgasync.impl.io.Decoder;
18-
import com.github.pgasync.impl.message.b.BIndicators;
18+
import com.github.pgasync.impl.message.backend.BIndicators;
1919

2020
import java.nio.ByteBuffer;
2121

src/main/java/com/github/pgasync/impl/io/b/CloseCompleteDecoder.java renamed to src/main/java/com/github/pgasync/impl/io/backend/CloseCompleteDecoder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
* limitations under the License.
1313
*/
1414

15-
package com.github.pgasync.impl.io.b;
15+
package com.github.pgasync.impl.io.backend;
1616

1717
import com.github.pgasync.impl.io.Decoder;
18-
import com.github.pgasync.impl.message.b.BIndicators;
18+
import com.github.pgasync.impl.message.backend.BIndicators;
1919

2020
import java.nio.ByteBuffer;
2121

src/main/java/com/github/pgasync/impl/io/b/CommandCompleteDecoder.java renamed to src/main/java/com/github/pgasync/impl/io/backend/CommandCompleteDecoder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
* limitations under the License.
1313
*/
1414

15-
package com.github.pgasync.impl.io.b;
15+
package com.github.pgasync.impl.io.backend;
1616

1717
import com.github.pgasync.impl.io.Decoder;
18-
import com.github.pgasync.impl.message.b.CommandComplete;
18+
import com.github.pgasync.impl.message.backend.CommandComplete;
1919

2020
import java.nio.ByteBuffer;
2121

src/main/java/com/github/pgasync/impl/io/b/DataRowDecoder.java renamed to src/main/java/com/github/pgasync/impl/io/backend/DataRowDecoder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
* limitations under the License.
1313
*/
1414

15-
package com.github.pgasync.impl.io.b;
15+
package com.github.pgasync.impl.io.backend;
1616

1717
import com.github.pgasync.impl.io.Decoder;
18-
import com.github.pgasync.impl.message.b.DataRow;
18+
import com.github.pgasync.impl.message.backend.DataRow;
1919

2020
import java.nio.ByteBuffer;
2121

src/main/java/com/github/pgasync/impl/io/b/ErrorResponseDecoder.java renamed to src/main/java/com/github/pgasync/impl/io/backend/ErrorResponseDecoder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
* limitations under the License.
1313
*/
1414

15-
package com.github.pgasync.impl.io.b;
15+
package com.github.pgasync.impl.io.backend;
1616

1717
import com.github.pgasync.impl.io.Decoder;
18-
import com.github.pgasync.impl.message.b.ErrorResponse;
18+
import com.github.pgasync.impl.message.backend.ErrorResponse;
1919

2020
import java.nio.ByteBuffer;
2121

src/main/java/com/github/pgasync/impl/io/b/NoticeResponseDecoder.java renamed to src/main/java/com/github/pgasync/impl/io/backend/NoticeResponseDecoder.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package com.github.pgasync.impl.io.b;
1+
package com.github.pgasync.impl.io.backend;
22

33
import com.github.pgasync.impl.io.Decoder;
4-
import com.github.pgasync.impl.message.b.NoticeResponse;
4+
import com.github.pgasync.impl.message.backend.NoticeResponse;
55

66
import java.nio.ByteBuffer;
77
import java.util.ArrayList;
@@ -29,7 +29,7 @@
2929
* The field value.
3030
* </pre>
3131
*
32-
* @author Antti Laisi
32+
* @author Marat Gainullin
3333
*/
3434
public class NoticeResponseDecoder implements Decoder<NoticeResponse> {
3535

src/main/java/com/github/pgasync/impl/io/b/NotificationResponseDecoder.java renamed to src/main/java/com/github/pgasync/impl/io/backend/NotificationResponseDecoder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package com.github.pgasync.impl.io.b;
1+
package com.github.pgasync.impl.io.backend;
22

33
import com.github.pgasync.impl.io.Decoder;
4-
import com.github.pgasync.impl.message.b.NotificationResponse;
4+
import com.github.pgasync.impl.message.backend.NotificationResponse;
55

66
import java.nio.ByteBuffer;
77

src/main/java/com/github/pgasync/impl/io/b/ParseCompleteDecoder.java renamed to src/main/java/com/github/pgasync/impl/io/backend/ParseCompleteDecoder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
* limitations under the License.
1313
*/
1414

15-
package com.github.pgasync.impl.io.b;
15+
package com.github.pgasync.impl.io.backend;
1616

1717
import com.github.pgasync.impl.io.Decoder;
18-
import com.github.pgasync.impl.message.b.BIndicators;
18+
import com.github.pgasync.impl.message.backend.BIndicators;
1919

2020
import java.nio.ByteBuffer;
2121

src/main/java/com/github/pgasync/impl/io/b/ReadyForQueryDecoder.java renamed to src/main/java/com/github/pgasync/impl/io/backend/ReadyForQueryDecoder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
* limitations under the License.
1313
*/
1414

15-
package com.github.pgasync.impl.io.b;
15+
package com.github.pgasync.impl.io.backend;
1616

1717
import com.github.pgasync.impl.io.Decoder;
18-
import com.github.pgasync.impl.message.b.ReadyForQuery;
18+
import com.github.pgasync.impl.message.backend.ReadyForQuery;
1919

2020
import java.nio.ByteBuffer;
2121

src/main/java/com/github/pgasync/impl/io/b/RowDescriptionDecoder.java renamed to src/main/java/com/github/pgasync/impl/io/backend/RowDescriptionDecoder.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
* limitations under the License.
1313
*/
1414

15-
package com.github.pgasync.impl.io.b;
15+
package com.github.pgasync.impl.io.backend;
1616

1717
import com.github.pgasync.impl.Oid;
1818
import com.github.pgasync.impl.io.Decoder;
19-
import com.github.pgasync.impl.message.b.RowDescription;
20-
import com.github.pgasync.impl.message.b.RowDescription.ColumnDescription;
19+
import com.github.pgasync.impl.message.backend.RowDescription;
2120

2221
import java.nio.ByteBuffer;
2322

@@ -62,14 +61,14 @@ public byte getMessageId() {
6261

6362
@Override
6463
public RowDescription read(ByteBuffer buffer) {
65-
ColumnDescription[] columns = new ColumnDescription[buffer.getShort()];
64+
RowDescription.ColumnDescription[] columns = new RowDescription.ColumnDescription[buffer.getShort()];
6665

6766
for (int i = 0; i < columns.length; i++) {
6867
String name = getCString(buffer);
6968
buffer.position(buffer.position() + 6);
7069
Oid type = Oid.valueOfId(buffer.getInt());
7170
buffer.position(buffer.position() + 8);
72-
columns[i] = new ColumnDescription(name, type);
71+
columns[i] = new RowDescription.ColumnDescription(name, type);
7372
}
7473

7574
return new RowDescription(columns);

src/main/java/com/github/pgasync/impl/io/f/BindEncoder.java renamed to src/main/java/com/github/pgasync/impl/io/frontend/BindEncoder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
* limitations under the License.
1313
*/
1414

15-
package com.github.pgasync.impl.io.f;
15+
package com.github.pgasync.impl.io.frontend;
1616

1717
import com.github.pgasync.impl.io.IO;
18-
import com.github.pgasync.impl.message.f.Bind;
18+
import com.github.pgasync.impl.message.frontend.Bind;
1919

2020
import java.nio.ByteBuffer;
2121

0 commit comments

Comments
 (0)