@Override @Nullable public String getClobAsString(ResultSet rs, int columnIndex) throws SQLException { logger.debug("Returning CLOB as string"); if (this.wrapAsLob) { Clob clob = rs.getClob(columnIndex); return clob.getSubString(1, (int) clob.length()); } else { return rs.getString(columnIndex); } }
public String getClobAsString(ResultSet rs, int columnIndex) throws SQLException { Clob clob = rs.getClob(columnIndex); if (clob == null) { return null; } return clob.getSubString(1, (int) clob.length()); }
private String readClobAsString(Clob logClob) throws SQLException { if (logClob == null) { return StringUtils.EMPTY; } long length = logClob.length(); return logClob.getSubString(1, (int) length); }
private static String asString(final Clob in) throws SQLException { return in.getSubString(1, (int) in.length()); }
@Nullable @Override public String convert(Clob clob) { try { return Math.toIntExact(clob.length()) == 0 // ? "" // : clob.getSubString(1, Math.toIntExact(clob.length())); } catch (SQLException e) { throw new IllegalStateException("Failed to convert CLOB to String.", e); } } }));
static String extractSqlClob(Object value) { if (value == null) return null; try { if (value instanceof Clob) { // we trim the Clob value to a max length an int can hold int maxLength = (((Clob)value).length() < Integer.MAX_VALUE - 2) ? (int)((Clob)value).length() : Integer.MAX_VALUE - 2; return ((Clob)value).getSubString(1L, maxLength); } else { return value.toString(); } } catch (SQLException sqle) { return null; } }
ModelMapEntry(String name, Clob description) { key = name; value = new Model(); value.name = name; try { value.description = description.getSubString(1, (int) description.length()); } catch (SQLException se) { throw new RuntimeException(se); } }
obj = clob.getSubString(1, (int) clob.length());
@Override public long position(final Clob clob, final long start) throws SQLException { requireNonNull(clob); assertNotFreeNotCalled(); return position(clob.getSubString(1, (int) clob.length()), start); }
/** * Returns the value as a String. * * @param columnIndex (1,2,...) * @return the value */ @Override public String getString(int columnIndex) throws SQLException { Object o = get(columnIndex); if (o == null) { return null; } switch (columns.get(columnIndex - 1).sqlType) { case Types.CLOB: Clob c = (Clob) o; return c.getSubString(1, MathUtils.convertLongToInt(c.length())); } return o.toString(); }
@Override public String clob_getSubString(ClobProxy clob, long pos, int length) throws SQLException { if (this.pos < filterSize) { return nextFilter().clob_getSubString(this, clob, pos, length); } return clob.getRawClob().getSubString(pos, length); }
@Override public String toJavaType(Column column, Class<?> entityType, Clob value) { if (value == null) { return null; } else try { if (value.length() < Integer.MAX_VALUE) { return value.getSubString(1, (int) value.length()); } else { throw new SpeedmentTypeMapperException( "The provided Clob contains too many characters >" + Integer.MAX_VALUE ); } } catch (final SQLException sqle) { throw new SpeedmentTypeMapperException("Unable to convert Clob to String.", sqle); } }
/** * Returns the value as a String. * * @param columnIndex (1,2,...) * @return the value */ @Override public String getString(int columnIndex) throws SQLException { Object o = get(columnIndex); if (o == null) { return null; } switch (columns.get(columnIndex - 1).sqlType) { case Types.CLOB: Clob c = (Clob) o; return c.getSubString(1, MathUtils.convertLongToInt(c.length())); } return o.toString(); }
protected final String extractString(Clob clob) throws SQLException { if ( StringClobImpl.class.isInstance( clob ) ) { return ( (StringClobImpl) clob ).getValue(); } return clob.getSubString( 1, (int)clob.length() ); }
throw new TypeConversionException("Clob is too big."); return clob.getSubString(1, (int) length); } catch (SQLException sex) { throw new TypeConversionException(value, sex);
row.put(k, clob.getSubString(1, (int) clob.length()));
try { assertThat( clobField.getSubString( 1, (int) clobField.length() ), is( value3 ) );
b.getClob().getSubString(2, 3); b.setBlob(null); b.getClob().getSubString(1, 6); s.beginTransaction(); b = (Blobber) s.load( Blobber.class, new Integer( b.getId() ) ); assertTrue( b.getClob().getSubString(1, 7).equals("xcvfxvc") );
b.getClob().getSubString(2, 3); b.setBlob(null); b.getClob().getSubString(1, 6); s.beginTransaction(); b = (Blobber) s.load( Blobber.class, new Integer( b.getId() ) ); assertTrue( b.getClob().getSubString(1, 7).equals("xcvfxvc") );
@Test void testStringConverter() throws SQLException { StringConverter stringConverter = new StringConverter(); assertNull(stringConverter.convert(null)); assertEquals("123", stringConverter.convert("123")); assertEquals("65,66", stringConverter.convert(arrb(65, 66))); assertEquals("Ab", stringConverter.convert(arrc('A', 'b'))); assertEquals("One,two", stringConverter.convert(arrs("One", "two"))); assertEquals("123", stringConverter.convert(123)); assertEquals("java.lang.String", stringConverter.convert(String.class)); assertEquals("123,456", stringConverter.convert(arri(123,456))); assertEquals("123,456", stringConverter.convert(arrl(123L,456L))); assertEquals("777777.6,-32321.7", stringConverter.convert(arrf(777777.6f, -32321.7F))); assertEquals("777777.6676732,-32321.700985", stringConverter.convert(arrd(777777.6676732D, -32321.700985D))); assertEquals("12,-66", stringConverter.convert(arrs(12,-66))); assertEquals("true,false,true", stringConverter.convert(arrl(true,false,true))); { // Clob via Mock final Clob mock = Mockito.mock(Clob.class); Mockito.when(mock.length()).thenReturn(123456789L); Mockito.when(mock.getSubString(Mockito.eq(1L), Mockito.eq(123456789))).thenReturn("Hello there :-)"); assertEquals("Hello there :-)", stringConverter.convert(mock)); } } }