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);
}
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();
}
}
}
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);
}
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);
}
}
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();
}
Aggregations