use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase in project dbeaver by serge-rider.
the class PostgreDatabaseManager method addObjectCreateActions.
@Override
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command) {
final PostgreDatabase database = command.getObject();
actions.add(//$NON-NLS-2$
new SQLDatabasePersistAction("Create database", "CREATE DATABASE " + DBUtils.getQuotedIdentifier(database)));
}
use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase in project dbeaver by dbeaver.
the class PostgreSqlDebugCore method createConfiguration.
public static ILaunchConfigurationWorkingCopy createConfiguration(DBSObject launchable) throws CoreException {
boolean isInstance = launchable instanceof PostgreProcedure;
if (!isInstance) {
throw DebugCore.abort(PostgreDebugCoreMessages.PostgreSqlDebugCore_e_procedure_required);
}
PostgreProcedure procedure = (PostgreProcedure) launchable;
PostgreDataSource dataSource = procedure.getDataSource();
DBPDataSourceContainer dataSourceContainer = dataSource.getContainer();
PostgreDatabase database = procedure.getDatabase();
PostgreSchema schema = procedure.getContainer();
String databaseName = database.getName();
String schemaName = schema.getName();
String procedureName = procedure.getName();
Object[] bindings = new Object[] { dataSourceContainer.getName(), databaseName, procedureName, schemaName };
String name = NLS.bind(PostgreDebugCoreMessages.PostgreSqlDebugCore_launch_configuration_name, bindings);
// Let's use metadata area for storage
IContainer container = null;
ILaunchConfigurationWorkingCopy workingCopy = DebugCore.createConfiguration(container, CONFIGURATION_TYPE, name);
workingCopy.setAttribute(DebugCore.ATTR_DRIVER_ID, dataSourceContainer.getDriver().getId());
workingCopy.setAttribute(DebugCore.ATTR_DATASOURCE_ID, dataSourceContainer.getId());
workingCopy.setAttribute(DebugCore.ATTR_DATABASE_NAME, databaseName);
workingCopy.setAttribute(DebugCore.ATTR_SCHEMA_NAME, schemaName);
workingCopy.setAttribute(DebugCore.ATTR_PROCEDURE_OID, String.valueOf(procedure.getObjectId()));
workingCopy.setAttribute(DebugCore.ATTR_PROCEDURE_NAME, procedureName);
workingCopy.setAttribute(DebugCore.ATTR_ATTACH_PROCESS, DebugCore.ATTR_ATTACH_PROCESS_DEFAULT);
workingCopy.setAttribute(DebugCore.ATTR_ATTACH_KIND, DebugCore.ATTR_ATTACH_KIND_DEFAULT);
workingCopy.setAttribute(DebugCore.ATTR_SCRIPT_EXECUTE, DebugCore.ATTR_SCRIPT_EXECUTE_DEFAULT);
workingCopy.setAttribute(DebugCore.ATTR_SCRIPT_TEXT, DebugCore.composeScriptText(procedure));
final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
DBNDatabaseNode node = navigatorModel.getNodeByObject(procedure);
workingCopy.setAttribute(DebugCore.ATTR_NODE_PATH, node.getNodeItemPath());
return workingCopy;
}
use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase in project dbeaver by dbeaver.
the class PostgreResolver method resolveObject.
@Override
public DBSObject resolveObject(Map<String, Object> context, Object identifier, DBRProgressMonitor monitor) throws DBException {
Long oid = null;
final String errorIdentifier = String.format("Unknown procedure identifier %s", identifier);
if (identifier instanceof Number) {
Number number = (Number) identifier;
oid = number.longValue();
} else if (identifier instanceof String) {
String string = (String) identifier;
try {
oid = Long.parseLong(string);
} catch (NumberFormatException e) {
throw new DBException(errorIdentifier, e, dataSource);
}
}
if (oid == null) {
throw new DBException(errorIdentifier);
}
String databaseName = String.valueOf(context.get(DBGController.DATABASE_NAME));
PostgreDatabase database = dataSource.getDatabase(databaseName);
if (database == null) {
return null;
}
String schemaName = String.valueOf(context.get(DBGController.SCHEMA_NAME));
PostgreSchema schema = null;
schema = database.getSchema(monitor, schemaName);
if (schema == null) {
return null;
}
PostgreProcedure procedure = schema.getProcedure(monitor, oid);
return procedure;
}
use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase in project dbeaver by dbeaver.
the class PostgreDatabaseManager method addObjectCreateActions.
@Override
protected void addObjectCreateActions(List<DBEPersistAction> actions, ObjectCreateCommand command, Map<String, Object> options) {
final PostgreDatabase database = command.getObject();
StringBuilder sql = new StringBuilder();
sql.append("CREATE DATABASE ").append(DBUtils.getQuotedIdentifier(database));
try {
VoidProgressMonitor monitor = new VoidProgressMonitor();
if (database.getDBA(monitor) != null) {
sql.append("\nOWNER = ").append(database.getDBA(monitor).getName());
}
if (!CommonUtils.isEmpty(database.getTemplateName())) {
sql.append("\nTEMPLATE = ").append(database.getTemplateName());
}
if (database.getDefaultEncoding(monitor) != null) {
sql.append("\nENCODING = '").append(database.getDefaultEncoding(monitor).getName()).append("'");
}
if (database.getDefaultTablespace(monitor) != null) {
sql.append("\nTABLESPACE = ").append(database.getDefaultTablespace(monitor).getName());
}
} catch (DBException e) {
log.error(e);
}
actions.add(new SQLDatabasePersistActionAtomic("Create database", sql.toString()));
}
use of org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase in project dbeaver by serge-rider.
the class PostgreDatabaseBackupSettings method fillExportObjectsFromInput.
public void fillExportObjectsFromInput() {
Map<PostgreDatabase, PostgreDatabaseBackupInfo> objMap = new LinkedHashMap<>();
for (DBSObject object : getDatabaseObjects()) {
PostgreDatabase database = null;
PostgreSchema schema = null;
if (object instanceof PostgreDatabase) {
database = (PostgreDatabase) object;
} else if (object instanceof PostgreSchema) {
database = ((PostgreSchema) object).getDatabase();
schema = (PostgreSchema) object;
} else if (object instanceof PostgreTableBase) {
database = ((PostgreTableBase) object).getDatabase();
schema = ((PostgreTableBase) object).getSchema();
}
if (database == null) {
continue;
}
PostgreDatabaseBackupInfo info = objMap.computeIfAbsent(database, db -> new PostgreDatabaseBackupInfo(db, null, null));
if (schema != null) {
List<PostgreSchema> schemas = info.getSchemas();
if (schemas == null) {
schemas = new ArrayList<>();
info.setSchemas(schemas);
}
if (!schemas.contains(schema)) {
schemas.add(schema);
}
}
if (object instanceof PostgreTableBase) {
List<PostgreTableBase> tables = info.getTables();
if (tables == null) {
tables = new ArrayList<>();
info.setTables(tables);
}
tables.add((PostgreTableBase) object);
}
}
getExportObjects().addAll(objMap.values());
updateDataSourceContainer();
}
Aggregations