Search in sources :

Example 1 with SQLHelpTopic

use of org.jkiss.dbeaver.model.sql.SQLHelpTopic in project dbeaver by serge-rider.

the class SQLContextInformer method readDataSourceHelp.

private static String readDataSourceHelp(DBRProgressMonitor monitor, DBPDataSource dataSource, DBPKeywordType keywordType, String keyword) {
    final SQLHelpProvider helpProvider = DBUtils.getAdapter(SQLHelpProvider.class, dataSource);
    if (helpProvider == null) {
        return null;
    }
    final SQLHelpTopic helpTopic = helpProvider.findHelpTopic(monitor, keyword, keywordType);
    if (helpTopic == null) {
        return null;
    }
    if (!CommonUtils.isEmpty(helpTopic.getContents())) {
        return helpTopic.getContents();
    } else if (!CommonUtils.isEmpty(helpTopic.getUrl())) {
        return "<a href=\"" + helpTopic.getUrl() + "\">" + keyword + "</a>";
    } else {
        return null;
    }
}
Also used : SQLHelpProvider(org.jkiss.dbeaver.model.sql.SQLHelpProvider) SQLHelpTopic(org.jkiss.dbeaver.model.sql.SQLHelpTopic)

Example 2 with SQLHelpTopic

use of org.jkiss.dbeaver.model.sql.SQLHelpTopic in project dbeaver by serge-rider.

the class MySQLHelpProvider method loadTopics.

private void loadTopics(DBRProgressMonitor monitor) {
    try (final JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Read MySQL help topicc")) {
        try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT name, description, example, url FROM mysql.help_topic")) {
            try (JDBCResultSet dbResult = dbStat.executeQuery()) {
                while (dbResult.next()) {
                    String topicName = dbResult.getString(1);
                    SQLHelpTopic helpTopic = new SQLHelpTopic();
                    helpTopic.setContents("<pre>" + dbResult.getString(2) + "</pre>");
                    helpTopic.setExample(dbResult.getString(3));
                    helpTopic.setUrl(dbResult.getString(4));
                    if (topicName != null) {
                        synchronized (topicCache) {
                            topicCache.put(topicName.toUpperCase(Locale.ENGLISH), helpTopic);
                        }
                    }
                }
            }
        } catch (SQLException e) {
            log.error("Error reading help topics", e);
        }
    } finally {
        isLoaded = true;
    }
}
Also used : JDBCPreparedStatement(org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement) JDBCSession(org.jkiss.dbeaver.model.exec.jdbc.JDBCSession) SQLException(java.sql.SQLException) JDBCResultSet(org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet) SQLHelpTopic(org.jkiss.dbeaver.model.sql.SQLHelpTopic)

Aggregations

SQLHelpTopic (org.jkiss.dbeaver.model.sql.SQLHelpTopic)2 SQLException (java.sql.SQLException)1 JDBCPreparedStatement (org.jkiss.dbeaver.model.exec.jdbc.JDBCPreparedStatement)1 JDBCResultSet (org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet)1 JDBCSession (org.jkiss.dbeaver.model.exec.jdbc.JDBCSession)1 SQLHelpProvider (org.jkiss.dbeaver.model.sql.SQLHelpProvider)1