001 /** 002 * Copyright 2005-2011 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 */ 016 package org.kuali.rice.test.lifecycles; 017 018 import org.apache.log4j.Logger; 019 import org.kuali.rice.core.api.config.property.ConfigContext; 020 import org.kuali.rice.core.api.lifecycle.BaseLifecycle; 021 import org.kuali.rice.test.SQLDataLoader; 022 023 /** 024 * A lifecycle for loading SQL datasets. 025 * This lifecycle will not be run (even if it is listed in the lifecycles list) 026 * if the 'use.sqlDataLoaderLifecycle' configuration property is defined, and is 027 * not 'true'. If the property is omitted the lifecycle runs as normal. 028 * 029 * @author Kuali Rice Team (rice.collab@kuali.org) 030 */ 031 public class SQLDataLoaderLifecycle extends BaseLifecycle { 032 private static final Logger LOG = Logger.getLogger(SQLDataLoaderLifecycle.class); 033 034 private SQLDataLoader sqlDataLoader; 035 036 private String filename; 037 038 private String delimiter; 039 040 public SQLDataLoaderLifecycle(String filename, String delimiter) { 041 this.filename = filename; 042 this.delimiter = delimiter; 043 } 044 045 public void start() throws Exception { 046 String useSqlDataLoaderLifecycle = ConfigContext.getCurrentContextConfig().getProperty("use.sqlDataLoaderLifecycle"); 047 if (useSqlDataLoaderLifecycle != null && !Boolean.valueOf(useSqlDataLoaderLifecycle)) { 048 LOG.debug("Skipping SQLDataLoaderLifecycle due to property: use.sqlDataLoaderLifecycle=" + useSqlDataLoaderLifecycle); 049 return; 050 } 051 052 sqlDataLoader = new SQLDataLoader(filename, delimiter); 053 sqlDataLoader.runSql(); 054 super.start(); 055 } 056 057 public void stop() throws Exception { 058 // TODO: may way to do something with the dataLoader 059 super.stop(); 060 } 061 }