use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class DataSourceAutoCommitHandler method updateElement.
@Override
public void updateElement(UIElement element, Map parameters) {
IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
return;
}
IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
if (activeEditor == null) {
return;
}
boolean autoCommit = true;
DBPTransactionIsolation isolation = null;
DBCExecutionContext context = getExecutionContext(activeEditor);
if (context != null && context.isConnected()) {
DBCTransactionManager txnManager = DBUtils.getTransactionManager(context);
if (txnManager != null) {
try {
// Change auto-commit mode
autoCommit = txnManager.isAutoCommit();
isolation = txnManager.getTransactionIsolation();
} catch (DBCException e) {
log.warn(e);
}
}
} else if (activeEditor instanceof IDataSourceContainerProvider) {
DBPDataSourceContainer container = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
if (container != null) {
autoCommit = container.isDefaultAutoCommit();
isolation = container.getActiveTransactionsIsolation();
}
}
element.setChecked(autoCommit);
// Update command image
element.setIcon(DBeaverIcons.getImageDescriptor(autoCommit ? UIIcon.TXN_COMMIT_AUTO : UIIcon.TXN_COMMIT_MANUAL));
String isolationName = isolation == null ? "?" : isolation.getTitle();
element.setText(autoCommit ? "Switch to manual commit (" + isolationName + ")" : "Switch to auto-commit");
element.setTooltip(autoCommit ? "Manual commit (" + isolationName + ")" : "Auto-commit");
}
use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class ComplexObjectEditor method extractValue.
public Object extractValue() {
DBDComplexValue complexValue = getInput();
final ComplexElement[] items = childrenMap.get(complexValue);
if (complexValue instanceof DBDValueCloneable) {
try {
complexValue = (DBDComplexValue) ((DBDValueCloneable) complexValue).cloneValue(VoidProgressMonitor.INSTANCE);
} catch (DBCException e) {
log.error("Error cloning complex value", e);
}
}
if (complexValue instanceof DBDComposite) {
for (int i = 0; i < items.length; i++) {
((DBDComposite) complexValue).setAttributeValue(((CompositeField) items[i]).attribute, items[i].value);
}
} else if (complexValue instanceof DBDCollection) {
if (items != null) {
final Object[] newValues = new Object[items.length];
for (int i = 0; i < items.length; i++) {
newValues[i] = items[i].value;
}
((DBDCollection) complexValue).setContents(newValues);
}
}
return complexValue;
}
use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class ExasolTable method read.
private void read(DBRProgressMonitor monitor) throws DBCException {
JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Read Table Details");
try (JDBCStatement stmt = session.createStatement()) {
String sql = String.format(readAdditionalInfo, ExasolUtils.quoteString(this.getSchema().getName()), ExasolUtils.quoteString(this.getName()), ExasolUtils.quoteString(this.getSchema().getName()), ExasolUtils.quoteString(this.getName()), ExasolUtils.quoteString(this.getSchema().getName()), ExasolUtils.quoteString(this.getName()));
try (JDBCResultSet dbResult = stmt.executeQuery(sql)) {
dbResult.next();
this.hasDistKey = JDBCUtils.safeGetBoolean(dbResult, "TABLE_HAS_DISTRIBUTION_KEY");
this.lastCommit = JDBCUtils.safeGetTimestamp(dbResult, "LAST_COMMIT");
this.sizeRaw = JDBCUtils.safeGetLong(dbResult, "RAW_OBJECT_SIZE");
this.sizeCompressed = JDBCUtils.safeGetLong(dbResult, "MEM_OBJECT_SIZE");
this.deletePercentage = JDBCUtils.safeGetFloat(dbResult, "DELETE_PERCENTAGE");
this.createTime = JDBCUtils.safeGetTimestamp(dbResult, "CREATED");
this.hasRead = true;
}
} catch (SQLException e) {
throw new DBCException(e, getDataSource());
}
}
use of org.jkiss.dbeaver.model.exec.DBCException in project dbeaver by serge-rider.
the class ExasolPlanAnalyser method explain.
public void explain(DBCSession session) throws DBCException {
rootNodes = new ArrayList<>();
JDBCSession connection = (JDBCSession) session;
boolean oldAutoCommit = false;
try {
oldAutoCommit = connection.getAutoCommit();
if (oldAutoCommit)
connection.setAutoCommit(false);
//alter session
JDBCUtils.executeSQL(connection, "ALTER SESSION SET PROFILE = 'ON'");
//execute query
JDBCUtils.executeSQL(connection, query);
//alter session
JDBCUtils.executeSQL(connection, "ALTER SESSION SET PROFILE = 'OFF'");
//rollback in case of DML
connection.rollback();
//alter session
JDBCUtils.executeSQL(connection, "FLUSH STATISTICS");
connection.commit();
//retrieve execute info
try (JDBCPreparedStatement stmt = connection.prepareStatement("SELECT * FROM EXA_USER_PROFILE_LAST_DAY WHERE SESSION_ID = CURRENT_SESSION AND STMT_ID = (select max(stmt_id) from EXA_USER_PROFILE_LAST_DAY where sql_text = ?)")) {
stmt.setString(1, query);
try (JDBCResultSet dbResult = stmt.executeQuery()) {
while (dbResult.next()) {
ExasolPlanNode node = new ExasolPlanNode(null, dbResult);
rootNodes.add(node);
}
}
}
} catch (SQLException e) {
throw new DBCException(e, session.getDataSource());
} finally {
//rollback changes because profile 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 StreamTransferConsumer method initExporter.
private void initExporter(DBCSession session) throws DBCException {
if (settings.getFormatterProfile() != null) {
session.setDataFormatterProfile(settings.getFormatterProfile());
}
exportSite = new StreamExportSite();
// Open output streams
boolean outputClipboard = settings.isOutputClipboard();
outputFile = outputClipboard ? null : makeOutputFile();
try {
if (outputClipboard) {
this.outputBuffer = new StringWriter(2048);
this.writer = new PrintWriter(this.outputBuffer, true);
} else {
this.outputStream = new BufferedOutputStream(new FileOutputStream(outputFile), 10000);
if (settings.isCompressResults()) {
zipStream = new ZipOutputStream(this.outputStream);
zipStream.putNextEntry(new ZipEntry(getOutputFileName()));
StreamTransferConsumer.this.outputStream = zipStream;
}
this.writer = new PrintWriter(new OutputStreamWriter(this.outputStream, settings.getOutputEncoding()), true);
}
// Check for BOM
if (!outputClipboard && settings.isOutputEncodingBOM()) {
byte[] bom = GeneralUtils.getCharsetBOM(settings.getOutputEncoding());
if (bom != null) {
outputStream.write(bom);
outputStream.flush();
}
}
} catch (IOException e) {
closeExporter();
throw new DBCException("Data transfer IO error", e);
}
try {
// init exporter
processor.init(exportSite);
} catch (DBException e) {
throw new DBCException("Can't initialize data exporter", e);
}
}
Aggregations