示例#1
0
  /** Returns a new query context. */
  public static QueryContext allocate() {
    QueryContext queryContext = _freeList.allocate();

    if (queryContext == null) queryContext = new QueryContext();

    queryContext.clearParameters();
    queryContext._limit = -1;
    queryContext._isNonLocking = false;

    return queryContext;
  }
示例#2
0
  /** Executes the query. */
  public boolean exists(QueryContext context, DbTransaction xa) throws SQLException {
    SelectResult result = SelectResult.create(_nullExprs, null);

    try {
      TableIterator[] rows = result.initRows(getFromItems());
      context.init(xa, rows, isReadOnly());

      return execute(result, rows, context, xa);
    } catch (IOException e) {
      throw new SQLExceptionWrapper(e);
    } finally {
      context.unlock();

      result.close();
    }
  }
  /** validate the constraint. */
  @Override
  public void validate(TableIterator[] sourceRows, QueryContext context, Transaction xa)
      throws SQLException {
    try {
      TableIterator sourceRow = sourceRows[0];

      byte[] sourceBuffer = sourceRow.getBuffer();
      int sourceOffset = sourceRow.getRowOffset();

      byte[] buffer = context.getBuffer();

      int length = _column.getLength();

      if (length <= 0) return;

      BTree index = _column.getIndex();

      long value = index.lookup(buffer, 0, length);

      if (value != 0) {
        Table table = sourceRow.getTable();
        long blockId = sourceRow.getBlockId();

        throw new SQLException(
            L.l(
                "`{0}' in {1}.{2} fails uniqueness constraint.",
                _column.getString(blockId, sourceBuffer, sourceOffset),
                table.getName(),
                _column.getName()));
      }
    } catch (IOException e) {
      throw new SQLExceptionWrapper(e);
    }
  }
  /** Executes the query. */
  public void execute(QueryContext queryContext, Transaction xa) throws SQLException {
    try {
      _factory.create();
    } catch (java.io.IOException e) {
      throw new SQLExceptionWrapper(e);
    }

    queryContext.setRowUpdateCount(0);
  }
示例#5
0
  private java.sql.ResultSet executeQuery(Query query, QueryContext queryContext)
      throws SQLException {
    DbTransaction xa = getConnectionImpl().getTransaction();

    queryContext.setNonLocking();

    SelectCursor result = query.executeCursor(queryContext, xa);

    return new CursorResultSetImpl(this, queryContext, result);
  }
  /**
   * Evaluates aggregate functions during the group phase.
   *
   * @param context the current database tuple
   */
  public void evalGroup(QueryContext context) throws SQLException {
    if (_expr.isNull(context)) return;

    switch (_type) {
      default:
        {
          String value = _expr.evalString(context);

          context.setGroupString(_index, value);
        }
        break;
    }
  }
示例#7
0
  public void init(QueryContext queryContext) throws SQLException {
    init(queryContext.getTransaction());

    _queryContext = queryContext;
  }
 public String evalString(QueryContext context) {
   return context.getGroupString(_index);
 }