-
Notifications
You must be signed in to change notification settings - Fork 170
[BACKLOG-48717] - list & test project support #1350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abryant-hv
wants to merge
1
commit into
master
Choose a base branch
from
abryant/BACKLOG-48717
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+534
−7
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
...c/main/java/org/pentaho/platform/dataaccess/datasource/utils/DatabaseConnectionUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| package org.pentaho.platform.dataaccess.datasource.utils; | ||
|
|
||
| import org.pentaho.database.model.IDatabaseConnection; | ||
| import org.pentaho.database.model.PartitionDatabaseMeta; | ||
| import org.pentaho.di.core.variables.VariableSpace; | ||
abryant-hv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Utility class for applying variable substitution to database connection fields. | ||
| * Applies environmentSubstitute to connection fields that may contain variable references | ||
| * (in the form ${VARIABLE_NAME}). | ||
| */ | ||
| public class DatabaseConnectionUtils { | ||
|
|
||
| /** | ||
| * Apply environment variable substitution to an IDatabaseConnection using the provided VariableSpace. | ||
| * Substitutes variables in the following fields: | ||
| * - name (connection identifier, may be used in pooling keys) | ||
| * - hostname | ||
| * - databaseName | ||
| * - databasePort | ||
| * - username | ||
| * - password | ||
| * - connectSql | ||
| * - sqlServerInstance | ||
| * - dataTablespace (Oracle and other database-specific tablespaces) | ||
| * - indexTablespace (Oracle and other database-specific tablespaces) | ||
| * - connectionPoolingProperties (all values) | ||
| * - partitioning information (if present) | ||
| * | ||
| * @param connection The database connection to update (modified in-place) | ||
| * @param variableSpace The variable space to use for substitution | ||
| */ | ||
| public static void applyEnvironmentSubstitution( final IDatabaseConnection connection, | ||
| final VariableSpace variableSpace ) { | ||
| if ( connection == null || variableSpace == null ) { | ||
| return; | ||
| } | ||
|
|
||
| // Substitute connection name (used for pooling and identification) | ||
| if ( connection.getName() != null ) { | ||
| connection.setName( variableSpace.environmentSubstitute( connection.getName() ) ); | ||
| } | ||
|
|
||
| // Substitute basic connection fields | ||
| if ( connection.getHostname() != null ) { | ||
| connection.setHostname( variableSpace.environmentSubstitute( connection.getHostname() ) ); | ||
| } | ||
|
|
||
| if ( connection.getDatabaseName() != null ) { | ||
| connection.setDatabaseName( variableSpace.environmentSubstitute( connection.getDatabaseName() ) ); | ||
| } | ||
|
|
||
| if ( connection.getDatabasePort() != null ) { | ||
| connection.setDatabasePort( variableSpace.environmentSubstitute( connection.getDatabasePort() ) ); | ||
| } | ||
|
|
||
| if ( connection.getUsername() != null ) { | ||
| connection.setUsername( variableSpace.environmentSubstitute( connection.getUsername() ) ); | ||
| } | ||
|
|
||
| if ( connection.getPassword() != null ) { | ||
| connection.setPassword( variableSpace.environmentSubstitute( connection.getPassword() ) ); | ||
| } | ||
|
|
||
| // Substitute connect SQL | ||
| if ( connection.getConnectSql() != null ) { | ||
| connection.setConnectSql( variableSpace.environmentSubstitute( connection.getConnectSql() ) ); | ||
| } | ||
|
|
||
| // Substitute SQL Server instance | ||
| if ( connection.getSQLServerInstance() != null ) { | ||
| connection.setSQLServerInstance( variableSpace.environmentSubstitute( connection.getSQLServerInstance() ) ); | ||
| } | ||
|
|
||
| // Substitute tablespace fields (Oracle and similar databases) | ||
| if ( connection.getDataTablespace() != null ) { | ||
| connection.setDataTablespace( variableSpace.environmentSubstitute( connection.getDataTablespace() ) ); | ||
| } | ||
|
|
||
| if ( connection.getIndexTablespace() != null ) { | ||
| connection.setIndexTablespace( variableSpace.environmentSubstitute( connection.getIndexTablespace() ) ); | ||
| } | ||
|
|
||
| // Substitute connection pooling properties | ||
| if ( connection.getConnectionPoolingProperties() != null | ||
| && !connection.getConnectionPoolingProperties().isEmpty() ) { | ||
| Map<String, String> substitutedPoolingProps = new HashMap<>(); | ||
| for ( Map.Entry<String, String> entry : connection.getConnectionPoolingProperties().entrySet() ) { | ||
| String substitutedValue = entry.getValue() != null ? variableSpace.environmentSubstitute( entry.getValue() ) | ||
| : null; | ||
| substitutedPoolingProps.put( entry.getKey(), substitutedValue ); | ||
| } | ||
| connection.setConnectionPoolingProperties( substitutedPoolingProps ); | ||
| } | ||
|
|
||
| // Substitute partitioning information if present | ||
| if ( connection.isPartitioned() && connection.getPartitioningInformation() != null ) { | ||
| for ( PartitionDatabaseMeta partition : connection.getPartitioningInformation() ) { | ||
| applyEnvironmentSubstitutionToPartition( partition, variableSpace ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Apply environment variable substitution to a PartitionDatabaseMeta. | ||
| * Substitutes variables in hostname, port, and database name fields. | ||
| * | ||
| * @param partition The partition metadata to update (modified in-place) | ||
| * @param variableSpace The variable space to use for substitution | ||
| */ | ||
| private static void applyEnvironmentSubstitutionToPartition( final PartitionDatabaseMeta partition, | ||
| final VariableSpace variableSpace ) { | ||
| if ( partition == null || variableSpace == null ) { | ||
| return; | ||
| } | ||
|
|
||
| if ( partition.getHostname() != null ) { | ||
| partition.setHostname( variableSpace.environmentSubstitute( partition.getHostname() ) ); | ||
| } | ||
|
|
||
| if ( partition.getPort() != null ) { | ||
| partition.setPort( variableSpace.environmentSubstitute( partition.getPort() ) ); | ||
| } | ||
|
|
||
| if ( partition.getDatabaseName() != null ) { | ||
| partition.setDatabaseName( variableSpace.environmentSubstitute( partition.getDatabaseName() ) ); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.