public static Set<org.talend.core.model.metadata.builder.connection.MetadataTable>
      getTablesFromCurrentCatalogOrSchema(String dbsid, String schema, DatabaseConnection dbconn) {

    Set<org.talend.core.model.metadata.builder.connection.MetadataTable> allTables =
        new HashSet<org.talend.core.model.metadata.builder.connection.MetadataTable>();
    /* context model show all tables */
    if (dbconn.isContextMode()) {
      allTables = ConnectionHelper.getTables(dbconn);
    } else {
      boolean hasSchemaInCatalog = false;
      Catalog c = (Catalog) ConnectionHelper.getPackage(dbsid, dbconn, Catalog.class);
      Schema s = (Schema) ConnectionHelper.getPackage(schema, dbconn, Schema.class);
      List<Schema> subschemas = new ArrayList<Schema>();
      if (c != null) {
        subschemas = CatalogHelper.getSchemas(c);
        hasSchemaInCatalog = subschemas.size() > 0;
      }
      if (c != null && s == null && !hasSchemaInCatalog) { // only catalog
        PackageHelper.getAllTables(c, allTables);
        // PackageHelper.addMetadataTable(dbtable, c);

      } else if (s != null && !hasSchemaInCatalog && c == null) { // only schema
        PackageHelper.getAllTables(s, allTables);
        // PackageHelper.addMetadataTable(dbtable, s);
      } else if (c != null && hasSchemaInCatalog) { // both schema and catalog
        subschemas = CatalogHelper.getSchemas(c);
        hasSchemaInCatalog = subschemas.size() > 0;
        if (subschemas.size() > 0) {
          for (Schema current : subschemas) {
            if (current.getName() == null) {
              /* if the current schema no name should set an empty string for name, bug 17244 */
              current.setName("");
            }
            if (current.getName().equals(schema)) {
              s = current;
              break;
            }
          }
          /**
           * if dont specifc a schema because of getUiSchema() is null,show all cataogs table by
           * default,or it will cause bug 0016578
           */
          if (s == null || "".equals(s)) {
            // allTables = ConnectionHelper.getTables(dbconn);
            PackageHelper.getAllTables(c, allTables);
          } else {
            PackageHelper.getAllTables(s, allTables);
          }
          // PackageHelper.addMetadataTable(dbtable, s);
        }
      } else {
        // return nothing
      }
    }
    return allTables;
  }
 /*
  * ADD gdbu 2011-7-25 bug : 23220
  *
  * children count : only read from the file
  */
 private int getChildrenCount() {
   List<TdView> tables = new ArrayList<TdView>();
   IRepositoryViewObject object = this.getParent().getObject();
   if (object instanceof MetadataCatalogRepositoryObject) {
     catalog = ((MetadataCatalogRepositoryObject) object).getCatalog();
     tables = PackageHelper.getViews(catalog);
   } else {
     schema = ((MetadataSchemaRepositoryObject) object).getSchema();
     tables = PackageHelper.getViews(schema);
   }
   return tables.size();
 }
 private boolean hasChildrenInFile() {
   IRepositoryViewObject object = this.getParent().getObject();
   if (object instanceof MetadataCatalogRepositoryObject) {
     Catalog catalogInFile = ((MetadataCatalogRepositoryObject) object).getCatalog();
     List<TdView> views = PackageHelper.getViews(catalogInFile);
     if (views.isEmpty()) {
       return false;
     } else {
       return true;
     }
   } else if (object instanceof MetadataSchemaRepositoryObject) {
     Schema schemaInFile = ((MetadataSchemaRepositoryObject) object).getSchema();
     List<TdView> views = PackageHelper.getViews(schemaInFile);
     if (views.isEmpty()) {
       return false;
     } else {
       return true;
     }
   }
   return false;
 }
  public boolean addIndicator(NamedColumnSet set, Indicator... indicators) {
    if (!analysis.getContext().getAnalysedElements().contains(set)) {
      analysis.getContext().getAnalysedElements().add(set);
    }

    for (Indicator indicator : indicators) {
      // store first level of indicators in result.
      analysis.getResults().getIndicators().add(indicator);
      initializeIndicator(indicator, set);
    }
    DataManager connection = analysis.getContext().getConnection();
    if (connection == null) {
      // try to get one
      log.error(
          Messages.getString(
              "ColumnCorrelationAnalysisHandler.CONNNOTBEENSETINANALYSIS")); //$NON-NLS-1$
      connection =
          ConnectionHelper.getTdDataProvider(PackageHelper.getParentPackage((MetadataTable) set));
      analysis.getContext().setConnection(connection);
    }
    TypedReturnCode<Dependency> rc =
        DependenciesHandler.getInstance().setDependencyOn(analysis, connection);
    return rc.isOk();
  }
Exemplo n.º 5
0
  public SalesforceSchemaWizard(
      IWorkbench workbench,
      boolean creation,
      RepositoryNode node,
      String[] existingNames,
      boolean isSinglePageOnly) {
    super(workbench, creation);
    this.existingNames = existingNames;
    this.isSinglePageOnly = isSinglePageOnly;
    setNeedsProgressMonitor(true);

    // TODO: should to changed icon.
    setDefaultPageImageDescriptor(ImageProvider.getImageDesc(ECoreImage.DEFAULT_WIZ));
    switch (node.getType()) {
      case SIMPLE_FOLDER:
      case REPOSITORY_ELEMENT:
        pathToSave = RepositoryNodeUtilities.getPath(node);
        break;
      case SYSTEM_FOLDER:
        pathToSave = new Path(""); // $NON-NLS-1$
        break;
    }

    switch (node.getType()) {
      case SIMPLE_FOLDER:
      case SYSTEM_FOLDER:
        connection = ConnectionFactory.eINSTANCE.createSalesforceSchemaConnection();
        connection.setName(ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA.getKey());
        MetadataTable metadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        metadataTable.setId(factory.getNextId());
        RecordFile record =
            (RecordFile)
                ConnectionHelper.getPackage(connection.getName(), connection, RecordFile.class);
        if (record != null) { // hywang
          PackageHelper.addMetadataTable(metadataTable, record);
        } else {
          RecordFile newrecord = RecordFactory.eINSTANCE.createRecordFile();
          newrecord.setName(connection.getName());
          ConnectionHelper.addPackage(newrecord, connection);
          PackageHelper.addMetadataTable(metadataTable, newrecord);
        }
        connectionProperty = PropertiesFactory.eINSTANCE.createProperty();
        connectionProperty.setAuthor(
            ((RepositoryContext)
                    CoreRuntimePlugin.getInstance()
                        .getContext()
                        .getProperty(Context.REPOSITORY_CONTEXT_KEY))
                .getUser());
        connectionProperty.setVersion(VersionUtils.DEFAULT_VERSION);
        connectionProperty.setStatusCode(""); // $NON-NLS-1$

        connectionItem = PropertiesFactory.eINSTANCE.createSalesforceSchemaConnectionItem();
        connectionItem.setProperty(connectionProperty);
        connectionItem.setConnection(connection);
        initProxySettings(connection);
        break;

      case REPOSITORY_ELEMENT:
        connection =
            (SalesforceSchemaConnection)
                ((ConnectionItem) node.getObject().getProperty().getItem()).getConnection();
        connectionProperty = node.getObject().getProperty();
        connectionItem = (ConnectionItem) node.getObject().getProperty().getItem();
        // set the repositoryObject, lock and set isRepositoryObjectEditable
        setRepositoryObject(node.getObject());
        isRepositoryObjectEditable();
        initLockStrategy();
        break;
    }
    if (!creation) {
      this.originaleObjectLabel = this.connectionItem.getProperty().getLabel();
      this.originalVersion = this.connectionItem.getProperty().getVersion();
      this.originalDescription = this.connectionItem.getProperty().getDescription();
      this.originalPurpose = this.connectionItem.getProperty().getPurpose();
      this.originalStatus = this.connectionItem.getProperty().getStatusCode();
    }
    initConnection();
  }
Exemplo n.º 6
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
   */
  public void createControl(Composite parent) {
    // TODO Auto-generated method stub
    currentComposite = null;
    WSDLSchemaConnection connection = ((WSDLSchemaConnection) connectionItem.getConnection());
    if (ConnectionHelper.getTables(connection).size() < 2) {
      MetadataTable metadataTable =
          ConnectionHelper.getTables(connection).toArray(new MetadataTable[0])[0];
      metadataTable.setLabel("Output");
      MetadataTable inPutMetadataTable = ConnectionFactory.eINSTANCE.createMetadataTable();
      IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
      inPutMetadataTable.setLabel("Input");
      inPutMetadataTable.setId(factory.getNextId());
      GenericPackage g =
          (GenericPackage)
              ConnectionHelper.getPackage(
                  connection.getName(), (Connection) connection, GenericPackage.class);
      if (g != null) { // hywang
        g.getOwnedElement().add(inPutMetadataTable);
        ConnectionHelper.getTables(connection).add(inPutMetadataTable);
      } else {
        GenericPackage gpkg = ConnectionFactory.eINSTANCE.createGenericPackage();
        PackageHelper.addMetadataTable(inPutMetadataTable, gpkg);
        ConnectionHelper.addPackage(gpkg, connection);
      }
      // connection.getTables().add(inPutMetadataTable);
    }

    switch (step) {
      case 2:
        currentComposite =
            new WebServiceStep1Form(
                parent, connectionItem, null, new String[] {}, contextModeManager);
        break;
      case 3:
        MetadataTable metadataTable2 = null;
        Set<MetadataTable> tables = ConnectionHelper.getTables(connection);
        Iterator<MetadataTable> it = tables.iterator();
        while (it.hasNext()) {
          MetadataTable table = (MetadataTable) it.next();
          if (table.getLabel().equals("Output")) {
            metadataTable2 = table;
          }
        }
        currentComposite =
            new WebServiceStep2Form(parent, connectionItem, contextModeManager, metadataTable2);
        break;
      default:
        System.out.println("error...");
    }
    currentComposite.setReadOnly(!isRepositoryObjectEditable);
    AbstractForm.ICheckListener listener =
        new AbstractForm.ICheckListener() {

          public void checkPerformed(final AbstractForm source) {

            if (source.isStatusOnError()) {
              WebServiceSchemaWizardPage.this.setPageComplete(false);
              setErrorMessage(source.getStatus());
            } else {
              WebServiceSchemaWizardPage.this.setPageComplete(isRepositoryObjectEditable);
              setErrorMessage(null);
              setMessage(source.getStatus());
            }
          }
        };
    currentComposite.setListener(listener);
    setControl((Composite) currentComposite);
  }
  private static void addTableForTemCatalogOrSchema(
      String dbsid,
      String schema,
      DatabaseConnection connection,
      MetadataTable dbtable,
      IMetadataConnection iMetadataConnection,
      int stackCount)
      throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
    if (3 < stackCount) {
      // if loop count is more than 3 times, seems it will never end this loop, and will never get
      // the dbsid and
      // schema
      return;
    }
    boolean hasSchemaInCatalog = false;
    boolean isAccess =
        EDatabaseTypeName.ACCESS.getDisplayName().equals(iMetadataConnection.getDbType());
    Catalog c = (Catalog) ConnectionHelper.getPackage(dbsid, connection, Catalog.class);
    Schema s = (Schema) ConnectionHelper.getPackage(schema, connection, Schema.class);
    List<Schema> subschemas = new ArrayList<Schema>();
    if (c != null) {
      subschemas = CatalogHelper.getSchemas(c);
      hasSchemaInCatalog = subschemas.size() > 0;
    }
    if (c != null && s == null && !hasSchemaInCatalog) { // only catalog
      PackageHelper.addMetadataTable(dbtable, c);

    } else if (s != null && !hasSchemaInCatalog && c == null) { // only schema
      PackageHelper.addMetadataTable(dbtable, s);
    } else if (c != null && hasSchemaInCatalog) { // both schema and catalog
      subschemas = CatalogHelper.getSchemas(c);
      hasSchemaInCatalog = subschemas.size() > 0;
      if (subschemas.size() > 0) {
        for (Schema current : subschemas) {
          if (current.getName().equals(schema)) {
            s = current;
            break;
          }
        }

        if (s != null) {
          // for bug 16794
          if (s instanceof SchemaImpl) {
            SchemaImpl schemaElement = (SchemaImpl) s;
            EList<ModelElement> ownedElement = schemaElement.getOwnedElement();
            ownedElement.add(dbtable);
          }
        } else if (subschemas.size() > 0) {
          // added for bug 17467
          // set db connection's schema as null, and retrieve schema again, to add some tables
          for (int i = 0; i < subschemas.size(); i++) {
            SchemaImpl schemaElement = (SchemaImpl) subschemas.get(i);
            EList<ModelElement> ownedElement = schemaElement.getOwnedElement();
            ownedElement.add(dbtable);
          }
        }
        // PackageHelper.addMetadataTable(dbtable, s);
      }
    } else if (s == null
        && c == null
        && !isAccess
        && stackCount == 1) { // TDI-20584:after migration from 4.0 to
      // 4.2,lost all catalogs
      // and schemas for database
      // in case after migration connetion from the version before 4.0,there is no any db structure
      // on
      // temConnection,it will casue pbs,so sychronize with imetadataConnection
      fillCatalogAndSchemas(iMetadataConnection, connection);
      addTableForTemCatalogOrSchema(
          dbsid, schema, connection, dbtable, iMetadataConnection, stackCount + 1);
    } else {
      /*
       * if there is no catalog or schema,create the structure correctly rather than always create a catalog,found
       * this issue when fixing bug 16636
       */
      ProjectNodeHelper.addCatalogOrSchema(iMetadataConnection, connection);
      if (isAccess) {
        addTableForTemCatalogOrSchema(
            dbsid, connection.getName(), connection, dbtable, iMetadataConnection, stackCount + 1);
      } else {
        addTableForTemCatalogOrSchema(
            dbsid, schema, connection, dbtable, iMetadataConnection, stackCount + 1);
      }
    }
  }
  /**
   * Create TableFolderNodeRepositoryNode.
   *
   * @param node parent RepositoryNode
   * @param metadataObject parent CatalogViewObject or SchemaViewObject
   */
  private void createRepositoryNodeViewFolderNode(
      List<IRepositoryNode> node, IRepositoryViewObject metadataObject) {
    List<TdView> views = new ArrayList<TdView>();
    String filterCharacter = null;
    try {
      if (metadataObject instanceof MetadataCatalogRepositoryObject) {
        viewObject = ((MetadataCatalogRepositoryObject) metadataObject).getViewObject();
        if (((MetadataCatalogRepositoryObject) metadataObject).getCatalog().eIsProxy()) {
          // reload the connection to make sure the connection(and all it's owned elements) is not
          // proxy
          reloadConnectionViewObject();
        }
        catalog = ((MetadataCatalogRepositoryObject) metadataObject).getCatalog();
        item = (ConnectionItem) viewObject.getProperty().getItem();
        views = PackageHelper.getViews(catalog);
        filterCharacter = RepositoryNodeHelper.getViewFilter(catalog, schema);

        // MOD gdbu 2011-6-29 bug : 22204
        // MOD TDQ-8718 20140505 yyin --the repository view cares about if use the filter or not,
        // the column
        // select dialog cares about if connect to DB or not.
        if (views.isEmpty()) {
          connection = item.getConnection();
          if (isCallingFromColumnDialog()) {
            views =
                DqRepositoryViewService.getViews(connection, catalog, null, isLoadDBFromDialog());
          } else if (!isOnFilterring()) {
            // MOD gdbu 2011-7-21 bug 23220
            views = DqRepositoryViewService.getViews(connection, catalog, null, true);
          }
          if (views != null && views.size() > 0) {
            ProxyRepositoryFactory.getInstance().save(item, false);
          }
        }

        ConnectionUtils.retrieveColumn(views);
        // ~22204
      } else if (metadataObject instanceof MetadataSchemaRepositoryObject) {
        viewObject = ((MetadataSchemaRepositoryObject) metadataObject).getViewObject();
        if (((MetadataSchemaRepositoryObject) metadataObject).getSchema().eIsProxy()) {
          // reload the connection to make sure the connection(and all it's owned elements) is not
          // proxy
          reloadConnectionViewObject();
        }
        schema = ((MetadataSchemaRepositoryObject) metadataObject).getSchema();
        item = (ConnectionItem) viewObject.getProperty().getItem();
        views = PackageHelper.getViews(schema);
        filterCharacter = RepositoryNodeHelper.getViewFilter(catalog, schema);
        RepositoryNode parent = metadataObject.getRepositoryNode().getParent();
        IRepositoryViewObject object = parent.getObject();
        if (object instanceof MetadataCatalogRepositoryObject
            && filterCharacter.equals(PluginConstant.EMPTY_STRING)) {
          filterCharacter =
              RepositoryNodeHelper.getViewFilter(
                  ((MetadataCatalogRepositoryObject) object).getCatalog(), null);
        }
        // MOD gdbu 2011-6-29 bug : 22204
        if (views.isEmpty()) {
          connection = item.getConnection();
          if (isCallingFromColumnDialog()) {
            views =
                DqRepositoryViewService.getViews(connection, schema, null, isLoadDBFromDialog());
          } else if (!isOnFilterring()) {
            // MOD gdbu 2011-7-21 bug 23220
            views = DqRepositoryViewService.getViews(connection, schema, null, true);
          }
          if (views != null && views.size() > 0) {
            ProxyRepositoryFactory.getInstance().save(item, false);
          }
        } else {
          ConnectionUtils.retrieveColumn(views);
        }
        // ~22204
      }

    } catch (Exception e) {
      log.error(e, e);
    }
    if (filterCharacter != null && !filterCharacter.equals(PluginConstant.EMPTY_STRING)) {
      views = RepositoryNodeHelper.filterViews(views, filterCharacter);
    }
    createViewRepositoryNode(views, node);
  }