use of org.jkiss.dbeaver.model.virtual.DBVEntity in project dbeaver by serge-rider.
the class CustomizeColorsAction method run.
@Override
public void run() {
final DBVEntity vEntity = getColorsVirtualEntity();
ColorSettingsDialog dialog = new ColorSettingsDialog(resultSetViewer, vEntity, curAttribute, row);
if (dialog.open() != IDialogConstants.OK_ID) {
return;
}
updateColors(vEntity);
}
use of org.jkiss.dbeaver.model.virtual.DBVEntity in project dbeaver by serge-rider.
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 ResultSetUtils method getBestIdentifier.
private static DBSEntityReferrer getBestIdentifier(@NotNull DBRProgressMonitor monitor, @NotNull DBSEntity table, DBDAttributeBindingMeta[] bindings) throws DBException {
List<DBSEntityReferrer> identifiers = new ArrayList<>(2);
// Check for pseudo attrs (ROWID)
for (DBDAttributeBindingMeta column : bindings) {
DBDPseudoAttribute pseudoAttribute = column.getPseudoAttribute();
if (pseudoAttribute != null && pseudoAttribute.getType() == DBDPseudoAttributeType.ROWID) {
identifiers.add(new DBDPseudoReferrer(table, column));
break;
}
}
if (table instanceof DBSTable && ((DBSTable) table).isView()) {
// Skip physical identifiers for views. There are nothing anyway
} else if (identifiers.isEmpty()) {
// Check indexes first.
if (table instanceof DBSTable) {
try {
Collection<? extends DBSTableIndex> indexes = ((DBSTable) table).getIndexes(monitor);
if (!CommonUtils.isEmpty(indexes)) {
for (DBSTableIndex index : indexes) {
if (DBUtils.isIdentifierIndex(monitor, index)) {
identifiers.add(index);
break;
}
}
}
} catch (Exception e) {
// Indexes are not supported or not available
// Just skip them
log.debug(e);
}
}
if (identifiers.isEmpty()) {
// Check constraints
Collection<? extends DBSEntityConstraint> constraints = table.getConstraints(monitor);
if (constraints != null) {
for (DBSEntityConstraint constraint : constraints) {
if (DBUtils.isIdentifierConstraint(monitor, constraint)) {
identifiers.add((DBSEntityReferrer) constraint);
}
}
}
}
}
if (CommonUtils.isEmpty(identifiers)) {
// No physical identifiers
// Make new or use existing virtual identifier
DBVEntity virtualEntity = DBVUtils.findVirtualEntity(table, true);
identifiers.add(virtualEntity.getBestIdentifier());
}
if (!CommonUtils.isEmpty(identifiers)) {
// Find PK or unique key
DBSEntityReferrer uniqueId = null;
for (DBSEntityReferrer referrer : identifiers) {
if (isGoodReferrer(monitor, bindings, referrer)) {
if (referrer.getConstraintType() == DBSEntityConstraintType.PRIMARY_KEY) {
return referrer;
} else if (referrer.getConstraintType().isUnique() || (referrer instanceof DBSTableIndex && ((DBSTableIndex) referrer).isUnique())) {
uniqueId = referrer;
}
}
}
return uniqueId;
}
return null;
}
use of org.jkiss.dbeaver.model.virtual.DBVEntity in project dbeaver by dbeaver.
the class ResultSetUtils method getBestIdentifier.
private static DBSEntityReferrer getBestIdentifier(@NotNull DBRProgressMonitor monitor, @NotNull DBSEntity table, DBDAttributeBindingMeta[] bindings) throws DBException {
List<DBSEntityReferrer> identifiers = new ArrayList<>(2);
// Check for pseudo attrs (ROWID)
for (DBDAttributeBindingMeta column : bindings) {
DBDPseudoAttribute pseudoAttribute = column.getPseudoAttribute();
if (pseudoAttribute != null && pseudoAttribute.getType() == DBDPseudoAttributeType.ROWID) {
identifiers.add(new DBDPseudoReferrer(table, column));
break;
}
}
if (table instanceof DBSTable && ((DBSTable) table).isView()) {
// Skip physical identifiers for views. There are nothing anyway
} else if (identifiers.isEmpty()) {
// 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.add(index);
break;
}
}
}
} catch (Exception e) {
// Indexes are not supported or not available
// Just skip them
log.debug(e);
}
}
if (identifiers.isEmpty()) {
// Check constraints
Collection<? extends DBSEntityConstraint> constraints = table.getConstraints(monitor);
if (constraints != null) {
for (DBSEntityConstraint constraint : constraints) {
if (DBUtils.isIdentifierConstraint(monitor, constraint)) {
identifiers.add((DBSEntityReferrer) constraint);
}
}
}
}
}
if (CommonUtils.isEmpty(identifiers)) {
// No physical identifiers
// Make new or use existing virtual identifier
DBVEntity virtualEntity = DBVUtils.findVirtualEntity(table, true);
identifiers.add(virtualEntity.getBestIdentifier());
}
if (!CommonUtils.isEmpty(identifiers)) {
// Find PK or unique key
DBSEntityReferrer uniqueId = null;
for (DBSEntityReferrer referrer : identifiers) {
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;
}
}
}
return uniqueId;
}
return null;
}
use of org.jkiss.dbeaver.model.virtual.DBVEntity in project dbeaver by serge-rider.
the class AssociationDeleteCommand method undo.
/**
* Restores the relationship
*/
@Override
public void undo() {
if (association.getSourceEntity() != null) {
return;
}
DBSEntityAssociation entityAssociation = association.getObject();
if (entityAssociation instanceof DBVEntityForeignKey) {
DBVEntity vEntity = DBVUtils.getVirtualEntity(entityAssociation.getParentObject(), false);
if (vEntity != null) {
vEntity.addForeignKey((DBVEntityForeignKey) entityAssociation);
}
}
association.setSourceEntity(sourceEntity);
association.setTargetEntity(targetEntity);
sourceEntity.addAssociation(association, true);
targetEntity.addReferenceAssociation(association, true);
}
Aggregations