use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase in project dbeaver by serge-rider.
the class PostgreDatabaseBackupSettings method loadDatabaseExportInfo.
private PostgreDatabaseBackupInfo loadDatabaseExportInfo(DBRRunnableContext runnableContext, String catalogId, List<String> schemaNames, List<String> tableNames) {
PostgreDatabaseBackupInfo[] exportInfo = new PostgreDatabaseBackupInfo[1];
try {
runnableContext.run(true, true, monitor -> {
try {
PostgreDatabase database = (PostgreDatabase) DBUtils.findObjectById(monitor, getProject(), catalogId);
if (database == null) {
throw new DBException("Database " + catalogId + " not found");
}
List<PostgreSchema> schemas = null;
List<PostgreTableBase> tables = null;
if (!CommonUtils.isEmpty(schemaNames)) {
schemas = new ArrayList<>();
for (String schemaName : schemaNames) {
PostgreSchema schema = database.getSchema(monitor, schemaName);
if (schema != null) {
schemas.add(schema);
} else {
log.debug("Schema '" + schemaName + "' not found in database '" + database.getName() + "'");
}
}
}
if (!CommonUtils.isEmpty(tableNames) && !CommonUtils.isEmpty(schemas)) {
PostgreSchema schema = schemas.get(0);
tables = new ArrayList<>();
for (String tableName : tableNames) {
PostgreTableBase table = schema.getTableCache().getObject(monitor, schema, tableName);
if (table != null) {
tables.add(table);
} else {
log.debug("Table '" + tableName + "' not found in schema '" + schema.getName() + "'");
}
}
}
exportInfo[0] = new PostgreDatabaseBackupInfo(database, schemas, tables);
} catch (Throwable e) {
throw new InvocationTargetException(e);
}
});
} catch (InvocationTargetException e) {
log.error("Error loading objects configuration", e);
} catch (InterruptedException e) {
// Ignore
}
return exportInfo[0];
}
use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase in project dbeaver by serge-rider.
the class PostgreDatabaseRestoreSettings method loadSettings.
@Override
public void loadSettings(DBRRunnableContext runnableContext, DBPPreferenceStore store) throws DBException {
super.loadSettings(runnableContext, store);
inputFile = store.getString("pg.restore.inputFile");
cleanFirst = store.getBoolean("pg.restore.cleanFirst");
noOwner = store.getBoolean("pg.restore.noOwner");
if (store instanceof DBPPreferenceMap) {
String catalogId = store.getString("pg.restore.database");
if (!CommonUtils.isEmpty(catalogId)) {
try {
runnableContext.run(true, true, monitor -> {
try {
PostgreDatabase database = (PostgreDatabase) DBUtils.findObjectById(monitor, getProject(), catalogId);
if (database == null) {
throw new DBException("Database " + catalogId + " not found");
}
restoreInfo = new PostgreDatabaseRestoreInfo(database);
} catch (Throwable e) {
throw new InvocationTargetException(e);
}
});
} catch (InvocationTargetException e) {
log.error("Error loading objects configuration", e);
} catch (InterruptedException e) {
// Ignore
}
} else {
for (DBSObject object : getDatabaseObjects()) {
if (object instanceof PostgreDatabase) {
restoreInfo = new PostgreDatabaseRestoreInfo((PostgreDatabase) object);
break;
}
}
}
}
if (restoreInfo == null) {
throw new DBException("Cannot find database for restoring");
}
}
use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase in project dbeaver by dbeaver.
the class PostgreSqlDebugCore method resolveFunction.
public static PostgreProcedure resolveFunction(DBRProgressMonitor monitor, DBPDataSourceContainer dsContainer, Map<String, Object> configuration) throws DBException {
if (!dsContainer.isConnected()) {
dsContainer.connect(monitor, true, true);
}
long functionId = CommonUtils.toLong(configuration.get(PostgreDebugConstants.ATTR_FUNCTION_OID));
String databaseName = (String) configuration.get(PostgreDebugConstants.ATTR_DATABASE_NAME);
String schemaName = (String) configuration.get(PostgreDebugConstants.ATTR_SCHEMA_NAME);
PostgreDataSource ds = (PostgreDataSource) dsContainer.getDataSource();
PostgreDatabase database = ds.getDatabase(databaseName);
if (database != null) {
PostgreSchema schema = database.getSchema(monitor, schemaName);
if (schema != null) {
PostgreProcedure function = schema.getProcedure(monitor, functionId);
if (function != null) {
return function;
}
throw new DBException("Function " + functionId + " not found in schema " + schemaName);
} else {
throw new DBException("Schema '" + schemaName + "' not found in database " + databaseName);
}
} else {
throw new DBException("Database '" + databaseName + "' not found");
}
}
use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase in project dbeaver by dbeaver.
the class PostgreToolRestore method execute.
@Override
public void execute(IWorkbenchWindow window, IWorkbenchPart activePart, Collection<DBSObject> objects) throws DBException {
for (DBSObject object : objects) {
PostgreDatabase database;
if (object instanceof PostgreSchema) {
database = ((PostgreSchema) object).getDatabase();
} else if (object instanceof PostgreDatabase) {
database = (PostgreDatabase) object;
} else {
continue;
}
NativeToolWizardDialog dialog = new NativeToolWizardDialog(window, new PostgreRestoreWizard(database));
dialog.open();
}
}
use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase in project dbeaver by dbeaver.
the class PostgreToolScript method execute.
@Override
public void execute(IWorkbenchWindow window, IWorkbenchPart activePart, Collection<DBSObject> objects) throws DBException {
for (DBSObject object : objects) {
if (object instanceof PostgreDatabase) {
NativeToolWizardDialog dialog = new NativeToolWizardDialog(window, new PostgreScriptExecuteWizard((PostgreDatabase) object));
dialog.open();
}
}
}
Aggregations