コード例 #1
0
  public static List<ERDEntity> generateEntityList(
      final EntityDiagram diagram, Collection<DBPNamedObject> objects) {
    final List<DBSObject> roots = new ArrayList<>();
    for (DBPNamedObject object : objects) {
      if (object instanceof DBSObject) {
        roots.add((DBSObject) object);
      }
    }

    final List<ERDEntity> entities = new ArrayList<>();

    try {
      DBeaverUI.runInProgressService(
          new DBRRunnableWithProgress() {
            @Override
            public void run(DBRProgressMonitor monitor)
                throws InvocationTargetException, InterruptedException {
              DiagramObjectCollector collector = new DiagramObjectCollector(diagram);
              try {
                collector.generateDiagramObjects(monitor, roots);
              } catch (DBException e) {
                throw new InvocationTargetException(e);
              }
              entities.addAll(collector.getDiagramEntities());
            }
          });
    } catch (InvocationTargetException e) {
      log.error(e.getTargetException());
    } catch (InterruptedException e) {
      // interrupted
    }
    return entities;
  }
コード例 #2
0
ファイル: DBNDatabaseNode.java プロジェクト: thecocce/dbeaver
 public DBXTreeItem getItemsMeta() {
   List<DBXTreeNode> metaChildren = getMeta().getChildren(this);
   if (metaChildren != null
       && metaChildren.size() == 1
       && metaChildren.get(0) instanceof DBXTreeItem) {
     return (DBXTreeItem) metaChildren.get(0);
   } else {
     return null;
   }
 }
コード例 #3
0
ファイル: DBNDatabaseNode.java プロジェクト: thecocce/dbeaver
 protected void reloadChildren(DBRProgressMonitor monitor) throws DBException {
   DBNDatabaseNode[] oldChildren;
   synchronized (this) {
     if (childNodes == null) {
       // Nothing to reload
       return;
     }
     oldChildren = Arrays.copyOf(childNodes, childNodes.length);
   }
   List<DBNDatabaseNode> newChildren = new ArrayList<>();
   loadChildren(monitor, getMeta(), oldChildren, newChildren);
   synchronized (this) {
     childNodes = newChildren.toArray(new DBNDatabaseNode[newChildren.size()]);
   }
 }
コード例 #4
0
ファイル: DBNDatabaseNode.java プロジェクト: thecocce/dbeaver
 @Override
 public DBNDatabaseNode[] getChildren(DBRProgressMonitor monitor) throws DBException {
   if (childNodes == null && allowsChildren()) {
     if (this.initializeNode(monitor, null)) {
       final List<DBNDatabaseNode> tmpList = new ArrayList<>();
       loadChildren(monitor, getMeta(), null, tmpList);
       if (!monitor.isCanceled()) {
         if (tmpList.isEmpty()) {
           this.childNodes = EMPTY_NODES;
         } else {
           this.childNodes = tmpList.toArray(new DBNDatabaseNode[tmpList.size()]);
         }
         this.afterChildRead();
       }
     }
   }
   return childNodes;
 }
コード例 #5
0
  public PostgreDataType getDataType(String typeName) {
    if (typeName.endsWith("[]")) {
      // In some cases ResultSetMetadata returns it as []
      typeName = "_" + typeName.substring(0, typeName.length() - 2);
    }
    String alias = PostgreConstants.DATA_TYPE_ALIASES.get(typeName);
    if (alias != null) {
      typeName = alias;
    }
    {
      // First check system catalog
      final PostgreSchema schema = getCatalogSchema();
      if (schema != null) {
        final PostgreDataType dataType = schema.dataTypeCache.getCachedObject(typeName);
        if (dataType != null) {
          return dataType;
        }
      }
    }

    // Check schemas in search path
    final List<String> searchPath = dataSource.getSearchPath();
    for (String schemaName : searchPath) {
      final PostgreSchema schema = schemaCache.getCachedObject(schemaName);
      if (schema != null) {
        final PostgreDataType dataType = schema.dataTypeCache.getCachedObject(typeName);
        if (dataType != null) {
          return dataType;
        }
      }
    }
    // Check the rest
    for (PostgreSchema schema : schemaCache.getCachedObjects()) {
      if (searchPath.contains(schema.getName())) {
        continue;
      }
      final PostgreDataType dataType = schema.dataTypeCache.getCachedObject(typeName);
      if (dataType != null) {
        return dataType;
      }
    }
    log.debug("Data type '" + typeName + "' not found in database '" + getName() + "'");
    return null;
  }
コード例 #6
0
 private void addDiagramEntity(DBRProgressMonitor monitor, DBSEntity table) {
   if (diagram.containsTable(table)) {
     // Avoid duplicates
     return;
   }
   ERDEntity erdEntity = ERDEntity.fromObject(monitor, diagram, table);
   if (erdEntity != null) {
     erdEntities.add(erdEntity);
     tableMap.put(table, erdEntity);
   }
 }
コード例 #7
0
ファイル: DBNDatabaseNode.java プロジェクト: thecocce/dbeaver
  /**
   * Extract items using reflect api
   *
   * @param monitor progress monitor
   * @param meta items meta info
   * @param oldList previous child items
   * @param toList list ot add new items @return true on success
   * @return true on success
   * @throws DBException on any DB error
   */
  private boolean loadTreeItems(
      DBRProgressMonitor monitor,
      DBXTreeItem meta,
      final DBNDatabaseNode[] oldList,
      final List<DBNDatabaseNode> toList)
      throws DBException {
    if (this.isDisposed()) {
      // Property reading can take really long time so this node can be disposed at this moment -
      // check it
      return false;
    }
    // Read property using reflection
    Object valueObject = getValueObject();
    if (valueObject == null) {
      return false;
    }
    String propertyName = meta.getPropertyName();
    Object propertyValue = extractPropertyValue(monitor, valueObject, propertyName);
    if (propertyValue == null) {
      return false;
    }
    if (!(propertyValue instanceof Collection<?>)) {
      log.warn(
          "Bad property '"
              + propertyName
              + "' value: "
              + propertyValue.getClass().getName()); // $NON-NLS-1$ //$NON-NLS-2$
      return false;
    }

    DBSObjectFilter filter = getNodeFilter(meta, false);
    this.filtered = filter != null && !filter.isEmpty();

    Collection<?> itemList = (Collection<?>) propertyValue;
    if (itemList.isEmpty()) {
      return false;
    }
    if (this.isDisposed()) {
      // Property reading can take really long time so this node can be disposed at this moment -
      // check it
      return false;
    }

    DBPDataSourceContainer dataSourceContainer = getDataSourceContainer();
    boolean showSystem = dataSourceContainer == null || dataSourceContainer.isShowSystemObjects();
    for (Object childItem : itemList) {
      if (childItem == null) {
        continue;
      }
      if (!(childItem instanceof DBSObject)) {
        log.warn("Bad item type: " + childItem.getClass().getName()); // $NON-NLS-1$
        continue;
      }
      if (DBUtils.isHiddenObject(childItem)) {
        // Skip hidden objects
        continue;
      }
      if (!showSystem
          && childItem instanceof DBPSystemObject
          && ((DBPSystemObject) childItem).isSystem()) {
        // Skip system objects
        continue;
      }
      if (filter != null && !filter.matches(((DBSObject) childItem).getName())) {
        // Doesn't match filter
        continue;
      }
      DBSObject object = (DBSObject) childItem;
      boolean added = false;
      if (oldList != null) {
        // Check that new object is a replacement of old one
        for (DBNDatabaseNode oldChild : oldList) {
          if (oldChild.getMeta() == meta && equalObjects(oldChild.getObject(), object)) {
            oldChild.reloadObject(monitor, object);

            if (oldChild.allowsChildren() && !oldChild.needsInitialization()) {
              // Refresh children recursive
              oldChild.reloadChildren(monitor);
            }
            getModel().fireNodeUpdate(this, oldChild, DBNEvent.NodeChange.REFRESH);

            toList.add(oldChild);
            added = true;
            break;
          }
        }
      }
      if (!added) {
        // Simply add new item
        DBNDatabaseItem treeItem = new DBNDatabaseItem(this, meta, object, oldList != null);
        toList.add(treeItem);
      }
    }

    if (oldList != null) {
      // Now remove all non-existing items
      for (DBNDatabaseNode oldChild : oldList) {
        if (oldChild.getMeta() != meta) {
          // Wrong type
          continue;
        }
        boolean found = false;
        for (Object childItem : itemList) {
          if (childItem instanceof DBSObject
              && equalObjects(oldChild.getObject(), (DBSObject) childItem)) {
            found = true;
            break;
          }
        }
        if (!found) {
          // Remove old child object
          oldChild.dispose(true);
        }
      }
    }
    return true;
  }
コード例 #8
0
ファイル: DBNDatabaseNode.java プロジェクト: thecocce/dbeaver
  private void loadChildren(
      DBRProgressMonitor monitor,
      final DBXTreeNode meta,
      final DBNDatabaseNode[] oldList,
      final List<DBNDatabaseNode> toList)
      throws DBException {
    if (monitor.isCanceled()) {
      return;
    }
    this.filtered = false;

    List<DBXTreeNode> childMetas = meta.getChildren(this);
    if (CommonUtils.isEmpty(childMetas)) {
      return;
    }
    monitor.beginTask(ModelMessages.model_navigator_load_items_, childMetas.size());

    for (DBXTreeNode child : childMetas) {
      if (monitor.isCanceled()) {
        break;
      }
      monitor.subTask(
          ModelMessages.model_navigator_load_
              + " "
              + child.getChildrenType(getObject().getDataSource()));
      if (child instanceof DBXTreeItem) {
        final DBXTreeItem item = (DBXTreeItem) child;
        boolean isLoaded = loadTreeItems(monitor, item, oldList, toList);
        if (!isLoaded && item.isOptional() && item.getRecursiveLink() == null) {
          // This may occur only if no child nodes was read
          // Then we try to go on next DBX level
          loadChildren(monitor, item, oldList, toList);
        }
      } else if (child instanceof DBXTreeFolder) {
        if (oldList == null) {
          // Load new folders only if there are no old ones
          toList.add(new DBNDatabaseFolder(this, (DBXTreeFolder) child));
        } else {
          for (DBNDatabaseNode oldFolder : oldList) {
            if (oldFolder.getMeta() == child) {
              oldFolder.reloadChildren(monitor);
              toList.add(oldFolder);
              break;
            }
          }
        }
      } else if (child instanceof DBXTreeObject) {
        if (oldList == null) {
          // Load new objects only if there are no old ones
          toList.add(new DBNDatabaseObject(this, (DBXTreeObject) child));
        } else {
          for (DBNDatabaseNode oldObject : oldList) {
            if (oldObject.getMeta() == child) {
              oldObject.reloadChildren(monitor);
              toList.add(oldObject);
              break;
            }
          }
        }
      } else {
        log.warn("Unsupported meta node type: " + child); // $NON-NLS-1$
      }
      monitor.worked(1);
    }
    monitor.done();

    if (filtered) {
      getModel().fireNodeUpdate(this, this, DBNEvent.NodeChange.REFRESH);
    }
  }