Search in sources :

Example 1 with DBVEntity

use of org.jkiss.dbeaver.model.virtual.DBVEntity in project dbeaver by dbeaver.

the class ResultSetModel method updateColorMapping.

void updateColorMapping() {
    colorMapping.clear();
    DBSEntity entity = getSingleSource();
    if (entity == null) {
        return;
    }
    DBVEntity virtualEntity = DBVUtils.findVirtualEntity(entity, false);
    if (virtualEntity != null) {
        List<DBVColorOverride> coList = virtualEntity.getColorOverrides();
        if (!CommonUtils.isEmpty(coList)) {
            for (DBVColorOverride co : coList) {
                DBDAttributeBinding binding = getAttributeBinding(entity, co.getAttributeName());
                if (binding != null) {
                    List<AttributeColorSettings> cmList = colorMapping.get(binding);
                    if (cmList == null) {
                        cmList = new ArrayList<>();
                        colorMapping.put(binding, cmList);
                    }
                    cmList.add(new AttributeColorSettings(co));
                }
            }
        }
    }
    updateRowColors(curRows);
}
Also used : DBVColorOverride(org.jkiss.dbeaver.model.virtual.DBVColorOverride) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity)

Example 2 with DBVEntity

use of org.jkiss.dbeaver.model.virtual.DBVEntity in project dbeaver by serge-rider.

the class GISLeafletViewer method saveAttributeSettings.

private void saveAttributeSettings() {
    if (valueController instanceof IAttributeController) {
        DBDAttributeBinding binding = ((IAttributeController) valueController).getBinding();
        if (binding.getEntityAttribute() != null) {
            DBVEntity vEntity = DBVUtils.getVirtualEntity(binding, true);
            DBVEntityAttribute vAttr = vEntity.getVirtualAttribute(binding, true);
            if (vAttr != null) {
                vAttr.setProperty(PROP_FLIP_COORDINATES, String.valueOf(flipCoordinates));
                vAttr.setProperty(PROP_SRID, String.valueOf(getValueSRID()));
            }
            valueController.getExecutionContext().getDataSource().getContainer().getRegistry().flushConfig();
        }
    }
}
Also used : DBVEntityAttribute(org.jkiss.dbeaver.model.virtual.DBVEntityAttribute) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) IAttributeController(org.jkiss.dbeaver.ui.data.IAttributeController) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity)

Example 3 with DBVEntity

use of org.jkiss.dbeaver.model.virtual.DBVEntity in project dbeaver by serge-rider.

the class AssociationDeleteCommand method execute.

/**
 * Removes the relationship
 */
@Override
public void execute() {
    DBSEntityAssociation entityAssociation = association.getObject();
    if (entityAssociation instanceof DBVEntityForeignKey) {
        if (!UIUtils.confirmAction("Delete logical key", "Are you sure you want to delete logical key '" + part.getAssociation().getName() + "'?")) {
            return;
        }
        DBVEntity vEntity = DBVUtils.getVirtualEntity(entityAssociation.getParentObject(), false);
        if (vEntity == null) {
            UIUtils.showMessageBox(UIUtils.getActiveWorkbenchShell(), "No virtual entity", "Can't find association owner virtual entity", SWT.ICON_ERROR);
            return;
        }
        vEntity.removeForeignKey((DBVEntityForeignKey) entityAssociation);
    }
    part.markAssociatedAttributes(EditPart.SELECTED_NONE);
    targetEntity.removeReferenceAssociation(association, true);
    sourceEntity.removeAssociation(association, true);
    association.setSourceEntity(null);
    association.setTargetEntity(null);
}
Also used : DBSEntityAssociation(org.jkiss.dbeaver.model.struct.DBSEntityAssociation) DBVEntityForeignKey(org.jkiss.dbeaver.model.virtual.DBVEntityForeignKey) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity)

Example 4 with DBVEntity

use of org.jkiss.dbeaver.model.virtual.DBVEntity in project dbeaver by serge-rider.

the class AssociationCreateCommand method execute.

@Override
public void execute() {
    if (sourceEntity instanceof ERDEntity && targetEntity instanceof ERDEntity) {
        DBSEntity srcEntityObject = ((ERDEntity) sourceEntity).getObject();
        DBSEntity targetEntityObject = ((ERDEntity) targetEntity).getObject();
        List<DBSEntityAttribute> srcAttrs = ERDUtils.getObjectsFromERD(sourceAttributes);
        List<DBSEntityAttribute> refAttrs = ERDUtils.getObjectsFromERD(targetAttributes);
        DBVEntity vEntity = DBVUtils.getVirtualEntity(srcEntityObject, true);
        DBVEntityForeignKey vfk = EditForeignKeyPage.createVirtualForeignKey(vEntity, targetEntityObject, new EditForeignKeyPage.FKType[] { EditForeignKeyPage.FK_TYPE_LOGICAL }, srcAttrs, refAttrs);
        if (vfk == null) {
            return;
        }
        vEntity.persistConfiguration();
        association = new ERDAssociation(vfk, (ERDEntity) sourceEntity, (ERDEntity) targetEntity, true);
    } else {
        association = createAssociation(sourceEntity, targetEntity, true);
    }
}
Also used : DBVEntityForeignKey(org.jkiss.dbeaver.model.virtual.DBVEntityForeignKey) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) EditForeignKeyPage(org.jkiss.dbeaver.ui.editors.object.struct.EditForeignKeyPage) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity)

Example 5 with DBVEntity

use of org.jkiss.dbeaver.model.virtual.DBVEntity in project dbeaver by serge-rider.

the class DBExecUtils method getBestIdentifier.

public static DBSEntityConstraint getBestIdentifier(@NotNull DBRProgressMonitor monitor, @NotNull DBSEntity table, DBDAttributeBinding[] bindings, boolean readMetaData) throws DBException {
    if (table instanceof DBSDocumentContainer) {
        return new DBSDocumentConstraint((DBSDocumentContainer) table);
    }
    List<DBSEntityConstraint> identifiers = new ArrayList<>(2);
    if (readMetaData) {
        if (table instanceof DBSTable && ((DBSTable) table).isView()) {
        // Skip physical identifiers for views. There are nothing anyway
        } else {
            // Check indexes first.
            if (table instanceof DBSTable) {
                try {
                    Collection<? extends DBSTableIndex> indexes = ((DBSTable) table).getIndexes(monitor);
                    if (!CommonUtils.isEmpty(indexes)) {
                        // First search for primary index
                        for (DBSTableIndex index : indexes) {
                            if (index.isPrimary() && DBUtils.isIdentifierIndex(monitor, index)) {
                                identifiers.add(index);
                                break;
                            }
                        }
                        // Then search for unique index
                        for (DBSTableIndex index : indexes) {
                            if (DBUtils.isIdentifierIndex(monitor, index) && !identifiers.contains(index)) {
                                identifiers.add(index);
                                break;
                            }
                        }
                    }
                } catch (Exception e) {
                    // Indexes are not supported or not available
                    // Just skip them
                    log.debug(e);
                }
            }
            {
                // Check constraints
                Collection<? extends DBSEntityConstraint> constraints = table.getConstraints(monitor);
                if (constraints != null) {
                    for (DBSEntityConstraint constraint : constraints) {
                        if (DBUtils.isIdentifierConstraint(monitor, constraint)) {
                            identifiers.add(constraint);
                        }
                    /* else {
                                if (nonIdentifyingConstraints == null) nonIdentifyingConstraints = new ArrayList<>();
                                nonIdentifyingConstraints.add(constraint);
                            }*/
                    }
                }
            }
        }
    }
    if (!CommonUtils.isEmpty(identifiers)) {
        // Find PK or unique key
        DBSEntityConstraint uniqueId = null;
        for (DBSEntityConstraint constraint : identifiers) {
            if (constraint instanceof DBSEntityReferrer) {
                DBSEntityReferrer referrer = (DBSEntityReferrer) constraint;
                if (isGoodReferrer(monitor, bindings, referrer)) {
                    if (referrer.getConstraintType() == DBSEntityConstraintType.PRIMARY_KEY) {
                        return referrer;
                    } else if (uniqueId == null && (referrer.getConstraintType().isUnique() || (referrer instanceof DBSTableIndex && ((DBSTableIndex) referrer).isUnique()))) {
                        uniqueId = referrer;
                    }
                }
            } else {
                uniqueId = constraint;
            }
        }
        if (uniqueId != null) {
            return uniqueId;
        }
    }
    {
        // Do this after natural identifiers search (see #3829)
        for (DBDAttributeBinding column : bindings) {
            DBDPseudoAttribute pseudoAttribute = column instanceof DBDAttributeBindingMeta ? ((DBDAttributeBindingMeta) column).getPseudoAttribute() : null;
            if (pseudoAttribute != null && pseudoAttribute.getType() == DBDPseudoAttributeType.ROWID) {
                return new DBDPseudoReferrer(table, column);
            }
        }
    }
    // No physical identifiers or row ids
    // Make new or use existing virtual identifier
    DBVEntity virtualEntity = DBVUtils.getVirtualEntity(table, true);
    return virtualEntity.getBestIdentifier();
}
Also used : DBSTable(org.jkiss.dbeaver.model.struct.rdb.DBSTable) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) DBVEntity(org.jkiss.dbeaver.model.virtual.DBVEntity) DBSTableIndex(org.jkiss.dbeaver.model.struct.rdb.DBSTableIndex)

Aggregations

DBVEntity (org.jkiss.dbeaver.model.virtual.DBVEntity)22 DBException (org.jkiss.dbeaver.DBException)5 DBVEntityAttribute (org.jkiss.dbeaver.model.virtual.DBVEntityAttribute)5 DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)4 DBVEntityForeignKey (org.jkiss.dbeaver.model.virtual.DBVEntityForeignKey)4 DBSTable (org.jkiss.dbeaver.model.struct.rdb.DBSTable)3 DBSTableIndex (org.jkiss.dbeaver.model.struct.rdb.DBSTableIndex)3 DBVColorOverride (org.jkiss.dbeaver.model.virtual.DBVColorOverride)3 RGB (org.eclipse.swt.graphics.RGB)2 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)2 DBDAttributeBindingCustom (org.jkiss.dbeaver.model.data.DBDAttributeBindingCustom)2 DBSEntityAssociation (org.jkiss.dbeaver.model.struct.DBSEntityAssociation)2 DBVEntityConstraint (org.jkiss.dbeaver.model.virtual.DBVEntityConstraint)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 java.util (java.util)1 IStatus (org.eclipse.core.runtime.IStatus)1 Color (org.eclipse.swt.graphics.Color)1 ColorDialog (org.eclipse.swt.widgets.ColorDialog)1 Shell (org.eclipse.swt.widgets.Shell)1 NotNull (org.jkiss.code.NotNull)1