Java SQL Type mapECLtype2SQLtype(String ecltype)

Here you can find the source of mapECLtype2SQLtype(String ecltype)

Description

map EC Ltype SQ Ltype

License

Open Source License

Declaration

public static int mapECLtype2SQLtype(String ecltype) 

Method Source Code

//package com.java2s;
/*##############################################################################

 Copyright (C) 2011 HPCC Systems.//from   www .ja v  a  2 s.c  om

 All rights reserved. This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as
 published by the Free Software Foundation, either version 3 of the
 License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU Affero General Public License for more details.

 You should have received a copy of the GNU Affero General Public License
 along with this program. If not, see <http://www.gnu.org/licenses/>.
 ############################################################################## */

import java.util.HashMap;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public final static HashMap<String, Integer> mapECLTypeNameToSQLType = new HashMap<String, Integer>();
    public final static Pattern TRAILINGNUMERICPATTERN = Pattern.compile(
            "(.*\\s+?)*([A-Z]+)(([0-9]+)(_([0-9]+))?)*", Pattern.DOTALL);

    public static int mapECLtype2SQLtype(String ecltype) {
        if (mapECLTypeNameToSQLType.containsKey(ecltype)) {
            return mapECLTypeNameToSQLType.get(ecltype); //let's try to find the type as is
        } else {
            String postfixUpper = ecltype.substring(
                    ecltype.lastIndexOf(':') + 1).toUpperCase();
            if (mapECLTypeNameToSQLType.containsKey(postfixUpper))
                return mapECLTypeNameToSQLType.get(postfixUpper);
            else {
                //TRAILINGNUMERICPATTERN attemps to match optional leading spaces
                //followed by a string of alphas, followed by optional string of numerics
                //then we look up the string of alphas in the known ECL type map (group(2))
                Matcher m = TRAILINGNUMERICPATTERN.matcher(postfixUpper);
                if (m.matches()
                        && mapECLTypeNameToSQLType.containsKey(m.group(2)))
                    return mapECLTypeNameToSQLType.get(m.group(2));
                else
                    return java.sql.Types.OTHER;
            }
        }
    }
}

Related

  1. jdbcType2javaType(int jdbcType)
  2. jdbcTypeToKylinDataType(int sqlType)
  3. listToJson(List list)
  4. loadAllTypesData(Connection conn)
  5. loadTestDataForEveryType(Connection conn)
  6. mapType(Class javaType)
  7. mapXSDTypeName2SQLtype(String xsdtype)
  8. marshalCurlType(String javaType, boolean isAllowNull, boolean generateGenerics)
  9. matchMethods(String name, Method[] methods, Class[] spt, int mrs, boolean exact)

  10. HOME | Copyright © www.java2s.com 2016