Package org.apache.derbyTesting.functionTests.util.streams

Examples of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader


        getConnection().setAutoCommit(false);

        PreparedStatement ps = prepareStatement(
                "insert into testClob(b, a) values(?,?)");
        for (int i = 0; i < 3; i++) {
            Reader fis = new LoopingAlphabetReader(300000);
            ps.setInt(1, i);
            ps.setCharacterStream(2, fis, 300000);
            ps.executeUpdate();
            fis.close();
        }
        commit();

        getConnection().setAutoCommit(true);
View Full Code Here


            PreparedStatement ps,
            CharAlphabet alphabet,
            int lobLength)
        throws Exception
    {
        ps.setCharacterStream(1, new LoopingAlphabetReader(lobLength, alphabet),
                lobLength);
        ps.setInt(2, lobLength);
        ps.setLong(3, -1);
        ps.executeUpdate();
    }
View Full Code Here

        // Make a lob table and insert one row
        s.executeUpdate("create table lobtable(i int, c clob)");
        PreparedStatement ps = prepareStatement(
            "insert into lobtable values (1,?)");
        ps.setCharacterStream(
            1, new LoopingAlphabetReader(1000), 1000);
        ps.executeUpdate();

        // Export the lob table
        s.executeUpdate("call SYSCS_UTIL.SYSCS_EXPORT_TABLE_LOBS_TO_EXTFILE(" +
                        "    'SYS'," +
View Full Code Here

        PreparedStatement ps =
                prepareStatement("insert into t2017_len values (?,?)");
        // Test small values.
        for (int i=0; i < 512; i++) {
            ps.setInt(1, i);
            ps.setCharacterStream(2, new LoopingAlphabetReader(i), i);
            ps.executeUpdate();
        }
        commit();

        // Test values at the buffer boundary. Assumes UTF-16 and a ~32 KB
        // transmit buffer.
        for (int i=16000; i < 18000; i++) {
            ps.setInt(1, i);
            ps.setCharacterStream(2, new LoopingAlphabetReader(i), i);
            ps.executeUpdate();
            // Commit periodically.
            if (i % 1000 == 0) {
                commit();
            }
        }
        commit();

        for (int i=32500; i < 33000; i++) {
            ps.setInt(1, i);
            ps.setCharacterStream(2, new LoopingAlphabetReader(i), i);
            ps.executeUpdate();
        }
        commit();

        // Verify the data, basically making sure the status flag isn't
        // included as part of the user data.
        ResultSet rs = stmt.executeQuery("select len, c from t2017_len");
        int rows = 0;
        while (rs.next()) {
            rows++;
            assertEquals(new LoopingAlphabetReader(rs.getInt(1)),
                         rs.getCharacterStream(2));
        }
    }
View Full Code Here

                prepareStatement("insert into t2017_id values (?, ?)");
        // Insert the 3 first rows (id is 1-based).
        for (int i=0; i < 3; i++) {
            ps.setInt(1, i+1);
            int length = INSERT[i];
            ps.setCharacterStream(2, new LoopingAlphabetReader(length), length);
            assertEquals(1, ps.executeUpdate());
        }

        // Insert the 4th row with a stream that's longer than the specified
        // length, then the 5th row that's shorter. Both should fail, and the
        // data shouldn't be inserted into the database.

        Reader r4 = new LoopingAlphabetReader(INSERT[3]);
        ps.setInt(1, 4);
        ps.setCharacterStream(2, r4, INSERT[3] - 5);
        try {
            ps.executeUpdate();
            fail("Insert should have failed, stream too long");
        } catch (SQLException sqle) {
            // The states are different between client and embedded.
            assertSQLState(usingEmbedded() ? "XSDA4" : "XN015", sqle);
            if (rollbackOnError) {
                rollback();
            }
        }

        Reader r5 = new LoopingAlphabetReader(INSERT[4]);
        ps.setInt(1, 5);
        ps.setCharacterStream(2, r5, INSERT[4] + 5);
        try {
            ps.executeUpdate();
            fail("Insert should have failed, stream too short");
        } catch (SQLException sqle) {
            // The states are different between client and embedded.
            assertSQLState(usingEmbedded() ? "XSDA4" : "XN017", sqle);
            if (rollbackOnError) {
                rollback();
            }
        }

        // The errors above should have statement severity. Insert the last
        // two rows and make sure the transaction commits.
        for (int i=5; i < INSERT.length; i++) {
            ps.setInt(1, i+1);
            int length = INSERT[i];
            ps.setCharacterStream(2, new LoopingAlphabetReader(length), length);
            assertEquals(1, ps.executeUpdate());
        }

        if (!autoCommit) {
            commit();
        }

        // Make sure we have the expected number of rows.
        ResultSet rs = stmt.executeQuery("select count(*) from t2017_id");
        rs.next();
        assertEquals((rollbackOnError && !autoCommit ? 2 : 5), rs.getInt(1));

        // Select data in the table, compare to what we expect.
        rs = stmt.executeQuery( "select * from t2017_id order by id asc");
        // Check rows 1-4 if rollback on error is false.
        if (autoCommit || !rollbackOnError) {
            for (int i=0; i < 3; i++) {
                rs.next();
                int id = rs.getInt(1);
                assertTrue(id - 1 == i);
                assertEquals(new LoopingAlphabetReader(INSERT[i]),
                             rs.getCharacterStream(2));
            }
        }
        // Check rows 6 and 7.
        for (int i=5; i < 7; i++) {
            rs.next();
            int id = rs.getInt(1);
            assertTrue(id - 1 == i);
            assertEquals(new LoopingAlphabetReader(INSERT[i]),
                         rs.getCharacterStream(2));
        }
        assertFalse(rs.next());
        rs.close();
    }
View Full Code Here

         * @param failAtPos the position to fail at (specifying zero or a
         *      negative value causes an exception on the first read request)
         */
        public FailingReader(long length, long failAtPos) {
            this.failAtPos = failAtPos;
            this.in = new LoopingAlphabetReader(length);
        }
View Full Code Here

        for (int i = 0 ; i < 17 ; i++) {
            ps.setInt(1 , id++);
            ps.setString(2 , "book" +i);
            blobSize +=  1024 * i;
            int clobSize = 1024 * i;
            Reader reader = new LoopingAlphabetReader(clobSize);
            ps.setCharacterStream(3, reader, clobSize);
            InputStream stream = new LoopingAlphabetStream(blobSize);
            ps.setBinaryStream(4, stream, blobSize);
            ps.executeUpdate();

View Full Code Here

     * @return A string.
     * @throws IOException if reading from the source stream fails
     */
    public static String getString(int length, CharAlphabet alphabet)
            throws IOException {
        LoopingAlphabetReader reader =
                new LoopingAlphabetReader(length, alphabet);
        char[] strChar = new char[length];
        int read = 0;
        while (read < length) {
            int readNow = reader.read(strChar, read, length - read);
            if (readNow < 1) {
                fail("Creating string failed, stream returned " + readNow);
            }
            read += readNow;
        }
View Full Code Here

        name = new_name;
        l_name = new_lname;
        try {
          // to create a stream of random length between 200 bytes and 3MB
          int clobLength = Rn.nextInt(3078000 - 200 + 1) + 200;
          streamReader = new LoopingAlphabetReader(clobLength,
              CharAlphabet.modernLatinLowercase());
          insertFirst.setCharacterStream(4, streamReader, clobLength);
        } catch (Exception e) {
          MailJdbc.logAct.logMsg(LogFile.ERROR + thread_name + " : "
              + "File not found Exception : " + e.getMessage());
View Full Code Here

     * @return A string.
     * @throws IOException if reading from the source stream fails
     */
    public static String getString(int length, CharAlphabet alphabet)
            throws IOException {
        LoopingAlphabetReader reader =
                new LoopingAlphabetReader(length, alphabet);
        char[] strChar = new char[length];
        int read = 0;
        while (read < length) {
            int readNow = reader.read(strChar, read, length - read);
            if (readNow < 1) {
                fail("Creating string failed, stream returned " + readNow);
            }
            read += readNow;
        }
View Full Code Here

TOP

Related Classes of org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.