use of java.sql.SQLXML in project druid by alibaba.
the class ConnectionProxyImpl method createSQLXML.
@Override
public SQLXML createSQLXML() throws SQLException {
FilterChainImpl chain = createChain();
SQLXML value = chain.connection_createSQLXML(this);
recycleFilterChain(chain);
return value;
}
use of java.sql.SQLXML 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.SQLXML in project voltdb by VoltDB.
the class JDBCResultSet method getSQLXML.
//#endif JAVA6
/**
* Retrieves the value of the designated column in the current row of
* this <code>ResultSet</code> as a
* <code>java.sql.SQLXML</code> object in the Java programming language.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return a <code>SQLXML</code> object that maps an <code>SQL XML</code> value
* @throws SQLException if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since JDK 1.6, HSQLDB 1.9.0
*/
//#ifdef JAVA6
public SQLXML getSQLXML(int columnIndex) throws SQLException {
checkColumn(columnIndex);
SQLXML sqlxml;
int type = resultMetaData.columnTypes[columnIndex - 1].typeCode;
switch(type) {
case Types.SQL_XML:
{
Object object = getObject(columnIndex);
if (object == null) {
sqlxml = null;
} else if (object instanceof SQLXML) {
sqlxml = (SQLXML) object;
} else {
throw Util.notSupported();
}
break;
}
case Types.SQL_CLOB:
{
Clob clob = getClob(columnIndex);
if (clob == null) {
sqlxml = null;
} else {
sqlxml = new JDBCSQLXML(clob.getCharacterStream());
}
break;
}
case Types.SQL_CHAR:
case Types.SQL_VARCHAR:
case Types.VARCHAR_IGNORECASE:
{
java.io.Reader reader = getCharacterStream(columnIndex);
if (reader == null) {
sqlxml = null;
} else {
sqlxml = new JDBCSQLXML(reader);
}
break;
}
case Types.SQL_NCHAR:
case Types.SQL_NVARCHAR:
{
java.io.Reader nreader = getNCharacterStream(columnIndex);
if (nreader == null) {
sqlxml = null;
} else {
sqlxml = new JDBCSQLXML(nreader);
}
break;
}
case Types.SQL_BLOB:
{
Blob blob = getBlob(columnIndex);
if (blob == null) {
sqlxml = null;
} else {
sqlxml = new JDBCSQLXML(blob.getBinaryStream());
}
break;
}
case Types.SQL_BINARY:
case Types.SQL_VARBINARY:
{
java.io.InputStream inputStream = getBinaryStream(columnIndex);
if (inputStream == null) {
sqlxml = null;
} else {
sqlxml = new JDBCSQLXML(inputStream);
}
break;
}
case Types.OTHER:
case Types.JAVA_OBJECT:
{
Object data = getObject(columnIndex);
if (data == null) {
sqlxml = null;
} else if (data instanceof SQLXML) {
sqlxml = (SQLXML) data;
} else if (data instanceof String) {
sqlxml = new JDBCSQLXML((String) data);
} else if (data instanceof byte[]) {
sqlxml = new JDBCSQLXML((byte[]) data);
} else if (data instanceof Blob) {
Blob blob = (Blob) data;
sqlxml = new JDBCSQLXML(blob.getBinaryStream());
} else if (data instanceof Clob) {
Clob clob = (Clob) data;
sqlxml = new JDBCSQLXML(clob.getCharacterStream());
} else {
throw Util.notSupported();
}
break;
}
default:
{
throw Util.notSupported();
}
}
return sqlxml;
}
use of java.sql.SQLXML in project databus by linkedin.
the class OracleAvroGenericEventFactory method putSimpleValue.
/**
* Copies the value of a simple-type event fields from DB field value to an Avro record
* @param record the Avro record to populate
* @param schemaFieldName the name of the Avro field
* @param avroFieldType the type of the Avro field
* @param databaseFieldValue the JDBC field value from the ResultSet (cannot be null)
* @throws EventCreationException if the conversion from JDBC type to Avro type failed
*/
private void putSimpleValue(GenericRecord record, String schemaFieldName, Type avroFieldType, Object databaseFieldValue) throws EventCreationException {
assert null != databaseFieldValue;
switch(avroFieldType) {
case BOOLEAN:
record.put(schemaFieldName, ((Boolean) databaseFieldValue).booleanValue());
break;
case BYTES:
if (databaseFieldValue instanceof byte[]) {
record.put(schemaFieldName, ByteBuffer.wrap((byte[]) databaseFieldValue));
} else {
record.put(schemaFieldName, extractBlobBytes((Blob) databaseFieldValue, schemaFieldName));
}
break;
case DOUBLE:
record.put(schemaFieldName, ((Number) databaseFieldValue).doubleValue());
break;
case FLOAT:
record.put(schemaFieldName, ((Number) databaseFieldValue).floatValue());
break;
case INT:
record.put(schemaFieldName, ((Number) databaseFieldValue).intValue());
break;
case LONG:
Class<?> timestampClass = null, dateClass = null;
Method timestampValueMethod = null;
try {
timestampClass = OracleJarUtils.loadClass("oracle.sql.TIMESTAMP");
dateClass = OracleJarUtils.loadClass("oracle.sql.DATE");
timestampValueMethod = timestampClass.getMethod("timestampValue");
} catch (Exception e) {
String errMsg = "Cannot convert " + databaseFieldValue.getClass() + " to long for field " + schemaFieldName + " Unable to get oracle datatypes " + e.getMessage();
throw new EventCreationException(errMsg);
}
if (databaseFieldValue instanceof Timestamp) {
long time = ((Timestamp) databaseFieldValue).getTime();
record.put(schemaFieldName, time);
} else if (databaseFieldValue instanceof Date) {
long time = ((Date) databaseFieldValue).getTime();
record.put(schemaFieldName, time);
} else if (timestampClass.isInstance(databaseFieldValue)) {
try {
Object tsc = timestampClass.cast(databaseFieldValue);
Timestamp tsValue = (Timestamp) timestampValueMethod.invoke(tsc);
long time = tsValue.getTime();
record.put(schemaFieldName, time);
} catch (Exception ex) {
throw new EventCreationException("SQLException reading oracle.sql.TIMESTAMP value for field " + schemaFieldName, ex);
}
} else if (dateClass.isInstance(databaseFieldValue)) {
try {
Object dsc = dateClass.cast(databaseFieldValue);
Timestamp tsValue = (Timestamp) timestampValueMethod.invoke(dsc);
long time = tsValue.getTime();
record.put(schemaFieldName, time);
} catch (Exception ex) {
throw new EventCreationException("SQLException reading oracle.sql.TIMESTAMP value for field " + schemaFieldName, ex);
}
} else /**
* This needs to stay after Oracle.sql.Timestamp because the timestamp class extends/implements the Number,BigDecimal classes,
* so it will pass as a number in the instanceof check. To avoid this we stick to this order.
*/
if (databaseFieldValue instanceof Number) {
long lvalue = ((Number) databaseFieldValue).longValue();
record.put(schemaFieldName, lvalue);
} else {
throw new EventCreationException("Cannot convert " + databaseFieldValue.getClass() + " to long for field " + schemaFieldName);
}
break;
case STRING:
if (databaseFieldValue instanceof Clob) {
String text = extractClobText((Clob) databaseFieldValue, schemaFieldName);
record.put(schemaFieldName, text);
} else if (databaseFieldValue instanceof SQLXML) {
SQLXML xmlInst = (SQLXML) databaseFieldValue;
try {
record.put(schemaFieldName, xmlInst.getString());
} catch (SQLException e) {
throw new EventCreationException("Cannot convert " + databaseFieldValue.getClass() + " to string field " + schemaFieldName + " cause: " + e);
}
} else {
String text = databaseFieldValue.toString();
record.put(schemaFieldName, text);
}
break;
case NULL:
record.put(schemaFieldName, null);
break;
default:
throw new EventCreationException("unknown simple type " + avroFieldType.toString() + " for field " + schemaFieldName);
}
}
use of java.sql.SQLXML in project druid by alibaba.
the class ResultSetProxyImpl method getSQLXML.
@Override
public SQLXML getSQLXML(int columnIndex) throws SQLException {
FilterChainImpl chain = createChain();
SQLXML value = chain.resultSet_getSQLXML(this, columnIndex);
recycleFilterChain(chain);
return value;
}
Aggregations