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; }
@Override public byte[] toJavaType(Column column, Class<?> entityType, Blob value) { if (value == null) { return null; } else try { if (value.length() < Integer.MAX_VALUE) { return value.getBytes(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 Blob to byte[].", sqle); } }
/** * <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; }