Class ViewDefinitionParser

java.lang.Object
org.compiere.process.ViewDefinitionParser

public final class ViewDefinitionParser extends Object
Split the SQL text of a database view (as returned by PostgreSQL pg_get_viewdef or stored in Oracle ALL_VIEWS.TEXT) into the parts kept in AD_ViewComponent and AD_ViewColumn.
Only the constructs that the view component model can represent are accepted: one or more SELECT statements combined with UNION / UNION ALL.
  • Method Details

    • parse

      public static List<ViewDefinitionParser.Component> parse(String viewSQL)
      Parse the SQL text of a view
      Parameters:
      viewSQL - select statement of the view, without the CREATE VIEW part
      Returns:
      components, in the order they appear in the view
      Throws:
      AdempiereException - with the unsupported construct as message, if the view can't be represented as view components
    • removeCasts

      public static String removeCasts(String sql)
      Remove all the PostgreSQL type casts (::type), outside string literals and quoted identifiers.
      Some casts are needed by PostgreSQL (e.g. lpad(integer::text, ...)) or define the data type of a column, so the result must be reviewed.
      Parameters:
      sql -
      Returns:
      sql without ::type casts