use of org.jkiss.dbeaver.model.DBPNamedObject in project dbeaver by serge-rider.
the class CompareObjectsExecutor method compareProperties.
private void compareProperties(DBRProgressMonitor monitor, List<DBNDatabaseNode> nodes) throws DBException, InterruptedException {
// Clear compare singletons
this.initializedCount = 0;
this.initializeError = null;
this.propertyValues.clear();
StringBuilder title = new StringBuilder();
// Initialize nodes
{
monitor.subTask("Initialize nodes");
for (DBNDatabaseNode node : nodes) {
if (title.length() > 0)
title.append(", ");
title.append(node.getNodeFullName());
node.initializeNode(null, initializeFinisher);
monitor.worked(1);
}
while (initializedCount != nodes.size()) {
if (initializeError != null) {
throw new DBException(initializeError.getMessage());
}
Thread.sleep(100);
if (monitor.isCanceled()) {
throw new InterruptedException();
}
}
}
monitor.subTask("Compare " + title.toString());
boolean compareLazyProperties = false;
DBNDatabaseNode firstNode = nodes.get(0);
List<ObjectPropertyDescriptor> properties = ObjectPropertyDescriptor.extractAnnotations(null, firstNode.getObject().getClass(), getDataSourceFilter(firstNode));
for (ObjectPropertyDescriptor prop : properties) {
if (prop.isLazy()) {
compareLazyProperties = true;
break;
}
}
compareLazyProperties = compareLazyProperties && settings.isCompareLazyProperties();
// Load all properties
for (DBNDatabaseNode node : nodes) {
if (monitor.isCanceled()) {
throw new InterruptedException();
}
DBSObject databaseObject = node.getObject();
Map<DBPPropertyDescriptor, Object> nodeProperties = propertyValues.get(databaseObject);
if (nodeProperties == null) {
nodeProperties = new IdentityHashMap<>();
propertyValues.put(databaseObject, nodeProperties);
}
PropertyCollector propertySource = new PropertyCollector(databaseObject, compareLazyProperties);
for (ObjectPropertyDescriptor prop : properties) {
Object propertyValue = propertySource.getPropertyValue(monitor, databaseObject, prop);
synchronized (PROPS_LOCK) {
if (propertyValue instanceof DBPNamedObject) {
// Compare just object names
propertyValue = ((DBPNamedObject) propertyValue).getName();
}
nodeProperties.put(prop, propertyValue);
}
}
monitor.worked(1);
}
// Compare properties
for (ObjectPropertyDescriptor prop : properties) {
reportPropertyCompare(prop);
}
}
use of org.jkiss.dbeaver.model.DBPNamedObject in project dbeaver by serge-rider.
the class PropertySourceEditable method updatePropertyValue.
private boolean updatePropertyValue(@Nullable DBRProgressMonitor monitor, Object editableValue, ObjectPropertyDescriptor prop, Object value, boolean force) throws IllegalArgumentException {
// Write property value
try {
// If value should be a named object then try to obtain it from list provider
if (value != null && value.getClass() == String.class) {
final Object[] items = prop.getPossibleValues(editableValue);
if (items != null) {
boolean found = false;
if (items.length > 0) {
for (int i = 0, itemsLength = items.length; i < itemsLength; i++) {
if ((items[i] instanceof DBPNamedObject && value.equals(((DBPNamedObject) items[i]).getName())) || (items[i] instanceof Enum && value.equals(((Enum) items[i]).name()))) {
value = items[i];
found = true;
break;
}
}
}
if (!found) {
if (value.getClass() != prop.getDataType()) {
value = null;
}
}
}
}
final Object oldValue = getPropertyValue(monitor, editableValue, prop);
if (CommonUtils.equalObjects(oldValue, value)) {
return false;
}
prop.writeValue(editableValue, value);
// Fire object update event
if (editableValue instanceof DBSObject) {
DBUtils.fireObjectUpdate((DBSObject) editableValue, prop);
}
return true;
} catch (Throwable e) {
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
log.error("Can't write property '" + prop.getDisplayName() + "' value", e);
return false;
}
}
Aggregations