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;
017
018 import org.kuali.common.jdbc.context.JdbcContext;
019 import org.kuali.common.util.FormatUtils;
020 import org.kuali.common.util.execute.Executable;
021 import org.slf4j.Logger;
022 import org.slf4j.LoggerFactory;
023 import org.springframework.util.Assert;
024
025 /**
026 * @deprecated
027 */
028 @Deprecated
029 public class JdbcExecutable implements Executable {
030
031 private static final Logger logger = LoggerFactory.getLogger(JdbcExecutable.class);
032 public static final JdbcService DEFAULT_JDBC_SERVICE = new DefaultJdbcService();
033
034 JdbcService service = DEFAULT_JDBC_SERVICE;
035 JdbcContext context;
036 boolean skip;
037
038 public JdbcExecutable() {
039 this(DEFAULT_JDBC_SERVICE, null);
040 }
041
042 public JdbcExecutable(JdbcContext context) {
043 this(DEFAULT_JDBC_SERVICE, context);
044 }
045
046 public JdbcExecutable(JdbcService service, JdbcContext context) {
047 super();
048 this.service = service;
049 this.context = context;
050 }
051
052 @Override
053 public void execute() {
054 if (skip) {
055 logger.info("Skipping execution");
056 return;
057 }
058
059 Assert.notNull(service, "service is null");
060 Assert.notNull(context, "context is null");
061
062 ExecutionResult result = service.executeSql(context);
063 if (result.getStatementsExecuted() > 0) {
064 String updates = FormatUtils.getCount(result.getUpdateCount());
065 String statements = FormatUtils.getCount(result.getStatementsExecuted());
066 String elapsed = FormatUtils.getTime(result.getElapsed());
067 Object[] args = { updates, statements, elapsed };
068 logger.info("Rows updated: {} SQL Statements: {} Total time: {}", args);
069 }
070 }
071
072 public JdbcService getService() {
073 return service;
074 }
075
076 public void setService(JdbcService service) {
077 this.service = service;
078 }
079
080 public JdbcContext getContext() {
081 return context;
082 }
083
084 public void setContext(JdbcContext context) {
085 this.context = context;
086 }
087
088 public boolean isSkip() {
089 return skip;
090 }
091
092 public void setSkip(boolean skip) {
093 this.skip = skip;
094 }
095
096 }