提交 49b20439 编写于 作者: S Serge Rider

Postgre database info read

上级 f236d7ab
......@@ -65,6 +65,7 @@ public class PostgreDataSource extends JDBCDataSource implements DBSObjectSelect
private final DatabaseCache databaseCache = new DatabaseCache();
private String activeDatabaseName;
private String activeSchemaName;
private final List<String> searchPath = new ArrayList<>();
private String activeUser;
......@@ -153,7 +154,14 @@ public class PostgreDataSource extends JDBCDataSource implements DBSObjectSelect
activeDatabaseName = getContainer().getConnectionConfiguration().getDatabaseName();
try (JDBCSession session = DBUtils.openMetaSession(monitor, this, "Load meta info")) {
activeUser = JDBCUtils.queryString(session, "SELECT SESSION_USER");
try (JDBCPreparedStatement stat = session.prepareStatement("SELECT current_database(), current_schema(),session_user")) {
try (JDBCResultSet rs = stat.executeQuery()) {
rs.nextRow();
activeDatabaseName = JDBCUtils.safeGetString(rs, 1);
activeSchemaName = JDBCUtils.safeGetString(rs, 2);
activeUser = JDBCUtils.safeGetString(rs, 3);
}
}
String searchPathStr = JDBCUtils.queryString(session, "SHOW search_path");
if (searchPathStr != null) {
Collections.addAll(this.searchPath, searchPathStr.replace("$user", activeUser).split(","));
......@@ -263,6 +271,14 @@ public class PostgreDataSource extends JDBCDataSource implements DBSObjectSelect
return activeUser;
}
public String getActiveSchemaName() {
return activeSchemaName;
}
public void setActiveSchemaName(String activeSchemaName) {
this.activeSchemaName = activeSchemaName;
}
public List<String> getSearchPath() {
return searchPath;
}
......@@ -276,12 +292,12 @@ public class PostgreDataSource extends JDBCDataSource implements DBSObjectSelect
}
private void useDatabase(DBRProgressMonitor monitor, JDBCExecutionContext context, PostgreDatabase catalog) throws DBCException {
throw new DBCException("Active database change not supported yet");
//context.reconnect();
}
@Override
protected Connection openConnection(@NotNull DBRProgressMonitor monitor, @NotNull String purpose) throws DBCException {
Connection mysqlConnection = super.openConnection(monitor, purpose);
Connection pgConnection = super.openConnection(monitor, purpose);
{
// Provide client info
......@@ -289,7 +305,7 @@ public class PostgreDataSource extends JDBCDataSource implements DBSObjectSelect
if (product != null) {
String appName = DBeaverCore.getProductTitle();
try {
mysqlConnection.setClientInfo("ApplicationName", appName + " - " + purpose);
pgConnection.setClientInfo("ApplicationName", appName + " - " + purpose);
} catch (Throwable e) {
// just ignore
log.debug(e);
......@@ -297,7 +313,7 @@ public class PostgreDataSource extends JDBCDataSource implements DBSObjectSelect
}
}
return mysqlConnection;
return pgConnection;
}
@Override
......
......@@ -354,13 +354,7 @@ public class PostgreDatabase implements DBSInstance, DBSCatalog, DBPRefreshableO
@Nullable
@Override
public PostgreSchema getSelectedObject() {
for (String schemaName : dataSource.getSearchPath()) {
final PostgreSchema schema = schemaCache.getCachedObject(schemaName);
if (schema != null) {
return schema;
}
}
return null;
return schemaCache.getCachedObject(dataSource.getActiveSchemaName());
}
@Override
......@@ -378,6 +372,7 @@ public class PostgreDatabase implements DBSInstance, DBSCatalog, DBPRefreshableO
throw new DBCException("Error setting search path", e, dataSource);
}
}
dataSource.setActiveSchemaName(object.getName());
dataSource.setSearchPath(object.getName());
if (oldActive != null) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册