use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class DiagramObjectCollector method generateEntityList.
public static List<ERDEntity> generateEntityList(final EntityDiagram diagram, Collection<DBPNamedObject> objects) {
final List<DBSObject> roots = new ArrayList<>();
for (DBPNamedObject object : objects) {
if (object instanceof DBSObject) {
roots.add((DBSObject) object);
}
}
final List<ERDEntity> entities = new ArrayList<>();
try {
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
DiagramObjectCollector collector = new DiagramObjectCollector(diagram);
try {
collector.generateDiagramObjects(monitor, roots);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
entities.addAll(collector.getDiagramEntities());
}
});
} catch (InvocationTargetException e) {
log.error(e.getTargetException());
} catch (InterruptedException e) {
// interrupted
}
return entities;
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class ERDEditorStandalone method loadDiagram.
/*
protected void createActions()
{
super.createActions();
//addEditorAction(new SaveAction(this));
}
*/
@Override
protected synchronized void loadDiagram(boolean refreshMetadata) {
if (diagramLoadingJob != null) {
// Do not start new one while old is running
return;
}
diagramLoadingJob = LoadingJob.createService(new AbstractLoadService<EntityDiagram>("Load diagram '" + getEditorInput().getName() + "'") {
@Override
public EntityDiagram evaluate(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
return loadContentFromFile(monitor);
} catch (DBException e) {
log.error(e);
}
return null;
}
@Override
public Object getFamily() {
return ERDEditorStandalone.this;
}
}, progressControl.createLoadVisualizer());
diagramLoadingJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
diagramLoadingJob = null;
}
});
diagramLoadingJob.schedule();
setPartName(getEditorInput().getName());
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class JDBCTable method countData.
@Override
public long countData(@NotNull DBCExecutionSource source, @NotNull DBCSession session, @Nullable DBDDataFilter dataFilter) throws DBCException {
DBRProgressMonitor monitor = session.getProgressMonitor();
//$NON-NLS-1$
StringBuilder query = new StringBuilder("SELECT COUNT(*) FROM ");
query.append(getFullyQualifiedName(DBPEvaluationContext.DML));
appendQueryConditions(query, null, dataFilter);
monitor.subTask(ModelMessages.model_jdbc_fetch_table_row_count);
try (DBCStatement dbStat = session.prepareStatement(DBCStatementType.QUERY, query.toString(), false, false, false)) {
dbStat.setStatementSource(source);
if (!dbStat.executeStatement()) {
return 0;
}
DBCResultSet dbResult = dbStat.openResultSet();
if (dbResult == null) {
return 0;
}
try {
if (dbResult.nextRow()) {
Object result = dbResult.getAttributeValue(0);
if (result == null) {
return 0;
} else if (result instanceof Number) {
return ((Number) result).longValue();
} else {
return Long.parseLong(result.toString());
}
} else {
return 0;
}
} finally {
dbResult.close();
}
}
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class SQLQueryJob method fetchQueryData.
private boolean fetchQueryData(DBCSession session, DBCResultSet resultSet, SQLQueryResult result, DBDDataReceiver dataReceiver, boolean updateStatistics) throws DBCException {
if (dataReceiver == null) {
// No data pump - skip fetching stage
return false;
}
if (resultSet == null) {
return false;
}
boolean keepCursor = keepStatementOpen();
if (keepCursor) {
curResultSets.add(resultSet);
}
DBRProgressMonitor monitor = session.getProgressMonitor();
monitor.subTask("Fetch result set");
long rowCount = 0;
dataReceiver.fetchStart(session, resultSet, rsOffset, rsMaxRows);
try {
//resultSet.getResultSetName();
String sourceName = null;
if (result != null) {
final String queryTitle = result.getStatement().getQueryTitle();
if (!CommonUtils.isEmpty(queryTitle)) {
sourceName = queryTitle;
} else {
// Retrieve source entity
DBCResultSetMetaData rsMeta = resultSet.getMeta();
for (DBCAttributeMetaData attr : rsMeta.getAttributes()) {
String entityName = attr.getEntityName();
if (!CommonUtils.isEmpty(entityName)) {
if (sourceName == null) {
sourceName = entityName;
} else if (!sourceName.equals(entityName)) {
// Multiple source entities
sourceName += "(+)";
break;
}
}
}
/*
if (CommonUtils.isEmpty(sourceName)) {
try {
sourceName = resultSet.getResultSetName();
} catch (DBCException e) {
log.debug(e);
}
}
*/
}
if (CommonUtils.isEmpty(sourceName)) {
sourceName = "Result";
}
result.setResultSetName(sourceName);
}
long fetchStartTime = System.currentTimeMillis();
// Fetch all rows
while ((!hasLimits() || rowCount < rsMaxRows) && resultSet.nextRow()) {
if (monitor.isCanceled()) {
break;
}
rowCount++;
if (rowCount > 0 && rowCount % 100 == 0) {
monitor.subTask(rowCount + " rows fetched");
monitor.worked(100);
}
dataReceiver.fetchRow(session, resultSet);
}
if (updateStatistics) {
statistics.addFetchTime(System.currentTimeMillis() - fetchStartTime);
}
} finally {
if (!keepCursor) {
try {
resultSet.close();
} catch (Throwable e) {
log.error("Error while closing resultset", e);
}
}
try {
dataReceiver.fetchEnd(session, resultSet);
} catch (Throwable e) {
log.error("Error while handling end of result set fetch", e);
}
dataReceiver.close();
}
if (result != null) {
result.setRowCount(rowCount);
}
if (updateStatistics) {
statistics.setRowsFetched(rowCount);
}
monitor.subTask(rowCount + " rows fetched");
return true;
}
use of org.jkiss.dbeaver.model.runtime.DBRProgressMonitor in project dbeaver by serge-rider.
the class DBeaverSettingsImporter method migrateWorkspace.
private void migrateWorkspace(final File oldDir, final File newDir) {
progressLabel.setText("Counting workspace files...");
final int totalFiles = countWorkspaceFiles(oldDir);
progressBar.setMinimum(0);
progressBar.setMaximum(totalFiles);
final DBRProgressMonitor monitor = new BaseProgressMonitor() {
int filesProcessed = 0;
@Override
public void subTask(final String name) {
display.syncExec(new Runnable() {
@Override
public void run() {
progressLabel.setText(name);
}
});
}
@Override
public void worked(final int work) {
display.syncExec(new Runnable() {
@Override
public void run() {
filesProcessed += work;
progressBar.setSelection(filesProcessed);
}
});
}
};
new Thread() {
@Override
public void run() {
try {
if (!newDir.exists()) {
if (!newDir.mkdirs()) {
System.err.println("Can't create target workspace directory '" + newDir.getAbsolutePath() + "'");
return;
}
}
copyWorkspaceFiles(monitor, DIR_TYPE.WORKSPACE, oldDir, newDir);
} finally {
DBeaverApplication.WORKSPACE_MIGRATED = true;
display.syncExec(new Runnable() {
@Override
public void run() {
showMessageBox("Import completed", "Configuration was imported to '" + newDir.getAbsolutePath() + "'", SWT.ICON_INFORMATION | SWT.OK);
shellResult = SWT.OK;
windowShell.dispose();
}
});
}
}
}.start();
}
Aggregations