Example usage for java.sql DatabaseMetaData getTimeDateFunctions

List of usage examples for java.sql DatabaseMetaData getTimeDateFunctions

Introduction

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

Prototype

String getTimeDateFunctions() throws SQLException;

Source Link

Document

Retrieves a comma-separated list of the time and date functions available with this database.

Usage

From source file:org.apache.zeppelin.impala.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();

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

    if (null != connection) {
        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();
            keywords += "," + driverKeywords.toUpperCase();
        }/*from  www  .  j  ava  2 s .  c om*/

        // 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.jdbc.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();

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

    if (null != connection) {
        DatabaseMetaData metaData = connection.getMetaData();

        // Add the driver specific SQL completions
        String driverSpecificKeywords = "/" + metaData.getDriverName().replace(" ", "-").toLowerCase()
                + "-sql.keywords";
        logger.info("JDBC DriverName:" + driverSpecificKeywords);
        try {/*from  w  ww . jav  a  2s.c o  m*/
            if (SqlCompleter.class.getResource(driverSpecificKeywords) != null) {
                String driverKeywords = new BufferedReader(
                        new InputStreamReader(SqlCompleter.class.getResourceAsStream(driverSpecificKeywords)))
                                .readLine();
                keywords += "," + driverKeywords.toUpperCase();
            }
        } catch (Exception e) {
            logger.debug(
                    "fail to get driver specific SQL completions for " + driverSpecificKeywords + " : " + e, e);
        }

        // 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);
        }

        // Set all keywords to lower-case versions
        keywords = keywords.toLowerCase();

    }

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

    return completions;
}

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();/*ww w  . jav  a  2s  .c  om*/
        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();// w w w.ja va 2  s.  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  ava  2s . 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;
    }/*from www .j a  v a2 s  . c  om*/
    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;
}