java/jdbc-loopback-driver/src/info/globalcode/jdbc/loopback/ResultSet.java
author František Kučera <franta-hg@frantovo.cz>
Tue, 26 Feb 2019 18:19:49 +0100
branchv_0
changeset 236 a3ec71fa8e17
parent 171 701ec4db43fb
permissions -rw-r--r--
Avoid reusing/rewriting the DB connection properties.
There was weird random errors while testing connection to multiple DB in parallel when one of them was meta connection to same DB connection.
Two kinds of exception: 1) missing password 2) „Passing DB password as CLI parameter is insecure!“
     1 /**
     2  * SQL-DK
     3  * Copyright © 2014 František Kučera (frantovo.cz)
     4  *
     5  * This program is free software: you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation, either version 3 of the License, or
     8  * (at your option) any later version.
     9  *
    10  * This program is distributed in the hope that it will be useful,
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  * GNU General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU General Public License
    16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
    17  */
    18 package info.globalcode.jdbc.loopback;
    19 
    20 import java.sql.SQLException;
    21 import java.util.Iterator;
    22 import java.util.List;
    23 
    24 /**
    25  *
    26  * @author Ing. František Kučera (frantovo.cz)
    27  */
    28 public class ResultSet extends AbstractResultSet {
    29 
    30 	private final ResultSetMetaData metadata;
    31 	private final Iterator<Object[]> data;
    32 	private Object[] currentRow;
    33 
    34 	public ResultSet(ResultSetMetaData metadata, List<Object[]> table) {
    35 		data = table.listIterator();
    36 		this.metadata = metadata;
    37 	}
    38 
    39 	@Override
    40 	public boolean next() throws SQLException {
    41 		if (data.hasNext()) {
    42 			currentRow = data.next();
    43 			return true;
    44 		} else {
    45 			return false;
    46 		}
    47 	}
    48 
    49 	@Override
    50 	public Object getObject(int columnNumber) throws SQLException {
    51 		return currentRow[columnNumber - 1];
    52 	}
    53 
    54 	@Override
    55 	public ResultSetMetaData getMetaData() throws SQLException {
    56 		return metadata;
    57 	}
    58 
    59 	@Override
    60 	public void close() throws SQLException {
    61 	}
    62 
    63 	@Override
    64 	public boolean isClosed() throws SQLException {
    65 		return false;
    66 	}
    67 }