public void deleteKey(final int id) throws SQLException { final String query = "DELETE FROM prekeystore WHERE id = ?"; try (PreparedStatement stmt = Database.ensureTableExists(this).prepareStatement(query)) { stmt.setInt(1, id); stmt.execute(); } }
public void storeKey(final int id, final PreKeyRecord preKey) throws SQLException { final String query = "MERGE INTO prekeystore VALUES (?, ?)"; try (PreparedStatement stmt = Database.ensureTableExists(this).prepareStatement(query)) { stmt.setInt(1, id); stmt.setBytes(2, preKey.serialize()); stmt.execute(); } }
public PreKeyRecord getKey(final int id) throws SQLException { final String query = "SELECT prekey FROM prekeystore WHERE id = ?"; try (PreparedStatement stmt = Database.ensureTableExists(this).prepareStatement(query)) { stmt.setInt(1, id); final ResultSet result = stmt.executeQuery(); if (result.first()) { try { return new PreKeyRecord(result.getBytes(1)); } catch (final IOException e) { throw new SQLException("PreKeyTable: Value of prekey for id [" + id + "] is invalid.", e); } } else { return null; } } }