Example usage for java.sql DatabaseMetaData getNumericFunctions

List of usage examples for java.sql DatabaseMetaData getNumericFunctions

Introduction

In this page you can find the example usage for java.sql DatabaseMetaData getNumericFunctions.

Prototype

String getNumericFunctions() throws SQLException;

Source Link

Document

Retrieves a comma-separated list of math functions available with this database.

Usage

From source file:org.apache.zeppelin.mysql.SqlCompleter.java

public static Set<String> getSqlKeywordsCompletions(Connection connection) throws IOException, SQLException {

    // Add the default SQL completions
    String keywords = new BufferedReader(
            new InputStreamReader(SqlCompleter.class.getResourceAsStream("/ansi.sql.keywords"))).readLine();

    DatabaseMetaData metaData = connection.getMetaData();

    // Add the driver specific SQL completions
    String driverSpecificKeywords = "/" + metaData.getDriverName().replace(" ", "-").toLowerCase()
            + "-sql.keywords";

    logger.info("JDBC DriverName:" + driverSpecificKeywords);

    if (SqlCompleter.class.getResource(driverSpecificKeywords) != null) {
        String driverKeywords = new BufferedReader(
                new InputStreamReader(SqlCompleter.class.getResourceAsStream(driverSpecificKeywords)))
                        .readLine();//  w ww .ja  va2 s.  c  o  m
        keywords += "," + driverKeywords.toUpperCase();
    }

    Set<String> completions = new TreeSet<>();

    // Add the keywords from the current JDBC connection
    try {
        keywords += "," + metaData.getSQLKeywords();
    } catch (Exception e) {
        logger.debug("fail to get SQL key words from database metadata: " + e, e);
    }
    try {
        keywords += "," + metaData.getStringFunctions();
    } catch (Exception e) {
        logger.debug("fail to get string function names from database metadata: " + e, e);
    }
    try {
        keywords += "," + metaData.getNumericFunctions();
    } catch (Exception e) {
        logger.debug("fail to get numeric function names from database metadata: " + e, e);
    }
    try {
        keywords += "," + metaData.getSystemFunctions();
    } catch (Exception e) {
        logger.debug("fail to get system function names from database metadata: " + e, e);
    }
    try {
        keywords += "," + metaData.getTimeDateFunctions();
    } catch (Exception e) {
        logger.debug("fail to get time date function names from database metadata: " + e, e);
    }

    // Also allow lower-case versions of all the keywords
    keywords += "," + keywords.toLowerCase();

    StringTokenizer tok = new StringTokenizer(keywords, ", ");
    while (tok.hasMoreTokens()) {
        completions.add(tok.nextToken());
    }

    return completions;
}

From source file:org.apache.zeppelin.postgresql.SqlCompleter.java

public static Set<String> getSqlKeywordsCompletions(Connection connection) throws IOException, SQLException {

    // Add the default SQL completions
    String keywords = new BufferedReader(
            new InputStreamReader(SqlCompleter.class.getResourceAsStream("/ansi.sql.keywords"))).readLine();

    DatabaseMetaData metaData = connection.getMetaData();

    // Add the driver specific SQL completions
    String driverSpecificKeywords = "/" + metaData.getDriverName().replace(" ", "-").toLowerCase()
            + "-sql.keywords";

    logger.info("JDBC DriverName:" + driverSpecificKeywords);

    if (SqlCompleter.class.getResource(driverSpecificKeywords) != null) {
        String driverKeywords = new BufferedReader(
                new InputStreamReader(SqlCompleter.class.getResourceAsStream(driverSpecificKeywords)))
                        .readLine();//from   ww  w .j  a  v a  2s  .  c  o m
        keywords += "," + driverKeywords.toUpperCase();
    }

    Set<String> completions = new TreeSet<String>();

    // Add the keywords from the current JDBC connection
    try {
        keywords += "," + metaData.getSQLKeywords();
    } catch (Exception e) {
        logger.debug("fail to get SQL key words from database metadata: " + e, e);
    }
    try {
        keywords += "," + metaData.getStringFunctions();
    } catch (Exception e) {
        logger.debug("fail to get string function names from database metadata: " + e, e);
    }
    try {
        keywords += "," + metaData.getNumericFunctions();
    } catch (Exception e) {
        logger.debug("fail to get numeric function names from database metadata: " + e, e);
    }
    try {
        keywords += "," + metaData.getSystemFunctions();
    } catch (Exception e) {
        logger.debug("fail to get system function names from database metadata: " + e, e);
    }
    try {
        keywords += "," + metaData.getTimeDateFunctions();
    } catch (Exception e) {
        logger.debug("fail to get time date function names from database metadata: " + e, e);
    }

    // Also allow lower-case versions of all the keywords
    keywords += "," + keywords.toLowerCase();

    StringTokenizer tok = new StringTokenizer(keywords, ", ");
    while (tok.hasMoreTokens()) {
        completions.add(tok.nextToken());
    }

    return completions;
}

From source file:org.executequery.gui.editor.autocomplete.AutoCompleteSelectionsFactory.java

private void databaseSystemFunctionsForHost(DatabaseHost databaseHost,
        List<AutoCompleteListItem> listSelections) {

    trace("Building autocomplete object list using [ " + databaseHost.getName()
            + " ] for type - SYSTEM_FUNCTION");

    ResultSet rs = null;//from   w  ww.  j a  v  a2 s. c  om
    DatabaseMetaData databaseMetaData = databaseHost.getDatabaseMetaData();

    try {

        List<String> tableNames = new ArrayList<String>();

        extractNames(tableNames, databaseMetaData.getStringFunctions());
        extractNames(tableNames, databaseMetaData.getNumericFunctions());
        extractNames(tableNames, databaseMetaData.getTimeDateFunctions());

        addKeywordsFromList(tableNames, listSelections, DATABASE_SYSTEM_FUNCTION_DESCRIPTION,
                AutoCompleteListItemType.SYSTEM_FUNCTION);

    } catch (SQLException e) {

        error("Values not available for type SYSTEM_FUNCTION - driver returned: " + e.getMessage());

    } finally {

        releaseResources(rs);
        trace("Finished autocomplete object list using [ " + databaseHost.getName()
                + " ] for type - SYSTEM_FUNCTION");
    }

}

From source file:org.talend.core.model.metadata.builder.database.ExtractMetaDataUtils.java

private List<String> getAllDBFuctions(DatabaseMetaData dbMetadata) {
    List<String> functionlist = new ArrayList<String>();
    if (dbMetadata == null) {
        return functionlist;
    }//  w  w w  . j ava  2  s.  com
    try {
        final String CommaSplit = ",\\s*"; //$NON-NLS-1$

        String[] systemFunctions = null;
        if (dbMetadata.getSystemFunctions() != null) {
            systemFunctions = dbMetadata.getSystemFunctions().split(CommaSplit);
        }
        String[] numericFunctions = null;
        if (dbMetadata.getNumericFunctions() != null) {
            numericFunctions = dbMetadata.getNumericFunctions().split(CommaSplit);
        }

        String[] stringFunctions = null;
        if (dbMetadata.getStringFunctions() != null) {
            stringFunctions = dbMetadata.getStringFunctions().split(CommaSplit);
        }

        String[] timeFunctions = null;
        if (dbMetadata.getTimeDateFunctions() != null) {
            timeFunctions = dbMetadata.getTimeDateFunctions().split(CommaSplit);
        }

        convertFunctions2Array(functionlist, systemFunctions);

        convertFunctions2Array(functionlist, numericFunctions);

        convertFunctions2Array(functionlist, stringFunctions);

        convertFunctions2Array(functionlist, timeFunctions);

    } catch (SQLException e) {
        ExceptionHandler.process(e);
    }
    return functionlist;
}