All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.unitils.dbunit.util.MultiSchemaDataSet Maven / Gradle / Ivy

/*
 * Copyright 2008,  Unitils.org
 *
 * 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 org.unitils.dbunit.util;

import org.dbunit.dataset.IDataSet;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Represents a DbUnit dataset that may contain data for multiple database schema's. For each schema, a DbUnit
 * IDataSet object can be registered using {@link #setDataSetForSchema(String,org.dbunit.dataset.IDataSet)}.
 * A schema's IDataSet can later be retrieved using {@link #getDataSetForSchema(String)}. Getting all the
 * schema names for which a IDataSet exists can be done with {@link #getSchemaNames()}.
 *
 * @author Filip Neven
 * @author Tim Ducheyne
 */
public class MultiSchemaDataSet {

    /* Maps schemanames on dbunit datasets */
    public Map schemaDataSetMap = new HashMap();


    /**
     * Returns the dbunit IDataSet for the given schema name, if any
     *
     * @param schemaName The schema name
     * @return The dbunit dataset, or null if none registered for the given schema name
     */
    public IDataSet getDataSetForSchema(String schemaName) {
        return schemaDataSetMap.get(schemaName);
    }

    /**
     * Sets a dbunit IDataSet for the given schema. If a data set already existed for this schema,
     * the old one is returned.
     *
     * @param schema  The schema name
     * @param dataSet The dbunit dataset
     * @return The replaced data set, null if none replaced
     */
    public IDataSet setDataSetForSchema(String schema, IDataSet dataSet) {
        return schemaDataSetMap.put(schema, dataSet);
    }


    /**
     * @return The names of all schema's for which a dbunit dataset exists
     */
    public Set getSchemaNames() {
        return schemaDataSetMap.keySet();
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy