|
| 1 | +/* |
| 2 | + * Copyright 2016-2018 shardingsphere.io. |
| 3 | + * <p> |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * </p> |
| 16 | + */ |
| 17 | + |
| 18 | +package io.shardingsphere.core.merger.dal.show; |
| 19 | + |
| 20 | +import io.shardingsphere.core.merger.MergedResult; |
| 21 | + |
| 22 | +import java.io.InputStream; |
| 23 | +import java.io.Reader; |
| 24 | +import java.sql.Blob; |
| 25 | +import java.sql.Clob; |
| 26 | +import java.sql.SQLException; |
| 27 | +import java.sql.SQLFeatureNotSupportedException; |
| 28 | +import java.sql.SQLXML; |
| 29 | +import java.util.Calendar; |
| 30 | +import java.util.List; |
| 31 | + |
| 32 | +/** |
| 33 | + * Proxy merged result for show databases. |
| 34 | + * |
| 35 | + * @author chenqingyang |
| 36 | + */ |
| 37 | +public final class ProxyShowDatabasesMergedResult implements MergedResult { |
| 38 | + |
| 39 | + private List<String> schemas; |
| 40 | + |
| 41 | + private int currenIndex; |
| 42 | + |
| 43 | + public ProxyShowDatabasesMergedResult(final List<String> schemas) { |
| 44 | + this.schemas = schemas; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public boolean next() throws SQLException { |
| 49 | + if (currenIndex < schemas.size()) { |
| 50 | + currenIndex++; |
| 51 | + return true; |
| 52 | + } |
| 53 | + return false; |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public Object getValue(final int columnIndex, final Class<?> type) throws SQLException { |
| 58 | + if (Blob.class == type || Clob.class == type || Reader.class == type || InputStream.class == type || SQLXML.class == type) { |
| 59 | + throw new SQLFeatureNotSupportedException(); |
| 60 | + } |
| 61 | + Object result = schemas.get(currenIndex - 1); |
| 62 | + return result; |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public Object getValue(final String columnLabel, final Class<?> type) throws SQLException { |
| 67 | + return new SQLFeatureNotSupportedException(); |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public Object getCalendarValue(final int columnIndex, final Class<?> type, final Calendar calendar) throws SQLException { |
| 72 | + throw new SQLFeatureNotSupportedException(); |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public Object getCalendarValue(final String columnLabel, final Class<?> type, final Calendar calendar) throws SQLException { |
| 77 | + throw new SQLFeatureNotSupportedException(); |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + public InputStream getInputStream(final int columnIndex, final String type) throws SQLException { |
| 82 | + throw new SQLFeatureNotSupportedException(); |
| 83 | + } |
| 84 | + |
| 85 | + @Override |
| 86 | + public InputStream getInputStream(final String columnLabel, final String type) throws SQLException { |
| 87 | + throw new SQLFeatureNotSupportedException(); |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + public boolean wasNull() throws SQLException { |
| 92 | + return false; |
| 93 | + } |
| 94 | +} |
0 commit comments