@Test
  public void testObjectInfo() throws Exception {
    WbConnection con = PostgresTestUtil.getPostgresConnection();
    assertNotNull(con);

    TestUtil.executeScript(con, "set search_path=path_2,path_1");

    ObjectInfo info = new ObjectInfo();
    StatementRunnerResult result = info.getObjectInfo(con, "t1", false, false);

    assertNotNull(result);
    assertTrue(result.hasDataStores());
    assertEquals(1, result.getDataStores().size());
    assertEquals("path_1.t1 (TABLE)", result.getDataStores().get(0).getResultName());

    result = info.getObjectInfo(con, "t2", false, false);

    assertNotNull(result);
    assertTrue(result.hasDataStores());
    assertEquals(1, result.getDataStores().size());
    assertEquals("path_2.t2 (TABLE)", result.getDataStores().get(0).getResultName());
  }
Example #2
0
  @Override
  public StatementRunnerResult execute(String aSql) throws SQLException {
    StatementRunnerResult result = new StatementRunnerResult();
    String parm = SqlUtil.stripVerb(aSql);

    cmdLine.parse(parm);

    WbFile inputFile = evaluateFileArgument(cmdLine.getValue(ARG_INPUT));
    WbFile outputFile = evaluateFileArgument(cmdLine.getValue(ARG_OUTPUT));
    WbFile xsltFile = evaluateFileArgument(cmdLine.getValue(ARG_STYLESHEET));

    if (!cmdLine.hasArguments()) {
      result.addErrorMessageByKey("ErrXsltWrongParameter");
      return result;
    }

    if (inputFile == null) {
      result.addErrorMessageByKey("ErrXsltMissingInputFile");
      return result;
    }

    if (!inputFile.exists()) {
      result.addErrorMessageByKey("ErrFileNotFound", cmdLine.getValue(ARG_INPUT));
      return result;
    }

    if (outputFile == null) {
      result.addErrorMessageByKey("ErrXsltMissingOutputFile");
      return result;
    }

    if (xsltFile == null) {
      result.addErrorMessageByKey("ErrXsltMissingStylesheet");
      return result;
    }

    if (!xsltFile.exists()) {
      result.addErrorMessageByKey("ErrFileNotFound", cmdLine.getValue(ARG_STYLESHEET));
      return result;
    }

    Map<String, String> params = getParameters(cmdLine);

    XsltTransformer transformer = new XsltTransformer();

    try {
      transformer.setSaveSystemOutMessages(true);
      transformer.setXsltBaseDir(getXsltBaseDir());

      transformer.transform(inputFile, outputFile, xsltFile, params);

      String msg = transformer.getAllOutputs();
      if (msg.length() != 0) {
        result.addMessage(msg);
        result.addMessage(""); // create newline
      }

      WbFile xsltUsed = new WbFile(transformer.getXsltUsed());
      WbFile userXslt = new WbFile(xsltFile);
      if (xsltUsed != null && !userXslt.equals(xsltUsed)) {
        // If the xslt file has been "automatically" found, inform the user about this
        result.addMessage(ResourceMgr.getFormattedString("MsgXsltUsed", xsltUsed.getFullPath()));
      }
      result.addMessage(ResourceMgr.getFormattedString("MsgXsltSuccessful", outputFile));
      result.setSuccess();
    } catch (Exception e) {
      LogMgr.logError(
          "WbXslt.execute()",
          "Error when transforming '" + inputFile + "' to '" + outputFile + "' using " + xsltFile,
          e);
      String msg = transformer.getAllOutputs(e);
      LogMgr.logError("WbXslt.execute()", msg, null);
      result.addErrorMessage(msg);
    }
    return result;
  }