use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class DBVEntityForeignKey method getRealReferenceConstraint.
@NotNull
public DBSEntityConstraint getRealReferenceConstraint(@NotNull DBRProgressMonitor monitor) throws DBException {
if (refEntityId == null) {
throw new DBException("Ref entity ID not set for virtual FK " + getName());
}
DBNNode refNode = DBWorkbench.getPlatform().getNavigatorModel().getNodeByPath(monitor, refEntityId);
if (!(refNode instanceof DBNDatabaseNode)) {
throw new DBException("Can't find reference node " + refEntityId + " for virtual foreign key");
}
DBSObject object = ((DBNDatabaseNode) refNode).getObject();
if (object instanceof DBSEntity) {
List<DBSEntityConstraint> constraints = DBVUtils.getAllConstraints(monitor, (DBSEntity) object);
DBSObject refEntityConstraint = DBUtils.findObject(constraints, refConstraintId);
if (refEntityConstraint == null) {
throw new DBException("Can't find constraint " + refConstraintId + " in entity " + refEntityId);
}
return (DBSEntityConstraint) refEntityConstraint;
} else {
throw new DBException("Object " + refEntityId + " is not an entity");
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class DBVEntityForeignKey method setReferencedConstraint.
public synchronized void setReferencedConstraint(DBRProgressMonitor monitor, DBSEntityConstraint constraint) throws DBException {
DBSEntity refEntity = constraint.getParentObject();
if (refEntity instanceof DBVEntity) {
refEntity = ((DBVEntity) refEntity).getRealEntity(monitor);
}
DBNDatabaseNode refNode = DBWorkbench.getPlatform().getNavigatorModel().getNodeByObject(monitor, refEntity, true);
if (refNode == null) {
log.warn("Can't find navigator node for object " + DBUtils.getObjectFullId(refEntity));
return;
}
if (refEntityId != null) {
DBVModel.removeFromCache(this);
}
this.refEntityId = refNode.getNodeItemPath();
this.refConstraintId = constraint.getName();
if (refEntityId != null) {
DBVModel.addToCache(this);
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class DBVModel method handleEntityRename.
private static void handleEntityRename(DBSEntity object, String oldName, String newName) {
DBNDatabaseNode objectNode = DBWorkbench.getPlatform().getNavigatorModel().getNodeByObject(object);
if (objectNode != null) {
String objectNodePath = objectNode.getNodeItemPath();
renameEntityInGlobalCache(objectNodePath, oldName, newName);
}
if (object.getDataSource() != null) {
DBVModel vModel = object.getDataSource().getContainer().getVirtualModel();
DBVEntity vEntity = vModel.findEntity(object, oldName, false);
if (vEntity != null) {
vEntity.handleRename(oldName, newName);
vEntity.persistConfiguration();
}
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class SQLToolTaskWizard method refreshOnFinish.
private void refreshOnFinish() throws Exception {
try {
getContainer().run(true, true, monitor -> {
monitor.beginTask("Object refreshing", objectList.size());
for (DBSObject object : objectList) {
try {
DBNDatabaseNode objectNode = DBNUtils.getNodeByObject(object);
if (objectNode != null) {
objectNode.refreshNode(new DefaultProgressMonitor(monitor), DBNEvent.FORCE_REFRESH);
if (monitor.isCanceled()) {
break;
}
monitor.worked(1);
}
} catch (Exception e) {
log.error("Error refreshing object '" + object.getName() + "'", e);
}
}
monitor.done();
});
} catch (InvocationTargetException e) {
throw new DBCException("Refresh error", e.getTargetException());
} catch (InterruptedException e) {
// ignore
}
}
use of org.jkiss.dbeaver.model.navigator.DBNDatabaseNode in project dbeaver by dbeaver.
the class GenerateMultiSQLDialog method executeSQL.
@Override
protected void executeSQL() {
final String jobName = getShell().getText();
final SQLScriptProgressListener<T> scriptListener = getScriptListener();
final List<T> objects = getCheckedObjects();
final Map<T, List<String>> objectsSQL = new LinkedHashMap<>();
for (T object : objects) {
final List<String> lines = new ArrayList<>();
generateObjectCommand(lines, object);
objectsSQL.put(object, lines);
}
final DataSourceJob job = new DataSourceJob(jobName, getExecutionContext()) {
Exception objectProcessingError;
@Override
protected IStatus run(final DBRProgressMonitor monitor) {
final DataSourceJob curJob = this;
UIUtils.asyncExec(() -> scriptListener.beginScriptProcessing(curJob, objects));
monitor.beginTask(jobName, objects.size());
try (DBCSession session = getExecutionContext().openSession(monitor, DBCExecutionPurpose.UTIL, jobName)) {
if (isRunInSeparateTransaction()) {
commitChanges(session);
}
for (int i = 0; i < objects.size(); i++) {
if (monitor.isCanceled()) {
break;
}
final int objectNumber = i;
final T object = objects.get(i);
monitor.subTask("Process " + DBUtils.getObjectFullName(object, DBPEvaluationContext.UI));
objectProcessingError = null;
UIUtils.asyncExec(() -> scriptListener.beginObjectProcessing(object, objectNumber));
try {
final List<String> lines = objectsSQL.get(object);
for (String line : lines) {
try (final DBCStatement statement = DBUtils.makeStatement(session, line, false)) {
if (statement.executeStatement()) {
try (DBCResultSet resultSet = statement.openResultSet()) {
// Run in sync because we need result set
UIUtils.syncExec(() -> {
try {
scriptListener.processObjectResults(object, statement, resultSet);
} catch (DBCException e) {
objectProcessingError = e;
}
});
}
if (objectProcessingError != null) {
break;
}
} else {
UIUtils.syncExec(() -> {
try {
scriptListener.processObjectResults(object, statement, null);
} catch (DBCException e) {
objectProcessingError = e;
}
});
}
}
}
} catch (Exception e) {
objectProcessingError = e;
} finally {
UIUtils.asyncExec(() -> scriptListener.endObjectProcessing(object, objectProcessingError));
}
monitor.worked(1);
}
if (isRunInSeparateTransaction()) {
commitChanges(session);
}
} finally {
monitor.done();
UIUtils.asyncExec(scriptListener::endScriptProcessing);
}
return Status.OK_STATUS;
}
};
job.setUser(false);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if (needsRefreshOnFinish()) {
List<T> objectToRefresh = new ArrayList<>(selectedObjects);
UIUtils.asyncExec(() -> {
try {
UIUtils.runInProgressDialog(monitor -> {
monitor.beginTask("Refresh objects", objectToRefresh.size());
for (T object : objectToRefresh) {
try {
DBNDatabaseNode objectNode = DBNUtils.getNodeByObject(object);
if (objectNode != null) {
objectNode.refreshNode(monitor, DBNEvent.FORCE_REFRESH);
}
} catch (Exception e) {
log.error("Error refreshing object '" + object.getName() + "'", e);
}
}
monitor.done();
});
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError("Objects refresh", "Error refreshing navigator objects", e);
}
});
}
}
});
job.schedule();
}
Aggregations