001 /** 002 * Copyright 2010-2013 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.common.jdbc.spring; 017 018 import java.util.ArrayList; 019 import java.util.List; 020 021 import org.kuali.common.jdbc.JdbcExecutable; 022 import org.kuali.common.jdbc.context.JdbcContext; 023 import org.kuali.common.jdbc.context.SqlMode; 024 import org.kuali.common.jdbc.listener.DataSummaryListener; 025 import org.kuali.common.jdbc.listener.MetaDataListener; 026 import org.kuali.common.jdbc.listener.NotifyingListener; 027 import org.kuali.common.jdbc.listener.SqlListener; 028 import org.kuali.common.util.execute.Executable; 029 import org.kuali.common.util.spring.SpringUtils; 030 import org.springframework.context.annotation.Bean; 031 import org.springframework.context.annotation.Configuration; 032 033 @Configuration 034 public class ResetDataConfig extends ResetBaseConfig { 035 036 public static final String TYPE = "data"; 037 public static final String SKIP_KEY = "jdbc.data.skip"; 038 039 @Bean 040 public Executable jdbcDataConcurrentExecutable() { 041 ResetConfigContext jcc = new ResetConfigContext(env, TYPE, SqlMode.CONCURRENT, commonConfig, dataSourceConfig); 042 JdbcContext ctx = ResetConfigUtils.getConcurrentJdbcContext(jcc); 043 ctx.setListener(getConcurrentListener()); 044 045 JdbcExecutable exec = new JdbcExecutable(); 046 exec.setSkip(SpringUtils.getBoolean(env, SKIP_KEY, false)); 047 exec.setService(commonConfig.jdbcService()); 048 exec.setContext(ctx); 049 return exec; 050 } 051 052 @Bean 053 public Executable jdbcDataSequentialExecutable() { 054 ResetConfigContext jcc = new ResetConfigContext(env, TYPE, SqlMode.SEQUENTIAL, commonConfig, dataSourceConfig); 055 JdbcContext ctx = ResetConfigUtils.getSequentialJdbcContext(jcc); 056 ctx.setListener(ResetConfigUtils.getSummaryAndProgressListener(env)); 057 JdbcExecutable exec = new JdbcExecutable(); 058 exec.setSkip(SpringUtils.getBoolean(env, SKIP_KEY, false)); 059 exec.setService(commonConfig.jdbcService()); 060 exec.setContext(ctx); 061 return exec; 062 } 063 064 protected SqlListener getConcurrentListener() { 065 ResetConfigContext rcc = new ResetConfigContext(env, TYPE, SqlMode.CONCURRENT, commonConfig, dataSourceConfig); 066 DataSummaryListener dsl = ResetConfigUtils.getConcurrentDataSummaryListener(rcc); 067 068 List<SqlListener> listeners = new ArrayList<SqlListener>(); 069 listeners.add(new MetaDataListener()); 070 listeners.add(dsl); 071 listeners.add(ResetConfigUtils.getLogSqlListener(env)); 072 return new NotifyingListener(listeners); 073 } 074 075 }