未验证 提交 4f980491 编写于 作者: S Serge Rider 提交者: GitHub

Merge pull request #14337 from dbeaver/postgrePath#13750

#13750 set $user in the end of the search path
......@@ -39,6 +39,7 @@ public class PostgreConstants {
public static final String DEFAULT_DATABASE = "postgres";
public static final String DEFAULT_DATA_TYPE = "varchar";
public static final String DEFAULT_USER = "postgres";
public static final String USER_VARIABLE = "$user";
public static final String PROP_CHOSEN_ROLE = DBConstants.INTERNAL_PROP_PREFIX + "chosen-role@";
public static final String PROP_SHOW_NON_DEFAULT_DB = DBConstants.INTERNAL_PROP_PREFIX + "show-non-default-db@";
......
......@@ -665,7 +665,7 @@ public class PostgreUtils {
}
public static String getRealSchemaName(PostgreDatabase database, String name) {
return name.replace("$user", database.getMetaContext().getActiveUser());
return name.replace(PostgreConstants.USER_VARIABLE, database.getMetaContext().getActiveUser());
}
}
......@@ -193,6 +193,7 @@ public class PostgreExecutionContext extends JDBCExecutionContext implements DBC
}
if (defaultSearchPath.isEmpty()) {
setUserInTheEndOfThePath(searchPath);
defaultSearchPath = new ArrayList<>(searchPath);
}
......@@ -243,9 +244,8 @@ public class PostgreExecutionContext extends JDBCExecutionContext implements DBC
// Remove from previous position
newSearchPath.remove(schemaIndex);
}
// Add it first (or after $user)
int newIndex = isUserFirstInPath(newSearchPath) ? 1 : 0;
newSearchPath.add(newIndex, defSchemaName);
// Add it first
newSearchPath.add(0, defSchemaName);
}
StringBuilder spString = new StringBuilder();
......@@ -261,7 +261,29 @@ public class PostgreExecutionContext extends JDBCExecutionContext implements DBC
}
private static boolean isUserFirstInPath(List<String> newSearchPath) {
return !newSearchPath.isEmpty() && newSearchPath.get(0).equals("$user");
return !newSearchPath.isEmpty() && newSearchPath.get(0).equals(PostgreConstants.USER_VARIABLE);
}
private void setUserInTheEndOfThePath(List<String> searchPath) {
if (CommonUtils.isEmpty(searchPath)) {
return;
}
if (isUserFirstInPath(searchPath)) {
searchPath.remove(0);
searchPath.add(PostgreConstants.USER_VARIABLE);
} else {
int userIndex = -1;
for (int i = 0; i < searchPath.size(); i++) {
if (searchPath.get(i).equals(PostgreConstants.USER_VARIABLE)) {
userIndex = i;
break;
}
}
if (userIndex != -1) {
searchPath.remove(userIndex);
searchPath.add(PostgreConstants.USER_VARIABLE);
}
}
}
private void setSearchPath(String path) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册