java/sql-dk/src/main/java/info/globalcode/sql/dk/formatting/FakeSqlArray.java
author František Kučera <franta-hg@frantovo.cz>
Thu, 24 Oct 2019 21:43:08 +0200
branchv_0
changeset 250 aae5009bd0af
parent 238 4a1864c3e867
permissions -rw-r--r--
fix license version: GNU GPLv3
franta-hg@159
     1
/**
franta-hg@159
     2
 * SQL-DK
franta-hg@159
     3
 * Copyright © 2014 František Kučera (frantovo.cz)
franta-hg@159
     4
 *
franta-hg@159
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@159
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@250
     7
 * the Free Software Foundation, version 3 of the License.
franta-hg@159
     8
 *
franta-hg@159
     9
 * This program is distributed in the hope that it will be useful,
franta-hg@159
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@159
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@159
    12
 * GNU General Public License for more details.
franta-hg@159
    13
 *
franta-hg@159
    14
 * You should have received a copy of the GNU General Public License
franta-hg@159
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@159
    16
 */
franta-hg@159
    17
package info.globalcode.sql.dk.formatting;
franta-hg@159
    18
franta-hg@159
    19
import info.globalcode.sql.dk.SQLType;
franta-hg@159
    20
import java.sql.Array;
franta-hg@159
    21
import java.sql.ResultSet;
franta-hg@159
    22
import java.sql.SQLException;
franta-hg@159
    23
import java.util.Map;
franta-hg@159
    24
franta-hg@159
    25
/**
franta-hg@159
    26
 * Fake SQL array, for formatting purposes only
franta-hg@159
    27
 *
franta-hg@159
    28
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@159
    29
 */
franta-hg@159
    30
public class FakeSqlArray implements Array {
franta-hg@159
    31
franta-hg@159
    32
	private static final UnsupportedOperationException exception = new UnsupportedOperationException("This is just a fake SQL array.");
franta-hg@159
    33
	private final Object[] data;
franta-hg@159
    34
	private final SQLType baseType;
franta-hg@159
    35
franta-hg@159
    36
	public FakeSqlArray(Object[] data, SQLType baseType) {
franta-hg@159
    37
		this.data = data;
franta-hg@159
    38
		this.baseType = baseType;
franta-hg@159
    39
	}
franta-hg@159
    40
franta-hg@159
    41
	@Override
franta-hg@164
    42
	public String toString() {
franta-hg@164
    43
		StringBuilder string = new StringBuilder();
franta-hg@164
    44
		for (Object o : data) {
franta-hg@164
    45
			string.append(o);
franta-hg@164
    46
			string.append("\n");
franta-hg@164
    47
		}
franta-hg@164
    48
		return string.toString();
franta-hg@164
    49
	}
franta-hg@164
    50
franta-hg@164
    51
	@Override
franta-hg@159
    52
	public String getBaseTypeName() throws SQLException {
franta-hg@159
    53
		return baseType.name();
franta-hg@159
    54
	}
franta-hg@159
    55
franta-hg@159
    56
	@Override
franta-hg@159
    57
	public int getBaseType() throws SQLException {
franta-hg@159
    58
		return baseType.getCode();
franta-hg@159
    59
	}
franta-hg@159
    60
franta-hg@159
    61
	@Override
franta-hg@159
    62
	public Object getArray() throws SQLException {
franta-hg@159
    63
		return data;
franta-hg@159
    64
	}
franta-hg@159
    65
franta-hg@159
    66
	@Override
franta-hg@159
    67
	public Object getArray(Map<String, Class<?>> map) throws SQLException {
franta-hg@159
    68
		throw exception;
franta-hg@159
    69
	}
franta-hg@159
    70
franta-hg@159
    71
	@Override
franta-hg@159
    72
	public Object getArray(long index, int count) throws SQLException {
franta-hg@159
    73
		throw exception;
franta-hg@159
    74
	}
franta-hg@159
    75
franta-hg@159
    76
	@Override
franta-hg@159
    77
	public Object getArray(long index, int count, Map<String, Class<?>> map) throws SQLException {
franta-hg@159
    78
		throw exception;
franta-hg@159
    79
	}
franta-hg@159
    80
franta-hg@159
    81
	@Override
franta-hg@159
    82
	public ResultSet getResultSet() throws SQLException {
franta-hg@159
    83
		throw exception;
franta-hg@159
    84
	}
franta-hg@159
    85
franta-hg@159
    86
	@Override
franta-hg@159
    87
	public ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException {
franta-hg@159
    88
		throw exception;
franta-hg@159
    89
	}
franta-hg@159
    90
franta-hg@159
    91
	@Override
franta-hg@159
    92
	public ResultSet getResultSet(long index, int count) throws SQLException {
franta-hg@159
    93
		throw exception;
franta-hg@159
    94
	}
franta-hg@159
    95
franta-hg@159
    96
	@Override
franta-hg@159
    97
	public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map) throws SQLException {
franta-hg@159
    98
		throw exception;
franta-hg@159
    99
	}
franta-hg@159
   100
franta-hg@159
   101
	@Override
franta-hg@159
   102
	public void free() throws SQLException {
franta-hg@159
   103
		throw exception;
franta-hg@159
   104
	}
franta-hg@159
   105
}