@Test
  public void JDBCExecutionContextRead() throws Exception {
    if (loadSQLite() == null) {
      return;
    }
    String[] args = new String[] {"-e", "jdbc:sqlite:"};
    CommandLineOptions options = CliFactory.parseArguments(CommandLineOptions.class, args);

    ExecutionContext testContext = new JDBCExecutionContext(options);
    MedicalLogicModule mlm =
        ActionTests.parseTemplate(
            "varA := read {drop table if exists person};\n"
                + "varB := read {create table person (id integer, name string)};\n"
                + "varC := read {insert into person values (1, 'A')};\n"
                + "varD := read {insert into person values (2, 'B')};\n"
                + "(varE, varF) := read {select * from person};\n",
            "conclude true;",
            "return (varE, varF);");
    ArdenValue[] result = mlm.run(testContext, null);
    Assert.assertEquals(1, result.length);

    ArdenValue[] expected = {
      new ArdenNumber(1), new ArdenNumber(2), new ArdenString("A"), new ArdenString("B")
    };
    ArdenValue[] resultList = ((ArdenList) (result[0])).values;

    Assert.assertArrayEquals(expected, resultList);
  }
Example #2
0
  private Command<?> toCommand(String commandLine) throws ArgumentValidationException {
    String[] commandLineArray = CommandLines.parseArguments(commandLine);
    String commandName = commandLineArray[0];
    String[] commandArgs = Arrays.copyOfRange(commandLineArray, 1, commandLineArray.length);

    Class<?> optionsClass = commandRegistry.getOptionsClass(commandName);
    Command<Object> command = commandRegistry.newCommand(commandName);
    command.setOptions(CliFactory.parseArguments(optionsClass, commandArgs));
    return command;
  }
  private static CLIArguments parseArguments(String[] unparsedArgs)
      throws ArgumentValidationException, Exception {

    CLIArguments args = CliFactory.parseArguments(CLIArguments.class, unparsedArgs);

    if (!CLIArgumentsUtil.isValid(args)) {
      throw new Exception(CLIArgumentsUtil.getErrorString(args));
    }
    return args;
  }
  private static void executeArgumentsGroup(CLIArgumentsGroup argumentsGroup) {

    /* load configuration file */

    Configuration config = new BaseConfiguration();

    if (argumentsGroup.getRepresentative().isConfig()) {
      try {
        config = new PropertiesConfiguration(argumentsGroup.getRepresentative().getConfig());
      } catch (ConfigurationException e) {
        System.err.println("could not read config, ignoring it: ");
        System.err.println(e);
      }
    }

    /* run selected mode */

    ProgramMode programMode = CLIArgumentsUtil.getProgramMode(argumentsGroup.getRepresentative());

    switch (programMode) {
      case HELP:
        System.out.println(
            CliFactory.createCli(CLIArguments.class).getHelpMessage()
                + "\n\nFor more information, see "
                + GlobalValues.WIKI_URI);
        break;

      case VERSION:
        System.out.println("OSM2World " + VERSION_STRING);
        break;

      case GUI:
        try {
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
          System.out.println("Error setting native look and feel: " + e);
        }
        new ViewerFrame(new Data(), new MessageManager(), new RenderOptions(), config)
            .setVisible(true);
        break;

      case CONVERT:
        try {
          Output.output(config, argumentsGroup);
        } catch (IOException e) {
          e.printStackTrace();
        }
        break;
    }
  }