Java SQL Type newArrayOfType(int typeCode, int size)

Here you can find the source of newArrayOfType(int typeCode, int size)

Description

Create a new array of the specified type and size.

License

Open Source License

Declaration


private static Object newArrayOfType(int typeCode, int size) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.sql.Types;

public class Main {
    /**/*from   w  w w .  j  a  v  a2s.c  o m*/
     * Create a new array of the specified type and size.
     */

    private static Object newArrayOfType(int typeCode, int size) {
        return newArrayOfType(typeCode, size, null);
    }

    /**
     * Create a new array of the specified size, initialize by copying values
     * from the specified array. Note that the length of curArray must be less
     * than or equal to "size".
     */
    private static Object newArrayOfType(int typeCode, int size,
            Object curArray) {
        Object result = null;

        switch (typeCode) {
        case Types.DOUBLE: {
            double[] newArray = new double[size];
            if (curArray != null) {
                double[] oldArray = (double[]) curArray;
                for (int i = 0; i < Math.min(oldArray.length, size); i++) {
                    newArray[i] = oldArray[i];
                }
            }
            result = newArray;
        }
            break;
        /*
        case Types.FLOAT: {
           float[] newArray = new float[size];
           if (curArray != null) {
              float[] oldArray = (float[]) curArray;
              for (int i = 0; i < Math.min(oldArray.length, size); i++) {
                 newArray[i] = oldArray[i];
              }
           }
           result = newArray;
        }
           break;
         */
        case Types.INTEGER: {
            /*
            if (is64Bit()) {
               long[] newArray = new long[size];
               if (curArray != null) {
                  long[] oldArray = (long[]) curArray;
                  for (int i = 0; i < Math.min(oldArray.length, size); i++) {
                     newArray[i] = oldArray[i];
                  }
               }
               result = newArray;
            }
            else {
               int[] newArray = new int[size];
               if (curArray != null) {
                  int[] oldArray = (int[]) curArray;
                  for (int i = 0; i < Math.min(oldArray.length, size); i++) {
                     newArray[i] = oldArray[i];
                  }
               }
               result = newArray;
            }
             */
            int[] newArray = new int[size];
            if (curArray != null) {
                int[] oldArray = (int[]) curArray;
                for (int i = 0; i < Math.min(oldArray.length, size); i++) {
                    newArray[i] = oldArray[i];
                }
            }
            result = newArray;
        }
            break;
        case Types.BIT: {
            boolean[] newArray = new boolean[size];
            if (curArray != null) {
                boolean[] oldArray = (boolean[]) curArray;
                for (int i = 0; i < Math.min(oldArray.length, size); i++) {
                    newArray[i] = oldArray[i];
                }
            }
            result = newArray;
        }
            break;
        default: {
            String[] newArray = new String[size];
            if (curArray != null) {
                String[] oldArray = (String[]) curArray;
                for (int i = 0; i < Math.min(oldArray.length, size); i++) {
                    newArray[i] = oldArray[i];
                }
            }
            result = newArray;
        }
            break;
        }

        return result;
    }
}

Related

  1. mapType(Class javaType)
  2. mapXSDTypeName2SQLtype(String xsdtype)
  3. marshalCurlType(String javaType, boolean isAllowNull, boolean generateGenerics)
  4. matchMethods(String name, Method[] methods, Class[] spt, int mrs, boolean exact)
  5. nativeSQL(String sql, boolean noBackslashEscapes)
  6. newInstance(Class clazz, Object... params)
  7. parse(String txt, int level)
  8. prettyPrint(Object obj)
  9. readAscii(Clob clob, String defaultValue)