List of usage examples for org.springframework.jdbc LobRetrievalFailureException LobRetrievalFailureException
public LobRetrievalFailureException(String msg, IOException ex)
From source file:org.dcache.chimera.FsSqlDriver.java
int read(FsInode inode, int level, long beginIndex, byte[] data, int offset, int len) { ResultSetExtractor<Integer> extractor = rs -> { try {//from w w w .j av a 2s . co m int count = 0; if (rs.next()) { InputStream in = rs.getBinaryStream(1); if (in != null) { in.skip(beginIndex); int c; while (((c = in.read()) != -1) && (count < len)) { data[offset + count] = (byte) c; ++count; } } } return count; } catch (IOException e) { throw new LobRetrievalFailureException(e.getMessage(), e); } }; if (level == 0) { return _jdbc.query("SELECT ifiledata FROM t_inodes_data WHERE inumber=?", extractor, inode.ino()); } else { return _jdbc.query("SELECT ifiledata FROM t_level_" + level + " WHERE inumber=?", extractor, inode.ino()); } }
From source file:org.dcache.chimera.FsSqlDriver.java
Map<String, byte[]> getAllTags(FsInode inode) { Map<String, byte[]> tags = new HashMap<>(); _jdbc.query("SELECT t.itagname, i.ivalue, i.isize " + "FROM t_tags t JOIN t_tags_inodes i ON t.itagid = i.itagid WHERE t.inumber=?", ps -> { ps.setLong(1, inode.ino()); }, rs -> {//from www . ja v a 2 s. co m try (InputStream in = rs.getBinaryStream("ivalue")) { byte[] data = new byte[Ints.saturatedCast(rs.getLong("isize"))]; // we get null if filed id NULL, e.g not set if (in != null) { ByteStreams.readFully(in, data); tags.put(rs.getString("itagname"), data); } } catch (IOException e) { throw new LobRetrievalFailureException(e.getMessage(), e); } }); return tags; }
From source file:org.dcache.chimera.FsSqlDriver.java
/** * get content of the tag associated with name for inode * * @param inode// w w w . j a v a 2s . c o m * @param tagName * @param data * @param offset * @param len * @return */ int getTag(FsInode inode, String tagName, byte[] data, int offset, int len) { return _jdbc.query("SELECT i.ivalue,i.isize FROM t_tags t JOIN t_tags_inodes i ON t.itagid = i.itagid " + "WHERE t.inumber=? AND t.itagname=?", ps -> { ps.setLong(1, inode.ino()); ps.setString(2, tagName); }, rs -> { if (rs.next()) { try (InputStream in = rs.getBinaryStream("ivalue")) { /* some databases (hsqldb in particular) fill a full record for * BLOBs and on read reads a full record, which is not what we expect. */ return ByteStreams.read(in, data, offset, Math.min(len, (int) rs.getLong("isize"))); } catch (IOException e) { throw new LobRetrievalFailureException(e.getMessage(), e); } } return 0; }); }