Example #1
0
  private void commitImport(final String source, ImportMessages importMessages) throws Exception {
    UnitOfWork trans = getTransaction();
    final String txName = trans.getName();
    trans.commit();

    Repository.UnitOfWorkListener uowListener = trans.getCallback();
    SynchronousCallback callback = null;
    if (uowListener != null && uowListener instanceof SynchronousCallback) {
      callback = (SynchronousCallback) uowListener;
    }
    final boolean success = callback.await(3, TimeUnit.MINUTES);
    if (success) {
      // For imports, if has callback error - add to import errors and return.
      if (callback.hasError()) {
        importMessages.addErrorMessage(callback.error());
        return;
      }
      final KException error = trans.getError();
      final Repository.UnitOfWork.State txState = trans.getState();

      if ((error != null) || !State.COMMITTED.equals(txState)) {
        throw new KException(I18n.bind(ShellI18n.transactionCommitError, txName), error);
      }
    } else {
      throw new KException(I18n.bind(ShellI18n.transactionTimeout, txName));
    }
  }
  /**
   * {@inheritDoc}
   *
   * @see org.komodo.shell.BuiltInShellCommand#tabCompletion(java.lang.String, java.util.List)
   */
  @Override
  public TabCompletionModifier tabCompletion(
      final String lastArgument, final List<CharSequence> candidates) throws Exception {
    final Arguments args = getArguments();

    try {
      List<String> existingDatasourceNames =
          ServerUtils.getDatasourceNames(getWorkspaceTeiidInstance());
      Collections.sort(existingDatasourceNames);

      if (args.isEmpty()) {
        if (lastArgument == null) {
          candidates.addAll(existingDatasourceNames);
        } else {
          for (final String item : existingDatasourceNames) {
            if (item.startsWith(lastArgument)) {
              candidates.add(item);
            }
          }
        }
      }
    } catch (Exception ex) {
      print();
      print(MESSAGE_INDENT, I18n.bind(ServerCommandsI18n.connectionErrorWillDisconnect));
      WkspStatusServerManager.getInstance(getWorkspaceStatus()).disconnectDefaultServer();
    }

    return TabCompletionModifier.AUTO;
  }
Example #3
0
  /**
   * {@inheritDoc}
   *
   * @see org.komodo.shell.BuiltInShellCommand#doExecute()
   */
  @Override
  protected CommandResult doExecute() {
    CommandResult result = null;

    try {
      final String viewName = requiredArgument(0, I18n.bind(ModelCommandsI18n.missingViewName));

      final Model model = getModel();
      model.addView(getTransaction(), viewName);

      result = new CommandResultImpl(I18n.bind(ModelCommandsI18n.viewAdded, viewName));
    } catch (final Exception e) {
      result = new CommandResultImpl(e);
    }

    return result;
  }
Example #4
0
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.shell.BuiltInShellCommand#doExecute()
  */
 @Override
 protected CommandResult doExecute() {
   try {
     getWorkspaceStatus().commit(CommitCommand.class.getName());
     return new CommandResultImpl(I18n.bind(ShellI18n.commitSuccess));
   } catch (final Exception e) {
     return new CommandResultImpl(e);
   }
 }
  /**
   * {@inheritDoc}
   *
   * @see org.komodo.shell.BuiltInShellCommand#doExecute()
   */
  @Override
  protected CommandResult doExecute() {
    CommandResult result = null;

    try {
      final String ucName =
          requiredArgument(0, I18n.bind(TableCommandsI18n.missingUniqueConstraintName));

      final Table table = getTable();
      table.addUniqueConstraint(getTransaction(), ucName);

      result = new CommandResultImpl(I18n.bind(TableCommandsI18n.uniqueConstraintAdded, ucName));
    } catch (final Exception e) {
      result = new CommandResultImpl(e);
    }

    return result;
  }
Example #6
0
  /**
   * {@inheritDoc}
   *
   * @see org.komodo.shell.BuiltInShellCommand#doExecute()
   */
  @Override
  protected CommandResult doExecute() {
    CommandResult result = null;

    try {
      final String mappedRoleName =
          requiredArgument(0, I18n.bind(DataRoleCommandsI18n.missingMappedRoleName));

      final DataRole dataRole = getDataRole();
      dataRole.addMappedRole(getTransaction(), mappedRoleName);

      result =
          new CommandResultImpl(I18n.bind(DataRoleCommandsI18n.mappedRoleAdded, mappedRoleName));
    } catch (final Exception e) {
      result = new CommandResultImpl(e);
    }

    return result;
  }
Example #7
0
 /*
  * Delete Schema used as temp location
  */
 private CommandResult deleteSchema(String schemaName) {
   DeleteSchemaCommand deleteCommand = new DeleteSchemaCommand(getWorkspaceStatus());
   try {
     deleteCommand.setArguments(new Arguments(schemaName));
     deleteCommand.execute();
   } catch (Exception e) {
     print(
         CompletionConstants.MESSAGE_INDENT,
         I18n.bind(ModelCommandsI18n.deleteTempContextFailedMsg, schemaName));
   }
   CommandResult result = null;
   return result;
 }
  /**
   * {@inheritDoc}
   *
   * @see org.komodo.shell.BuiltInShellCommand#doExecute()
   */
  @Override
  protected CommandResult doExecute() {
    CommandResult result = null;

    try {
      final String sourceTypeName =
          requiredArgument(0, I18n.bind(ServerCommandsI18n.missingDatasourceTypeName));

      // Validates that a server is connected
      CommandResult validationResult = validateHasConnectedWorkspaceServer();
      if (!validationResult.isOk()) {
        return validationResult;
      }

      Collection<TeiidPropertyDefinition> propDefns =
          getWorkspaceTeiidInstance().getTemplatePropertyDefns(sourceTypeName);
      if (propDefns == null) {
        return new CommandResultImpl(
            false,
            I18n.bind(ServerCommandsI18n.serverDatasourceTypeNotFound, sourceTypeName),
            null);
      }

      // Print title
      final String title =
          I18n.bind(
              ServerCommandsI18n.infoMessageDatasourceType,
              sourceTypeName,
              getWorkspaceServerName());
      print(MESSAGE_INDENT, title);
      print(MESSAGE_INDENT, I18n.bind(ServerCommandsI18n.datasourceTypePropertiesHeader));

      // Print DataSource Template Info
      ServerObjPrintUtils.printDatasourceTemplateProperties(
          getWriter(),
          MESSAGE_INDENT,
          propDefns,
          I18n.bind(ServerCommandsI18n.datasourceTypeNameLabel),
          I18n.bind(ServerCommandsI18n.datasourceTypeDefaultValueLabel));

      result = CommandResult.SUCCESS;
    } catch (final Exception e) {
      result = new CommandResultImpl(e);
    }

    return result;
  }
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.shell.BuiltInShellCommand#printHelpDescription(int)
  */
 @Override
 protected void printHelpDescription(final int indent) {
   print(indent, I18n.bind(TableCommandsI18n.addUniqueConstraintHelp, getName()));
 }
Example #10
0
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.relational.commands.datarole.DataRoleShellCommand#printHelpDescription(int)
  */
 @Override
 protected void printHelpDescription(final int indent) {
   print(indent, I18n.bind(ShellI18n.commitHelp, getName()));
 }
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.shell.BuiltInShellCommand#printHelpUsage(int)
  */
 @Override
 protected void printHelpUsage(final int indent) {
   print(indent, I18n.bind(ServerCommandsI18n.serverGetDatasourceUsage));
 }
Example #12
0
  /**
   * {@inheritDoc}
   *
   * @see org.komodo.shell.BuiltInShellCommand#doExecute()
   */
  @Override
  protected CommandResult doExecute() {
    try {
      String fileName = requiredArgument(0, I18n.bind(WorkspaceCommandsI18n.missingInputFileName));

      // If there is no file extension, add .ddl
      if (fileName.indexOf(DOT) == -1) {
        fileName = fileName + DOT + "ddl"; // $NON-NLS-1$
      }

      // Validates the supplied fileNameArg is a valid, readable file
      String validationResult = validateReadableFileArg(fileName);
      if (!CompletionConstants.OK.equals(validationResult)) {
        return new CommandResultImpl(
            false,
            I18n.bind(WorkspaceCommandsI18n.inputFileError, fileName, validationResult),
            null);
      }

      // Import the DDL into the target context
      File ddlFile = new File(fileName);
      ImportOptions importOptions = new ImportOptions();
      ImportMessages importMessages = new ImportMessages();

      // Create a temp schema to put the imported model
      KomodoObject tempSchema = createSchema(TEMP_IMPORT_CONTEXT);
      if (tempSchema == null) {
        return new CommandResultImpl(
            false, I18n.bind(ModelCommandsI18n.errorCreatingTempNode, TEMP_IMPORT_CONTEXT), null);
      }

      WorkspaceStatus wsStatus = getWorkspaceStatus();
      // Setup the import
      importDdl(getTransaction(), ddlFile, tempSchema, importOptions, importMessages);

      if (!importMessages.hasError()) {

        print(
            CompletionConstants.MESSAGE_INDENT,
            I18n.bind(ModelCommandsI18n.ddlImportInProgressMsg, ddlFile));

        // The commit will initiate sequencing
        commitImport(ImportCommand.class.getSimpleName(), importMessages);

        // No sequencing problems - success
        if (!importMessages.hasError()) {
          // Move the children underneath the supplied parent context
          KomodoObject[] children = tempSchema.getChildren(getTransaction());
          for (KomodoObject child : children) {
            RenameCommand renameCommand = new RenameCommand(getWorkspaceStatus());
            String oldFullName = wsStatus.getDisplayPath(child, null);
            String contextName = wsStatus.getDisplayPath(getContext(), null);
            renameCommand.setArguments(
                new Arguments(
                    oldFullName
                        + StringConstants.SPACE
                        + contextName
                        + StringConstants.FORWARD_SLASH
                        + child.getName(getTransaction())));
            renameCommand.execute();
          }
          // Clean up the temp schema
          deleteSchema(wsStatus.getDisplayPath(tempSchema, null));

          return new CommandResultImpl(
              true, I18n.bind(ModelCommandsI18n.ddlImportSuccessMsg, fileName), null);
          // Problem with the import.  Fail and delete all the parents children
        } else {
          print(
              CompletionConstants.MESSAGE_INDENT,
              I18n.bind(ModelCommandsI18n.importFailedMsg, fileName));
          print(CompletionConstants.MESSAGE_INDENT, importMessages.errorMessagesToString());

          deleteSchema(wsStatus.getDisplayPath(tempSchema, null));
        }
      } else {
        print(
            CompletionConstants.MESSAGE_INDENT,
            I18n.bind(ModelCommandsI18n.importFailedMsg, fileName));
        print(CompletionConstants.MESSAGE_INDENT, importMessages.errorMessagesToString());

        deleteSchema(wsStatus.getDisplayPath(tempSchema, null));
      }

      return new CommandResultImpl(
          false, I18n.bind(WorkspaceCommandsI18n.inputFileError, fileName), null);
    } catch (final Exception e) {
      return new CommandResultImpl(false, I18n.bind(ShellI18n.commandFailure, NAME), e);
    }
  }
  /**
   * {@inheritDoc}
   *
   * @see org.komodo.shell.BuiltInShellCommand#doExecute()
   */
  @Override
  protected CommandResult doExecute() {
    CommandResult result = null;

    try {
      String datasourceName =
          requiredArgument(0, I18n.bind(ServerCommandsI18n.missingDatasourceName));

      final String overwriteArg = optionalArgument(1, null);
      final boolean overwrite = !StringUtils.isBlank(overwriteArg);
      // make sure overwrite arg is valid
      if (overwrite && !VALID_OVERWRITE_ARGS.contains(overwriteArg)) {
        return new CommandResultImpl(
            false, I18n.bind(WorkspaceCommandsI18n.overwriteArgInvalid, overwriteArg), null);
      }

      // If datasource with same name is in workspace, make sure we can overwrite
      boolean hasDS =
          getWorkspaceManager(getTransaction())
              .hasChild(getTransaction(), datasourceName, DataVirtLexicon.Connection.NODE_TYPE);
      if (hasDS && !overwrite) {
        return new CommandResultImpl(
            false,
            I18n.bind(ServerCommandsI18n.datasourceOverwriteNotEnabled, datasourceName),
            null);
      }

      // Validates that a server is connected
      CommandResult validationResult = validateHasConnectedWorkspaceServer();
      if (!validationResult.isOk()) {
        return validationResult;
      }

      // Get the Data Source from the server
      TeiidDataSource serverDS = null;
      try {
        // Check the data source name to make sure its valid
        List<String> existingSourceNames =
            ServerUtils.getDatasourceNames(getWorkspaceTeiidInstance());
        if (!existingSourceNames.contains(datasourceName)) {
          return new CommandResultImpl(
              false, I18n.bind(ServerCommandsI18n.serverDatasourceNotFound, datasourceName), null);
        }
        // Get the data source
        serverDS = getWorkspaceTeiidInstance().getDataSource(datasourceName);
      } catch (Exception ex) {
        result =
            new CommandResultImpl(
                false, I18n.bind(ServerCommandsI18n.connectionErrorWillDisconnect), ex);
        WkspStatusServerManager.getInstance(getWorkspaceStatus()).disconnectDefaultServer();
        return result;
      }
      if (serverDS == null) {
        return new CommandResultImpl(
            false, I18n.bind(ServerCommandsI18n.serverDatasourceNotFound, datasourceName), null);
      }

      // If overwriting, delete existing first
      if (hasDS) {
        final KomodoObject datasourceToDelete =
            getWorkspaceManager(getTransaction())
                .getChild(getTransaction(), datasourceName, DataVirtLexicon.Connection.NODE_TYPE);
        getWorkspaceManager(getTransaction()).delete(getTransaction(), datasourceToDelete);
      }
      // Create the Data Source and set properties
      Datasource newDatasource =
          getWorkspaceManager(getTransaction())
              .createDatasource(getTransaction(), null, datasourceName);
      setRepoDatasourceProperties(newDatasource, serverDS.getProperties());

      print(MESSAGE_INDENT, I18n.bind(ServerCommandsI18n.datasourceCopyToRepoFinished));
      result = CommandResult.SUCCESS;
    } catch (final Exception e) {
      result = new CommandResultImpl(e);
    }

    return result;
  }
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.shell.BuiltInShellCommand#printHelpDescription(int)
  */
 @Override
 protected void printHelpDescription(final int indent) {
   print(indent, I18n.bind(TableCommandsI18n.unsetTablePropertyHelp, getName()));
 }
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.shell.BuiltInShellCommand#printHelpUsage(int)
  */
 @Override
 protected void printHelpUsage(final int indent) {
   print(indent, I18n.bind(TableCommandsI18n.unsetTablePropertyUsage));
 }
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.shell.BuiltInShellCommand#printHelpUsage(int)
  */
 @Override
 protected void printHelpUsage(final int indent) {
   print(indent, I18n.bind(DatasourceCommandsI18n.setDatasourcePropertyUsage));
 }
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.shell.BuiltInShellCommand#printHelpDescription(int)
  */
 @Override
 protected void printHelpDescription(final int indent) {
   print(indent, I18n.bind(DatasourceCommandsI18n.setDatasourcePropertyHelp, getName()));
 }
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.shell.BuiltInShellCommand#printHelpExamples(int)
  */
 @Override
 protected void printHelpExamples(final int indent) {
   print(indent, I18n.bind(TableCommandsI18n.addUniqueConstraintExamples));
 }
  /**
   * {@inheritDoc}
   *
   * @see org.komodo.shell.BuiltInShellCommand#doExecute()
   */
  @Override
  protected CommandResult doExecute() {
    CommandResult result = null;

    try {
      final String name =
          requiredArgument(0, I18n.bind(WorkspaceCommandsI18n.missingPropertyNameValue));
      final String value =
          requiredArgument(1, I18n.bind(WorkspaceCommandsI18n.missingPropertyNameValue));

      final Table table = getTable();
      final UnitOfWork transaction = getTransaction();
      String errorMsg = null;

      switch (name) {
        case DESCRIPTION:
          table.setDescription(transaction, value);
          break;
        case CARDINALITY:
          try {
            final int cardinality = Integer.parseInt(value);
            table.setCardinality(transaction, cardinality);
          } catch (final NumberFormatException e) {
            errorMsg = I18n.bind(WorkspaceCommandsI18n.invalidIntegerPropertyValue, CARDINALITY);
          }

          break;
        case MATERIALIZED:
          if (Boolean.TRUE.toString().equals(value) || Boolean.FALSE.toString().equals(value)) {
            table.setMaterialized(transaction, Boolean.parseBoolean(value));
          } else {
            errorMsg = I18n.bind(WorkspaceCommandsI18n.invalidBooleanPropertyValue, MATERIALIZED);
          }

          break;
        case MATERIALIZED_TABLE:
          table.setMaterializedTable(transaction, value);
          break;
        case NAME_IN_SOURCE:
          table.setNameInSource(transaction, value);
          break;
        case UPDATABLE:
          if (Boolean.TRUE.toString().equals(value) || Boolean.FALSE.toString().equals(value)) {
            table.setUpdatable(transaction, Boolean.parseBoolean(value));
          } else {
            errorMsg = I18n.bind(WorkspaceCommandsI18n.invalidBooleanPropertyValue, UPDATABLE);
          }

          break;
        case UUID:
          table.setUuid(transaction, value);
          break;
        case ON_COMMIT_VALUE:
          if (OnCommit.DELETE_ROWS.name().equals(value)) {
            table.setOnCommitValue(transaction, OnCommit.DELETE_ROWS);
          } else if (OnCommit.PRESERVE_ROWS.name().equals(value)) {
            table.setOnCommitValue(transaction, OnCommit.PRESERVE_ROWS);
          } else {
            errorMsg = I18n.bind(TableCommandsI18n.invalidOnCommitPropertyValue, ON_COMMIT_VALUE);
          }

          break;
        case QUERY_EXPRESSION:
          table.setQueryExpression(transaction, value);
          break;
        case SCHEMA_ELEMENT_TYPE:
          if (SchemaElement.SchemaElementType.FOREIGN.name().equals(value)) {
            table.setSchemaElementType(transaction, SchemaElement.SchemaElementType.FOREIGN);
          } else if (SchemaElement.SchemaElementType.VIRTUAL.name().equals(value)) {
            table.setSchemaElementType(transaction, SchemaElement.SchemaElementType.VIRTUAL);
          } else {
            errorMsg = I18n.bind(TableCommandsI18n.invalidSchemaElementTypePropertyValue, value);
          }

          break;
        case TEMPORARY_TABLE_TYPE:
          if (Table.TemporaryType.GLOBAL.name().equals(value)) {
            table.setTemporaryTableType(transaction, Table.TemporaryType.GLOBAL);
          } else if (Table.TemporaryType.LOCAL.name().equals(value)) {
            table.setTemporaryTableType(transaction, Table.TemporaryType.LOCAL);
          } else {
            errorMsg = I18n.bind(TableCommandsI18n.invalidTemporaryTableTypePropertyValue, value);
          }

          break;
        default:
          errorMsg =
              I18n.bind(
                  WorkspaceCommandsI18n.invalidPropertyName, name, Table.class.getSimpleName());
          break;
      }

      if (StringUtils.isBlank(errorMsg)) {
        result = new CommandResultImpl(I18n.bind(WorkspaceCommandsI18n.setPropertySuccess, name));
      } else {
        result = new CommandResultImpl(false, errorMsg, null);
      }
    } catch (final Exception e) {
      result = new CommandResultImpl(e);
    }

    return result;
  }
  /**
   * {@inheritDoc}
   *
   * @see org.komodo.shell.BuiltInShellCommand#doExecute()
   */
  @Override
  protected CommandResult doExecute() {
    CommandResult result = null;

    try {
      final String name =
          requiredArgument(0, I18n.bind(WorkspaceCommandsI18n.missingPropertyNameValue));
      final String value =
          requiredArgument(1, I18n.bind(WorkspaceCommandsI18n.missingPropertyNameValue));

      final DataRole dataRole = getDataRole();
      final UnitOfWork transaction = getTransaction();
      String errorMsg = null;

      switch (name) {
        case ALLOWED_CREATE_TEMPORARY_TABLES:
          if (Boolean.TRUE.toString().equals(value) || Boolean.FALSE.toString().equals(value)) {
            dataRole.setAllowCreateTempTables(transaction, Boolean.parseBoolean(value));
          } else {
            errorMsg =
                I18n.bind(
                    WorkspaceCommandsI18n.invalidBooleanPropertyValue,
                    ALLOWED_CREATE_TEMPORARY_TABLES);
          }

          break;
        case ANY_AUTHENTICATED:
          if (Boolean.TRUE.toString().equals(value) || Boolean.FALSE.toString().equals(value)) {
            dataRole.setAnyAuthenticated(transaction, Boolean.parseBoolean(value));
          } else {
            I18n.bind(WorkspaceCommandsI18n.invalidBooleanPropertyValue, ANY_AUTHENTICATED);
          }

          break;
        case DESCRIPTION:
          dataRole.setDescription(transaction, value);
          break;
        case GRANT_ALL:
          if (Boolean.TRUE.toString().equals(value) || Boolean.FALSE.toString().equals(value)) {
            dataRole.setGrantAll(transaction, Boolean.parseBoolean(value));
          } else {
            errorMsg = I18n.bind(WorkspaceCommandsI18n.invalidBooleanPropertyValue, GRANT_ALL);
          }

          break;
        default:
          errorMsg =
              I18n.bind(
                  WorkspaceCommandsI18n.invalidPropertyName, name, DataRole.class.getSimpleName());
          break;
      }

      if (StringUtils.isBlank(errorMsg)) {
        result = new CommandResultImpl(I18n.bind(WorkspaceCommandsI18n.setPropertySuccess, name));
      } else {
        result = new CommandResultImpl(false, errorMsg, null);
      }
    } catch (final Exception e) {
      result = new CommandResultImpl(e);
    }

    return result;
  }
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.shell.BuiltInShellCommand#printHelpUsage(int)
  */
 @Override
 protected void printHelpUsage(final int indent) {
   print(indent, I18n.bind(TableCommandsI18n.addUniqueConstraintUsage));
 }
Example #22
0
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.shell.BuiltInShellCommand#printHelpDescription(int)
  */
 @Override
 protected void printHelpDescription(final int indent) {
   print(indent, I18n.bind(ModelCommandsI18n.addViewHelp, getName()));
 }
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.shell.BuiltInShellCommand#printHelpExamples(int)
  */
 @Override
 protected void printHelpExamples(final int indent) {
   print(indent, I18n.bind(DatasourceCommandsI18n.setDatasourcePropertyExamples));
 }
Example #24
0
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.shell.BuiltInShellCommand#printHelpExamples(int)
  */
 @Override
 protected void printHelpExamples(final int indent) {
   print(indent, I18n.bind(ModelCommandsI18n.addViewExamples));
 }
  /**
   * {@inheritDoc}
   *
   * @see org.komodo.shell.BuiltInShellCommand#doExecute()
   */
  @Override
  protected CommandResult doExecute() {
    CommandResult result = null;

    try {
      final String name =
          requiredArgument(0, I18n.bind(WorkspaceCommandsI18n.missingPropertyNameValue));
      final String value =
          requiredArgument(1, I18n.bind(WorkspaceCommandsI18n.missingPropertyNameValue));

      final Datasource datasource = getDatasource();
      final UnitOfWork transaction = getTransaction();
      String errorMsg = null;

      switch (name) {
        case JNDI_NAME:
          datasource.setJndiName(transaction, value);
          break;
        case DRIVER_NAME:
          datasource.setDriverName(transaction, value);
          break;
        case CLASS_NAME:
          datasource.setClassName(transaction, value);
          break;
        case PROFILE_NAME:
          datasource.setProfileName(transaction, value);
          break;
        case JDBC:
          if (Boolean.TRUE.toString().equals(value) || Boolean.FALSE.toString().equals(value)) {
            datasource.setJdbc(transaction, Boolean.parseBoolean(value));
          } else {
            errorMsg = I18n.bind(WorkspaceCommandsI18n.invalidBooleanPropertyValue, JDBC);
          }

          break;
        case PREVIEW:
          if (Boolean.TRUE.toString().equals(value) || Boolean.FALSE.toString().equals(value)) {
            datasource.setPreview(transaction, Boolean.parseBoolean(value));
          } else {
            errorMsg = I18n.bind(WorkspaceCommandsI18n.invalidBooleanPropertyValue, PREVIEW);
          }

          break;
        default:
          errorMsg =
              I18n.bind(
                  WorkspaceCommandsI18n.invalidPropertyName,
                  name,
                  Datasource.class.getSimpleName());
          break;
      }

      if (StringUtils.isBlank(errorMsg)) {
        result = new CommandResultImpl(I18n.bind(WorkspaceCommandsI18n.setPropertySuccess, name));
      } else {
        result = new CommandResultImpl(false, errorMsg, null);
      }
    } catch (final Exception e) {
      result = new CommandResultImpl(e);
    }

    return result;
  }
Example #26
0
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.shell.BuiltInShellCommand#printHelpUsage(int)
  */
 @Override
 protected void printHelpUsage(final int indent) {
   print(indent, I18n.bind(ModelCommandsI18n.addViewUsage));
 }
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.shell.BuiltInShellCommand#printHelpExamples(int)
  */
 @Override
 protected void printHelpExamples(final int indent) {
   print(indent, I18n.bind(TableCommandsI18n.unsetTablePropertyExamples));
 }
Example #28
0
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.relational.commands.datarole.DataRoleShellCommand#printHelpExamples(int)
  */
 @Override
 protected void printHelpExamples(final int indent) {
   print(indent, I18n.bind(ShellI18n.commitExamples));
 }
  /**
   * {@inheritDoc}
   *
   * @see org.komodo.shell.BuiltInShellCommand#doExecute()
   */
  @Override
  protected CommandResult doExecute() {
    CommandResult result = null;

    try {
      final String name =
          requiredArgument(0, I18n.bind(WorkspaceCommandsI18n.unsetMissingPropertyName));

      final Table table = getTable();
      final UnitOfWork transaction = getTransaction();
      String errorMsg = null;

      switch (name) {
        case DESCRIPTION:
          table.setDescription(transaction, null);
          break;
        case CARDINALITY:
          table.setCardinality(transaction, Table.DEFAULT_CARDINALITY);
          break;
        case MATERIALIZED:
          table.setMaterialized(transaction, Table.DEFAULT_MATERIALIZED);
          break;
        case MATERIALIZED_TABLE:
          table.setMaterializedTable(transaction, null);
          break;
        case NAME_IN_SOURCE:
          table.setNameInSource(transaction, null);
          break;
        case UPDATABLE:
          table.setUpdatable(transaction, Table.DEFAULT_UPDATABLE);
          break;
        case UUID:
          table.setUuid(transaction, null);
          break;
        case ON_COMMIT_VALUE:
          table.setOnCommitValue(transaction, null);
          break;
        case QUERY_EXPRESSION:
          table.setQueryExpression(transaction, null);
          break;
        case SCHEMA_ELEMENT_TYPE:
          table.setSchemaElementType(transaction, null);
          break;
        case TEMPORARY_TABLE_TYPE:
          table.setTemporaryTableType(transaction, null);
          break;
        default:
          errorMsg =
              I18n.bind(
                  WorkspaceCommandsI18n.invalidPropertyName, name, Table.class.getSimpleName());
          break;
      }

      if (StringUtils.isBlank(errorMsg)) {
        result = new CommandResultImpl(I18n.bind(WorkspaceCommandsI18n.unsetPropertySuccess, name));
      } else {
        result = new CommandResultImpl(false, errorMsg, null);
      }
    } catch (final Exception e) {
      result = new CommandResultImpl(e);
    }

    return result;
  }
Example #30
0
 /**
  * {@inheritDoc}
  *
  * @see org.komodo.relational.commands.datarole.DataRoleShellCommand#printHelpUsage(int)
  */
 @Override
 protected void printHelpUsage(final int indent) {
   print(indent, I18n.bind(ShellI18n.commitUsage));
 }