use of java.sql.Clob in project fastjson by alibaba.
the class ClobSeriliazer method write.
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
try {
if (object == null) {
serializer.writeNull();
return;
}
Clob clob = (Clob) object;
Reader reader = clob.getCharacterStream();
StringBuilder buf = new StringBuilder();
try {
char[] chars = new char[2048];
for (; ; ) {
int len = reader.read(chars, 0, chars.length);
if (len < 0) {
break;
}
buf.append(chars, 0, len);
}
} catch (Exception ex) {
throw new JSONException("read string from reader error", ex);
}
String text = buf.toString();
reader.close();
serializer.write(text);
} catch (SQLException e) {
throw new IOException("write clob error", e);
}
}
use of java.sql.Clob in project hibernate-orm by hibernate.
the class StringValueMappingTest method testNormalClobHandling.
@Test
public void testNormalClobHandling() throws SQLException {
final ValueExtractor<String> extractor = clobSqlDescriptor.getExtractor(stringJavaDescriptor);
final ValueBinder<String> binder = clobSqlDescriptor.getBinder(stringJavaDescriptor);
final String fixture = "clob string";
final Clob clob = new StringClobImpl(fixture);
ResultSet resultSet = ResultSetProxy.generateProxy(clob);
final String value = extractor.extract(resultSet, COLUMN_NAME, wrapperOptions);
assertEquals(fixture, value);
PreparedStatement ps = PreparedStatementProxy.generateProxy(clob);
binder.bind(ps, fixture, BIND_POSITION, wrapperOptions);
}
use of java.sql.Clob in project jOOQ by jOOQ.
the class DefaultExecuteContext method clean.
/**
* Clean up blobs, clobs and the local configuration.
* <p>
* <h5>BLOBS and CLOBS</h5>
* <p>
* [#1326] This is necessary in those dialects that have long-lived
* temporary lob objects, which can cause memory leaks in certain contexts,
* where the lobs' underlying session / connection is long-lived as well.
* Specifically, Oracle and ojdbc have some trouble when streaming temporary
* lobs to UDTs:
* <ol>
* <li>The lob cannot have a call-scoped life time with UDTs</li>
* <li>Freeing the lob after binding will cause an ORA-22275</li>
* <li>Not freeing the lob after execution will cause an
* {@link OutOfMemoryError}</li>
* </ol>
* <p>
* <h5>Local configuration</h5>
* <p>
* [#1544] There exist some corner-cases regarding the {@link SQLOutput}
* API, used for UDT serialisation / deserialisation, which have no elegant
* solutions of obtaining a {@link Configuration} and thus a JDBC
* {@link Connection} object short of:
* <ul>
* <li>Making assumptions about the JDBC driver and using proprietary API,
* e.g. that of ojdbc</li>
* <li>Dealing with this problem globally by using such a local
* configuration</li>
* </ul>
*
* @see <a
* href="http://stackoverflow.com/q/11439543/521799">http://stackoverflow.com/q/11439543/521799</a>
*/
static final void clean() {
List<Blob> blobs = BLOBS.get();
List<Clob> clobs = CLOBS.get();
List<SQLXML> xmls = SQLXMLS.get();
List<Array> arrays = ARRAYS.get();
if (blobs != null) {
for (Blob blob : blobs) {
JDBCUtils.safeFree(blob);
}
BLOBS.remove();
}
if (clobs != null) {
for (Clob clob : clobs) {
JDBCUtils.safeFree(clob);
}
CLOBS.remove();
}
if (xmls != null) {
for (SQLXML xml : xmls) {
JDBCUtils.safeFree(xml);
}
SQLXMLS.remove();
}
if (arrays != null) {
for (Array array : arrays) {
JDBCUtils.safeFree(array);
}
SQLXMLS.remove();
}
LOCAL_CONFIGURATION.remove();
LOCAL_DATA.remove();
LOCAL_CONNECTION.remove();
}
use of java.sql.Clob in project jOOQ by jOOQ.
the class ClobBinding method set.
@Override
public final void set(BindingSetSQLOutputContext<String> ctx) throws SQLException {
Clob clob = newClob(ctx.configuration(), ctx.value());
DefaultExecuteContext.register(clob);
ctx.output().writeClob(clob);
}
use of java.sql.Clob in project jOOQ by jOOQ.
the class ClobBinding method newClob.
private final Clob newClob(Configuration configuration, String string) throws SQLException {
Connection c = configuration.connectionProvider().acquire();
try {
Clob clob = null;
switch(configuration.family()) {
default:
{
clob = c.createClob();
break;
}
}
clob.setString(1, string);
return clob;
} finally {
configuration.connectionProvider().release(c);
}
}
Aggregations