コード例 #1
0
 public void selectionChanged(SelectionChangedEvent event) {
   IStructuredSelection sel = (IStructuredSelection) event.getSelection();
   boolean state = false;
   if (sel.size() == 1) {
     SimpleUserNode node = (SimpleUserNode) sel.getFirstElement();
     if (node.getRealObject() instanceof IServerInternal) {
       IServerInternal s = (IServerInternal) node.getRealObject();
       if (s.isValid()
           && s.getConfig().isEnabled()
           && ServoyModelManager.getServoyModelManager().getServoyModel().getActiveProject()
               != null) {
         state = true;
       }
     }
   }
   setEnabled(state);
 }
コード例 #2
0
  public void run(IMarker marker) {
    if (uuid == null) return;

    UUID id = UUID.fromString(uuid);
    ServoyProject servoyProject =
        ServoyModelManager.getServoyModelManager().getServoyModel().getServoyProject(solutionName);
    if (servoyProject == null) return;

    try {
      IPersist persist = servoyProject.getEditingPersist(id);
      if (persist == null) return;

      IPersist parent = persist.getAncestor(parentTypeId);
      if (parent == null && parentTypeId == IRepository.TABLENODES && dataSource != null) {
        parent = servoyProject.getEditingSolution().getOrCreateTableNode(dataSource);
      }
      if (parent == null) return;

      MethodTemplate template = MethodTemplate.getTemplate(ScriptMethod.class, eventName);
      if (template == null) return;

      MethodArgument signature = template.getSignature();
      if (signature == null) return;

      Map<String, String> substitutions = null;
      if (dataSource != null) substitutions = Collections.singletonMap("dataSource", dataSource);
      ScriptMethod method =
          NewMethodAction.createNewMethod(
              UIUtils.getActiveShell(),
              parent,
              eventName,
              true,
              null,
              null,
              substitutions,
              null,
              null);
      if (method != null) {
        PropertyDescriptor descriptor = new PropertyDescriptor(eventName, persist.getClass());
        descriptor.getWriteMethod().invoke(persist, new Integer(method.getID()));
        servoyProject.saveEditingSolutionNodes(new IPersist[] {parent}, true);
      }
    } catch (Exception e) {
      ServoyLog.logError(e);
    }
  }
コード例 #3
0
 public void run(IMarker marker) {
   if (solutionName != null) {
     ServoyProject servoyProject =
         ServoyModelManager.getServoyModelManager()
             .getServoyModel()
             .getServoyProject(solutionName);
     if (servoyProject != null) {
       Solution solution = servoyProject.getEditingSolution();
       if (solution != null) {
         solution.setSolutionType(SolutionMetaData.WEB_CLIENT_ONLY);
         try {
           servoyProject.saveEditingSolutionNodes(new IPersist[] {solution}, false);
         } catch (RepositoryException e) {
           ServoyLog.logError(e);
         }
       }
     }
   }
 }
コード例 #4
0
    public List<RelationData> loadData(IServerInternal server, IProgressMonitor monitor) {
      List<RelationData> relations = new ArrayList<RelationData>();
      try {
        List<String> tableNames = server.getTableAndViewNames(true, true);
        // plus 1 for sorting at the end
        monitor.beginTask("Loading relations", tableNames.size() + 1);
        for (String tableName : tableNames) {
          if (isCanceled()) {
            return null;
          }
          Table table = server.getTable(tableName);
          Connection connection = null;
          ResultSet resultSet = null;
          try {
            connection = server.getConnection();
            DatabaseMetaData dbmd = connection.getMetaData();
            Map<String, List<List<String[]>>> relationInfo =
                new HashMap<String, List<List<String[]>>>();

            resultSet =
                dbmd.getExportedKeys(
                    server.getConfig().getCatalog(),
                    server.getConfig().getSchema(),
                    table.getSQLName());
            while (resultSet.next()) {
              String pcolumnName = resultSet.getString("PKCOLUMN_NAME");
              String ftableName = resultSet.getString("FKTABLE_NAME");
              String fcolumnName = resultSet.getString("FKCOLUMN_NAME");
              String fkname = resultSet.getString("FK_NAME");

              String relname = fkname;
              if (relname == null) relname = table.getSQLName() + "_to_" + ftableName;

              int keySeq = resultSet.getInt("KEY_SEQ");
              Debug.trace(
                  "Found (export) rel: name: "
                      + relname
                      + "  keyseq = "
                      + keySeq
                      + ' '
                      + table.getSQLName()
                      + ' '
                      + pcolumnName
                      + " -> "
                      + ftableName
                      + ' '
                      + fcolumnName);

              List<List<String[]>> rel_items_list = relationInfo.get(relname);
              if (rel_items_list == null) {
                rel_items_list = new ArrayList<List<String[]>>();
                relationInfo.put(relname, rel_items_list);
                rel_items_list.add(new ArrayList<String[]>());
              }
              // rel_items_list is a list of items-lists, we are adding items to the last of this
              // list
              rel_items_list
                  .get(rel_items_list.size() - 1)
                  .add(
                      new String[] {
                        table.getSQLName(), pcolumnName, ftableName, fcolumnName, fkname
                      });
            }
            resultSet = Utils.closeResultSet(resultSet);

            resultSet =
                dbmd.getImportedKeys(
                    server.getConfig().getCatalog(),
                    server.getConfig().getSchema(),
                    table.getSQLName());
            int lastKeySeq = Integer.MAX_VALUE;
            List<List<String[]>> fk_rel_items_list = new ArrayList<List<String[]>>();
            while (resultSet.next()) {
              String pcolumnName = resultSet.getString("PKCOLUMN_NAME");
              String ptableName = resultSet.getString("PKTABLE_NAME");
              String fcolumnName = resultSet.getString("FKCOLUMN_NAME");

              int keySeq = resultSet.getInt("KEY_SEQ");
              Debug.trace(
                  "Found (import) rel: name: "
                      + table.getSQLName()
                      + "_to_"
                      + ptableName
                      + " keyseq = "
                      + keySeq
                      + ' '
                      + table.getSQLName()
                      + ' '
                      + pcolumnName
                      + " -> "
                      + ptableName
                      + ' '
                      + fcolumnName);

              // assume KEY_SEQ ascending ordered, do not assume 0 or 1 based (jdbc spec is not
              // clear on this).
              // when KEY_SEQ is not increasing, we have a separate constraint between the same
              // tables.
              if (fk_rel_items_list.size() == 0 || keySeq <= lastKeySeq) {
                fk_rel_items_list.add(new ArrayList<String[]>());
              }
              lastKeySeq = keySeq;

              // add the item to the last list of rel_items_list
              fk_rel_items_list
                  .get(fk_rel_items_list.size() - 1)
                  .add(
                      new String[] {
                        table.getSQLName(), fcolumnName, ptableName, pcolumnName, null
                      });
            }

            // generate relation names for the inversed fk constraints
            for (List<String[]> rel_items_list : fk_rel_items_list) {
              String relationName = createInversedFKRelationName(table, rel_items_list);
              List<List<String[]>> rel_items = relationInfo.get(relationName);
              if (rel_items == null) {
                relationInfo.put(relationName, rel_items = new ArrayList<List<String[]>>());
              }
              rel_items.add(rel_items_list);
            }
            resultSet = Utils.closeResultSet(resultSet);

            for (Map.Entry<String, List<List<String[]>>> entry : relationInfo.entrySet()) {
              String rname = entry.getKey();
              List<List<String[]>> rel_items_list = entry.getValue();
              // we may have multiple lists of items defined for the same relation name
              for (int l = 0; l < rel_items_list.size(); l++) {
                List<Column> primaryColumns = new ArrayList<Column>();
                List<Column> foreignColumns = new ArrayList<Column>();

                for (String[] element : rel_items_list.get(l)) {
                  //									String ptableName = element[0];
                  String pcolumnName = element[1];
                  String ftableName = element[2];
                  String fcolumnName = element[3];
                  //									String fkname = element[4];

                  Table foreignTable = server.getTable(ftableName);
                  if (foreignTable == null || foreignTable.isMarkedAsHiddenInDeveloper()) continue;

                  Column primaryColumn = table.getColumn(pcolumnName);
                  Column foreignColumn = foreignTable.getColumn(fcolumnName);

                  if (primaryColumn == null || foreignColumn == null) continue;
                  primaryColumns.add(primaryColumn);
                  foreignColumns.add(foreignColumn);
                }

                if (primaryColumns.size() != 0) {
                  // postfix the relation name when there are multiple
                  String relationName = rname;
                  if (rel_items_list.size() > 1) {
                    relationName += "_" + (l + 1);
                  }

                  boolean defaultAdd =
                      ServoyModelManager.getServoyModelManager()
                              .getServoyModel()
                              .getFlattenedSolution()
                              .getRelation(relationName)
                          == null;

                  relations.add(
                      new RelationData(
                          relationName, table, primaryColumns, foreignColumns, defaultAdd));
                }
              }
            }
          } catch (RepositoryException e) {
            ServoyLog.logError(e);
          } catch (SQLException e) {
            ServoyLog.logError(e);
          } finally {
            Utils.closeResultSet(resultSet);
            Utils.closeConnection(connection);
          }
          monitor.worked(1);
        }
        monitor.done();
      } catch (RepositoryException ex) {
        ServoyLog.logError(ex);
      }
      return relations;
    }