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.listeners;
017
018 import java.util.List;
019
020 import org.kuali.common.jdbc.model.event.SqlEvent;
021 import org.kuali.common.jdbc.model.event.SqlExecutionEvent;
022 import org.kuali.common.util.Assert;
023 import org.kuali.common.util.ListUtils;
024
025 /**
026 * Notify other listeners about SQL related events
027 */
028 public final class NotifyingListener implements SqlListener {
029
030 private final List<SqlListener> listeners;
031
032 public NotifyingListener(List<SqlListener> listeners) {
033 Assert.noNulls(listeners);
034 this.listeners = ListUtils.newImmutableArrayList(listeners);
035 }
036
037 @Override
038 public void beforeExecution(SqlExecutionEvent event) {
039 for (SqlListener listener : listeners) {
040 listener.beforeExecution(event);
041 }
042 }
043
044 @Override
045 public void beforeExecuteSql(SqlEvent event) {
046 for (SqlListener listener : listeners) {
047 listener.beforeExecuteSql(event);
048 }
049 }
050
051 @Override
052 public void afterExecuteSql(SqlEvent event) {
053 for (SqlListener listener : listeners) {
054 listener.afterExecuteSql(event);
055 }
056 }
057
058 @Override
059 public void afterExecution(SqlExecutionEvent event) {
060 for (SqlListener listener : listeners) {
061 listener.afterExecution(event);
062 }
063 }
064
065 public List<SqlListener> getListeners() {
066 return listeners;
067 }
068
069 }