Skip to content

Commit

Permalink
Changes as per review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sfurti-yb committed Feb 18, 2025
1 parent 620e7c7 commit 2651a3c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
18 changes: 12 additions & 6 deletions src/main/java/com/yugabyte/sample/apps/AppBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,18 @@ protected Connection getPostgresConnection(String database, String username, Str
Properties newProps = new Properties();
newProps.setProperty("user", "yugabyte");
newProps.setProperty("password", appConfig.ybPassword);
Connection controlConnection = DriverManager.getConnection(connectStr, newProps);
Statement st = controlConnection.createStatement();
String grantPermission = String.format("grant create on schema public to %s with grant option;", username);
LOG.info("Granted create permission to user: " + username);
st.execute(grantPermission);
controlConnection.close();
Connection controlConnection = null;
try {
controlConnection = DriverManager.getConnection(connectStr, newProps);
Statement st = controlConnection.createStatement();
String grantPermission = String.format("grant create on schema public to %s with grant option;", username);
LOG.info("Granted create permission to user: " + username);
st.execute(grantPermission);
} finally {
if (controlConnection != null) {
controlConnection.close();
}
}
}
Connection connection = DriverManager.getConnection(connectStr, props);
return connection;
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/yugabyte/sample/common/CmdLineOpts.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ public void initialize(CommandLine commandLine) throws ClassNotFoundException {
AppBase.appConfig.dbPassword = commandLine.getOptionValue("password");
}
if (commandLine.hasOption("yugabyte_password")) {
if (commandLine.getOptionValue("username").equalsIgnoreCase("yugabyte") || commandLine.getOptionValue("username").equalsIgnoreCase("postgres")) {
LOG.error(("--yugabyte_password is not required when username is yugabyte or postgres"));
System.exit(1);
}
AppBase.appConfig.ybPassword = commandLine.getOptionValue("yugabyte_password");
}
if (commandLine.hasOption("load_balance")) {
Expand Down Expand Up @@ -797,7 +801,7 @@ public static CmdLineOpts createFromArgs(String[] args) throws Exception {
"If this option is set, the --username option is required.");
options.addOption("yugabyte_password", true,
"The password to use when connecting to the database with user yugabyte. " +
"This option is set when the --username is different from yugabyte or postgres");
"This option is required when the user specified via --username option is other than 'yugabyte' and 'postgres'.");
options.addOption("load_balance", true,
"Set up YugabyteDB JDBC driver with in-built load balancing capability.");
options.addOption("topology_keys", true,
Expand Down

0 comments on commit 2651a3c

Please sign in to comment.