<commit_before>/*
 * Copyright 2017 mk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package mk.gdx.firebase.android.database;

import com.google.firebase.database.Query;

import mk.gdx.firebase.android.database.providers.QueryFilteringProvider;
import mk.gdx.firebase.android.database.resolvers.QueryFilterResolver;
import mk.gdx.firebase.android.database.resolvers.QueryOrderByResolver;
import mk.gdx.firebase.database.FilteringProvider;
import mk.gdx.firebase.database.queries.GdxFireappQuery;

/**
 * Provides flow for android firebase call.
 * <p>
 * Flow is as follow:
 * <p>
 * - Gets {@code Query} instance and databasePath from {@link Database}.
 * - Applies filters if needed it
 * - Do some action on db
 * - Terminate query by clear given filters - if any - and call {@link Database#terminateOperation()}
 *
 * @param <R> Return type of {@link GdxFireappQuery#run()} method.
 */
public abstract class AndroidDatabaseQuery<R> extends GdxFireappQuery<Database, R>
{
    protected static final String SHOULD_BE_RUN_WITH_DATABASE_REFERENCE = "Set value should be call with DatabaseReference instance.";

    protected String databasePath;
    protected Query query;
    protected FilteringProvider<Query, QueryFilterResolver, QueryOrderByResolver> filtersProvider;

    public AndroidDatabaseQuery(Database databaseDistribution)
    {
        super(databaseDistribution);
        filtersProvider = new QueryFilteringProvider();
    }

    @Override
    protected void prepare()
    {
        query = databaseDistribution.databaseReference();
        databasePath = databaseDistribution.getDatabasePath();
    }

    @Override
    @SuppressWarnings("unchecked")
    protected void applyFilters()
    {
        filtersProvider.setFilters(filters)
                .setOrderByClause(orderByClause)
                .setQuery(query);
    }

    @Override
    protected void terminate()
    {
        databaseDistribution.terminateOperation();
        orderByClause = null;
        filtersProvider.clear();
    }
}
<commit_msg>AndroidDatabaseQuery refactoring<commit_after>/*
 * Copyright 2017 mk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package mk.gdx.firebase.android.database;

import com.google.firebase.database.Query;

import mk.gdx.firebase.android.database.providers.QueryFilteringProvider;
import mk.gdx.firebase.android.database.resolvers.QueryFilterResolver;
import mk.gdx.firebase.android.database.resolvers.QueryOrderByResolver;
import mk.gdx.firebase.database.FilteringProvider;
import mk.gdx.firebase.database.queries.GdxFireappQuery;

/**
 * Provides flow for android firebase call.
 * <p>
 * Flow is as follow:
 * <p>
 * - Gets {@code Query} instance and databasePath from {@link Database}.
 * - Applies filters if needed it
 * - Do some action on db
 * - Terminate query by clear given filters - if any - and call {@link Database#terminateOperation()}
 *
 * @param <R> Return type of {@link GdxFireappQuery#run()} method.
 */
public abstract class AndroidDatabaseQuery<R> extends GdxFireappQuery<Database, R>
{
    protected static final String SHOULD_BE_RUN_WITH_DATABASE_REFERENCE = "Set value should be call with DatabaseReference instance.";

    protected String databasePath;
    protected Query query;
    protected QueryFilteringProvider filtersProvider;

    public AndroidDatabaseQuery(Database databaseDistribution)
    {
        super(databaseDistribution);
        filtersProvider = new QueryFilteringProvider();
    }

    @Override
    protected void prepare()
    {
        query = databaseDistribution.databaseReference();
        databasePath = databaseDistribution.getDatabasePath();
    }

    @Override
    @SuppressWarnings("unchecked")
    protected void applyFilters()
    {
        filtersProvider.setFilters(filters)
                .setOrderByClause(orderByClause)
                .setQuery(query);
    }

    @Override
    protected void terminate()
    {
        databaseDistribution.terminateOperation();
        orderByClause = null;
        filtersProvider.clear();
    }
}

{'fraction_non_alphanumeric': 0.08451816745655608, 'fraction_numerical': 0.00315955766192733, 'mean_word_length': 3.70724907063197, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '264166', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1330, 'n_words': 417}