use of java.sql.Blob in project jdk8u_jdk by JetBrains.
the class BaseRowSetTests method testAdvancedParameters.
/*
* DataProvider used to set advanced parameters for types that are supported
*/
@DataProvider(name = "testAdvancedParameters")
private Object[][] testAdvancedParameters() throws SQLException {
byte[] bytes = new byte[10];
Ref aRef = new SerialRef(new StubRef("INTEGER", query));
Array aArray = new SerialArray(new StubArray("INTEGER", new Object[1]));
Blob aBlob = new SerialBlob(new StubBlob());
Clob aClob = new SerialClob(new StubClob());
Reader rdr = new StringReader(query);
InputStream is = new StringBufferInputStream(query);
;
brs = new StubBaseRowSet();
brs.setBytes(1, bytes);
brs.setAsciiStream(2, is, query.length());
brs.setRef(3, aRef);
brs.setArray(4, aArray);
brs.setBlob(5, aBlob);
brs.setClob(6, aClob);
brs.setBinaryStream(7, is, query.length());
brs.setUnicodeStream(8, is, query.length());
brs.setCharacterStream(9, rdr, query.length());
return new Object[][] { { 1, bytes }, { 2, is }, { 3, aRef }, { 4, aArray }, { 5, aBlob }, { 6, aClob }, { 7, is }, { 8, is }, { 9, rdr } };
}
use of java.sql.Blob in project adempiere by adempiere.
the class GridTable method readData.
// setDeleteable
/**************************************************************************
* Read Data from Recordset
* @param rs result set
* @return Data Array
*/
private Object[] readData(ResultSet rs) {
int size = m_fields.size();
Object[] rowData = new Object[size];
String columnName = null;
int displayType = 0;
// Types see also MField.createDefault
try {
// get row data
for (int j = 0; j < size; j++) {
// Column Info
GridField field = (GridField) m_fields.get(j);
columnName = field.getColumnName();
displayType = field.getDisplayType();
// Integer, ID, Lookup (UpdatedBy is a numeric column)
if (displayType == DisplayType.Integer || (DisplayType.isID(displayType) && (columnName.endsWith("_ID") || columnName.endsWith("_Acct") || columnName.equals("AD_Key") || columnName.equals("AD_Display"))) || columnName.endsWith("atedBy")) {
// Integer
rowData[j] = new Integer(rs.getInt(j + 1));
if (rs.wasNull())
rowData[j] = null;
} else // Number
if (DisplayType.isNumeric(displayType))
// BigDecimal
rowData[j] = rs.getBigDecimal(j + 1);
else // Date
if (DisplayType.isDate(displayType))
// Timestamp
rowData[j] = rs.getTimestamp(j + 1);
else // RowID or Key (and Selection)
if (displayType == DisplayType.RowID)
rowData[j] = null;
else // YesNo
if (displayType == DisplayType.YesNo) {
String str = rs.getString(j + 1);
if (field.isEncryptedColumn())
str = (String) decrypt(str);
// Boolean
rowData[j] = new Boolean("Y".equals(str));
} else // LOB
if (DisplayType.isLOB(displayType)) {
Object value = rs.getObject(j + 1);
if (rs.wasNull())
rowData[j] = null;
else if (value instanceof Clob) {
Clob lob = (Clob) value;
long length = lob.length();
rowData[j] = lob.getSubString(1, (int) length);
} else if (value instanceof Blob) {
Blob lob = (Blob) value;
long length = lob.length();
rowData[j] = lob.getBytes(1, (int) length);
} else if (value instanceof String)
rowData[j] = value;
else if (value instanceof byte[])
rowData[j] = value;
} else
// String
// String
rowData[j] = rs.getString(j + 1);
// Encrypted
if (field.isEncryptedColumn() && displayType != DisplayType.YesNo)
rowData[j] = decrypt(rowData[j]);
}
} catch (SQLException e) {
log.log(Level.SEVERE, columnName + ", DT=" + displayType, e);
}
return rowData;
}
use of java.sql.Blob in project adempiere by adempiere.
the class PO method get_LOB.
// getFindParameter
/**************************************************************************
* Load LOB
* @param value LOB
* @return object
*/
private Object get_LOB(Object value) {
log.fine("Value=" + value);
if (value == null)
return null;
//
Object retValue = null;
long length = -99;
try {
//[ 1643996 ] Chat not working in postgres port
if (value instanceof String || value instanceof byte[])
retValue = value;
else if (// returns String
value instanceof Clob) {
Clob clob = (Clob) value;
length = clob.length();
retValue = clob.getSubString(1, (int) length);
} else if (// returns byte[]
value instanceof Blob) {
Blob blob = (Blob) value;
length = blob.length();
// correct
int index = 1;
if (blob.getClass().getName().equals("oracle.jdbc.rowset.OracleSerialBlob"))
// Oracle Bug Invalid Arguments
index = 0;
// at oracle.jdbc.rowset.OracleSerialBlob.getBytes(OracleSerialBlob.java:130)
retValue = blob.getBytes(index, (int) length);
} else
log.log(Level.SEVERE, "Unknown: " + value);
} catch (Exception e) {
log.log(Level.SEVERE, "Length=" + length, e);
}
return retValue;
}
use of java.sql.Blob in project adempiere by adempiere.
the class WMediaDialog method createMedia.
// displayData
private AMedia createMedia() throws SQLException {
AMedia media;
String contentType = null;
if (m_data instanceof byte[]) {
media = new AMedia(this.getTitle(), null, contentType, (byte[]) m_data);
} else if (m_data instanceof Blob) {
media = new AMedia(this.getTitle(), null, contentType, ((Blob) m_data).getBinaryStream());
} else if (m_data instanceof Clob) {
Clob clob = (Clob) m_data;
long length = clob.length() > 100 ? 100 : clob.length();
String data = ((Clob) m_data).getSubString(1, new Long(length).intValue());
if (data.toUpperCase().indexOf("<html>") >= 0) {
contentType = "text/html";
} else {
contentType = "text/plain";
}
media = new AMedia(this.getTitle(), null, contentType, ((Clob) m_data).getCharacterStream());
} else {
contentType = "text/plain";
media = new AMedia(this.getTitle(), null, contentType, m_data.toString());
}
return media;
}
use of java.sql.Blob in project cubrid-manager by CUBRID.
the class CUBRIDConnectionProxyTest method methodCreateBlob.
/**
* Test method for
* {@link com.cubrid.jdbc.proxy.driver.CUBRIDConnectionProxy#createBlob()} .
*/
public void methodCreateBlob(CUBRIDConnectionProxy conn) throws SQLException {
Blob blob = conn.createBlob();
assertNotNull(blob);
}
Aggregations