java/sql-dk/src/info/globalcode/sql/dk/formatting/FakeSqlArray.java
branchv_0
changeset 238 4a1864c3e867
parent 237 7e08730da258
child 239 39e6c2ad3571
equal deleted inserted replaced
237:7e08730da258 238:4a1864c3e867
     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.sql.dk.formatting;
       
    19 
       
    20 import info.globalcode.sql.dk.SQLType;
       
    21 import java.sql.Array;
       
    22 import java.sql.ResultSet;
       
    23 import java.sql.SQLException;
       
    24 import java.util.Map;
       
    25 
       
    26 /**
       
    27  * Fake SQL array, for formatting purposes only
       
    28  *
       
    29  * @author Ing. František Kučera (frantovo.cz)
       
    30  */
       
    31 public class FakeSqlArray implements Array {
       
    32 
       
    33 	private static final UnsupportedOperationException exception = new UnsupportedOperationException("This is just a fake SQL array.");
       
    34 	private final Object[] data;
       
    35 	private final SQLType baseType;
       
    36 
       
    37 	public FakeSqlArray(Object[] data, SQLType baseType) {
       
    38 		this.data = data;
       
    39 		this.baseType = baseType;
       
    40 	}
       
    41 
       
    42 	@Override
       
    43 	public String toString() {
       
    44 		StringBuilder string = new StringBuilder();
       
    45 		for (Object o : data) {
       
    46 			string.append(o);
       
    47 			string.append("\n");
       
    48 		}
       
    49 		return string.toString();
       
    50 	}
       
    51 
       
    52 	@Override
       
    53 	public String getBaseTypeName() throws SQLException {
       
    54 		return baseType.name();
       
    55 	}
       
    56 
       
    57 	@Override
       
    58 	public int getBaseType() throws SQLException {
       
    59 		return baseType.getCode();
       
    60 	}
       
    61 
       
    62 	@Override
       
    63 	public Object getArray() throws SQLException {
       
    64 		return data;
       
    65 	}
       
    66 
       
    67 	@Override
       
    68 	public Object getArray(Map<String, Class<?>> map) throws SQLException {
       
    69 		throw exception;
       
    70 	}
       
    71 
       
    72 	@Override
       
    73 	public Object getArray(long index, int count) throws SQLException {
       
    74 		throw exception;
       
    75 	}
       
    76 
       
    77 	@Override
       
    78 	public Object getArray(long index, int count, Map<String, Class<?>> map) throws SQLException {
       
    79 		throw exception;
       
    80 	}
       
    81 
       
    82 	@Override
       
    83 	public ResultSet getResultSet() throws SQLException {
       
    84 		throw exception;
       
    85 	}
       
    86 
       
    87 	@Override
       
    88 	public ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException {
       
    89 		throw exception;
       
    90 	}
       
    91 
       
    92 	@Override
       
    93 	public ResultSet getResultSet(long index, int count) throws SQLException {
       
    94 		throw exception;
       
    95 	}
       
    96 
       
    97 	@Override
       
    98 	public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map) throws SQLException {
       
    99 		throw exception;
       
   100 	}
       
   101 
       
   102 	@Override
       
   103 	public void free() throws SQLException {
       
   104 		throw exception;
       
   105 	}
       
   106 }