Java JDBC Database Metadata isSybase(DatabaseMetaData metadata)

Here you can find the source of isSybase(DatabaseMetaData metadata)

Description

is Sybase

License

Open Source License

Declaration

public static boolean isSybase(DatabaseMetaData metadata) 

Method Source Code

//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

import java.sql.DatabaseMetaData;

import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;

public class Main {
    private static List<String> sybaseDBProductsNames;
    public static final String SYBASE_LANGUAGE = "Adaptive Server Enterprise | Sybase Adaptive Server IQ";

    /**/*  www  . ja v  a 2s  .  c o m*/
     * if the url include "sybase", return true, else return false
     * 
     * @param url
     * @return
     */
    public static boolean isSybase(String url) {
        return url.indexOf("sybase") > -1; //$NON-NLS-1$
    }

    /**
     * DOC zshen Comment method "isSybase".
     * 
     * @param connection
     * @return decide to whether is sybase connection
     * @throws SQLException
     */
    public static boolean isSybase(java.sql.Connection connection) throws SQLException {
        // DatabaseMetaData connectionMetadata = getConnectionMetadata(connection);
        DatabaseMetaData connectionMetadata = connection.getMetaData();
        if (connectionMetadata.getDriverName() != null && connectionMetadata.getDatabaseProductName() != null) {
            for (String keyString : getSybaseDBProductsName()) {
                if (keyString.equals(connectionMetadata.getDatabaseProductName().trim())) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean isSybase(DatabaseMetaData metadata) {
        boolean result = false;
        // if it is sybase database, it will be the fake DatabaseMetaData
        if (metadata != null && "org.talend.commons.utils.database.SybaseDatabaseMetaData" //$NON-NLS-1$
                .equals(metadata.getClass().getName())) {
            result = true;
        }
        return result;
    }

    /**
     * yyi 2010-08-25 for 14851, Sybase DB has several names with different productions and versions. For example the
     * Sybase IQ with version 12.6 is called 'Sybase' getting by JDBC but the version 15+ it is changed to 'Sybase IQ'.
     * it is user by org.talend.cwm.db.connection.ConnectionUtils.isSybase
     * 
     * @return All Sybase DB products name ,"Adaptive Server Enterprise","Sybase Adaptive Server IQ"
     * ,"Sybase IQ","Sybase"
     */
    public static String[] getSybaseDBProductsName() {
        if (null == sybaseDBProductsNames) {
            sybaseDBProductsNames = new ArrayList<String>();
            for (String name : SYBASE_LANGUAGE.split("\\|")) { //$NON-NLS-1$
                sybaseDBProductsNames.add(name.trim());
            }
            sybaseDBProductsNames.add("Sybase"); //$NON-NLS-1$
            sybaseDBProductsNames.add("Sybase IQ"); //$NON-NLS-1$
            sybaseDBProductsNames.add("Adaptive Server Enterprise | Sybase Adaptive Server IQ"); //$NON-NLS-1$
        }
        return sybaseDBProductsNames.toArray(new String[sybaseDBProductsNames.size()]);
    }
}

Related

  1. isDerbyDatabase(DatabaseMetaData metaData)
  2. isExistsTable(Connection con, String schema, String tableName)
  3. isIdGenerated(DatabaseMetaData metaData)
  4. isMysql(DatabaseMetaData metadata)
  5. isOracleForSid(DatabaseMetaData metadata, String oracleProduct)
  6. isSybaseDb(DatabaseMetaData metaData)
  7. printExistingTables(Connection conn)
  8. printMetaData(Connection con)
  9. printTableExistence(String name, Connection conn)