net.starschema.clouddb.jdbc.DMDResultSet Maven / Gradle / Ivy
Show all versions of bqjdbc Show documentation
/**
* Copyright (c) 2015, STARSCHEMA LTD. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
*
1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
*
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
This class implements the java.sql.ResultSet interface for Object[] and Object[][] types
* instead of GetQueryResultsResponse.getrows()
*/
package net.starschema.clouddb.jdbc;
import java.sql.SQLException;
import net.starschema.clouddb.jdbc.DMDResultSet.DMDResultSetType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// import net.starschema.clouddb.bqjdbc.logging.Logger;
/**
* this class implements the java.sql.ResultSetMetaData interface for usage in Resultsets which was
* made from DatabaseMetadata
*
* @author Horváth Attila
*/
class COLResultSetMetadata implements java.sql.ResultSetMetaData {
String[][] data = null;
String[] labels;
/** Instance of logger */
static Logger logger = LoggerFactory.getLogger(COLResultSetMetadata.class);
DMDResultSetType MetaDataType;
/**
* Constructor initializes variables
*
* @param data The column informations
* @param labels The name of columns
*/
public COLResultSetMetadata(String[][] data, String[] labels, DMDResultSetType type) {
this.labels = labels;
this.data = data;
this.MetaDataType = type;
}
/**
*
*
*
Implementation Details:
*
*
* Returns this.data[0][0]
*/
@Override
public String getCatalogName(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call getCatalogName parameter: " + column);
if (this.MetaDataType == DMDResultSetType.getColumns) {
return this.data[0][0];
}
if (this.MetaDataType == DMDResultSetType.getSchemas) {
return this.data[column - 1][1];
} else {
return "";
}
}
/**
*
*
* Implementation Details:
*
*
* returns java.lang.String.class.toString()
*/
@Override
public String getColumnClassName(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call getColumnClassName parameter: " + column);
return java.lang.String.class.toString();
}
/**
*
*
* Implementation Details:
*
*
* returns this.labels.length
*/
@Override
public int getColumnCount() throws SQLException {
COLResultSetMetadata.logger.debug("Function Call getColumnCount");
return this.labels.length;
}
/**
*
*
* Implementation Details:
*
*
* returns 64*1024
*/
@Override
public int getColumnDisplaySize(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call getColumnDisplaySize");
return 64 * 1024;
}
/**
*
*
* Implementation Details:
*
*
* returns this.labels[column - 1]
*/
@Override
public String getColumnLabel(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call getColumnLabel parameter: " + column);
return this.labels[column - 1];
}
/**
*
*
* Implementation Details:
*
*
* returns this.labels[column - 1]
*/
@Override
public String getColumnName(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call getColumnName parameter: " + column);
return this.labels[column - 1];
}
/**
*
*
* Implementation Details:
*
*
* returns java.sql.Types.VARCHAR
*/
@Override
public int getColumnType(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call getColumnType parameter: " + column);
return java.sql.Types.VARCHAR;
/*
* switch (column) { case 1: return java.sql.Types.VARCHAR; case 2:
* return java.sql.Types.VARCHAR; case 3: return java.sql.Types.VARCHAR;
* case 4: return java.sql.Types.VARCHAR; case 5: return
* java.sql.Types.VARCHAR; case 6: return java.sql.Types.VARCHAR; case
* 7: return java.sql.Types.INTEGER; case 8: return
* java.sql.Types.INTEGER; case 9: return java.sql.Types.INTEGER; case
* 10: return java.sql.Types.INTEGER; case 11: return
* java.sql.Types.INTEGER; case 12: return java.sql.Types.VARCHAR; case
* 13: return java.sql.Types.VARCHAR; case 14: return
* java.sql.Types.INTEGER; case 15: return java.sql.Types.INTEGER; case
* 16: return java.sql.Types.INTEGER; case 17: return
* java.sql.Types.INTEGER; case 18: return java.sql.Types.VARCHAR; case
* 19: return java.sql.Types.VARCHAR; case 20: return
* java.sql.Types.VARCHAR; case 21: return java.sql.Types.VARCHAR; case
* 22: return java.sql.Types.INTEGER; default: break; } return
* java.sql.Types.VARCHAR;
*/
}
/**
*
*
* Implementation Details:
*
*
* returns this.data[0][5]
*/
@Override
public String getColumnTypeName(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call getColumnTypeName parameter: " + column);
/*
* if(this.MetaDataType == DMDResultSetType.getColumns) return
* this.data[0][5]; else
*/
return "VARCHAR";
}
/**
*
*
* Implementation Details:
*
*
* returns 0
*/
@Override
public int getPrecision(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call getPrecision parameter: " + column);
return 0;
}
/**
*
*
* Implementation Details:
*
*
* returns 0
*/
@Override
public int getScale(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call getScale parameter: " + column);
return 0;
}
/**
*
*
* Implementation Details:
*
*
* returns this.data[0][1]
*/
@Override
public String getSchemaName(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call getSchemaName parameter: " + column);
if (this.MetaDataType == DMDResultSetType.getColumns) {
return this.data[0][1];
}
if (this.MetaDataType == DMDResultSetType.getSchemas) {
return this.data[column - 1][0];
} else {
return "";
}
}
/**
*
*
* Implementation Details:
*
*
* returns this.data[0][2]
*/
@Override
public String getTableName(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call getTableName parameter: " + column);
if (this.MetaDataType == DMDResultSetType.getColumns) {
return this.data[0][2];
} else {
return "";
}
}
/**
*
*
* Implementation Details:
*
*
* returns false
*/
@Override
public boolean isAutoIncrement(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call isAutoIncrement parameter: " + column);
return false;
}
/**
*
*
* Implementation Details:
*
*
* returns false
*/
@Override
public boolean isCaseSensitive(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call isCaseSensitive parameter: " + column);
return false;
}
/**
*
*
* Implementation Details:
*
*
* returns false
*/
@Override
public boolean isCurrency(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call isCurrency parameter: " + column);
return false;
}
/**
*
*
* Implementation Details:
*
*
* returns false
*/
@Override
public boolean isDefinitelyWritable(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call isDefinitelyWritable parameter: " + column);
return false;
}
/**
*
*
* Implementation Details:
*
*
* returns 1
*/
@Override
public int isNullable(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call getTableName parameter: " + column);
return 1;
}
/**
*
*
* Implementation Details:
*
*
* returns true
*/
@Override
public boolean isReadOnly(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call isReadOnly parameter: " + column);
return true;
}
/**
*
*
* Implementation Details:
*
*
* returns false
*/
@Override
public boolean isSearchable(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call isSearchable parameter: " + column);
return false;
}
/**
*
*
* Implementation Details:
*
*
* returns false
*/
@Override
public boolean isSigned(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call isSigned parameter: " + column);
return false;
}
/**
*
*
* Implementation Details:
*
*
* returns false
*/
@Override
public boolean isWrapperFor(Class> arg0) throws SQLException {
return false;
}
/**
*
*
* Implementation Details:
*
*
* returns false
*/
@Override
public boolean isWritable(int column) throws SQLException {
COLResultSetMetadata.logger.debug("Function Call isWritable parameter: " + column);
return false;
}
/**
*
*
* Implementation Details:
*
*
* Always Throws SQLException
*
* @throws SQLException always
*/
@Override
public T unwrap(Class arg0) throws SQLException {
throw new BQSQLException("not found");
}
}
/**
* This class implements the java.sql.ResultSet interface for Object[] and
*
* Object[][] types instead of GetQueryResultsResponse.getrows() for giving back Resultset Data
* from BQDatabaseMetadata
*
* @author Horváth Attila
*/
public class DMDResultSet extends ScrollableResultset