Esempio n. 1
0
  @Override
  public void serialize(QueryMetadata metadata, boolean forCountRow, SQLSerializer context) {
    if (!forCountRow && metadata.getModifiers().isRestricting() && !metadata.getJoins().isEmpty()) {
      QueryModifiers mod = metadata.getModifiers();

      if (mod.getOffset() == null) {
        context.append(limitQueryStart);
        context.serializeForQuery(metadata, forCountRow);
        context.handle(limitQueryEnd, mod.getLimit());
      } else {
        context.append(outerQueryStart);
        context.serializeForQuery(metadata, forCountRow);
        context.append(outerQueryEnd);

        if (mod.getLimit() == null) {
          context.handle(offsetTemplate, mod.getOffset());
        } else {
          context.handle(limitOffsetTemplate, mod.getOffset(), mod.getLimit());
        }
      }

    } else {
      context.serializeForQuery(metadata, forCountRow);
    }

    if (!metadata.getFlags().isEmpty()) {
      context.serialize(Position.END, metadata.getFlags());
    }
  }
Esempio n. 2
0
 private void serializeModifiersForDML(QueryMetadata metadata, SQLSerializer context) {
   if (metadata.getWhere() != null) {
     context.append(" and ");
   } else {
     context.append(getWhere());
   }
   context.append("rownum <= ");
   context.visitConstant(metadata.getModifiers().getLimit());
 }
Esempio n. 3
0
  @Override
  public void serializeDelete(
      QueryMetadata metadata, RelationalPath<?> entity, SQLSerializer context) {
    context.serializeForDelete(metadata, entity);

    // limit
    if (metadata.getModifiers().isRestricting()) {
      serializeModifiersForDML(metadata, context);
    }

    if (!metadata.getFlags().isEmpty()) {
      context.serialize(Position.END, metadata.getFlags());
    }
  }
Esempio n. 4
0
 protected SQLBindings createBindings(QueryMetadata metadata, SQLSerializer serializer) {
   String queryString = serializer.toString();
   ImmutableList.Builder<Object> args = ImmutableList.builder();
   Map<ParamExpression<?>, Object> params = metadata.getParams();
   for (Object o : serializer.getConstants()) {
     if (o instanceof ParamExpression) {
       if (!params.containsKey(o)) {
         throw new ParamNotSetException((ParamExpression<?>) o);
       }
       o = metadata.getParams().get(o);
     }
     args.add(o);
   }
   return new SQLBindings(queryString, args.build());
 }
Esempio n. 5
0
  @Override
  public void serialize(QueryMetadata metadata, boolean forCountRow, SQLSerializer context) {
    if (!forCountRow && metadata.getModifiers().isRestricting() && !metadata.getJoins().isEmpty()) {
      QueryModifiers mod = metadata.getModifiers();
      if (mod.getOffset() == null) {
        // select top ...
        metadata = metadata.clone();
        metadata.addFlag(
            new QueryFlag(
                QueryFlag.Position.AFTER_SELECT,
                Expressions.template(Integer.class, topTemplate, mod.getLimit())));
        context.serializeForQuery(metadata, forCountRow);
      } else {
        throw new IllegalStateException("offset not supported");
      }

    } else {
      context.serializeForQuery(metadata, forCountRow);
    }

    if (!metadata.getFlags().isEmpty()) {
      context.serialize(Position.END, metadata.getFlags());
    }
  }
Esempio n. 6
0
 protected SQLSerializer createSerializer() {
   SQLSerializer serializer = new SQLSerializer(configuration, true);
   serializer.setUseLiterals(useLiterals);
   return serializer;
 }