com.googlecode.sqlsheet.stream.XlsStreamingResultSetMetaData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sqlsheet Show documentation
Show all versions of sqlsheet Show documentation
Jdbc API for xls/xlsx files using POI
/*
* Copyright 2012 pcal.net
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.googlecode.sqlsheet.stream;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Date;
/**
* SqlSheet implementation of java.sql.ResultSetMetaData.
*
* @author pcal
* @author sqlsheet
*/
public class XlsStreamingResultSetMetaData implements ResultSetMetaData {
private AbstractXlsSheetIterator iterator;
public XlsStreamingResultSetMetaData(AbstractXlsSheetIterator iterator) throws SQLException {
this.iterator = iterator;
}
public int getColumnCount() {
return iterator.getColumns().size();
}
public String getColumnLabel(int jdbcCol) {
return iterator.getColumns().get(jdbcCol - 1).stringValue;
}
public String getColumnName(int jdbcCol) {
return iterator.getColumns().get(jdbcCol - 1).stringValue;
}
public String getCatalogName(int arg0) throws SQLException {
return "";
}
public String getColumnClassName(int jdbcCol) throws SQLException {
return iterator.getCurrentRowValue(jdbcCol - 1).getType().getName();
}
public int getColumnDisplaySize(int arg0) {
return 0;
}
public int getColumnType(int jdbcCol) throws SQLException {
if (iterator.getCurrentRowValue(jdbcCol - 1).getType().isAssignableFrom(String.class)) {
return Types.VARCHAR;
} else if (iterator.getCurrentRowValue(jdbcCol - 1).getType().isAssignableFrom(Double.class)) {
return Types.DOUBLE;
} else if (iterator.getCurrentRowValue(jdbcCol - 1).getType().isAssignableFrom(Date.class)) {
return Types.DATE;
}
return Types.OTHER;
}
public String getColumnTypeName(int jdbcCol) throws SQLException {
if(iterator.getCurrentIteratorRowIndex() ==0) {
return iterator.getNextRowValue(jdbcCol - 1).getType().getName();
} else{
return iterator.getCurrentRowValue(jdbcCol - 1).getType().getName();
}
}
public int getPrecision(int arg0) throws SQLException {
return 0;
}
public int getScale(int arg0) throws SQLException {
return 0;
}
public String getSchemaName(int arg0) throws SQLException {
return "";
}
public String getTableName(int arg0) throws SQLException {
return iterator.getSheetName();
}
public boolean isAutoIncrement(int arg0) throws SQLException {
return false;
}
public boolean isCaseSensitive(int arg0) throws SQLException {
return false;
}
public boolean isCurrency(int arg0) throws SQLException {
return false;
}
public boolean isDefinitelyWritable(int arg0) throws SQLException {
return false;
}
public int isNullable(int arg0) throws SQLException {
return 0;
}
public boolean isReadOnly(int arg0) throws SQLException {
return false;
}
public boolean isSearchable(int arg0) throws SQLException {
return false;
}
public boolean isSigned(int arg0) throws SQLException {
return false;
}
public boolean isWritable(int arg0) throws SQLException {
return false;
}
public boolean isWrapperFor(Class> iface) throws SQLException {
return false;
}
public T unwrap(Class iface) throws SQLException {
return null;
}
}