use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase in project dbeaver by serge-rider.
the class ExasolExportTableTool method execute.
@Override
public void execute(IWorkbenchWindow window, IWorkbenchPart activePart, Collection<DBSObject> objects) throws DBException {
List<ExasolTable> tables = CommonUtils.filterCollection(objects, ExasolTable.class);
List<ExasolView> views = CommonUtils.filterCollection(objects, ExasolView.class);
List<ExasolSchema> schemas = CommonUtils.filterCollection(objects, ExasolSchema.class);
// add tables for all Schemas but ignore views in schema
for (ExasolSchema schema : schemas) {
tables.addAll(schema.getTables(new VoidProgressMonitor()));
}
// create TableBase Objects list
@SuppressWarnings({ "unchecked", "rawtypes" }) HashSet<ExasolTableBase> tableBaseObjects = new HashSet();
// add tables
for (ExasolTable table : tables) {
tableBaseObjects.add((ExasolTableBase) table);
}
// add views
for (ExasolView view : views) {
tableBaseObjects.add((ExasolTableBase) view);
}
if (!tableBaseObjects.isEmpty()) {
ExasolExportTableToolDialog dialog = new ExasolExportTableToolDialog(activePart.getSite(), tableBaseObjects);
dialog.open();
}
}
use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase in project dbeaver by serge-rider.
the class ExasolImportTableTool method execute.
@Override
public void execute(IWorkbenchWindow window, IWorkbenchPart activePart, Collection<DBSObject> objects) throws DBException {
List<ExasolTable> tables = CommonUtils.filterCollection(objects, ExasolTable.class);
List<ExasolSchema> schemas = CommonUtils.filterCollection(objects, ExasolSchema.class);
// add tables for all Schemas but ignore views in schema
for (ExasolSchema schema : schemas) {
tables.addAll(schema.getTables(new VoidProgressMonitor()));
}
// create TableBase Objects list
@SuppressWarnings({ "unchecked", "rawtypes" }) HashSet<ExasolTableBase> tableBaseObjects = new HashSet();
// add tables
for (ExasolTable table : tables) {
tableBaseObjects.add((ExasolTableBase) table);
}
if (!tableBaseObjects.isEmpty()) {
ExasolImportTableToolDialog dialog = new ExasolImportTableToolDialog(activePart.getSite(), tableBaseObjects);
dialog.open();
}
}
use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase in project dbeaver by serge-rider.
the class ExasolBaseTableToolDialog method executeSQL.
@Override
protected void executeSQL() {
final String jobName = getShell().getText();
final SQLScriptProgressListener<ExasolTableBase> scriptListener = getScriptListener();
final List<ExasolTableBase> objects = getCheckedObjects();
final Map<ExasolTableBase, List<String>> objectsSQL = new LinkedHashMap<>();
for (ExasolTableBase object : objects) {
final List<String> lines = new ArrayList<>();
generateObjectCommand(lines, object);
objectsSQL.put(object, lines);
}
final DataSourceJob job = new DataSourceJob(jobName, null, getExecutionContext()) {
public Exception objectProcessingError;
@SuppressWarnings("rawtypes")
@Override
protected IStatus run(final DBRProgressMonitor monitor) {
final DataSourceJob curJob = this;
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
scriptListener.beginScriptProcessing(curJob, objects);
}
});
monitor.beginTask(jobName, objects.size());
try (DBCSession session = getExecutionContext().openSession(monitor, DBCExecutionPurpose.UTIL, jobName)) {
for (int i = 0; i < objects.size(); i++) {
if (monitor.isCanceled()) {
break;
}
final int objectNumber = i;
final ExasolTableBase object = objects.get(i);
monitor.subTask("Process " + DBUtils.getObjectFullName(object, DBPEvaluationContext.UI));
objectProcessingError = null;
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
scriptListener.beginObjectProcessing(object, objectNumber);
}
});
try {
final List<String> lines = objectsSQL.get(object);
for (String line : lines) {
try (final Statement statement = ((JDBCSession) session).getOriginal().createStatement()) {
int affectedRows = statement.executeUpdate(line);
Integer[] resultSetData = new Integer[] { affectedRows };
final LocalResultSet resultSet = new LocalResultSet<>(session, new JDBCStatementImpl<>((JDBCSession) session, statement, true));
resultSet.addColumn("ROWS_AFFECTED", DBPDataKind.NUMERIC);
resultSet.addRow((Object[]) resultSetData);
// Run in sync because we need result set
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
try {
scriptListener.processObjectResults(object, null, resultSet);
} catch (DBCException e) {
objectProcessingError = e;
}
}
});
if (objectProcessingError != null) {
break;
}
}
}
} catch (Exception e) {
objectProcessingError = e;
} finally {
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
scriptListener.endObjectProcessing(object, objectProcessingError);
}
});
}
monitor.worked(1);
}
} finally {
monitor.done();
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
scriptListener.endScriptProcessing();
}
});
}
return Status.OK_STATUS;
}
};
job.setUser(false);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
}
});
job.schedule();
}
use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase in project dbeaver by serge-rider.
the class ExasolBaseTableToolDialog method getScriptListener.
@Override
protected SQLScriptProgressListener<ExasolTableBase> getScriptListener() {
final int nbExtraColumns = getNumberExtraResultingColumns();
return new SQLScriptStatusDialog<ExasolTableBase>(getShell(), getTitle() + " " + ExasolMessages.dialog_table_tools_progress, null) {
@Override
protected void createStatusColumns(Tree objectTree) {
TreeColumn msgColumn = new TreeColumn(objectTree, SWT.NONE);
msgColumn.setText(ExasolMessages.dialog_table_tools_result);
for (int i = 0; i < nbExtraColumns; i++) {
new TreeColumn(objectTree, SWT.NONE);
}
}
@Override
public void endObjectProcessing(@NotNull ExasolTableBase exasolTable, Exception exception) {
TreeItem treeItem = getTreeItem(exasolTable);
if (exception == null) {
treeItem.setText(1, ExasolMessages.dialog_table_tools_success_title);
} else {
treeItem.setText(1, exception.getMessage());
}
UIUtils.packColumns(treeItem.getParent(), false, null);
}
// DF: This method is for tools that return resultsets
@Override
public void processObjectResults(@NotNull ExasolTableBase exasolTable, @Nullable DBCStatement statement, @Nullable DBCResultSet resultSet) throws DBCException {
if (resultSet == null) {
return;
}
// Retrieve column names
DBCResultSetMetaData rsMetaData = resultSet.getMeta();
try {
TreeItem treeItem = getTreeItem(exasolTable);
Font f = UIUtils.makeBoldFont(treeItem.getFont());
if (treeItem != null) {
// Display the column names
TreeItem subItem = null;
subItem = new TreeItem(treeItem, SWT.NONE);
subItem.setFont(f);
for (DBCAttributeMetaData column : rsMetaData.getAttributes()) {
subItem.setText(column.getOrdinalPosition(), column.getName());
subItem.setGrayed(true);
}
// Display the data for each row
while (resultSet.nextRow()) {
subItem = new TreeItem(treeItem, SWT.NONE);
for (int i = 0; i < rsMetaData.getAttributes().size(); i++) {
subItem.setText(i, CommonUtils.toString(resultSet.getAttributeValue(i)));
i++;
}
}
treeItem.setExpanded(true);
}
} catch (Exception e) {
throw new DBCException(e.getMessage());
}
}
};
}
use of org.jkiss.dbeaver.ext.exasol.model.ExasolTableBase in project dbeaver by serge-rider.
the class ExasolExportTableTool method execute.
@Override
public void execute(IWorkbenchWindow window, IWorkbenchPart activePart, Collection<DBSObject> objects) throws DBException {
List<ExasolTable> tables = CommonUtils.filterCollection(objects, ExasolTable.class);
List<ExasolView> views = CommonUtils.filterCollection(objects, ExasolView.class);
List<ExasolSchema> schemas = CommonUtils.filterCollection(objects, ExasolSchema.class);
//add tables for all Schemas but ignore views in schema
for (ExasolSchema schema : schemas) {
tables.addAll(schema.getTables(VoidProgressMonitor.INSTANCE));
}
// create TableBase Objects list
@SuppressWarnings({ "unchecked", "rawtypes" }) HashSet<ExasolTableBase> tableBaseObjects = new HashSet();
//add tables
for (ExasolTable table : tables) {
tableBaseObjects.add((ExasolTableBase) table);
}
//add views
for (ExasolView view : views) {
tableBaseObjects.add((ExasolTableBase) view);
}
if (!tableBaseObjects.isEmpty()) {
ExasolExportTableToolDialog dialog = new ExasolExportTableToolDialog(activePart.getSite(), tableBaseObjects);
dialog.open();
}
}
Aggregations