/**
* OrbisGIS is a java GIS application dedicated to research in GIScience.
* OrbisGIS is developed by the GIS group of the DECIDE team of the
* Lab-STICC CNRS laboratory, see <http://www.lab-sticc.fr/>.
*
* The GIS group of the DECIDE team is located at :
*
* Laboratoire Lab-STICC – CNRS UMR 6285
* Equipe DECIDE
* UNIVERSITÉ DE BRETAGNE-SUD
* Institut Universitaire de Technologie de Vannes
* 8, Rue Montaigne - BP 561 56017 Vannes Cedex
*
* OrbisGIS is distributed under GPL 3 license.
*
* Copyright (C) 2007-2014 CNRS (IRSTV FR CNRS 2488)
* Copyright (C) 2015-2017 CNRS (Lab-STICC UMR CNRS 6285)
*
* This file is part of OrbisGIS.
*
* OrbisGIS is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* OrbisGIS is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* OrbisGIS. If not, see <http://www.gnu.org/licenses/>.
*
* For more information, please consult: <http://www.orbisgis.org/>
* or contact directly:
* info_at_ orbisgis.org
*/
package org.orbisgis.view.toc.actions.cui.components;
import com.vividsolutions.jts.geom.Geometry;
import org.orbisgis.corejdbc.AbstractRowSet;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
import java.sql.NClob;
import java.sql.Ref;
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;
/**
* Convert a Map into a one line ResultSet.
* @author Nicolas Fortin
*/
public class OneLineResultSet extends AbstractRowSet {
private Map<String, Integer> columns;
private Object[] values;
private int index = 0;
private int geometryIndex = -1;
public OneLineResultSet(String[] fields, Object[] values) {
this.values = values;
this.columns = new HashMap<>(fields.length);
for(int i = 0; i< fields.length; i++) {
if(values[i] instanceof Geometry) {
geometryIndex = i + 1;
}
columns.put(fields[i].toUpperCase(), i);
}
}
@Override
public boolean next() throws SQLException {
if(index < 2) {
index++;
return true;
} else {
return false;
}
}
@Override
public Geometry getGeometry() throws SQLException {
if(geometryIndex == -1) {
return null;
} else {
return (Geometry)values[geometryIndex];
}
}
@Override
public void updateGeometry(int columnIndex, Geometry geometry) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateGeometry(String columnLabel, Geometry geometry) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void close() throws SQLException {
}
@Override
public boolean wasNull() throws SQLException {
return false;
}
@Override
public SQLWarning getWarnings() throws SQLException {
return null;
}
@Override
public void clearWarnings() throws SQLException {
}
@Override
public String getCursorName() throws SQLException {
return null;
}
@Override
public ResultSetMetaData getMetaData() throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public Object getObject(int columnIndex) throws SQLException {
return values[columnIndex];
}
@Override
public int findColumn(String columnLabel) throws SQLException {
Integer columnId = columns.get(columnLabel.toUpperCase());
if(columnId == null) {
throw new SQLException("This result set does not contain the column "+columnLabel);
}
return columnId;
}
@Override
public boolean isBeforeFirst() throws SQLException {
return index == 0;
}
@Override
public boolean isAfterLast() throws SQLException {
return index == 1;
}
@Override
public boolean isFirst() throws SQLException {
return index == 1;
}
@Override
public boolean isLast() throws SQLException {
return isFirst();
}
@Override
public void beforeFirst() throws SQLException {
index = 0;
}
@Override
public void afterLast() throws SQLException {
index = 2;
}
@Override
public boolean first() throws SQLException {
index = 1;
return true;
}
@Override
public boolean last() throws SQLException {
index = 1;
return true;
}
@Override
public int getRow() throws SQLException {
return index;
}
@Override
public boolean absolute(int row) throws SQLException {
index = row;
return true;
}
@Override
public boolean relative(int rows) throws SQLException {
return absolute(index + rows);
}
@Override
public boolean previous() throws SQLException {
return absolute(Math.max(0, index - 1));
}
@Override
public boolean rowUpdated() throws SQLException {
return false;
}
@Override
public boolean rowInserted() throws SQLException {
return false;
}
@Override
public boolean rowDeleted() throws SQLException {
return false;
}
@Override
public void updateNull(int columnIndex) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBoolean(int columnIndex, boolean x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateByte(int columnIndex, byte x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateShort(int columnIndex, short x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateInt(int columnIndex, int x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateLong(int columnIndex, long x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateFloat(int columnIndex, float x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateDouble(int columnIndex, double x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateString(int columnIndex, String x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBytes(int columnIndex, byte[] x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateDate(int columnIndex, Date x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateTime(int columnIndex, Time x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateObject(int columnIndex, Object x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateNull(String columnLabel) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBoolean(String columnLabel, boolean x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateByte(String columnLabel, byte x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateShort(String columnLabel, short x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateInt(String columnLabel, int x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateLong(String columnLabel, long x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateFloat(String columnLabel, float x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateDouble(String columnLabel, double x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateString(String columnLabel, String x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBytes(String columnLabel, byte[] x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateDate(String columnLabel, Date x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateTime(String columnLabel, Time x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateObject(String columnLabel, Object x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void insertRow() throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateRow() throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void deleteRow() throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void refreshRow() throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void cancelRowUpdates() throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void moveToInsertRow() throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void moveToCurrentRow() throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public Statement getStatement() throws SQLException {
return null;
}
@Override
public void updateRef(int columnIndex, Ref x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateRef(String columnLabel, Ref x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBlob(int columnIndex, Blob x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBlob(String columnLabel, Blob x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateClob(int columnIndex, Clob x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateClob(String columnLabel, Clob x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateArray(int columnIndex, Array x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateArray(String columnLabel, Array x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public RowId getRowId(int columnIndex) throws SQLException {
return null;
}
@Override
public RowId getRowId(String columnLabel) throws SQLException {
return null;
}
@Override
public void updateRowId(int columnIndex, RowId x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateRowId(String columnLabel, RowId x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public int getHoldability() throws SQLException {
return 0;
}
@Override
public boolean isClosed() throws SQLException {
return false;
}
@Override
public void updateNString(int columnIndex, String nString) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateNString(String columnLabel, String nString) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateNClob(int columnIndex, NClob nClob) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateNClob(String columnLabel, NClob nClob) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateClob(int columnIndex, Reader reader, long length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateClob(String columnLabel, Reader reader, long length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateCharacterStream(int columnIndex, Reader x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateClob(int columnIndex, Reader reader) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateClob(String columnLabel, Reader reader) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateNClob(int columnIndex, Reader reader) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
@Override
public void updateNClob(String columnLabel, Reader reader) throws SQLException {
throw new SQLFeatureNotSupportedException("Read only RowSet");
}
}