Esempio n. 1
0
  /**
   * creates an SeQuery with the filters provided to the constructor and returns it. Queries created
   * with this method can be used to execute and fetch results. They cannot be used for other
   * operations, such as calculating layer extents, or result count.
   *
   * <p>Difference with {@link #createSeQueryForFetch(Session, String[])} is tha this function tells
   * <code>SeQuery.setSpatialConstraints</code> to NOT return geometry based bitmasks, which are
   * needed for calculating the query extent and result count, but not for fetching SeRows.
   *
   * @param propertyNames names of attributes to build the query for, respecting order
   * @throws SeException if the ArcSDE Java API throws it while creating the SeQuery or setting it
   *     the spatial constraints.
   * @throws IOException
   */
  private SeQuery createSeQueryForFetch(String[] propertyNames) throws SeException, IOException {
    if (LOGGER.isLoggable(Level.FINEST)) {
      LOGGER.finest(
          "constructing new sql query with connection: "
              + session
              + ", propnames: "
              + java.util.Arrays.asList(propertyNames)
              + " sqlConstruct where clause: '"
              + this.filters.getSeSqlConstruct().getWhere()
              + "'");
    }

    final SeQueryInfo qInfo = filters.getQueryInfo(propertyNames);
    if (sortByClause != null) {
      qInfo.setByClause(sortByClause);
    }

    final SeFilter[] spatialConstraints = this.filters.getSpatialFilters();
    if (LOGGER.isLoggable(Level.FINER)) {
      String msg = "ArcSDE query is: " + toString(qInfo);
      LOGGER.finer(msg);
    }

    final SeQuery seQuery;

    seQuery = session.prepareQuery(qInfo, spatialConstraints, versioningHandler);

    return seQuery;
  }
Esempio n. 2
0
    /**
     * Returns an SeQueryInfo that can be used to retrieve a set of SeRows from an ArcSDE layer or a
     * layer with joins. The SeQueryInfo object lacks the set of column names to fetch. It is the
     * responsibility of the calling code to call setColumns(String []) on the returned object to
     * specify which properties to fetch.
     *
     * @param unqualifiedPropertyNames non null, possibly empty, list of property names to fetch
     * @return
     * @throws IOException
     */
    public SeQueryInfo getQueryInfo(final String[] unqualifiedPropertyNames) throws IOException {
      assert unqualifiedPropertyNames != null;
      String[] tables;
      String byClause = null;

      final SeSqlConstruct plainSqlConstruct = getSeSqlConstruct();

      String where = plainSqlConstruct.getWhere();

      try {
        if (definitionQuery == null) {
          tables = new String[] {this.sdeTable.getQualifiedName()};
        } else {
          tables = definitionQuery.getConstruct().getTables();
          String joinWhere = definitionQuery.getConstruct().getWhere();
          if (where == null) {
            where = joinWhere;
          } else {
            where = joinWhere == null ? where : (joinWhere + " AND " + where);
          }
          try {
            byClause = definitionQuery.getByClause();
          } catch (NullPointerException e) {
            // no-op
          }
        }

        final SeQueryInfo qInfo = new SeQueryInfo();
        final SeSqlConstruct sqlConstruct = new SeSqlConstruct();
        sqlConstruct.setTables(tables);
        if (where != null && where.length() > 0) {
          sqlConstruct.setWhere(where);
        }

        final int queriedAttCount = unqualifiedPropertyNames.length;

        if (queriedAttCount > 0) {
          String[] sdeAttNames = new String[queriedAttCount];
          FilterToSQLSDE sqlEncoder = getSqlEncoder();

          for (int i = 0; i < queriedAttCount; i++) {
            String attName = unqualifiedPropertyNames[i];
            String coldef = sqlEncoder.getColumnDefinition(attName);
            sdeAttNames[i] = coldef;
          }
          qInfo.setColumns(sdeAttNames);
        }

        qInfo.setConstruct(sqlConstruct);
        if (byClause != null) {
          qInfo.setByClause(byClause);
        }
        return qInfo;
      } catch (SeException e) {
        throw new ArcSdeException(e);
      }
    }
Esempio n. 3
0
  public static SeQueryInfo parse(ISession session, PlainSelect select)
      throws SeException, IOException {
    String[] columns = null;
    String[] tables = null;
    String where = null;
    String orderAndOrGroupByClause = null;

    if (LOGGER.isLoggable(Level.FINER)) {
      LOGGER.finer("building SeQueryInfo to reflect " + select);
    }

    // obtain needed SeQueryInfo components

    columns = getColumns(session, select.getSelectItems());
    tables = getTables(select.getFromItems());

    Expression whereClause = select.getWhere();
    if (whereClause != null) {
      where = whereClause.toString();
    }

    if (select.getGroupByColumnReferences() != null
        && select.getGroupByColumnReferences().size() > 0) {
      String gb = PlainSelect.getFormatedList(select.getGroupByColumnReferences(), " GROUP BY ");
      orderAndOrGroupByClause = gb;
    }
    if (select.getOrderByElements() != null && select.getOrderByElements().size() > 0) {
      String ob = PlainSelect.orderByToString(select.getOrderByElements());
      if (orderAndOrGroupByClause == null) {
        orderAndOrGroupByClause = "";
      }
      orderAndOrGroupByClause += " " + ob;
    }

    // build SeQueryInfo
    SeQueryInfo qinfo = new SeQueryInfo();
    qinfo.setColumns(columns);

    SeSqlConstruct sqlConstruct = new SeSqlConstruct();
    sqlConstruct.setTables(tables);
    if (where != null) {
      sqlConstruct.setWhere(where);
    }

    qinfo.setConstruct(sqlConstruct);

    if (orderAndOrGroupByClause != null) {
      qinfo.setByClause(orderAndOrGroupByClause);
    }

    return qinfo;
  }