提交 5ad6d91e 编写于 作者: S Serge Rider

#271 AuthId access denied workaroun

上级 a6931a32
...@@ -44,6 +44,7 @@ import org.jkiss.dbeaver.model.struct.rdb.DBSCatalog; ...@@ -44,6 +44,7 @@ import org.jkiss.dbeaver.model.struct.rdb.DBSCatalog;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
/** /**
* PostgreDatabase * PostgreDatabase
...@@ -399,7 +400,7 @@ public class PostgreDatabase implements DBSInstance, DBSCatalog, DBPRefreshableO ...@@ -399,7 +400,7 @@ public class PostgreDatabase implements DBSInstance, DBSCatalog, DBPRefreshableO
throws SQLException throws SQLException
{ {
return session.prepareStatement( return session.prepareStatement(
"SELECT a.oid,a.* FROM pg_catalog.pg_authid a " + "SELECT a.oid,a.* FROM pg_catalog.pg_authid1 a " +
"\nORDER BY a.oid" "\nORDER BY a.oid"
); );
} }
...@@ -410,6 +411,17 @@ public class PostgreDatabase implements DBSInstance, DBSCatalog, DBPRefreshableO ...@@ -410,6 +411,17 @@ public class PostgreDatabase implements DBSInstance, DBSCatalog, DBPRefreshableO
{ {
return new PostgreAuthId(owner, dbResult); return new PostgreAuthId(owner, dbResult);
} }
@Override
protected boolean handleCacheReadError(DBException error) {
// #271: in some databases (AWS?) pg_authid is not accessible
// if (PostgreConstants.EC_PERMISSION_DENIED.equals(error.getDatabaseState())) {
// log.warn(error);
setCache(Collections.<PostgreAuthId>emptyList());
// return true;
// }
return false;
}
} }
class AccessMethodCache extends JDBCObjectCache<PostgreDatabase, PostgreAccessMethod> { class AccessMethodCache extends JDBCObjectCache<PostgreDatabase, PostgreAccessMethod> {
......
...@@ -84,35 +84,40 @@ public abstract class JDBCObjectCache<OWNER extends DBSObject, OBJECT extends DB ...@@ -84,35 +84,40 @@ public abstract class JDBCObjectCache<OWNER extends DBSObject, OBJECT extends DB
if (dataSource == null) { if (dataSource == null) {
throw new DBException("Not connected to database"); throw new DBException("Not connected to database");
} }
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Load objects from " + owner.getName())) { try {
try (JDBCStatement dbStat = prepareObjectsStatement(session, owner)) { try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Load objects from " + owner.getName())) {
monitor.subTask("Execute query"); try (JDBCStatement dbStat = prepareObjectsStatement(session, owner)) {
dbStat.setFetchSize(DBConstants.METADATA_FETCH_SIZE); monitor.subTask("Execute query");
dbStat.executeStatement(); dbStat.setFetchSize(DBConstants.METADATA_FETCH_SIZE);
JDBCResultSet dbResult = dbStat.getResultSet(); dbStat.executeStatement();
if (dbResult != null) { JDBCResultSet dbResult = dbStat.getResultSet();
try { if (dbResult != null) {
while (dbResult.next()) { try {
if (monitor.isCanceled()) { while (dbResult.next()) {
break; if (monitor.isCanceled()) {
break;
}
OBJECT object = fetchObject(session, owner, dbResult);
if (object == null) {
continue;
}
tmpObjectList.add(object);
monitor.subTask(object.getName());
} }
} finally {
OBJECT object = fetchObject(session, owner, dbResult); dbResult.close();
if (object == null) {
continue;
}
tmpObjectList.add(object);
monitor.subTask(object.getName());
} }
} finally {
dbResult.close();
} }
} }
} catch (SQLException ex) {
throw new DBException(ex, dataSource);
}
} catch (DBException e) {
if (!handleCacheReadError(e)) {
throw e;
} }
}
catch (SQLException ex) {
throw new DBException(ex, dataSource);
} }
Comparator<OBJECT> comparator = getListOrderComparator(); Comparator<OBJECT> comparator = getListOrderComparator();
...@@ -127,5 +132,10 @@ public abstract class JDBCObjectCache<OWNER extends DBSObject, OBJECT extends DB ...@@ -127,5 +132,10 @@ public abstract class JDBCObjectCache<OWNER extends DBSObject, OBJECT extends DB
} }
} }
// Can be implemented to provide custom cache error handler
protected boolean handleCacheReadError(DBException error) {
return false;
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册