<commit_before>/**
 * Copyright (C) 2009-2013 FoundationDB, LLC
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.foundationdb.server.store;

import com.foundationdb.ais.model.AkibanInformationSchema;
import com.foundationdb.ais.model.Group;
import com.foundationdb.ais.model.GroupIndex;
import com.foundationdb.ais.model.HasStorage;
import com.foundationdb.ais.model.Index;
import com.foundationdb.ais.model.Sequence;
import com.foundationdb.ais.model.StorageDescription;
import com.foundationdb.ais.model.Table;
import com.foundationdb.ais.model.TableIndex;
import com.foundationdb.qp.operator.StoreAdapter;
import com.foundationdb.qp.rowtype.Schema;
import com.foundationdb.qp.storeadapter.indexrow.PersistitIndexRowBuffer;
import com.foundationdb.qp.storeadapter.indexrow.SpatialColumnHandler;
import com.foundationdb.server.api.dml.ColumnSelector;
import com.foundationdb.server.api.dml.scan.NewRow;
import com.foundationdb.server.api.dml.scan.ScanLimit;
import com.foundationdb.server.rowdata.RowData;
import com.foundationdb.server.rowdata.RowDef;
import com.foundationdb.server.service.session.Session;
import com.foundationdb.server.service.tree.KeyCreator;
import com.foundationdb.server.store.TableChanges.ChangeSet;
import com.persistit.Key;
import com.persistit.Value;

import java.util.Collection;
import java.util.List;

public interface Store extends KeyCreator {

    /** Get the RowDef for the given ID. Note, a transaction should be active before calling this. */
    AkibanInformationSchema getAIS(Session session);

    /**  If not {@code null}, only maintain the given {@code tableIndexes} and {@code groupIndexes}. */
    void writeRow(Session session, RowData row);
    void writeRow(Session session, RowData row, TableIndex[] tableIndexes, Collection<GroupIndex> groupIndexes);
    void writeRow(Session session, RowDef rowDef, RowData row, TableIndex[] tableIndexes, Collection<GroupIndex> groupIndexes);
    void writeNewRow(Session session, NewRow row);

    void deleteRow(Session session, RowData row, boolean cascadeDelete);
    void deleteRow(Session session, RowDef rowDef, RowData row, boolean cascadeDelete);

    /** newRow can be partial, as specified by selector, but oldRow must be fully present. */
    void updateRow(Session session, RowData oldRow, RowData newRow, ColumnSelector selector);
    void updateRow(Session session, RowDef oldRowDef, RowData oldRow, RowDef newRowDef, RowData newRow, ColumnSelector selector);

    /** Save the TableIndex row for {@code rowData}. {@code hKey} must be populated. */
    void writeIndexRow(Session session, TableIndex index, RowData rowData, Key hKey, PersistitIndexRowBuffer buffer,
                       SpatialColumnHandler spatialColumnHandler, long zValue, boolean doLock);

    /** Clear the TableIndex row for {@code rowData]. {@code hKey} must be populated. */
    void deleteIndexRow(Session session, TableIndex index, RowData rowData, Key hKey, PersistitIndexRowBuffer buffer,
                        SpatialColumnHandler spatialColumnHandler, long zValue, boolean doLock);

    /** Save the GroupIndex rows for {@code rowData}. Locking handed by StoreGIHandler. */
    void writeIndexRows(Session session, Table table, RowData rowData, Collection<GroupIndex> indexes);

    /** Clear the GroupIndex rows for {@code rowData}. Locking handled by StoreGIHandler. */
    void deleteIndexRows(Session session, Table table, RowData rowData, Collection<GroupIndex> indexes);

    /** Compute and return the next value for the given sequence */
    long nextSequenceValue(Session session, Sequence sequence);

    /**
     * Retrieve the current value for the given sequence.
     * <p><i>Note: In general, the next value has no relationship to a given transaction's current.</i></p>
     */
    long curSequenceValue(Session session, Sequence sequence);

    /**
     * Create a new RowCollector.
     * 
     * @param session Session to use.
     * @param scanFlags Flags specifying collection parameters (see flags in {@link RowCollector})
     * @param rowDefId ID specifying the type of row to that will be collected.
     * @param indexId The indexId from the given rowDef to collect on or 0 for table scan
     * @param columnBitMap
     * @param start RowData containing values to begin the scan from.
     * @param startColumns ColumnSelector indicating which fields are set in <code>start</code>
     * @param end RowData containing values to stop the scan at.
     * @param endColumns ColumnSelector indicating which fields are set in <code>end</code>
     * @throws Exception 
     */
    RowCollector newRowCollector(Session session,
                                 int scanFlags,
                                 int rowDefId,
                                 int indexId,
                                 byte[] columnBitMap,
                                 RowData start,
                                 ColumnSelector startColumns,
                                 RowData end,
                                 ColumnSelector endColumns,
                                 ScanLimit scanLimit);

    /** Get the previously saved RowCollector for the specified tableId. */
    RowCollector getSavedRowCollector(Session session, int tableId);

    /** Push a RowCollector onto a stack so that it can subsequently be referenced by getSavedRowCollector. */
    void addSavedRowCollector(Session session, RowCollector rc);

    /** Remove a previously saved RowCollector. Must the the most recently added RowCollector for a table. */
    void removeSavedRowCollector(Session session, RowCollector rc);

    long getRowCount(Session session, boolean exact, RowData start, RowData end, byte[] columnBitMap);

    /**
     * Delete all data associated with the group. This includes
     * all indexes from all tables, group indexes, and the group itself.
     */
    void dropGroup(Session session, Group group);


    /**
     * Delete all data associated with the schema.
     */
    void dropSchema(Session session, com.foundationdb.ais.model.Schema schema);

    /** (Test helper) Drop all non-system schemas */
    void dropNonSystemSchemas(Session session, Collection<com.foundationdb.ais.model.Schema> schemas);

    /**
     * Truncate the given group. This includes indexes from all tables, group
     * indexes, the group itself, and all table statuses.
     */
    void truncateGroup(Session session, Group group);

    void truncateTableStatus(Session session, int rowDefId);

    void deleteIndexes(Session session, Collection<? extends Index> indexes);

    void deleteSequences (Session session, Collection<? extends Sequence> sequences);
    /**
     * Remove all trees, and their contents, associated with the given table.
     * @param session Session
     * @param table Table
     * @throws Exception
     */
    void removeTrees(Session session, Table table);/**

     /**
     * Remove all trees, and their contents, associated with the given schema.
     */
    void removeTrees(Session session, com.foundationdb.ais.model.Schema schema);
    void removeTree(Session session, HasStorage object);
    void truncateTree(Session session, HasStorage object);

    /**<commit_msg>Cleanup<commit_after>/**
 * Copyright (C) 2009-2013 FoundationDB, LLC
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.foundationdb.server.store;

import com.foundationdb.ais.model.AkibanInformationSchema;
import com.foundationdb.ais.model.Group;
import com.foundationdb.ais.model.GroupIndex;
import com.foundationdb.ais.model.HasStorage;
import com.foundationdb.ais.model.Index;
import com.foundationdb.ais.model.Sequence;
import com.foundationdb.ais.model.StorageDescription;
import com.foundationdb.ais.model.Table;
import com.foundationdb.ais.model.TableIndex;
import com.foundationdb.qp.operator.StoreAdapter;
import com.foundationdb.qp.rowtype.Schema;
import com.foundationdb.qp.storeadapter.indexrow.PersistitIndexRowBuffer;
import com.foundationdb.qp.storeadapter.indexrow.SpatialColumnHandler;
import com.foundationdb.server.api.dml.ColumnSelector;
import com.foundationdb.server.api.dml.scan.NewRow;
import com.foundationdb.server.api.dml.scan.ScanLimit;
import com.foundationdb.server.rowdata.RowData;
import com.foundationdb.server.rowdata.RowDef;
import com.foundationdb.server.service.session.Session;
import com.foundationdb.server.service.tree.KeyCreator;
import com.foundationdb.server.store.TableChanges.ChangeSet;
import com.persistit.Key;
import com.persistit.Value;

import java.util.Collection;
import java.util.List;

public interface Store extends KeyCreator {

    /** Get the RowDef for the given ID. Note, a transaction should be active before calling this. */
    AkibanInformationSchema getAIS(Session session);

    /**  If not {@code null}, only maintain the given {@code tableIndexes} and {@code groupIndexes}. */
    void writeRow(Session session, RowData row);
    void writeRow(Session session, RowData row, TableIndex[] tableIndexes, Collection<GroupIndex> groupIndexes);
    void writeRow(Session session, RowDef rowDef, RowData row, TableIndex[] tableIndexes, Collection<GroupIndex> groupIndexes);
    void writeNewRow(Session session, NewRow row);

    void deleteRow(Session session, RowData row, boolean cascadeDelete);
    void deleteRow(Session session, RowDef rowDef, RowData row, boolean cascadeDelete);

    /** newRow can be partial, as specified by selector, but oldRow must be fully present. */
    void updateRow(Session session, RowData oldRow, RowData newRow, ColumnSelector selector);
    void updateRow(Session session, RowDef oldRowDef, RowData oldRow, RowDef newRowDef, RowData newRow, ColumnSelector selector);

    /** Save the TableIndex row for {@code rowData}. {@code hKey} must be populated. */
    void writeIndexRow(Session session, TableIndex index, RowData rowData, Key hKey, PersistitIndexRowBuffer buffer,
                       SpatialColumnHandler spatialColumnHandler, long zValue, boolean doLock);

    /** Clear the TableIndex row for {@code rowData]. {@code hKey} must be populated. */
    void deleteIndexRow(Session session, TableIndex index, RowData rowData, Key hKey, PersistitIndexRowBuffer buffer,
                        SpatialColumnHandler spatialColumnHandler, long zValue, boolean doLock);

    /** Save the GroupIndex rows for {@code rowData}. Locking handed by StoreGIHandler. */
    void writeIndexRows(Session session, Table table, RowData rowData, Collection<GroupIndex> indexes);

    /** Clear the GroupIndex rows for {@code rowData}. Locking handled by StoreGIHandler. */
    void deleteIndexRows(Session session, Table table, RowData rowData, Collection<GroupIndex> indexes);

    /** Compute and return the next value for the given sequence */
    long nextSequenceValue(Session session, Sequence sequence);

    /**
     * Retrieve the current value for the given sequence.
     * <p><i>Note: In general, the next value has no relationship to a given transaction's current.</i></p>
     */
    long curSequenceValue(Session session, Sequence sequence);

    /**
     * Create a new RowCollector.
     * 
     * @param session Session to use.
     * @param scanFlags Flags specifying collection parameters (see flags in {@link RowCollector})
     * @param rowDefId ID specifying the type of row to that will be collected.
     * @param indexId The indexId from the given rowDef to collect on or 0 for table scan
     * @param columnBitMap
     * @param start RowData containing values to begin the scan from.
     * @param startColumns ColumnSelector indicating which fields are set in <code>start</code>
     * @param end RowData containing values to stop the scan at.
     * @param endColumns ColumnSelector indicating which fields are set in <code>end</code>
     * @throws Exception 
     */
    RowCollector newRowCollector(Session session,
                                 int scanFlags,
                                 int rowDefId,
                                 int indexId,
                                 byte[] columnBitMap,
                                 RowData start,
                                 ColumnSelector startColumns,
                                 RowData end,
                                 ColumnSelector endColumns,
                                 ScanLimit scanLimit);

    /** Get the previously saved RowCollector for the specified tableId. */
    RowCollector getSavedRowCollector(Session session, int tableId);

    /** Push a RowCollector onto a stack so that it can subsequently be referenced by getSavedRowCollector. */
    void addSavedRowCollector(Session session, RowCollector rc);

    /** Remove a previously saved RowCollector. Must the the most recently added RowCollector for a table. */
    void removeSavedRowCollector(Session session, RowCollector rc);

    long getRowCount(Session session, boolean exact, RowData start, RowData end, byte[] columnBitMap);

    /**
     * Delete all data associated with the group. This includes
     * all indexes from all tables, group indexes, and the group itself.
     */
    void dropGroup(Session session, Group group);


    /**
     * Delete all data associated with the schema.
     */
    void dropSchema(Session session, com.foundationdb.ais.model.Schema schema);

    /** (Test helper) Drop all non-system schemas */
    void dropNonSystemSchemas(Session session, Collection<com.foundationdb.ais.model.Schema> schemas);

    /**
     * Truncate the given group. This includes indexes from all tables, group
     * indexes, the group itself, and all table statuses.
     */
    void truncateGroup(Session session, Group group);

    void truncateTableStatus(Session session, int rowDefId);

    void deleteIndexes(Session session, Collection<? extends Index> indexes);

    void deleteSequences (Session session, Collection<? extends Sequence> sequences);
    /**
     * Remove all trees, and their contents, associated with the given table.
     * @param session Session
     * @param table Table
     * @throws Exception
     */
    void removeTrees(Session session, Table table);

     /**
     * Remove all trees, and their contents, associated with the given schema.
     */
    void removeTrees(Session session, com.foundationdb.ais.model.Schema schema);
    void removeTree(Session session, HasStorage object);
    void truncateTree(Session session, HasStorage object);

    /**
{'fraction_non_alphanumeric': 0.0789961044766588, 'fraction_numerical': 0.0012772207676096812, 'mean_word_length': 3.4038245219347583, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3310796', 'n_tokens_mistral': 4097, 'n_tokens_neox': 3966, 'n_words': 1480}