use of org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor 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.preferences.DBPPropertyDescriptor in project dbeaver by serge-rider.
the class CompareObjectsExecutor method reportPropertyCompare.
private void reportPropertyCompare(ObjectPropertyDescriptor property) {
CompareReportProperty reportProperty = new CompareReportProperty(property);
reportProperty.values = new Object[rootNodes.size()];
for (int i = 0; i < lastLine.nodes.length; i++) {
DBNDatabaseNode node = lastLine.nodes[i];
if (node == null) {
continue;
}
Map<DBPPropertyDescriptor, Object> valueMap = propertyValues.get(node.getObject());
if (valueMap != null) {
reportProperty.values[i] = valueMap.get(property);
}
}
if (lastLine.properties == null) {
lastLine.properties = new ArrayList<>();
}
lastLine.properties.add(reportProperty);
Object firstValue = reportProperty.values[0];
for (int i = 1; i < rootNodes.size(); i++) {
if (!CompareUtils.equalPropertyValues(reportProperty.values[i], firstValue)) {
lastLine.hasDifference = true;
break;
}
}
}
use of org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor in project dbeaver by serge-rider.
the class DataFormatterProfile method getFormatterProperties.
@Override
public Map<Object, Object> getFormatterProperties(String typeId) {
DataFormatterDescriptor formatter = DataFormatterRegistry.getInstance().getDataFormatter(typeId);
Map<Object, Object> defaultProperties = formatter.getSample().getDefaultProperties(locale);
Map<Object, Object> formatterProps = new HashMap<>();
for (DBPPropertyDescriptor prop : formatter.getProperties()) {
Object defaultValue = defaultProperties.get(prop.getId());
Object propValue = PrefUtils.getPreferenceValue(store, DATAFORMAT_TYPE_PREFIX + formatter.getId() + "." + prop.getId(), prop.getDataType());
if (propValue != null && !CommonUtils.equalObjects(defaultValue, propValue)) {
formatterProps.put(prop.getId(), propValue);
}
}
return formatterProps;
}
use of org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor in project dbeaver by serge-rider.
the class DataFormatterProfile method reset.
@Override
public void reset() {
if (store instanceof SimplePreferenceStore) {
// Set all formatter properties to default
store.setToDefault(PROP_LANGUAGE);
store.setToDefault(PROP_COUNTRY);
store.setToDefault(PROP_VARIANT);
for (DataFormatterDescriptor formatter : DataFormatterRegistry.getInstance().getDataFormatters()) {
for (DBPPropertyDescriptor prop : formatter.getProperties()) {
store.setToDefault(DATAFORMAT_TYPE_PREFIX + formatter.getId() + "." + prop.getId());
}
}
}
loadProfile();
}
Aggregations