Java SQL Type columnTypesDiffer(int t1, int t2)

Here you can find the source of columnTypesDiffer(int t1, int t2)

Description

Checks if the given column types materially differ.

License

Open Source License

Parameter

Parameter Description
t1 One of the column types to compare
t2 One of the column types to compare.

Return

True iff the given column types are materially different

Declaration

public static boolean columnTypesDiffer(int t1, int t2) 

Method Source Code

//package com.java2s;
/*//from  w  w  w. j av a  2s  . c om
 * Copyright (c) 2008, SQL Power Group Inc.
 *
 * This file is part of Power*Architect.
 *
 * Power*Architect is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Power*Architect 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */

import java.sql.Types;

public class Main {
    /**
     * Checks if the given column types materially differ. Some data 
     * types (for example, DECIMAL and NUMERIC) are essentially the same.
     * 
     * @param t1 One of the column types to compare
     * @param t2 One of the column types to compare.
     * @return True iff the given column types are materially different
     */
    public static boolean columnTypesDiffer(int t1, int t2) {
        int sourceType = compressType(t1);
        int targetType = compressType(t2);
        return sourceType != targetType;
    }

    /**
     * Compresses all the different kinds of essentially identical types
     * into an arbitrarily chosen one of them.  For instance, NUMERIC
     * and DECIMAL both compress to NUMERIC.
     * 
     * @param type
     * @return
     */
    private static int compressType(int type) {
        if (type == Types.DECIMAL) {
            return Types.NUMERIC;
        } else {
            return type;
        }
    }
}

Related

  1. callPro2(String sql, String[] inparameters, Integer[] outparameters)
  2. columnClassName(int columnType)
  3. columnDisplaySize(int columnType)
  4. columnPrecision(int columnType)
  5. columnScale(int columnType)
  6. compressType(int type)
  7. convert2MysqlType(String cls)
  8. convertBoolean(Object value, int srcType, int destType)
  9. convertKnownType(Object one, Class to)