@Test public void testGetOperationByHash() throws FailedVerificationException { OpBlockChain opBlockChain = dbConsensusManager.init(metadataDb); generateOperations(formatter, opBlockChain); OpBlock opBlock = opBlockChain.createBlock(serverName, serverKeyPair); opBlock.getOperations().forEach(opOperation -> dbConsensusManager.insertOperation(opOperation)); OpOperation opOperation = opBlock.getOperations().get(0); assertNotNull(dbConsensusManager.getOperationByHash(opOperation.getHash())); assertEquals(1, dbConsensusManager.removeOperations(new HashSet<>(Collections.singletonList(opOperation.getHash())))); assertNull(dbConsensusManager.getOperationByHash(opOperation.getHash())); }
public OpOperation getOperationByHash(String hash) { final byte[] bhash = SecUtils.getHashBytes(hash); OpOperation[] res = new OpOperation[1]; jdbcTemplate.query("SELECT content from " + OPERATIONS_TABLE + " where hash = ?", new Object[]{bhash}, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { res[0] = formatter.parseOperation(rs.getString(1)); } }); return res[0]; }
DBConsensusManager { public OpOperation getOperationByHash(String hash) { final byte[] bhash = SecUtils.getHashBytes(hash); OpOperation[] res = new OpOperation[1]; jdbcTemplate.query("SELECT content from " + OPERATIONS_TABLE + " where hash = ?", new Object[]{bhash}, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { res[0] = formatter.parseOperation(rs.getString(1)); } }); return res[0]; } }
DBConsensusManager { public OpOperation getOperationByHash(String hash) { final byte[] bhash = SecUtils.getHashBytes(hash); OpOperation[] res = new OpOperation[1]; jdbcTemplate.query("SELECT content from " + OPERATIONS_TABLE + " where hash = ?", new Object[]{bhash}, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { res[0] = formatter.parseOperation(rs.getString(1)); } }); return res[0]; }  }
DBConsensusManager { public OpOperation getOperationByHash(String hash) { final byte[] bhash = SecUtils.getHashBytes(hash); OpOperation[] res = new OpOperation[1]; jdbcTemplate.query("SELECT content from " + OPERATIONS_TABLE + " where hash = ?", new Object[]{bhash}, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { res[0] = formatter.parseOperation(rs.getString(1)); } }); return res[0]; }  Map<String, OpBlock> getOrphanedBlocks(); String getSuperblockHash(); OpBlockChain init(MetadataDb metadataDB); OpIndexColumn getIndex(String type, String columnId); Collection<OpIndexColumn> getIndicesForType(String type); void insertBlock(OpBlock opBlock); OpBlockChain saveMainBlockchain(OpBlockChain blc); OpBlockChain compact(int prevSize, OpBlockChain blc, boolean db); int removeOperations(Set<String> ops); boolean removeFullBlock(OpBlock block); OpBlockChain unloadSuperblockFromDB(OpBlockChain blc); ResourceDTO storeResourceObject(ResourceDTO imageDTO); ResourceDTO getResourceObjectIfExists(ResourceDTO imageDTO); List<ResourceDTO> getResources(boolean status, int addedMoreThanSecondsAgo); void removeResource(ResourceDTO resDTO); void updateResourceActiveStatus(ResourceDTO imageDTO, boolean status); Long getAmountResourcesInDB(); boolean validateExistingOperation(OpOperation op); void insertOperation(OpOperation op); OpOperation getOperationByHash(String hash); String getSetting(String key); Map<String, Map<String, OpIndexColumn>> getIndices(); }
DBConsensusManager { public OpOperation getOperationByHash(String hash) { final byte[] bhash = SecUtils.getHashBytes(hash); OpOperation[] res = new OpOperation[1]; jdbcTemplate.query("SELECT content from " + OPERATIONS_TABLE + " where hash = ?", new Object[]{bhash}, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { res[0] = formatter.parseOperation(rs.getString(1)); } }); return res[0]; }  Map<String, OpBlock> getOrphanedBlocks(); String getSuperblockHash(); OpBlockChain init(MetadataDb metadataDB); OpIndexColumn getIndex(String type, String columnId); Collection<OpIndexColumn> getIndicesForType(String type); void insertBlock(OpBlock opBlock); OpBlockChain saveMainBlockchain(OpBlockChain blc); OpBlockChain compact(int prevSize, OpBlockChain blc, boolean db); int removeOperations(Set<String> ops); boolean removeFullBlock(OpBlock block); OpBlockChain unloadSuperblockFromDB(OpBlockChain blc); ResourceDTO storeResourceObject(ResourceDTO imageDTO); ResourceDTO getResourceObjectIfExists(ResourceDTO imageDTO); List<ResourceDTO> getResources(boolean status, int addedMoreThanSecondsAgo); void removeResource(ResourceDTO resDTO); void updateResourceActiveStatus(ResourceDTO imageDTO, boolean status); Long getAmountResourcesInDB(); boolean validateExistingOperation(OpOperation op); void insertOperation(OpOperation op); OpOperation getOperationByHash(String hash); String getSetting(String key); Map<String, Map<String, OpIndexColumn>> getIndices();  }