use of org.jkiss.dbeaver.model.virtual.DBVEntity in project dbeaver by serge-rider.
the class DBUtils method injectAndFilterAttributeBindings.
public static DBDAttributeBinding[] injectAndFilterAttributeBindings(@NotNull DBPDataSource dataSource, @NotNull DBSDataContainer dataContainer, DBDAttributeBinding[] bindings, boolean filterAttributes) {
// Add custom attributes
DBVEntity vEntity = DBVUtils.getVirtualEntity(dataContainer, false);
if (vEntity != null) {
List<DBVEntityAttribute> customAttributes = DBVUtils.getCustomAttributes(vEntity);
if (!CommonUtils.isEmpty(customAttributes)) {
DBDAttributeBinding[] customBindings = new DBDAttributeBinding[customAttributes.size()];
for (int i = 0; i < customAttributes.size(); i++) {
customBindings[i] = new DBDAttributeBindingCustom(null, dataContainer, dataSource, customAttributes.get(i), bindings.length + i);
}
DBDAttributeBinding[] combinedAttrs = new DBDAttributeBinding[bindings.length + customBindings.length];
System.arraycopy(bindings, 0, combinedAttrs, 0, bindings.length);
System.arraycopy(customBindings, 0, combinedAttrs, bindings.length, customBindings.length);
bindings = combinedAttrs;
}
}
if (filterAttributes && dataContainer instanceof DBDAttributeFilter) {
return ((DBDAttributeFilter) dataContainer).filterAttributeBindings(bindings);
} else {
return bindings;
}
}
use of org.jkiss.dbeaver.model.virtual.DBVEntity in project dbeaver by serge-rider.
the class VirtualAttributeAddAction method run.
@Override
public void run() {
DBVEntity vEntity = resultSetViewer.getModel().getVirtualEntity(false);
DBVEntityAttribute vAttr = new DBVEntityAttribute(vEntity, null, "vcolumn");
if (new EditVirtualAttributePage(resultSetViewer, vAttr).edit(resultSetViewer.getControl().getShell())) {
vAttr.setCustom(true);
vEntity.addVirtualAttribute(vAttr);
vEntity.persistConfiguration();
resultSetViewer.refreshMetaData();
DBDAttributeConstraint vAttrConstr = resultSetViewer.getModel().getDataFilter().getConstraint(vAttr, false);
if (vAttrConstr != null) {
}
}
}
use of org.jkiss.dbeaver.model.virtual.DBVEntity in project dbeaver by serge-rider.
the class VirtualAttributeEditAction method run.
@Override
public void run() {
if (attr == null) {
return;
}
DBVEntityAttribute vAttr = ((DBDAttributeBindingCustom) attr).getEntityAttribute();
DBVEntity vEntity = resultSetViewer.getModel().getVirtualEntity(false);
if (new EditVirtualAttributePage(resultSetViewer, vAttr).edit(resultSetViewer.getControl().getShell())) {
vEntity.persistConfiguration();
resultSetViewer.refreshMetaData();
}
}
use of org.jkiss.dbeaver.model.virtual.DBVEntity in project dbeaver by serge-rider.
the class ReferencesResultsContainer method refreshReferenceKeyList.
/**
* Load list of referencing keys
*/
private void refreshReferenceKeyList() {
activeReferenceKey = null;
referenceKeys.clear();
UIUtils.syncExec(() -> {
dataViewer.clearData();
fkCombo.removeAll();
dataViewer.showEmptyPresentation();
});
List<DBDAttributeBinding> visibleAttributes = parentController.getModel().getVisibleAttributes();
if (visibleAttributes.isEmpty()) {
return;
}
parentDataContainer = parentController.getDataContainer();
if (parentDataContainer == null) {
return;
}
Set<DBSEntity> allEntities = new LinkedHashSet<>();
for (DBDAttributeBinding attr : visibleAttributes) {
DBSEntityAttribute entityAttribute = attr.getEntityAttribute();
if (entityAttribute != null) {
allEntities.add(entityAttribute.getParentObject());
}
}
if (allEntities.isEmpty() && parentDataContainer instanceof DBSEntity) {
allEntities.add((DBSEntity) parentDataContainer);
}
List<ReferenceKeyMemo> refKeyMemos = new ArrayList<>();
{
DBVEntity vEntityOwner = DBVUtils.getVirtualEntity(parentDataContainer, false);
if (vEntityOwner != null) {
Object activeAssociations = vEntityOwner.getProperty(V_PROP_ACTIVE_ASSOCIATIONS);
if (activeAssociations instanceof Collection) {
for (Object refKeyMemoMap : (Collection) activeAssociations) {
if (refKeyMemoMap instanceof Map) {
refKeyMemos.add(new ReferenceKeyMemo((Map) refKeyMemoMap));
}
}
}
}
}
if (!allEntities.isEmpty()) {
new AbstractJob("Load reference keys") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
monitor.beginTask("Load references", allEntities.size());
try {
List<ReferenceKey> refs = new ArrayList<>();
for (DBSEntity entity : allEntities) {
monitor.subTask(entity.getName());
if (entity instanceof DBVEntity) {
// Skip virtual entities
continue;
}
// Foreign keys
Collection<? extends DBSEntityAssociation> associations = DBVUtils.getAllAssociations(monitor, entity);
for (DBSEntityAssociation assoc : associations) {
if (assoc instanceof DBSEntityReferrer) {
List<? extends DBSEntityAttributeRef> attrs = ((DBSEntityReferrer) assoc).getAttributeReferences(monitor);
if (!CommonUtils.isEmpty(attrs)) {
ReferenceKey referenceKey = new ReferenceKey(monitor, false, assoc.getAssociatedEntity(), assoc, attrs);
refs.add(referenceKey);
}
}
}
// References
Collection<? extends DBSEntityAssociation> references = DBVUtils.getAllReferences(monitor, entity);
{
for (DBSEntityAssociation assoc : references) {
if (assoc instanceof DBSEntityReferrer) {
List<? extends DBSEntityAttributeRef> attrs = ((DBSEntityReferrer) assoc).getAttributeReferences(monitor);
if (!CommonUtils.isEmpty(attrs)) {
ReferenceKey referenceKey = new ReferenceKey(monitor, true, entity, assoc, attrs);
refs.add(referenceKey);
}
}
}
}
monitor.worked(1);
}
synchronized (referenceKeys) {
referenceKeys.clear();
referenceKeys.addAll(refs);
// Detect active ref key from memo
if (!referenceKeys.isEmpty()) {
if (!refKeyMemos.isEmpty()) {
for (ReferenceKey key : referenceKeys) {
for (ReferenceKeyMemo memo : refKeyMemos) {
if (key.matches(memo)) {
activeReferenceKey = key;
break;
}
}
if (activeReferenceKey != null)
break;
}
}
if (activeReferenceKey == null) {
activeReferenceKey = referenceKeys.get(0);
}
}
}
UIUtils.syncExec(() -> fillKeysCombo());
} catch (DBException e) {
log.debug("Error reading references", e);
// Do not show errors. References or FKs may be unsupported by current database
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
}.schedule();
}
}
use of org.jkiss.dbeaver.model.virtual.DBVEntity in project dbeaver by serge-rider.
the class VirtualAttributeDeleteAction method run.
@Override
public void run() {
if (!(attr instanceof DBDAttributeBindingCustom)) {
return;
}
DBVEntityAttribute vAttr = ((DBDAttributeBindingCustom) attr).getEntityAttribute();
if (!UIUtils.confirmAction(resultSetViewer.getControl().getShell(), "Delete column '" + vAttr.getName() + "'", "Are you sure you want to delete virtual column '" + vAttr.getName() + "'?")) {
return;
}
DBVEntity vEntity = resultSetViewer.getModel().getVirtualEntity(false);
vEntity.removeVirtualAttribute(vAttr);
vEntity.persistConfiguration();
resultSetViewer.refreshMetaData();
}
Aggregations