Search in sources :

Example 11 with DBPPropertyDescriptor

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);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPSystemObject(org.jkiss.dbeaver.model.DBPSystemObject) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 12 with DBPPropertyDescriptor

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;
        }
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPSystemObject(org.jkiss.dbeaver.model.DBPSystemObject) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)

Example 13 with DBPPropertyDescriptor

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;
}
Also used : HashMap(java.util.HashMap) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)

Example 14 with DBPPropertyDescriptor

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();
}
Also used : SimplePreferenceStore(org.jkiss.dbeaver.model.impl.preferences.SimplePreferenceStore) DBPPropertyDescriptor(org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)

Aggregations

DBPPropertyDescriptor (org.jkiss.dbeaver.model.preferences.DBPPropertyDescriptor)14 PropertyDescriptor (org.jkiss.dbeaver.model.impl.PropertyDescriptor)4 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 DBPNamedObject (org.jkiss.dbeaver.model.DBPNamedObject)2 DBPSystemObject (org.jkiss.dbeaver.model.DBPSystemObject)2 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)2 DriverPropertyInfo (java.sql.DriverPropertyInfo)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1