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.Arrays;
019
020 import org.kuali.common.jdbc.JdbcExecutable;
021 import org.kuali.common.jdbc.context.JdbcContext;
022 import org.kuali.common.jdbc.listener.LogSqlListener;
023 import org.kuali.common.jdbc.listener.LogSqlMode;
024 import org.kuali.common.jdbc.supplier.ComplexStringSupplier;
025 import org.kuali.common.jdbc.supplier.SqlSupplier;
026 import org.kuali.common.util.LoggerLevel;
027 import org.kuali.common.util.execute.Executable;
028 import org.kuali.common.util.spring.SpringUtils;
029
030 /**
031 * @deprecated
032 */
033 @Deprecated
034 public abstract class AbstractSqlDbaConfig extends SqlBaseConfig {
035
036 // This indicates before/after
037 protected abstract String getPhase();
038
039 // This must return the fully prepared executable to use and must have a unique bean name for the context
040 public abstract Executable getDbaPhaseExecutable();
041
042 protected Executable getDbaExecutable() {
043 JdbcExecutable exec = new JdbcExecutable();
044 exec.setSkip(SpringUtils.getBoolean(env, "jdbc.dba." + getPhase() + ".skip", false));
045 exec.setService(commonConfig.jdbcService());
046 exec.setContext(getJdbcContext());
047 return exec;
048 }
049
050 protected JdbcContext getJdbcContext() {
051 JdbcContext ctx = new JdbcContext();
052 // All dba SQL executes sequentially
053 ctx.setMessage("[dba:" + getPhase() + "]");
054 ctx.setSkip(SpringUtils.getBoolean(env, "sql.dba." + getPhase() + ".skip", false));
055 ctx.setDataSource(dataSourceConfig.jdbcDbaDataSource());
056 ctx.setSuppliers(Arrays.asList(getSqlSupplier()));
057 ctx.setListener(new LogSqlListener(LoggerLevel.INFO, LogSqlMode.BEFORE));
058 return ctx;
059 }
060
061 protected SqlSupplier getSqlSupplier() {
062 String sql = SpringUtils.getProperty(env, "sql.dba." + getPhase());
063 ComplexStringSupplier css = new ComplexStringSupplier();
064 css.setReader(commonConfig.jdbcSqlReader());
065 css.setStrings(Arrays.asList(sql));
066 return css;
067 }
068
069 }