Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions jdbc-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
compileOnly(project(":jdbc-grpc"))
compileOnly(libs.grpc.stub)
compileOnly(libs.grpc.protobuf)
compileOnly(libs.grpc.netty) // For DirectDataCloudConnection SSL support

implementation(project(":jdbc-util"))
implementation(libs.slf4j.api)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.salesforce.datacloud.jdbc.core.DataCloudConnection;
import com.salesforce.datacloud.jdbc.core.GrpcChannelProperties;
import com.salesforce.datacloud.jdbc.core.JdbcDriverStubProvider;
import com.salesforce.datacloud.jdbc.core.SslProperties;
import com.salesforce.datacloud.jdbc.exception.DataCloudJDBCException;
import com.salesforce.datacloud.jdbc.util.JdbcURL;
import com.salesforce.datacloud.jdbc.util.PropertyParsingUtils;
Expand Down Expand Up @@ -52,7 +53,14 @@ public class HyperDatasource implements DataSource {

@Override
public Connection getConnection() throws SQLException {
return createConnection(host, port, connectionProperties, grpcChannelProperties, dataspace, /*jdbcUrl=*/ null);
// Always use SSL - let SslProperties determine the mode
SslProperties sslProps = SslProperties.ofDestructive(new Properties());
log.info("SSL mode detected: {}", sslProps.determineSslMode().getDescription());

// Create SSL channel using SslProperties
ManagedChannelBuilder<?> sslChannelBuilder = sslProps.createChannelBuilder(host, port);
JdbcDriverStubProvider sslStubProvider = JdbcDriverStubProvider.of(sslChannelBuilder, grpcChannelProperties);
return DataCloudConnection.of(sslStubProvider, connectionProperties, dataspace, null);
}

/**
Expand Down Expand Up @@ -84,40 +92,25 @@ public static DataCloudConnection connectUsingProperties(@NonNull String url, Pr
int port = jdbcUrl.getPort();
val properties = info != null ? (Properties) info.clone() : new Properties();
jdbcUrl.addParametersToProperties(properties);

// Always use SSL - let SslProperties determine the mode
SslProperties sslProps = SslProperties.ofDestructive(properties);
log.info("SSL mode detected: {}", sslProps.determineSslMode().getDescription());

// Create SSL channel using SslProperties
ManagedChannelBuilder<?> sslChannelBuilder = sslProps.createChannelBuilder(host, port);
JdbcDriverStubProvider sslStubProvider =
JdbcDriverStubProvider.of(sslChannelBuilder, GrpcChannelProperties.ofDestructive(properties));
val connectionProperties = ConnectionProperties.ofDestructive(properties);
val grpcChannelProperties = GrpcChannelProperties.ofDestructive(properties);
String dataspace = takeOptional(properties, "dataspace").orElse("");
PropertyParsingUtils.validateRemainingProperties(properties);

// Setup the connection
return createConnection(host, port, connectionProperties, grpcChannelProperties, dataspace, jdbcUrl);
return DataCloudConnection.of(sslStubProvider, connectionProperties, dataspace, jdbcUrl);
} catch (SQLException e) {
log.error("Failed to connect with URL {}: {}", url, e.getMessage(), e);
throw e;
}
}

/**
* Internal utility function to create a DataCloudConnection with the given properties.
*
* The jdbcUrl is optional and will only influence `DatabaseMetaData.getURL()`.
* The actual connection will be created with the properties provided.
*/
private static DataCloudConnection createConnection(
@NonNull String host,
int port,
@NonNull ConnectionProperties connectionProperties,
@NonNull GrpcChannelProperties grpcChannelProperties,
@NonNull String dataspace,
JdbcURL jdbcUrl)
throws SQLException {
port = port == -1 ? 7483 : port;
ManagedChannelBuilder<?> builder =
ManagedChannelBuilder.forAddress(host, port).usePlaintext();
JdbcDriverStubProvider stubProvider = JdbcDriverStubProvider.of(builder, grpcChannelProperties);
return DataCloudConnection.of(stubProvider, connectionProperties, dataspace, jdbcUrl);
}

@Override
public Connection getConnection(String username, String password) throws SQLException {
throw new DataCloudJDBCException(NOT_SUPPORTED_IN_DATACLOUD_QUERY, SqlErrorCodes.FEATURE_NOT_SUPPORTED);
Expand Down
Loading
Loading