Refine search
@Override public BigInteger toJavaType(Column column, Class<?> entityType, Blob value) { if (value == null) return null; try { final byte[] bytes = value.getBytes(1, Math.toIntExact(value.length())); return new BigInteger(bytes); } catch (final SQLException ex) { throw new SpeedmentTypeMapperException( "Error mapping Blob to BigInteger.", ex); } }
/** * This is simply passing the byte value of the pattern Blob. * * @param pattern search pattern * @param start start position * @return position of given pattern * @throws SQLException if something goes wrong */ public synchronized long position(Blob pattern, long start) throws SQLException { return position(pattern.getBytes(1, (int) pattern.length()), start); }
/** * Blob 转为 String 格式 * * @param blob Blob 对象 * @return 转换后的 */ public static String blob2String(Blob blob) { if (null != blob) { try { byte[] returnValue = blob.getBytes(1, (int) blob.length()); return new String(returnValue, StandardCharsets.UTF_8); } catch (Exception e) { throw ExceptionUtils.mpe("Blob Convert To String Error!"); } } return null; }
/** * <p> This method should be overridden by any delegate subclasses that need * special handling for BLOBs. The default implementation uses standard JDBC * <code>java.sql.Blob</code> operations. </p> * * @param rs the result set, already queued to the correct row * @param colName the column name for the BLOB * @return the deserialized Object from the ResultSet BLOB * @throws ClassNotFoundException if a class found during deserialization * cannot be found * @throws IOException if deserialization causes an error */ @Override protected Object getObjectFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException { Object obj = null; InputStream binaryInput; Blob blob = rs.getBlob(colName); byte[] bytes = blob.getBytes(1, (int) blob.length()); if (bytes != null && bytes.length != 0) { binaryInput = new ByteArrayInputStream(bytes); ObjectInputStream in = new ObjectInputStream(binaryInput); try { obj = in.readObject(); } finally { in.close(); } } return obj; }
/** * <p> This method should be overridden by any delegate subclasses that need * special handling for BLOBs. The default implementation uses standard JDBC * <code>java.sql.Blob</code> operations. </p> * * @param rs the result set, already queued to the correct row * @param colName the column name for the BLOB * @return the deserialized Object from the ResultSet BLOB * @throws ClassNotFoundException if a class found during deserialization * cannot be found * @throws IOException if deserialization causes an error */ @Override protected Object getObjectFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException { Object obj = null; InputStream binaryInput; Blob blob = rs.getBlob(colName); byte[] bytes = blob.getBytes(1, (int) blob.length()); if (bytes != null && bytes.length != 0) { binaryInput = new ByteArrayInputStream(bytes); ObjectInputStream in = new ObjectInputStream(binaryInput); try { obj = in.readObject(); } finally { in.close(); } } return obj; }
static byte[] extractSqlBlob(Object value) throws MetaException { if (value == null) return null; if (value instanceof Blob) { //derby, oracle try { // getBytes function says: pos the ordinal position of the first byte in // the BLOB value to be extracted; the first byte is at position 1 return ((Blob) value).getBytes(1, (int) ((Blob) value).length()); } catch (SQLException e) { throw new MetaException("Encounter error while processing blob."); } } else if (value instanceof byte[]) { // mysql, postgres, sql server return (byte[]) value; } else { // this may happen when enablebitvector is false LOG.debug("Expected blob type but got " + value.getClass().getName()); return null; } }