Java Code Examples for java.sql.Clob#setAsciiStream()
The following examples show how to use
java.sql.Clob#setAsciiStream() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Dialect.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public Clob mergeClob(Clob original, Clob target, SharedSessionContractImplementor session) { if ( original != target ) { try { // the CLOB just read during the load phase of merge final OutputStream connectedStream = target.setAsciiStream( 1L ); // the CLOB from the detached state final InputStream detachedStream = original.getAsciiStream(); StreamCopier.copy( detachedStream, connectedStream ); return target; } catch (SQLException e ) { throw session.getFactory().getSQLExceptionHelper().convert( e, "unable to merge CLOB data" ); } } else { return NEW_LOCATOR_LOB_MERGE_STRATEGY.mergeClob( original, target, session ); } }
Example 2
Source File: JdbcUtil.java From iaf with Apache License 2.0 | 5 votes |
/** * retrieves an outputstream to a clob column from an updatable resultset. */ public static OutputStream getClobUpdateOutputStreamxxx(ResultSet rs, int columnIndex) throws SQLException, JdbcException { Clob clob = rs.getClob(columnIndex); if (clob==null) { throw new JdbcException("no clob found in column ["+columnIndex+"]"); } return clob.setAsciiStream(1L); }
Example 3
Source File: LobStreamsTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * 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()); long new_length = rs3.getClob(1).length(); assertEquals("FAIL -- wrong clob length", streamSize[1], new_length); // Check contents ... InputStream fStream = new LoopingAlphabetStream(streamSize[1]); InputStream lStream = rs3.getClob(1).getAsciiStream(); assertTrue("FAIL - Clob and file contents do not match", compareLob2File(fStream, lStream)); fStream.close(); lStream.close(); rs3.close(); stmt3.close(); }
Example 4
Source File: LobStreamsTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * 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()); long new_length = rs3.getClob(1).length(); assertEquals("FAIL -- wrong clob length", streamSize[0], new_length); // Check contents ... InputStream fStream = new LoopingAlphabetStream(streamSize[0]); InputStream lStream = rs3.getClob(1).getAsciiStream(); assertTrue("FAIL - Clob and file contents do not match", compareLob2File(fStream, lStream)); fStream.close(); lStream.close(); rs3.close(); stmt3.close(); }
Example 5
Source File: ConnectionMethodsTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Test the createClob method implementation in the Connection interface * * @exception SQLException, FileNotFoundException, Exception if error occurs */ public void testCreateClob() throws SQLException, FileNotFoundException, IOException, Exception{ Connection conn = getConnection(); int b, c; Clob clob; Statement s = createStatement(); PreparedStatement ps = prepareStatement("insert into clobtable2 (n, clobcol)" + " values(?,?)"); ps.setInt(1,1000); clob = conn.createClob(); try { is = (FileInputStream) AccessController.doPrivileged( new PrivilegedExceptionAction() { public Object run() throws FileNotFoundException { return new FileInputStream("extin/short.txt"); } }); } catch (PrivilegedActionException e) { // e.getException() should be an instance of FileNotFoundException, // as only "checked" exceptions will be "wrapped" in a // PrivilegedActionException. throw (FileNotFoundException) e.getException(); } OutputStream os = clob.setAsciiStream(1); ArrayList beforeUpdateList = new ArrayList(); c = is.read(); while(c>0) { os.write(c); beforeUpdateList.add(c); c = is.read(); } ps.setClob(2, clob); ps.executeUpdate(); Statement stmt = createStatement(); ResultSet rs = stmt.executeQuery("select clobcol from clobtable2 where n = 1000"); assertTrue(rs.next()); clob = rs.getClob(1); assertEquals(beforeUpdateList.size(), clob.length()); //Get the InputStream from this Clob. InputStream in = clob.getAsciiStream(); ArrayList afterUpdateList = new ArrayList(); b = in.read(); while (b > -1) { afterUpdateList.add(b); b = in.read(); } assertEquals(beforeUpdateList.size(), afterUpdateList.size()); //Now check if the two InputStreams //match for (int i = 0; i < clob.length(); i++) { assertEquals(beforeUpdateList.get(i), afterUpdateList.get(i)); } os.close(); is.close(); }
Example 6
Source File: LobStreamsTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * 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()); long new_length = rs3.getClob(1).length(); assertEquals("FAIL -- wrong clob length", streamSize[1], new_length); // Check contents ... InputStream fStream = new LoopingAlphabetStream(streamSize[1]); InputStream lStream = rs3.getClob(1).getAsciiStream(); assertTrue("FAIL - Clob and file contents do not match", compareLob2File(fStream, lStream)); fStream.close(); lStream.close(); rs3.close(); stmt3.close(); }
Example 7
Source File: LobStreamsTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * 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()); long new_length = rs3.getClob(1).length(); assertEquals("FAIL -- wrong clob length", streamSize[0], new_length); // Check contents ... InputStream fStream = new LoopingAlphabetStream(streamSize[0]); InputStream lStream = rs3.getClob(1).getAsciiStream(); assertTrue("FAIL - Clob and file contents do not match", compareLob2File(fStream, lStream)); fStream.close(); lStream.close(); rs3.close(); stmt3.close(); }
Example 8
Source File: ConnectionMethodsTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Test the createClob method implementation in the Connection interface * * @exception SQLException, FileNotFoundException, Exception if error occurs */ public void testCreateClob() throws SQLException, FileNotFoundException, IOException, Exception{ Connection conn = getConnection(); int b, c; Clob clob; Statement s = createStatement(); PreparedStatement ps = prepareStatement("insert into clobtable2 (n, clobcol)" + " values(?,?)"); ps.setInt(1,1000); clob = conn.createClob(); try { is = (FileInputStream) AccessController.doPrivileged( new PrivilegedExceptionAction() { public Object run() throws FileNotFoundException { return new FileInputStream("extin/short.txt"); } }); } catch (PrivilegedActionException e) { // e.getException() should be an instance of FileNotFoundException, // as only "checked" exceptions will be "wrapped" in a // PrivilegedActionException. throw (FileNotFoundException) e.getException(); } OutputStream os = clob.setAsciiStream(1); ArrayList beforeUpdateList = new ArrayList(); c = is.read(); while(c>0) { os.write(c); beforeUpdateList.add(c); c = is.read(); } ps.setClob(2, clob); ps.executeUpdate(); Statement stmt = createStatement(); ResultSet rs = stmt.executeQuery("select clobcol from clobtable2 where n = 1000"); assertTrue(rs.next()); clob = rs.getClob(1); assertEquals(beforeUpdateList.size(), clob.length()); //Get the InputStream from this Clob. InputStream in = clob.getAsciiStream(); ArrayList afterUpdateList = new ArrayList(); b = in.read(); while (b > -1) { afterUpdateList.add(b); b = in.read(); } assertEquals(beforeUpdateList.size(), afterUpdateList.size()); //Now check if the two InputStreams //match for (int i = 0; i < clob.length(); i++) { assertEquals(beforeUpdateList.get(i), afterUpdateList.get(i)); } os.close(); is.close(); }
Example 9
Source File: LobStreamsTest.java From spliceengine with GNU Affero General Public License v3.0 | 4 votes |
/** * 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(); }
Example 10
Source File: LobStreamsTest.java From spliceengine with GNU Affero General Public License v3.0 | 4 votes |
/** * 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(); }
Example 11
Source File: ConnectionMethodsTest.java From spliceengine with GNU Affero General Public License v3.0 | 4 votes |
/** * Test the createClob method implementation in the Connection interface * * @exception SQLException, FileNotFoundException, Exception if error occurs */ public void testCreateClob() throws SQLException, FileNotFoundException, IOException, Exception{ Connection conn = getConnection(); int b, c; Clob clob; Statement s = createStatement(); PreparedStatement ps = prepareStatement("insert into clobtable2 (n, clobcol)" + " values(?,?)"); ps.setInt(1,1000); clob = conn.createClob(); try { is = AccessController.doPrivileged( new PrivilegedExceptionAction<FileInputStream>() { public FileInputStream run() throws FileNotFoundException { return new FileInputStream("extin/short.txt"); } }); } catch (PrivilegedActionException e) { // e.getException() should be an instance of FileNotFoundException, // as only "checked" exceptions will be "wrapped" in a // PrivilegedActionException. throw (FileNotFoundException) e.getException(); } OutputStream os = clob.setAsciiStream(1); ArrayList<Integer> beforeUpdateList = new ArrayList<Integer>(); c = is.read(); while(c>0) { os.write(c); beforeUpdateList.add(c); c = is.read(); } ps.setClob(2, clob); ps.executeUpdate(); Statement stmt = createStatement(); ResultSet rs = stmt.executeQuery("select clobcol from clobtable2 where n = 1000"); assertTrue(rs.next()); clob = rs.getClob(1); assertEquals(beforeUpdateList.size(), clob.length()); //Get the InputStream from this Clob. InputStream in = clob.getAsciiStream(); ArrayList<Integer> afterUpdateList = new ArrayList<Integer>(); b = in.read(); while (b > -1) { afterUpdateList.add(b); b = in.read(); } assertEquals(beforeUpdateList.size(), afterUpdateList.size()); //Now check if the two InputStreams //match for (int i = 0; i < clob.length(); i++) { assertEquals(beforeUpdateList.get(i), afterUpdateList.get(i)); } os.close(); is.close(); }