Esempio n. 1
0
  @Test
  public void testOdata() throws Exception {
    String vdb =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
            + "<vdb name=\"Loopy\" version=\"1\">\n"
            + "    <model name=\"MarketData\">\n"
            + "        <source name=\"text-connector2\" translator-name=\"loopback\" />\n"
            + "         <metadata type=\"DDL\"><![CDATA[\n"
            + "                CREATE FOREIGN TABLE G1 (e1 string, e2 integer PRIMARY KEY);\n"
            + "                CREATE FOREIGN TABLE G2 (e1 string, e2 integer PRIMARY KEY) OPTIONS (UPDATABLE 'true');\n"
            + "        ]]> </metadata>\n"
            + "    </model>\n"
            + "</vdb>";

    admin.deploy(
        "loopy-vdb.xml", new ReaderInputStream(new StringReader(vdb), Charset.forName("UTF-8")));

    assertTrue(AdminUtil.waitForVDBLoad(admin, "Loopy", 1, 3));

    WebClient client =
        WebClient.create("http://*****:*****@mm://localhost:31000;user=user;password=user", null);

    PreparedStatement ps =
        conn.prepareCall(
            "select t.* from xmltable('/*:Edmx/*:DataServices/*:Schema[@Alias=\"MarketData\"]' passing xmlparse(document cast(? as clob))) as t");
    ps.setAsciiStream(1, (InputStream) response.getEntity());

    ResultSet rs = ps.executeQuery();
    rs.next();

    assertEquals(
        ObjectConverterUtil.convertFileToString(
            UnitTestUtil.getTestDataFile("loopy-metadata4-results.txt")),
        rs.getString(1));

    conn.close();

    // try an invalid url
    client = WebClient.create("http://localhost:8080/odata/x/y$metadata");
    client.header(
        "Authorization",
        "Basic " + Base64.encodeBytes(("user:user").getBytes())); // $NON-NLS-1$ //$NON-NLS-2$
    response = client.invoke("GET", null);
    assertEquals(500, response.getStatus());

    admin.undeploy("loopy-vdb.xml");
  }
 public void setAsciiStream(int parameterIndex, java.io.InputStream x, int length)
     throws SQLException {
   checkOpen();
   try {
     _stmt.setAsciiStream(parameterIndex, x, length);
   } catch (SQLException e) {
     handleException(e);
   }
 }
Esempio n. 3
0
  public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
    Profiler profiler = _profilerPoint.start();

    try {
      _preparedStatement.setAsciiStream(parameterIndex, x, length);
    } finally {
      profiler.finish();
    }
  }
 public void setAsciiStream(int idx, InputStream is) throws SQLException {
   try {
     is = markableInputStream(is);
     addMementoEntry("setAsciiStream", new Class[] {InputStream.class}, idx, is);
     wrapped.setAsciiStream(idx, is);
     resetInputStream(is);
   } catch (SQLException e) {
     throw new UcanaccessSQLException(e);
   }
 }
Esempio n. 5
0
  /** This function is called when a page is fetched and ready to be processed by your program. */
  @Override
  public void visit(Page page) {
    if (page.getParseData() instanceof HtmlParseData) {
      ResultSet res = null;
      try {
        HtmlParseData htmlParseData = (HtmlParseData) page.getParseData();
        String html = htmlParseData.getHtml();
        Document doc = Jsoup.parse(html);

        // check if the page must be crawled
        String url = page.getWebURL().getURL();
        if (!shouldVisit(url)) {
          return;
        }

        currentPage = getDocumentURL(url.toLowerCase());

        // check if the page was already crawled
        queryDocumentFind.setString(1, currentPage);
        res = queryDocumentFind.executeQuery();
        if (res.next()) {
          return;
        }
        logger.debug("Code: " + currentPage);

        // insert into DOCUMENT
        queryDocumentInsert.setString(1, getSHA256(currentPage));
        queryDocumentInsert.setString(2, currentPage);
        queryDocumentInsert.setString(3, getDocumentType(url).name());
        queryDocumentInsert.setString(4, getDocumentBand(url, doc));
        queryDocumentInsert.setString(5, getDocumentAlbum(url, doc));
        queryDocumentInsert.setAsciiStream(6, getDocumentContent(url, doc));
        queryDocumentInsert.setDate(7, getDocumentCreationDate(url, doc));
        queryDocumentInsert.setString(8, getDocumentCover(url, doc));
        queryDocumentInsert.setString(9, getDocumentAuthor(url, doc));
        queryDocumentInsert.setString(10, getDocumentGenre(url, doc));
        queryDocumentInsert.setInt(11, getDocumentYear(url, doc));
        queryDocumentInsert.setString(12, getDocumentLabel(url, doc));
        queryDocumentInsert.setFloat(13, getDocumentVote(url, doc));
        queryDocumentInsert.setBoolean(14, getDocumentMilestone(url, doc));
        queryDocumentInsert.executeUpdate();
        logger.info("Document " + currentPage + " added into DOCUMENT");
      } catch (Throwable t) {
        logger.error("Error parsing page " + page.getWebURL().getURL() + ": " + t.getMessage());
      } finally {
        try {
          if (res != null) {
            res.close();
          }
        } catch (Throwable t) {
          // do nothing
        }
      }
    }
  }
 public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
   String methodCall = "setAsciiStream(" + parameterIndex + ", " + x + ")";
   argTraceSet(parameterIndex, "(Ascii InputStream)", "<Ascii InputStream>");
   try {
     realPreparedStatement.setAsciiStream(parameterIndex, x);
   } catch (SQLException s) {
     reportException(methodCall, s);
     throw s;
   }
   reportReturn(methodCall);
 }
Esempio n. 7
0
 @SuppressWarnings("deprecation")
 @Override
 public void setParameter(final PreparedStatement pstmt, final int index) throws SQLException {
   final ByteArrayInputStream bais = new ByteArrayInputStream(value);
   switch (type) {
     case TYPE_ASCII:
       pstmt.setAsciiStream(index, bais, length);
       break;
     case TYPE_UNICODE:
       // its ok to downcast here as there is no setUnicodeStream()
       // variant with a long length value
       pstmt.setUnicodeStream(index, bais, (int) length);
       break;
     case TYPE_BINARY:
       pstmt.setBinaryStream(index, bais, length);
       break;
   }
 }
Esempio n. 8
0
 public void setClobValue(int iindex, String value, PreparedStatement pstmt) throws SQLException {
   if (value == null) value = "";
   StringBufferInputStream sbis = new StringBufferInputStream(value);
   pstmt.setAsciiStream(iindex, sbis, sbis.available());
 }
 public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
   saveParam(parameterIndex, "" + x + "(" + length + ")", "AsciiStream");
   statement.setAsciiStream(parameterIndex, x, length);
 }
 public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
   delegate.setAsciiStream(parameterIndex, x);
 }
  private void testClob(Connection conn) throws SQLException {
    trace("testClob");
    Statement stat = conn.createStatement();
    PreparedStatement prep;
    ResultSet rs;
    stat.execute("CREATE TABLE T_CLOB(ID INT PRIMARY KEY,V1 CLOB,V2 CLOB)");
    StringBuilder asciiBuffer = new StringBuilder();
    int len = getLength();
    for (int i = 0; i < len; i++) {
      asciiBuffer.append((char) ('a' + (i % 20)));
    }
    String ascii1 = asciiBuffer.toString();
    String ascii2 = "Number2 " + ascii1;
    prep = conn.prepareStatement("INSERT INTO T_CLOB VALUES(?,?,?)");

    prep.setInt(1, 1);
    prep.setString(2, null);
    prep.setNull(3, Types.CLOB);
    prep.executeUpdate();

    prep.clearParameters();
    prep.setInt(1, 2);
    prep.setAsciiStream(2, null, 0);
    prep.setCharacterStream(3, null, 0);
    prep.executeUpdate();

    prep.clearParameters();
    prep.setInt(1, 3);
    prep.setCharacterStream(2, new StringReader(ascii1), ascii1.length());
    prep.setCharacterStream(3, null, 0);
    prep.setAsciiStream(3, new ByteArrayInputStream(ascii2.getBytes()), ascii2.length());
    prep.executeUpdate();

    prep.clearParameters();
    prep.setInt(1, 4);
    prep.setNull(2, Types.CLOB);
    prep.setString(2, ascii2);
    prep.setCharacterStream(3, null, 0);
    prep.setNull(3, Types.CLOB);
    prep.setString(3, ascii1);
    prep.executeUpdate();

    prep.clearParameters();
    prep.setInt(1, 5);
    prep.setObject(2, new StringReader(ascii1));
    prep.setObject(3, new StringReader(ascii2), Types.CLOB, 0);
    prep.executeUpdate();

    rs = stat.executeQuery("SELECT ID, V1, V2 FROM T_CLOB ORDER BY ID");

    rs.next();
    assertEquals(1, rs.getInt(1));
    assertTrue(rs.getCharacterStream(2) == null && rs.wasNull());
    assertTrue(rs.getAsciiStream(3) == null && rs.wasNull());

    rs.next();
    assertEquals(2, rs.getInt(1));
    assertTrue(rs.getString(2) == null && rs.wasNull());
    assertTrue(rs.getString(3) == null && rs.wasNull());

    rs.next();
    assertEquals(3, rs.getInt(1));
    assertEquals(ascii1, rs.getString(2));
    assertEquals(ascii2, rs.getString(3));

    rs.next();
    assertEquals(4, rs.getInt(1));
    assertEquals(ascii2, rs.getString(2));
    assertEquals(ascii1, rs.getString(3));

    rs.next();
    assertEquals(5, rs.getInt(1));
    assertEquals(ascii1, rs.getString(2));
    assertEquals(ascii2, rs.getString(3));

    assertFalse(rs.next());
    assertTrue(prep.getWarnings() == null);
    prep.clearWarnings();
    assertTrue(prep.getWarnings() == null);
    assertTrue(conn == prep.getConnection());
  }
 @Override
 public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
   stmt.setAsciiStream(parameterIndex, x, length);
   logValue(parameterIndex, x == null ? null : "<AsciiStream>");
 }