/*
 * Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0,
 * or the Eclipse Distribution License v. 1.0 which is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
 */

// Contributors:
//     Oracle - initial API and implementation from Oracle TopLink
package org.eclipse.persistence.testing.models.multipletable;

import org.eclipse.persistence.sessions.DatabaseSession;
import org.eclipse.persistence.sessions.UnitOfWork;
import org.eclipse.persistence.testing.framework.TestSystem;
import org.eclipse.persistence.tools.schemaframework.PopulationManager;

/**
 * System for the MultipleTableModel
 *
 * @author Guy Pelletier
 * @version 1.0
 */
public class MultipleTableSystem extends TestSystem {
    public MultipleTableSystem() {
        project = new MultipleTableProject();
    }

    @Override
    public void addDescriptors(DatabaseSession session) {
        session.addDescriptors(project);
    }

    @Override
    public void createTables(DatabaseSession session) {
        new MultipleTableTableCreator().replaceTables(session);
    }
    @Override
    public void populate(DatabaseSession session) {
        PopulationManager manager = PopulationManager.getDefaultManager();
        UnitOfWork uow = session.acquireUnitOfWork();

        Cow cow1 = Cow.getCow1();
        manager.registerObject(cow1,"cow1");
        uow.registerObject(cow1);

        SuperCow superCow1 = SuperCow.getSuperCow1();
        manager.registerObject(superCow1, "superCow1");
        uow.registerObject(superCow1);

        Horse horse1 = Horse.getHorse1();
        manager.registerObject(horse1, "horse1");
        uow.registerObject(horse1);

        SuperHorse superHorse1 = SuperHorse.getSuperHorse1();
        manager.registerObject(superHorse1, "superHorse1");
        uow.registerObject(superHorse1);

        Swan swan1 = Swan.getSwan1();
        manager.registerObject(swan1, "cwan1");
        uow.registerObject(swan1);

        SuperSwan superSwan1 = SuperSwan.getSuperSwan1();
        manager.registerObject(superSwan1, "superSwan1");
        uow.registerObject(superSwan1);

        uow.commit();
    }
}
