1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package util;
  24 
  25 import java.sql.Array;
  26 import java.sql.JDBCType;
  27 import java.sql.ResultSet;
  28 import java.sql.SQLException;
  29 import java.util.Arrays;
  30 import java.util.Map;
  31 
  32 public class StubArray implements Array {
  33 
  34     private String typeName;
  35     Object[] elements;
  36 
  37     public StubArray(String name, Object[] values) {
  38         typeName = name;
  39         elements = Arrays.copyOf(values, values.length);
  40 
  41     }
  42 
  43     @Override
  44     public String getBaseTypeName() throws SQLException {
  45         return typeName;
  46     }
  47 
  48     @Override
  49     public int getBaseType() throws SQLException {
  50         return JDBCType.valueOf(typeName).getVendorTypeNumber();
  51     }
  52 
  53     @Override
  54     public Object getArray() throws SQLException {
  55         return Arrays.copyOf(elements, elements.length);
  56     }
  57 
  58     @Override
  59     public Object getArray(Map<String, Class<?>> map) throws SQLException {
  60         return getArray();
  61     }
  62 
  63     @Override
  64     public Object getArray(long index, int count) throws SQLException {
  65         return getArray();
  66     }
  67 
  68     @Override
  69     public Object getArray(long index, int count, Map<String, Class<?>> map) throws SQLException {
  70         return getArray();
  71     }
  72 
  73     @Override
  74     public ResultSet getResultSet() throws SQLException {
  75         throw new UnsupportedOperationException("Not supported yet.");
  76     }
  77 
  78     @Override
  79     public ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException {
  80         throw new UnsupportedOperationException("Not supported yet.");
  81     }
  82 
  83     @Override
  84     public ResultSet getResultSet(long index, int count) throws SQLException {
  85         throw new UnsupportedOperationException("Not supported yet.");
  86     }
  87 
  88     @Override
  89     public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map) throws SQLException {
  90         throw new UnsupportedOperationException("Not supported yet.");
  91     }
  92 
  93     @Override
  94     public void free() throws SQLException {
  95         elements = null;
  96         typeName = null;
  97     }
  98 
  99 }