Java SQL Type createSignature(Method m)

Here you can find the source of createSignature(Method m)

Description

Extracts parameters from a given method object and formats the string names of the methods parameters into a compatible signature

License

Apache License

Parameter

Parameter Description
m Method object

Declaration

private static String createSignature(Method m) throws Exception 

Method Source Code

//package com.java2s;
/**********************************************************************
 // @@@ START COPYRIGHT @@@//from ww w  .java2  s  . co m
 //
 // (C) Copyright 1997-2014 Hewlett-Packard Development Company, L.P.
 //
 //  Licensed under the Apache License, Version 2.0 (the "License");
 //  you may not use this file except in compliance with the License.
 //  You may obtain a copy of the License at
 //
 //      http://www.apache.org/licenses/LICENSE-2.0
 //
 //  Unless required by applicable law or agreed to in writing, software
 //  distributed under the License is distributed on an "AS IS" BASIS,
 //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 //  See the License for the specific language governing permissions and
 //  limitations under the License.
 //
 // @@@ END COPYRIGHT @@@
 **********************************************************************/

import java.lang.reflect.Method;

public class Main {
    /**
     * Extracts parameters from a given method object and formats
     * the string names of the methods parameters into a compatible signature
     * @param  m          Method object
     * @returns           The created signature
     **/
    private static String createSignature(Method m) throws Exception {
        StringBuffer sb = new StringBuffer();
        Class[] params = m.getParameterTypes();
        sb.append("(");
        for (int i = 0; i < params.length; i++) {
            String str1 = params[i].getName();
            if (str1.equals("short")) // IN TYPES
                sb.append("S");
            else if (str1.equals("int"))
                sb.append("I");
            else if (str1.equals("long"))
                sb.append("J");
            else if (str1.equals("float"))
                sb.append("F");
            else if (str1.equals("double"))
                sb.append("D");
            else if (str1.equals("java.lang.String"))
                sb.append("L" + str1.replace('.', '/') + ';');
            else if (str1.equals("java.math.BigDecimal"))
                sb.append("L" + str1.replace('.', '/') + ';');
            else if (str1.equals("java.sql.Date"))
                sb.append("L" + str1.replace('.', '/') + ';');
            else if (str1.equals("java.sql.Timestamp"))
                sb.append("L" + str1.replace('.', '/') + ';');
            else if (str1.equals("java.sql.Time"))
                sb.append("L" + str1.replace('.', '/') + ';');
            else if (str1.equals("java.lang.Integer"))
                sb.append("L" + str1.replace('.', '/') + ';');
            else if (str1.equals("java.lang.Long"))
                sb.append("L" + str1.replace('.', '/') + ';');
            else if (str1.equals("java.lang.Float"))
                sb.append("L" + str1.replace('.', '/') + ';');
            else if (str1.equals("java.lang.Double"))
                sb.append("L" + str1.replace('.', '/') + ';');
            else if (str1.equals("[S")) // OUT TYPES
                sb.append(str1);
            else if (str1.equals("[I"))
                sb.append(str1);
            else if (str1.equals("[J"))
                sb.append(str1);
            else if (str1.equals("[F"))
                sb.append(str1);
            else if (str1.equals("[D"))
                sb.append(str1);
            else if (str1.equals("[Ljava.lang.String;"))
                sb.append(str1.replace('.', '/'));
            else if (str1.equals("[Ljava.math.BigDecimal;"))
                sb.append(str1.replace('.', '/'));
            else if (str1.equals("[Ljava.sql.Date;"))
                sb.append(str1.replace('.', '/'));
            else if (str1.equals("[Ljava.sql.Timestamp;"))
                sb.append(str1.replace('.', '/'));
            else if (str1.equals("[Ljava.sql.Time;"))
                sb.append(str1.replace('.', '/'));
            else if (str1.equals("[Ljava.lang.Integer;"))
                sb.append(str1.replace('.', '/'));
            else if (str1.equals("[Ljava.lang.Long;"))
                sb.append(str1.replace('.', '/'));
            else if (str1.equals("[Ljava.lang.Float;"))
                sb.append(str1.replace('.', '/'));
            else if (str1.equals("[Ljava.lang.Double;"))
                sb.append(str1.replace('.', '/'));
            else if (str1.equals("[Ljava.sql.ResultSet;"))
                sb.append(str1.replace('.', '/'));
            else {
                String msg = "An internal error occurred in the SQL/MX language manager. "
                        + "An unknown parameter type name "
                        + "'"
                        + str1
                        + "' "
                        + "was encountered while trying to create the packed signature.";
                throw new Exception(msg);
            }
        }
        sb.append(")V");
        return sb.toString();

    }
}

Related

  1. convertToString(int datatype)
  2. convertType(final int type)
  3. convertType(final int type, final String typeName)
  4. createAllTypesTable(Connection conn)
  5. createArrTypSql(String[] arr)
  6. createSqlDataType(@Nonnull final String javaDataType)
  7. createTable2()
  8. createTestData()
  9. decodeJavaType(Object pType)