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