001/**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.test.lifecycles;
017
018import org.apache.logging.log4j.Logger;
019import org.apache.logging.log4j.LogManager;
020import org.kuali.rice.core.api.config.property.ConfigContext;
021import org.kuali.rice.core.api.lifecycle.BaseLifecycle;
022import org.kuali.rice.test.SQLDataLoader;
023
024/**
025 * A lifecycle for loading SQL datasets.
026 * This lifecycle will not be run (even if it is listed in the lifecycles list)
027 * if the 'use.sqlDataLoaderLifecycle' configuration property is defined, and is
028 * not 'true'.  If the property is omitted the lifecycle runs as normal.
029 * 
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 */
032public class SQLDataLoaderLifecycle extends BaseLifecycle {
033    private static final Logger LOG = LogManager.getLogger(SQLDataLoaderLifecycle.class);
034
035    private SQLDataLoader sqlDataLoader;
036
037    private String filename;
038
039    private String delimiter;
040
041    public SQLDataLoaderLifecycle(String filename, String delimiter) {
042        this.filename = filename;
043        this.delimiter = delimiter;
044    }
045
046    public void start() throws Exception {
047        String useSqlDataLoaderLifecycle = ConfigContext.getCurrentContextConfig().getProperty("use.sqlDataLoaderLifecycle");
048        if (useSqlDataLoaderLifecycle != null && !Boolean.valueOf(useSqlDataLoaderLifecycle)) {
049            LOG.debug("Skipping SQLDataLoaderLifecycle due to property: use.sqlDataLoaderLifecycle=" + useSqlDataLoaderLifecycle);
050            return;
051        }
052
053        sqlDataLoader = new SQLDataLoader(filename, delimiter);
054        sqlDataLoader.runSql();
055        super.start();
056    }
057
058    public void stop() throws Exception {
059        // TODO: may way to do something with the dataLoader
060        super.stop();
061    }
062}