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.supplier;
017
018 import java.util.Arrays;
019 import java.util.List;
020
021 import org.kuali.common.jdbc.SqlMetaData;
022 import org.springframework.util.Assert;
023
024 /**
025 * Supply SQL from strings that have one SQL statement each
026 *
027 * @deprecated
028 */
029 @Deprecated
030 public class SimpleStringSupplier extends AbstractSupplier {
031
032 List<String> strings;
033 boolean closed = true;
034
035 public SimpleStringSupplier() {
036 this((String) null);
037 }
038
039 public SimpleStringSupplier(String sql) {
040 this(Arrays.asList(sql));
041 }
042
043 public SimpleStringSupplier(List<String> strings) {
044 super();
045 this.strings = strings;
046 }
047
048 @Override
049 public void open() {
050 // Make sure we've got something to work with
051 Assert.notNull(strings, "strings is null");
052 Assert.isTrue(closed, "closed is false");
053 this.closed = false;
054 }
055
056 @Override
057 public List<String> getSql() {
058 if (closed) {
059 return null;
060 } else {
061 this.closed = true;
062 return strings;
063 }
064 }
065
066 @Override
067 public void close() {
068 this.closed = true;
069 }
070
071 @Override
072 public void fillInMetaData() {
073 int count = strings.size();
074 long size = 0;
075 for (String string : strings) {
076 size += string.length();
077 }
078 this.metaData = new SqlMetaData(count, size);
079 }
080
081 public List<String> getStrings() {
082 return strings;
083 }
084
085 public void setStrings(List<String> strings) {
086 this.strings = strings;
087 }
088
089 }