use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class TableToolDialog method getScriptListener.
@Override
protected SQLScriptProgressListener<PostgreObject> getScriptListener() {
return new SQLScriptStatusDialog<PostgreObject>(getShell(), getTitle() + " progress", null) {
@Override
protected void createStatusColumns(Tree objectTree) {
TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
msgColumn.setText("Message");
}
@Override
public void processObjectResults(@NotNull PostgreObject object, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
if (statement == null) {
return;
}
TreeItem treeItem = getTreeItem(object);
if (treeItem != null) {
try {
int warnNum = 0;
SQLWarning warning = ((JDBCStatement) statement).getWarnings();
while (warning != null) {
if (warnNum == 0) {
treeItem.setText(1, warning.getMessage());
} else {
TreeItem warnItem = new TreeItem(treeItem, SWT.NONE);
warnItem.setText(0, "");
warnItem.setText(1, warning.getMessage());
}
warnNum++;
warning = warning.getNextWarning();
}
if (warnNum == 0) {
treeItem.setText(1, "Done");
}
} catch (SQLException e) {
// ignore
}
treeItem.setExpanded(true);
}
}
@Override
public void endObjectProcessing(@NotNull PostgreObject object, Exception error) {
super.endObjectProcessing(object, error);
if (error != null) {
TreeItem treeItem = getTreeItem(object);
if (treeItem != null) {
treeItem.setText(1, error.getMessage());
}
}
}
};
}
use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class PostgreStructValueHandler method bindParameter.
@Override
protected void bindParameter(JDBCSession session, JDBCPreparedStatement statement, DBSTypedObject paramType, int paramIndex, Object value) throws DBCException, SQLException {
if (value == null) {
statement.setNull(paramIndex, Types.STRUCT);
} else if (value instanceof DBDComposite) {
DBDComposite struct = (DBDComposite) value;
if (struct.isNull()) {
statement.setNull(paramIndex, Types.STRUCT);
} else if (struct instanceof JDBCComposite) {
final Object[] values = ((JDBCComposite) struct).getValues();
final String string = PostgreUtils.generateObjectString(values);
statement.setObject(paramIndex, string, Types.OTHER);
}
} else {
throw new DBCException("Struct parameter type '" + value.getClass().getName() + "' not supported");
}
}
use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class PostgrePlanAnalyser method explain.
public void explain(DBCSession session) throws DBCException {
JDBCSession connection = (JDBCSession) session;
boolean oldAutoCommit = false;
try {
oldAutoCommit = connection.getAutoCommit();
if (oldAutoCommit) {
connection.setAutoCommit(false);
}
try (JDBCPreparedStatement dbStat = connection.prepareStatement("EXPLAIN (FORMAT XML, ANALYSE) " + query)) {
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
if (dbResult.next()) {
SQLXML planXML = dbResult.getSQLXML(1);
parsePlan(planXML);
}
} catch (XMLException e) {
throw new DBCException("Can't parse plan XML", e);
}
}
} catch (SQLException e) {
throw new DBCException(e, session.getDataSource());
} finally {
// Rollback changes because EXPLAIN actually executes query and it could be INSERT/UPDATE
try {
connection.rollback();
if (oldAutoCommit) {
connection.setAutoCommit(true);
}
} catch (SQLException e) {
log.error("Error closing plan analyser", e);
}
}
}
use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class WMIClass method readData.
@NotNull
@Override
public DBCStatistics readData(@NotNull DBCExecutionSource source, @NotNull DBCSession session, @NotNull DBDDataReceiver dataReceiver, DBDDataFilter dataFilter, long firstRow, long maxRows, long flags) throws DBCException {
DBCStatistics statistics = new DBCStatistics();
try {
long startTime = System.currentTimeMillis();
WMIObjectCollectorSink sink = new WMIObjectCollectorSink(session.getProgressMonitor(), getNamespace().getService(), firstRow, maxRows);
getNamespace().getService().enumInstances(getName(), sink, WMIConstants.WBEM_FLAG_SHALLOW);
statistics.setExecuteTime(System.currentTimeMillis() - startTime);
startTime = System.currentTimeMillis();
sink.waitForFinish();
WMIResultSet resultSet = new WMIResultSet(session, this, sink.getObjectList());
long resultCount = 0;
try {
dataReceiver.fetchStart(session, resultSet, firstRow, maxRows);
while (resultSet.nextRow()) {
resultCount++;
dataReceiver.fetchRow(session, resultSet);
}
} finally {
try {
dataReceiver.fetchEnd(session, resultSet);
} catch (DBCException e) {
//$NON-NLS-1$
log.error("Error while finishing result set fetch", e);
}
resultSet.close();
dataReceiver.close();
}
statistics.setFetchTime(System.currentTimeMillis() - startTime);
statistics.setRowsFetched(resultCount);
return statistics;
} catch (WMIException e) {
throw new DBCException(e, getDataSource());
}
}
use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class PostgreTable method getSubInheritance.
@NotNull
public List<PostgreTableInheritance> getSubInheritance(@NotNull DBRProgressMonitor monitor) throws DBException {
if (subTables == null) {
try (JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Load table inheritance info")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT i.*,c.relnamespace " + "FROM pg_catalog.pg_inherits i,pg_catalog.pg_class c " + "WHERE i.inhparent=? AND c.oid=i.inhrelid")) {
dbStat.setLong(1, getObjectId());
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
final long subSchemaId = JDBCUtils.safeGetLong(dbResult, "relnamespace");
final long subTableId = JDBCUtils.safeGetLong(dbResult, "inhrelid");
PostgreSchema schema = getDatabase().getSchema(monitor, subSchemaId);
if (schema == null) {
log.warn("Can't find sub-table's schema '" + subSchemaId + "'");
continue;
}
PostgreTableBase subTable = schema.getTable(monitor, subTableId);
if (subTable == null) {
log.warn("Can't find sub-table '" + subTableId + "' in '" + schema.getName() + "'");
continue;
}
if (subTables == null) {
subTables = new ArrayList<>();
}
subTables.add(new PostgreTableInheritance(subTable, this, JDBCUtils.safeGetInt(dbResult, "inhseqno"), true));
}
}
}
} catch (SQLException e) {
throw new DBCException(e, getDataSource());
}
if (subTables == null) {
subTables = Collections.emptyList();
}
}
return subTables;
}
Aggregations