Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.vertx.pgclient;

/**
* Defines the target server type when connecting to a PostgreSQL cluster with multiple hosts.
* This is similar to the {@code targetServerType} parameter in the PostgreSQL JDBC driver
* and {@code target_session_attrs} in libpq.
*/
public enum TargetServerType {

/**
* Connect to any server (default).
*/
ANY,

/**
* Connect only to a primary (read-write) server.
*/
PRIMARY,

/**
* Connect only to a secondary (read-only/hot standby) server.
*/
SECONDARY,

/**
* Prefer connecting to a primary server, but fall back to a secondary if no primary is available.
*/
PREFER_PRIMARY,

/**
* Prefer connecting to a secondary server, but fall back to a primary if no secondary is available.
*/
PREFER_SECONDARY
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,30 @@
*/
package io.vertx.pgclient.impl;

import io.vertx.pgclient.PgConnectOptions;
import io.vertx.pgclient.TargetServerType;
import io.vertx.sqlclient.PoolOptions;

import java.util.List;

public class PgPoolOptions extends PoolOptions {

public PgPoolOptions(PoolOptions other) {
super(other);
}
private boolean pipelined;
private TargetServerType targetServerType = TargetServerType.ANY;
private List<PgConnectOptions> servers;

public PgPoolOptions() {
}

private boolean pipelined;
public PgPoolOptions(PoolOptions other) {
super(other);
if (other instanceof PgPoolOptions) {
PgPoolOptions pgOther = (PgPoolOptions) other;
this.pipelined = pgOther.pipelined;
this.targetServerType = pgOther.targetServerType;
this.servers = pgOther.servers;
}
}

public boolean isPipelined() {
return pipelined;
Expand All @@ -37,4 +49,22 @@ public PgPoolOptions setPipelined(boolean pipelined) {
this.pipelined = pipelined;
return this;
}

public TargetServerType getTargetServerType() {
return targetServerType;
}

public PgPoolOptions setTargetServerType(TargetServerType targetServerType) {
this.targetServerType = targetServerType;
return this;
}

public List<PgConnectOptions> getServers() {
return servers;
}

public PgPoolOptions setServers(List<PgConnectOptions> servers) {
this.servers = servers;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class PgSocketConnection extends SocketConnectionBase {
public int processId;
public int secretKey;
public PgDatabaseMetadata dbMetaData;
public ServerType serverType = ServerType.UNDEFINED;
private PgConnectOptions connectOptions;

public PgSocketConnection(NetSocketInternal socket,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.vertx.pgclient.impl;

/**
* Internal enum representing the detected server type of a PostgreSQL instance.
*/
public enum ServerType {

PRIMARY,
SECONDARY,
UNDEFINED
}
Loading