@Override
  public void exception(ExecuteContext ctx) {
    SQLDialect dialect = ctx.configuration().dialect();
    SQLExceptionTranslator translator =
        (dialect != null)
            ? new SQLErrorCodeSQLExceptionTranslator(dialect.name())
            : new SQLStateSQLExceptionTranslator();

    ctx.exception(translator.translate("jOOQ", ctx.sql(), ctx.sqlException()));
  }
Пример #2
0
  public String toSQL(SQLDialect dialect) {
    if (this == EXCEPT) {
      if (dialect.family() == SQLDialect.ORACLE) {
        return "minus";
      }
    }

    return sql;
  }
 @Bean
 @ConditionalOnMissingBean(org.jooq.Configuration.class)
 public DefaultConfiguration jooqConfiguration() {
   DefaultConfiguration configuration = new DefaultConfiguration();
   if (!StringUtils.isEmpty(this.properties.getSqlDialect())) {
     configuration.set(SQLDialect.valueOf(this.properties.getSqlDialect()));
   }
   configuration.set(this.connectionProvider);
   if (this.transactionProvider != null) {
     configuration.set(this.transactionProvider);
   }
   if (this.recordMapperProvider != null) {
     configuration.set(this.recordMapperProvider);
   }
   if (this.settings != null) {
     configuration.set(this.settings);
   }
   configuration.set(this.recordListenerProviders);
   configuration.set(this.executeListenerProviders);
   configuration.set(this.visitListenerProviders);
   return configuration;
 }
Пример #4
0
  @Override
  public final void toSQL(RenderContext context) {
    if (context.declareFields() || context.declareTables()) {
      SQLDialect dialect = context.configuration().dialect();
      boolean simulateDerivedColumnList = false;

      // [#1801] Some databases don't allow "derived column names" in
      // "simple class specifications". Hence, wrap the table reference in
      // a subselect
      if (fieldAliases != null
          && asList(CUBRID, FIREBIRD, SQLSERVER, SYBASE).contains(dialect.family())
          && wrapped instanceof TableImpl) {

        @SuppressWarnings("unchecked")
        Select<Record> select = select(list(field("*"))).from(((Table<?>) wrapped).as(alias));

        context
            .sql("(")
            .formatIndentStart()
            .formatNewLine()
            .visit(select)
            .formatIndentEnd()
            .formatNewLine()
            .sql(")");
      }

      // [#1801] Some databases do not support "derived column names".
      // They can be simulated by concatenating a dummy SELECT with no
      // results using UNION ALL
      else if (fieldAliases != null
          && asList(H2, MARIADB, MYSQL, ORACLE, SQLITE).contains(dialect.family())) {
        simulateDerivedColumnList = true;

        SelectFieldList fields = new SelectFieldList();
        for (String fieldAlias : fieldAliases) {
          fields.add(field("null").as(fieldAlias));
        }

        Select<Record> select =
            select(fields)
                .where(falseCondition())
                .unionAll(select(field("*")).from(((Table<?>) wrapped).as(alias)));

        context
            .sql("(")
            .formatIndentStart()
            .formatNewLine()
            .visit(select)
            .formatIndentEnd()
            .formatNewLine()
            .sql(")");
      }

      // The default behaviour
      else {
        toSQLWrapped(context);
      }

      // [#291] some aliases cause trouble, if they are not explicitly marked using "as"
      toSQLAs(context);

      context.sql(" ");
      context.literal(alias);

      // [#1801] Add field aliases to the table alias, if applicable
      if (fieldAliases != null && !simulateDerivedColumnList) {
        toSQLDerivedColumnList(context);
      } else {
        // [#756] If the aliased object is an anonymous table (usually an
        // unnested array), then field names must be part of the alias
        // declaration. For example:
        //
        // SELECT t.column_value FROM UNNEST(ARRAY[1, 2]) AS t(column_value)

        // TODO: Is this still needed?
        switch (dialect) {
          case HSQLDB:
          case POSTGRES:
            {
              // The javac compiler doesn't like casting of generics
              Object o = wrapped;

              if (context.declareTables() && o instanceof ArrayTable) {
                ArrayTable table = (ArrayTable) o;

                context.sql("(");
                Utils.fieldNames(context, table.fields());
                context.sql(")");
              }

              break;
            }
        }
      }
    } else {
      context.literal(alias);
    }
  }