Search in sources :

Example 1 with PostgreViewManager

use of org.jkiss.dbeaver.ext.postgresql.edit.PostgreViewManager in project dbeaver by serge-rider.

the class PostgreUtils method getViewDDL.

public static String getViewDDL(DBRProgressMonitor monitor, PostgreViewBase view, String definition) throws DBException {
    // In some cases view definition already has view header (e.g. Redshift + with no schema binding)
    if (definition.toLowerCase(Locale.ENGLISH).startsWith("create ")) {
        return definition;
    }
    StringBuilder sql = new StringBuilder(view instanceof PostgreView ? "CREATE OR REPLACE " : "CREATE ");
    sql.append(view.getViewType()).append(" ").append(view.getFullyQualifiedName(DBPEvaluationContext.DDL));
    final DBERegistry editorsRegistry = view.getDataSource().getContainer().getPlatform().getEditorsRegistry();
    final PostgreViewManager entityEditor = editorsRegistry.getObjectManager(view.getClass(), PostgreViewManager.class);
    if (entityEditor != null) {
        entityEditor.appendViewDeclarationPrefix(monitor, sql, view);
    }
    definition = definition.trim();
    while (definition.endsWith(";")) {
        definition = definition.substring(0, definition.length() - 1);
    }
    sql.append("\nAS ").append(definition);
    if (entityEditor != null) {
        entityEditor.appendViewDeclarationPostfix(monitor, sql, view);
    }
    sql.append(";");
    return sql.toString();
}
Also used : PostgreViewManager(org.jkiss.dbeaver.ext.postgresql.edit.PostgreViewManager) DBERegistry(org.jkiss.dbeaver.model.edit.DBERegistry)

Example 2 with PostgreViewManager

use of org.jkiss.dbeaver.ext.postgresql.edit.PostgreViewManager in project dbeaver by dbeaver.

the class PostgreUtils method getViewDDL.

public static String getViewDDL(DBRProgressMonitor monitor, PostgreViewBase view, String definition) throws DBException {
    // In some cases view definition already has view header (e.g. Redshift + with no schema binding)
    if (definition.toLowerCase(Locale.ENGLISH).startsWith("create ")) {
        return definition;
    }
    StringBuilder sql = new StringBuilder(view instanceof PostgreView ? "CREATE OR REPLACE " : "CREATE ");
    sql.append(view.getViewType()).append(" ").append(view.getFullyQualifiedName(DBPEvaluationContext.DDL));
    final DBERegistry editorsRegistry = view.getDataSource().getContainer().getPlatform().getEditorsRegistry();
    final PostgreViewManager entityEditor = editorsRegistry.getObjectManager(view.getClass(), PostgreViewManager.class);
    if (entityEditor != null) {
        entityEditor.appendViewDeclarationPrefix(monitor, sql, view);
    }
    definition = definition.trim();
    while (definition.endsWith(";")) {
        definition = definition.substring(0, definition.length() - 1);
    }
    sql.append("\nAS ").append(definition);
    if (entityEditor != null) {
        entityEditor.appendViewDeclarationPostfix(monitor, sql, view);
    }
    sql.append(";");
    return sql.toString();
}
Also used : PostgreViewManager(org.jkiss.dbeaver.ext.postgresql.edit.PostgreViewManager) DBERegistry(org.jkiss.dbeaver.model.edit.DBERegistry)

Aggregations

PostgreViewManager (org.jkiss.dbeaver.ext.postgresql.edit.PostgreViewManager)2 DBERegistry (org.jkiss.dbeaver.model.edit.DBERegistry)2