Ejemplo n.º 1
0
  protected String transform(String sql) {
    sql = PortalUtil.transformCustomSQL(sql);

    StringBundler sb = new StringBundler();

    try {
      UnsyncBufferedReader unsyncBufferedReader =
          new UnsyncBufferedReader(new UnsyncStringReader(sql));

      String line = null;

      while ((line = unsyncBufferedReader.readLine()) != null) {
        sb.append(line.trim());
        sb.append(StringPool.SPACE);
      }

      unsyncBufferedReader.close();
    } catch (IOException ioe) {
      return sql;
    }

    return sb.toString();
  }
Ejemplo n.º 2
0
  private SQLQuery buildSearchQuery(
      Session session,
      long companyId,
      String keywords,
      Boolean configured,
      Long paymentMethodId,
      OrderByComparator obc,
      boolean count,
      boolean withPermissionCheck)
      throws PortalException, SystemException {

    String sql =
        "SELECT "
            + (count ? "count(*) as COUNT_VALUE" : " {Payment_PaymentPlugin.*}")
            + " FROM Payment_PaymentPlugin";

    if (Validator.isNotNull(paymentMethodId))
      sql +=
          " INNER JOIN Payment_PaymentPlugin_PaymentMethod ON (Payment_PaymentPlugin.paymentPluginId = Payment_PaymentPlugin_PaymentMethod.paymentPluginId)";

    sql += " WHERE (Payment_PaymentPlugin.companyId = ?)";

    if (Validator.isNotNull(keywords)) {
      sql += " AND (Payment_PaymentPlugin.name LIKE ?)";
    }
    if (Validator.isNotNull(configured)) {
      sql += " AND (Payment_PaymentPlugin.configured = ?)";
    }
    if (Validator.isNotNull(paymentMethodId)) {
      sql += " AND (Payment_PaymentPlugin_PaymentMethod.paymentMethodId = ?)";
    }

    if (!count) sql += " ORDER BY Payment_PaymentPlugin.name ASC";

    sql = PortalUtil.transformCustomSQL(sql);
    sql = CustomSQLUtil.replaceIsNull(sql);
    if (!count) sql = CustomSQLUtil.replaceOrderBy(sql, obc);

    if (withPermissionCheck) {
      Group guestGroup = GroupLocalServiceUtil.getGroup(companyId, GroupConstants.GUEST);

      sql =
          InlineSQLHelperUtil.replacePermissionCheck(
              sql,
              PaymentPlugin.class.getName(),
              "Payment_PaymentPlugin.paymentPluginId",
              guestGroup.getGroupId());
    }

    SQLQuery q = session.createSQLQuery(sql);

    if (!count) q.addEntity("Payment_PaymentPlugin", PaymentPluginImpl.class);
    else q.addScalar(COUNT_COLUMN_NAME, Type.LONG);

    QueryPos qPos = QueryPos.getInstance(q);

    qPos.add(companyId);

    if (Validator.isNotNull(keywords)) {
      qPos.add("%" + keywords + "%");
    }
    if (Validator.isNotNull(configured)) {
      qPos.add(configured);
    }
    if (Validator.isNotNull(paymentMethodId)) {
      qPos.add(paymentMethodId);
    }

    return q;
  }