Package javax.sql.rowset.serial

Examples of javax.sql.rowset.serial.SerialBlob


    }

    public void testSetBytesJ$B() throws Exception {
        byte[] buf = { 1, 2, 3, 4, 5, 6, 7, 8 };
        byte[] theBytes = { 9, 10, 11 };
        SerialBlob serialBlob = new SerialBlob(buf);

        int count = serialBlob.setBytes(1, theBytes);
        byte[] res = serialBlob.getBytes(1, buf.length);
        byte[] expected = { 9, 10, 11, 4, 5, 6, 7, 8 };
        assertTrue(Arrays.equals(expected, res));
        assertEquals(3, count);

        count = serialBlob.setBytes(2, theBytes);
        res = serialBlob.getBytes(1, buf.length);
        expected = new byte[] { 9, 9, 10, 11, 5, 6, 7, 8 };
        assertTrue(Arrays.equals(expected, res));
        assertEquals(3, count);

        count = serialBlob.setBytes(6, theBytes);
        res = serialBlob.getBytes(1, buf.length);
        expected = new byte[] { 9, 9, 10, 11, 5, 9, 10, 11 };
        assertTrue(Arrays.equals(expected, res));
        assertEquals(3, count);

        try {
            serialBlob.setBytes(-1, theBytes);
            fail("should throw SerialException");
        } catch (SerialException e) {
            // expected
        }

        try {
            serialBlob.setBytes(10, theBytes);
            fail("should throw SerialException");
        } catch (SerialException e) {
            // expected
        }

        // Non bug difference from RI, Harmony-2836
        try {
            serialBlob.setBytes(7, theBytes);
            fail("should throw SerialException");
        } catch (SerialException e) {
            // expected
        }
View Full Code Here


    }

    public void testSetBytesJ$BII() throws Exception {
        byte[] buf = { 1, 2, 3, 4, 5, 6, 7, 8 };
        byte[] theBytes = { 9, 10, 11 };
        SerialBlob serialBlob = new SerialBlob(buf);

        int count = serialBlob.setBytes(1, theBytes, 0, 3);
        byte[] res = serialBlob.getBytes(1, buf.length);
        byte[] expected = { 9, 10, 11, 4, 5, 6, 7, 8 };
        assertTrue(Arrays.equals(expected, res));
        assertEquals(3, count);

        count = serialBlob.setBytes(3, theBytes, 1, 2);
        res = serialBlob.getBytes(1, buf.length);
        expected = new byte[] { 9, 10, 10, 11, 5, 6, 7, 8 };
        assertTrue(Arrays.equals(expected, res));
        assertEquals(2, count);

        count = serialBlob.setBytes(6, theBytes, 0, 2);
        res = serialBlob.getBytes(1, buf.length);
        expected = new byte[] { 9, 10, 10, 11, 5, 9, 10, 8 };
        assertTrue(Arrays.equals(expected, res));
        assertEquals(2, count);

        try {
            serialBlob.setBytes(7, theBytes, 0, 10);
            fail("should throw SerialException");
        } catch (SerialException e) {
            // expected
        }

        try {
            serialBlob.setBytes(-1, theBytes, 0, 2);
            fail("should throw SerialException");
        } catch (SerialException e) {
            // expected
        }

        try {
            serialBlob.setBytes(10, theBytes, 0, 2);
            fail("should throw SerialException");
        } catch (SerialException e) {
            // expected
        }

        try {
            serialBlob.setBytes(1, theBytes, -1, 2);
            fail("should throw SerialException");
        } catch (SerialException e) {
            // expected
        }

        try {
            serialBlob.setBytes(1, theBytes, 0, 10);
            fail("should throw SerialException");
        } catch (SerialException e) {
            // expected
        }

        // Non bug difference from RI, Harmony-2836
        try {
            serialBlob.setBytes(7, theBytes, 0, 3);
            fail("should throw SerialException");
        } catch (SerialException e) {
            // expected
        }

        // Non bug difference from RI, Harmony-2836
        try {
            serialBlob.setBytes(7, theBytes, 0, -1);
            fail("should throw SerialException");
        } catch (SerialException e) {
            // expected
        }
    }
View Full Code Here

        }
    }

    public void testPosition$BJ() throws Exception {
        byte[] buf = { 1, 2, 3, 4, 5, 6, 7, 8 };
        SerialBlob serialBlob = new SerialBlob(buf);

        assertBlobPosition_BytePattern(serialBlob);

        MockSerialBlob mockBlob = new MockSerialBlob();
        mockBlob.buf = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
        serialBlob = new SerialBlob(mockBlob);
        assertBlobPosition_BytePattern(serialBlob);
    }
View Full Code Here

        assertBlobPosition_BytePattern(serialBlob);
    }

    public void testPositionLBlobJ() throws Exception {
        byte[] buf = { 1, 2, 3, 4, 5, 6, 7, 8 };
        SerialBlob serialBlob = new SerialBlob(buf);
        assertBlobPosition_BlobPattern(serialBlob);

        MockSerialBlob mockBlob = new MockSerialBlob();
        mockBlob.buf = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
        serialBlob = new SerialBlob(mockBlob);
        assertBlobPosition_BlobPattern(serialBlob);
    }
View Full Code Here

        assertBlobPosition_BlobPattern(serialBlob);
    }

    public void testTruncateJ() throws Exception {
        byte[] buf = { 1, 2, 3, 4, 5, 6, 7, 8 };
        SerialBlob serialBlob1 = new SerialBlob(buf);
        MockSerialBlob mockBlob = new MockSerialBlob();
        mockBlob.buf = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
        SerialBlob serialBlob2 = new SerialBlob(mockBlob);
        SerialBlob[] serialBlobs = { serialBlob1, serialBlob2 };

        for (SerialBlob serialBlob : serialBlobs) {

            serialBlob.truncate(3);
View Full Code Here

    }

    public void testSetBinaryStreamJ() throws Exception {
        MockSerialBlob mockBlob = new MockSerialBlob();
        mockBlob.binaryStream = new ByteArrayOutputStream();
        SerialBlob serialBlob = new SerialBlob(mockBlob);
        OutputStream os = serialBlob.setBinaryStream(1);
        assertTrue(mockBlob.isSetBinaryStreamInvoked);
        assertEquals(1L, mockBlob.pos);
        assertSame(mockBlob.binaryStream, os);

        mockBlob.binaryStream = null;
        try {
            serialBlob.setBinaryStream(1);
            fail("should throw SerialException");
        } catch (SerialException e) {
            // expected
        }

        byte[] buf = new byte[1];
        serialBlob = new SerialBlob(buf);
        try {
            // Non bug difference from RI, Harmony-2971
            serialBlob.setBinaryStream(1);
            fail("should throw SerialException");
        } catch (SerialException e) {
            // expected
        }
    }
View Full Code Here

                        if (blobObject != null) {
                            entity.dangerousSetNoCheckButFast(curField, blobObject);
                        } else {
                            if (originalObject instanceof Blob) {
                                // NOTE using SerialBlob here instead of the Blob from the database to make sure we can pass it around, serialize it, etc
                                entity.dangerousSetNoCheckButFast(curField, new SerialBlob((Blob) originalObject));
                            } else {
                                entity.dangerousSetNoCheckButFast(curField, originalObject);
                            }
                        }
                    }
View Full Code Here

    @Test
    public void test_insert_complex() throws Exception {
        db3.prepare("INSERT INTO TESTTYPES(c13) VALUES(?)").setBytes(1, "hello".getBytes()).commit();                    // byte arrays
        db3.prepare("INSERT INTO TESTTYPES(c14) VALUES(?)").setObject(1, UUID.randomUUID()).commit();                    // java object seralized
        db3.prepare("INSERT INTO TESTTYPES(c18) VALUES(?)").setBlob(1, new SerialBlob("hello".getBytes())).commit();     // blob
        db3.prepare("INSERT INTO TESTTYPES(c19) VALUES(?)").setClob(1, new SerialClob("hello".toCharArray())).commit()// clob
        db3.prepare("INSERT INTO TESTTYPES(column21) VALUES(?)").setObjects(1, new Object[]{1, "h", 'R'}).commit();           // array
        System.out.println(db3.prepare("SELECT * FROM TESTTYPES").query());
    }
View Full Code Here

        while (true) {
            try {
                message.getBody();
                stmt = conn.prepareStatement("INSERT INTO " + getTableNameForTopic(topic) + " VALUES(?,?)");
                stmt.setLong(1, seqId);
                stmt.setBlob(2, new SerialBlob(message.toByteArray()));

                int rowCount = stmt.executeUpdate();
                stmt.close();
                if (rowCount != 1) {
                    logger.error("Unexpected number of affected rows from derby");
View Full Code Here

            PreparedStatement ps = connection.prepareStatement(
                "INSERT INTO blo(id, b) values(2, ?)");

            //st.executeUpdate("INSERT INTO blo (id, b) VALUES (1, x'A003')");
            ps.setBlob(1, new SerialBlob(baR1));
            ps.executeUpdate();

            rs = st.executeQuery("SELECT b FROM blo WHERE id = 2");

            if (!rs.next()) {
View Full Code Here

TOP

Related Classes of javax.sql.rowset.serial.SerialBlob

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.