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

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


        stmt.close();

        PreparedStatement ps = prepareStatement("insert into " + TBL +
                " values (?)");
        int length = 65*1024*1024; // 65K
        ps.setBinaryStream(1, new LoopingAlphabetStream(length), length);
        ps.executeUpdate();
        ps.close();

        stmt = createStatement();
        ResultSet rs = stmt.executeQuery("select B from " + TBL);
View Full Code Here


                            // (otherwise, materialization happens and a
                            // different code path is taken)

        for (int i = 0; i < rows; i++) {
            insert.setBinaryStream(
                    1, new LoopingAlphabetStream(length), length);
            insert.executeUpdate();
        }

        commit();

        ResultSet rs = s.executeQuery("select b from derby1511");
        for (int i = 0; i < rows; i++) {
            assertTrue("Too few rows", rs.next());
            // Second time this was called we used to get an error saying
            // container has been closed.
            assertEquals(new LoopingAlphabetStream(length),
                         rs.getBinaryStream(1));
            commit();
        }

        assertFalse("Too many rows", rs.next());
View Full Code Here

                    ps.setInt(2, length);
                    length = (int)(rnd.nextDouble() * 64.0 * 1024.0);
                    if (rnd.nextInt(1000) < 500) {
                        // Specify the length.
                        ps.setBinaryStream(3,
                                new LoopingAlphabetStream(length), length);
                    } else {
                        // Don't specify the length.
                        ps.setBinaryStream(3,
                                new LoopingAlphabetStream(length));
                    }
                    ps.setInt(4, length);
                    ps.setInt(5, rnd.nextInt());
                    ps.executeUpdate();
                }
View Full Code Here

        // We need a Blob represented as a stream in store.
        int length = 71*1024+7;
        PreparedStatement ps =
                prepareStatement("insert into testBlobX1(a,b) values (?,?)");
        ps.setInt(1, 2);
        ps.setBinaryStream(2, new LoopingAlphabetStream(length), length);
        ps.executeUpdate();
        ps.close();

        // Get a result set with the Blob.
        ps = prepareStatement("select b from testBlobX1 where a = ?");
View Full Code Here

    /**
     * Tests the BlobOutputStream.write(byte  b[], int off, int len) method
     **/
    public void testBlobWrite3Param() throws Exception {
        InputStream streamIn = new LoopingAlphabetStream(streamSize[0]);
        assertTrue("FAIL -- file not found", streamIn != null);

        PreparedStatement stmt3 = prepareStatement(
            "SELECT b FROM testBlobX1 WHERE a = 1");
        ResultSet rs3 = stmt3.executeQuery();
        rs3.next();
        Blob blob = rs3.getBlob(1);

        assertTrue ("FAIL -- blob is NULL", (blob != null));

        int count = 0;
        byte[] buffer = new byte[1024];
        OutputStream outstream = blob.setBinaryStream(1L);
        while ((count = streamIn.read(buffer)) != -1) {
            outstream.write(buffer, 0, count);
        }
        outstream.close();
        streamIn.close();

        PreparedStatement stmt4 = prepareStatement(
            "UPDATE testBlobX1 SET b = ? WHERE a = 1");
        stmt4.setBlob(1,  blob);
        stmt4.executeUpdate();
        stmt4.close();
        rs3.close();

        rs3 = stmt3.executeQuery();
        assertTrue("FAIL -- blob not found", rs3.next());

        blob = rs3.getBlob(1);
        long new_length = blob.length();
        assertEquals("FAIL -- wrong blob length;",
                streamSize[0], new_length);

        // Check contents ...
        InputStream fStream = new LoopingAlphabetStream(streamSize[0]);
        InputStream lStream = blob.getBinaryStream();
        assertTrue("FAIL - Blob and file contents do not match",
                compareLob2File(fStream, lStream));

        fStream.close();
        lStream.close();
        rs3.close();
        stmt3.close();
    }
View Full Code Here

    /**
     * Tests the BlobOutputStream.write(int b) method
     **/
    public void testBlobWrite1Param() throws Exception {
        InputStream streamIn = new LoopingAlphabetStream(streamSize[1]);

        PreparedStatement stmt3 = prepareStatement(
            "SELECT b FROM testBlobX1 WHERE a = 1");
        ResultSet rs3 = stmt3.executeQuery();
        rs3.next();
        Blob blob = rs3.getBlob(1);

        assertTrue("FAIL -- blob is NULL", blob != null);

        int buffer;
        OutputStream outstream = blob.setBinaryStream(1L);
        while ((buffer = streamIn.read()) != -1) {
            outstream.write(buffer);
        }
        outstream.close();
        streamIn.close();

        PreparedStatement stmt4 = prepareStatement(
            "UPDATE testBlobX1 SET b = ? WHERE a = 1");
        stmt4.setBlob(1,  blob);
        stmt4.executeUpdate();
        stmt4.close();

        rs3.close();
        rs3 = stmt3.executeQuery();

        assertTrue("FAIL -- blob not found", rs3.next());

        blob = rs3.getBlob(1);
        long new_length = blob.length();
        assertEquals("FAIL -- wrong blob length", streamSize[1], new_length);

        // Check contents ...
        InputStream fStream = new LoopingAlphabetStream(streamSize[1]);
        InputStream lStream = blob.getBinaryStream();
        assertTrue("FAIL - Blob and file contents do not match",
                compareLob2File(fStream, lStream));

        fStream.close();
        lStream.close();
        rs3.close();
        stmt3.close();
    }
View Full Code Here

    /**
     * Tests the ClobOutputStream.write(int b) method
     **/
    public void testClobAsciiWrite1Param() throws Exception
    {
        InputStream streamIn = new LoopingAlphabetStream(streamSize[1]);

        PreparedStatement stmt3 = prepareStatement(
            "SELECT c FROM testBlobX1 WHERE a = 1");
        ResultSet rs3 = stmt3.executeQuery();
        rs3.next();
        Clob clob = rs3.getClob(1);

        assertTrue("FAIL -- clob is NULL", clob != null);
        int buffer;
        OutputStream outstream = clob.setAsciiStream(1L);
        while ((buffer = streamIn.read()) != -1) {
            outstream.write(buffer);
        }
        outstream.close();
        streamIn.close();

        PreparedStatement stmt4 = prepareStatement(
            "UPDATE testBlobX1 SET c = ? WHERE a = 1");
        stmt4.setClob(1,  clob);
        stmt4.executeUpdate();
        stmt4.close();

        rs3.close();
        rs3 = stmt3.executeQuery();
        assertTrue("FAIL -- clob not found", rs3.next());

        clob = rs3.getClob(1);
        long new_length = clob.length();
        assertEquals("FAIL -- wrong clob length", streamSize[1], new_length);

        // Check contents ...
        InputStream fStream = new LoopingAlphabetStream(streamSize[1]);
        InputStream lStream = clob.getAsciiStream();
        assertTrue("FAIL - Clob and file contents do not match", compareLob2File(fStream, lStream));
        fStream.close();
        lStream.close();
        rs3.close();
        stmt3.close();
    }
View Full Code Here

    /**
     * Tests the ClobOutputStream.write(byte  b[], int off, int len) method
     **/
    public void testClobAsciiWrite3Param() throws Exception {
        InputStream streamIn = new LoopingAlphabetStream(streamSize[0]);
        assertTrue("FAIL -- file not found", streamIn != null);

        PreparedStatement stmt3 = prepareStatement(
            "SELECT c FROM testBlobX1 WHERE a = 1");
        ResultSet rs3 = stmt3.executeQuery();
        rs3.next();
        Clob clob = rs3.getClob(1);

        assertTrue("FAIL -- clob is NULL", clob != null);

        int count = 0;
        byte[] buffer = new byte[1024];
        OutputStream outstream = clob.setAsciiStream(1L);
        while ((count = streamIn.read(buffer)) != -1) {
            outstream.write(buffer, 0, count);
        }
        outstream.close();
        streamIn.close();

        PreparedStatement stmt4 = prepareStatement(
            "UPDATE testBlobX1 SET c = ? WHERE a = 1");
        stmt4.setClob(1,  clob);
        stmt4.executeUpdate();
        stmt4.close();

        rs3.close();
        rs3 = stmt3.executeQuery();

        assertTrue("FAIL -- clob not found", rs3.next());

        clob = rs3.getClob(1);
        long new_length = clob.length();
        assertEquals("FAIL -- wrong clob length",
                streamSize[0], new_length);
        // Check contents ...
        InputStream fStream = new LoopingAlphabetStream(streamSize[0]);
        InputStream lStream = clob.getAsciiStream();
        assertTrue("FAIL - Clob and file contents do not match",
                compareLob2File(fStream, lStream));

        fStream.close();
        lStream.close();
        rs3.close();
        stmt3.close();
    }
View Full Code Here

       
        PreparedStatement ps = prepareStatement("INSERT INTO BLOBTAB VALUES(?,?)");
        // We allocate 16MB for the test so use something bigger than that.
        ps.setInt(1,1);
        int blobLen = LONG_BLOB_LENGTH + extraLen;
        LoopingAlphabetStream stream = new LoopingAlphabetStream(blobLen);
        if (lengthless) {
            Method m = null;
            try {
                Class<?> c = ps.getClass();
                m = c.getMethod("setBinaryStream",new Class[] {Integer.TYPE,
View Full Code Here

        PreparedStatement ps = prepareStatement(
            "INSERT INTO T_MAIN(V) VALUES (?)");

        int blobLen = blobsize;
        LoopingAlphabetStream stream = new LoopingAlphabetStream(blobLen);
        ps.setBinaryStream(1, stream, blobLen);

        ps.executeUpdate();
        ps.close();

        s.executeUpdate("CREATE TABLE T_COPY ( V1 BLOB(" + blobsize +
                        "), V2 BLOB(" + blobsize + "))");

        // This failed in the repro for DERBY-3645 solved as part of
        // DERBY-4477:
        s.executeUpdate("INSERT INTO T_COPY SELECT  V, V FROM T_MAIN");

        // Check that the two results are identical:
        ResultSet rs = s.executeQuery("SELECT * FROM T_COPY");
        rs.next();
        InputStream is = rs.getBinaryStream(1);

        stream.reset();
        assertEquals(stream, is);

        is = rs.getBinaryStream(2);

        stream.reset();
        assertEquals(stream, is);
        rs.close();

        // This failed in the repro for DERBY-3646 solved as part of
        // DERBY-4477 (repro slightly rewoked here):
        rs = s.executeQuery("SELECT 'I', V, ID, V from T_MAIN");
        rs.next();

        is = rs.getBinaryStream(2);
        stream.reset();
        assertEquals(stream, is);

        is = rs.getBinaryStream(4);
        stream.reset();
        assertEquals(stream, is);

        // clean up
        stream.close();
        is.close();
        s.close();
        rs.close();

        rollback();
View Full Code Here

TOP

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

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.