本文整理了Java中java.sql.Clob.length()
方法的一些代码示例,展示了Clob.length()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Clob.length()
方法的具体详情如下:
包路径:java.sql.Clob
类名称:Clob
方法名:length
[英]Retrieves the number of characters in this Clob object.
[中]检索此Clob对象中的字符数。
代码示例来源:origin: alibaba/druid
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());
}
代码示例来源:origin: spring-projects/spring-framework
@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);
}
}
代码示例来源:origin: hibernate/hibernate-orm
/**
* Determine a buffer size for reading the underlying character stream.
*
* @param value The Clob value
*
* @return The appropriate buffer size ({@link java.sql.Clob#length()} by default.
*
* @throws SQLException
*/
private static long determineLengthForBufferSizing(Clob value) throws SQLException {
try {
return value.length();
}
catch ( SQLFeatureNotSupportedException e ) {
return BUFFER_SIZE;
}
}
代码示例来源:origin: apache/incubator-gobblin
private String readClobAsString(Clob logClob) throws SQLException {
if (logClob == null) {
return StringUtils.EMPTY;
}
long length = logClob.length();
return logClob.getSubString(1, (int) length);
}
代码示例来源:origin: apache/hive
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;
}
}
代码示例来源:origin: spring-projects/spring-data-examples
@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);
}
}
}));
代码示例来源:origin: org.postgresql/postgresql
private static String asString(final Clob in) throws SQLException {
return in.getSubString(1, (int) in.length());
}
代码示例来源:origin: spring-projects/spring-data-examples
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);
}
}
代码示例来源:origin: jfinal/jfinal
public String handleClob(Clob clob) throws SQLException {
if (clob == null)
return null;
Reader reader = null;
try {
reader = clob.getCharacterStream();
if (reader == null)
return null;
char[] buffer = new char[(int)clob.length()];
if (buffer.length == 0)
return null;
reader.read(buffer);
return new String(buffer);
} catch (IOException e) {
throw new RuntimeException(e);
}
finally {
if (reader != null)
try {reader.close();} catch (IOException e) {throw new RuntimeException(e);}
}
}
代码示例来源:origin: spring-projects/spring-framework
obj = clob.getSubString(1, (int) clob.length());
代码示例来源:origin: speedment/speedment
@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);
}
}
代码示例来源:origin: speedment/speedment
@Override
public long position(final Clob clob, final long start) throws SQLException {
requireNonNull(clob);
assertNotFreeNotCalled();
return position(clob.getSubString(1, (int) clob.length()), start);
}
代码示例来源:origin: com.h2database/h2
/**
* 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();
}
代码示例来源:origin: alibaba/druid
@Override
public long clob_length(ClobProxy clob) throws SQLException {
if (this.pos < filterSize) {
return nextFilter().clob_length(this, clob);
}
return clob.getRawClob().length();
}
代码示例来源:origin: hibernate/hibernate-orm
protected final String extractString(Clob clob) throws SQLException {
if ( StringClobImpl.class.isInstance( clob ) ) {
return ( (StringClobImpl) clob ).getValue();
}
return clob.getSubString( 1, (int)clob.length() );
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
Clob rsClob;
if ( HANAClobTypeDescriptor.this.useUnicodeStringTypes ) {
rsClob = rs.getNClob( name );
}
else {
rsClob = rs.getClob( name );
}
if ( rsClob == null || rsClob.length() < HANAClobTypeDescriptor.this.maxLobPrefetchSize ) {
return javaTypeDescriptor.wrap( rsClob, options );
}
Clob clob = new MaterializedNClob( DataHelper.extractString( rsClob ) );
return javaTypeDescriptor.wrap( clob, options );
}
代码示例来源:origin: redisson/redisson
Clob clob = (Clob) value;
try {
long length = clob.length();
if (length > Integer.MAX_VALUE) {
throw new TypeConversionException("Clob is too big.");
代码示例来源:origin: hibernate/hibernate-orm
@Override
public Clob mergeClob(Clob original, Clob target, SharedSessionContractImplementor session) {
if ( original == null && target == null ) {
return null;
}
try {
final LobCreator lobCreator = session.getFactory().getServiceRegistry().getService( JdbcServices.class ).getLobCreator( session );
return original == null
? lobCreator.createClob( "" )
: lobCreator.createClob( original.getCharacterStream(), original.length() );
}
catch (SQLException e) {
throw session.getFactory().getSQLExceptionHelper().convert( e, "unable to merge CLOB data" );
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testClob() {
final int id = doInHibernate( this::sessionFactory, s -> {
FileClob file = new FileClob();
file.setClob( s.getLobHelper().createClob( "TEST CASE" ) );
// merge transient entity
file = (FileClob) s.merge( file );
return file.getId();
} );
doInHibernate( this::sessionFactory, s -> {
FileClob file = s.get( FileClob.class, id );
assertFalse( Hibernate.isPropertyInitialized( file, "clob" ) );
Clob clob = file.getClob();
try {
final char[] chars = new char[(int) file.getClob().length()];
clob.getCharacterStream().read( chars );
assertTrue( Arrays.equals( "TEST CASE".toCharArray(), chars ) );
}
catch (SQLException ex ) {
fail( "could not determine Lob length" );
}
catch (IOException ex) {
fail( "could not read Lob" );
}
});
}
代码示例来源:origin: oblac/jodd
@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));
}
}
}
内容来源于网络,如有侵权,请联系作者删除!