@Test public void testGetFavorites() throws Exception { List<Map<String, byte[]>> queryResult = prepareFavorites(); Mockito.doReturn(queryResult).when(transaction).select(Mockito.anyString(), Mockito.eq(username.getUsername())); List<Experiment.ID> results = databaseFavoritesRepository.getFavorites(username); Assert.assertArrayEquals("Not all expected favorites are returned.", expectedResult(queryResult).toArray(), results.toArray()); }
@Override public List<Experiment.ID> getFavorites(UserInfo.Username username) { String updateSQL = "UPDATE user_experiment_properties INNER JOIN experiment " + "ON user_experiment_properties.experiment_id = experiment.id " + "SET user_experiment_properties.is_favorite = 0 " + "WHERE experiment.state = 'DELETED' AND user_experiment_properties.is_favorite = 1;"; transactionFactory.newTransaction().update(updateSQL); String sql = "SELECT experiment_id FROM user_experiment_properties WHERE user_id = ? AND is_favorite = 1;"; List list = transactionFactory.newTransaction().select(sql, username.toString()); List<Experiment.ID> favorites = new ArrayList<>(list.size()); for (Object row : list) { if (row instanceof Map) { Map map = (Map) row; if (map.get("experiment_id") instanceof byte[]) { favorites.add(Experiment.ID.valueOf((byte[]) map.get("experiment_id"))); } } } return favorites; }
DatabaseFavoritesRepository implements FavoritesRepository { @Override public List<Experiment.ID> getFavorites(UserInfo.Username username) { String updateSQL = "UPDATE user_experiment_properties INNER JOIN experiment " + "ON user_experiment_properties.experiment_id = experiment.id " + "SET user_experiment_properties.is_favorite = 0 " + "WHERE experiment.state = 'DELETED' AND user_experiment_properties.is_favorite = 1;"; transactionFactory.newTransaction().update(updateSQL); String sql = "SELECT experiment_id FROM user_experiment_properties WHERE user_id = ? AND is_favorite = 1;"; List list = transactionFactory.newTransaction().select(sql, username.toString()); List<Experiment.ID> favorites = new ArrayList<>(list.size()); for (Object row : list) { if (row instanceof Map) { Map map = (Map) row; if (map.get("experiment_id") instanceof byte[]) { favorites.add(Experiment.ID.valueOf((byte[]) map.get("experiment_id"))); } } } return favorites; } }
DatabaseFavoritesRepository implements FavoritesRepository { @Override public List<Experiment.ID> getFavorites(UserInfo.Username username) { String updateSQL = "UPDATE user_experiment_properties INNER JOIN experiment " + "ON user_experiment_properties.experiment_id = experiment.id " + "SET user_experiment_properties.is_favorite = 0 " + "WHERE experiment.state = 'DELETED' AND user_experiment_properties.is_favorite = 1;"; transactionFactory.newTransaction().update(updateSQL); String sql = "SELECT experiment_id FROM user_experiment_properties WHERE user_id = ? AND is_favorite = 1;"; List list = transactionFactory.newTransaction().select(sql, username.toString()); List<Experiment.ID> favorites = new ArrayList<>(list.size()); for (Object row : list) { if (row instanceof Map) { Map map = (Map) row; if (map.get("experiment_id") instanceof byte[]) { favorites.add(Experiment.ID.valueOf((byte[]) map.get("experiment_id"))); } } } return favorites; } @Inject  DatabaseFavoritesRepository(final TransactionFactory transactionFactory, final Flyway flyway,
                                       final @Named("mysql.mutagen.root.resource.path") String mutagenRootResourcePath); }
DatabaseFavoritesRepository implements FavoritesRepository { @Override public List<Experiment.ID> getFavorites(UserInfo.Username username) { String updateSQL = "UPDATE user_experiment_properties INNER JOIN experiment " + "ON user_experiment_properties.experiment_id = experiment.id " + "SET user_experiment_properties.is_favorite = 0 " + "WHERE experiment.state = 'DELETED' AND user_experiment_properties.is_favorite = 1;"; transactionFactory.newTransaction().update(updateSQL); String sql = "SELECT experiment_id FROM user_experiment_properties WHERE user_id = ? AND is_favorite = 1;"; List list = transactionFactory.newTransaction().select(sql, username.toString()); List<Experiment.ID> favorites = new ArrayList<>(list.size()); for (Object row : list) { if (row instanceof Map) { Map map = (Map) row; if (map.get("experiment_id") instanceof byte[]) { favorites.add(Experiment.ID.valueOf((byte[]) map.get("experiment_id"))); } } } return favorites; } @Inject  DatabaseFavoritesRepository(final TransactionFactory transactionFactory, final Flyway flyway,
                                       final @Named("mysql.mutagen.root.resource.path") String mutagenRootResourcePath); @Override List<Experiment.ID> getFavorites(UserInfo.Username username); @Override List<Experiment.ID> addFavorite(UserInfo.Username username, Experiment.ID experimentID); @Override List<Experiment.ID> deleteFavorite(UserInfo.Username username, Experiment.ID experimentID); }
DatabaseFavoritesRepository implements FavoritesRepository { @Override public List<Experiment.ID> getFavorites(UserInfo.Username username) { String updateSQL = "UPDATE user_experiment_properties INNER JOIN experiment " + "ON user_experiment_properties.experiment_id = experiment.id " + "SET user_experiment_properties.is_favorite = 0 " + "WHERE experiment.state = 'DELETED' AND user_experiment_properties.is_favorite = 1;"; transactionFactory.newTransaction().update(updateSQL); String sql = "SELECT experiment_id FROM user_experiment_properties WHERE user_id = ? AND is_favorite = 1;"; List list = transactionFactory.newTransaction().select(sql, username.toString()); List<Experiment.ID> favorites = new ArrayList<>(list.size()); for (Object row : list) { if (row instanceof Map) { Map map = (Map) row; if (map.get("experiment_id") instanceof byte[]) { favorites.add(Experiment.ID.valueOf((byte[]) map.get("experiment_id"))); } } } return favorites; } @Inject  DatabaseFavoritesRepository(final TransactionFactory transactionFactory, final Flyway flyway,
                                       final @Named("mysql.mutagen.root.resource.path") String mutagenRootResourcePath); @Override List<Experiment.ID> getFavorites(UserInfo.Username username); @Override List<Experiment.ID> addFavorite(UserInfo.Username username, Experiment.ID experimentID); @Override List<Experiment.ID> deleteFavorite(UserInfo.Username username, Experiment.ID experimentID);  }