use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class DB2ServerApplicationManager method alterSession.
@Override
public void alterSession(DBCSession session, DB2ServerApplication sessionType, Map<String, Object> options) throws DBException {
try {
String cmd = String.format(FORCE_APP_CMD, sessionType.getAgentId());
DB2Utils.callAdminCmd(session.getProgressMonitor(), dataSource, cmd);
} catch (SQLException e) {
throw new DBException(e, session.getDataSource());
}
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class ConfigImportWizardPageSqlDeveloper method loadConnections.
@Override
protected void loadConnections(ImportData importData) throws DBException {
importData.addDriver(oraDriver);
File homeFolder = RuntimeUtils.getUserHomeDir();
File sqlDevHome = new File(homeFolder, "AppData/Roaming/" + SQLD_HOME_FOLDER);
if (!sqlDevHome.exists()) {
sqlDevHome = new File(homeFolder, "Application Data/" + SQLD_HOME_FOLDER);
if (!sqlDevHome.exists()) {
throw new DBException("SQL Developer installation not found");
}
}
final File[] sysConfFolders = sqlDevHome.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.contains(SQLD_SYSCONFIG_FOLDER);
}
});
if (sysConfFolders == null || sysConfFolders.length == 0) {
throw new DBException("SQL Developer config not found");
}
for (File sysConfFolder : sysConfFolders) {
final File[] connectionFolders = sysConfFolder.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.contains(SQLD_CONNECTIONS_FOLDER);
}
});
if (connectionFolders == null || connectionFolders.length != 1) {
continue;
}
final File connectionFolder = connectionFolders[0];
final File connectionsFile = new File(connectionFolder, SQLD_CONFIG_FILE);
if (!connectionsFile.exists()) {
continue;
}
parseConnections(connectionsFile, importData);
}
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class PostgreTableManager method appendTableModifiers.
@Override
protected void appendTableModifiers(PostgreTableBase tableBase, NestedObjectCommand tableProps, StringBuilder ddl) {
if (tableBase instanceof PostgreTableRegular) {
final VoidProgressMonitor monitor = VoidProgressMonitor.INSTANCE;
PostgreTableRegular table = (PostgreTableRegular) tableBase;
try {
final List<PostgreTableInheritance> superTables = table.getSuperInheritance(monitor);
if (!CommonUtils.isEmpty(superTables)) {
ddl.append("\nINHERITS (");
for (int i = 0; i < superTables.size(); i++) {
if (i > 0)
ddl.append(",");
ddl.append(superTables.get(i).getAssociatedEntity().getFullyQualifiedName(DBPEvaluationContext.DDL));
}
ddl.append(")");
}
ddl.append("\nWITH (\n\tOIDS=").append(table.isHasOids() ? "TRUE" : "FALSE").append("\n)");
} catch (DBException e) {
log.error(e);
}
}
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class PostgreAttribute method loadInfo.
private void loadInfo(JDBCResultSet dbResult) throws DBException {
setName(JDBCUtils.safeGetString(dbResult, "attname"));
setOrdinalPosition(JDBCUtils.safeGetInt(dbResult, "attnum"));
setRequired(JDBCUtils.safeGetBoolean(dbResult, "attnotnull"));
final long typeId = JDBCUtils.safeGetLong(dbResult, "atttypid");
dataType = getTable().getDatabase().getDataType(typeId);
if (dataType == null) {
throw new DBException("Attribute data type '" + typeId + "' not found");
}
setTypeName(dataType.getTypeName());
setValueType(dataType.getTypeID());
setDefaultValue(JDBCUtils.safeGetString(dbResult, "def_value"));
int typeMod = JDBCUtils.safeGetInt(dbResult, "atttypmod");
int maxLength = PostgreUtils.getAttributePrecision(typeId, typeMod);
DBPDataKind dataKind = dataType.getDataKind();
if (dataKind == DBPDataKind.NUMERIC || dataKind == DBPDataKind.DATETIME) {
setMaxLength(0);
} else {
if (maxLength <= 0) {
maxLength = PostgreUtils.getDisplaySize(typeId, typeMod);
}
if (maxLength >= 0) {
setMaxLength(maxLength);
} else {
// TypeMod can be anything.
// It is often used in packed format and has no numeric meaning at all
//setMaxLength(typeMod);
}
}
setPrecision(maxLength);
setScale(PostgreUtils.getScale(typeId, typeMod));
this.description = JDBCUtils.safeGetString(dbResult, "description");
this.arrayDim = JDBCUtils.safeGetInt(dbResult, "attndims");
this.inheritorsCount = JDBCUtils.safeGetInt(dbResult, "attinhcount");
setPersisted(true);
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class PostgreDataSource method refreshDefaultObject.
@Override
public boolean refreshDefaultObject(@NotNull DBCSession session) throws DBException {
// Check only for schema change. Database cannot be changed by any SQL query
final PostgreDatabase activeDatabase = getDefaultObject();
if (activeDatabase == null) {
return false;
}
try {
String oldDefSchema = activeSchemaName;
determineDefaultObjects((JDBCSession) session);
if (activeSchemaName != null && !CommonUtils.equalObjects(oldDefSchema, activeSchemaName)) {
final PostgreSchema newSchema = activeDatabase.getSchema(session.getProgressMonitor(), activeSchemaName);
if (newSchema != null) {
activeDatabase.setDefaultObject(session.getProgressMonitor(), newSchema);
return true;
}
}
return false;
} catch (SQLException e) {
throw new DBException(e, this);
}
}
Aggregations