Package com.caucho.db.xa

Examples of com.caucho.db.xa.Transaction


   * Rebuilds the indexes
   */
  private void rebuildIndexes()
    throws IOException, SQLException
  {
    Transaction xa = Transaction.create();
    xa.setAutoCommit(true);

    try {
      TableIterator iter = createTableIterator();

      iter.init(xa);

      Column []columns = _row.getColumns();

      while (iter.nextBlock()) {
        iter.initRow();

        byte []blockBuffer = iter.getBuffer();

        while (iter.nextRow()) {
          try {
            long rowAddress = iter.getRowAddress();
            int rowOffset = iter.getRowOffset();

            for (int i = 0; i < columns.length; i++) {
              Column column = columns[i];

              /*
              if (column.getIndex() != null)
                System.out.println(Long.toHexString(iter.getBlock().getBlockId()) + ":" + Long.toHexString(rowAddress) + ":" + Long.toHexString(rowOffset) + ": " + column.getIndexKeyCompare().toString(blockBuffer, rowOffset + column.getColumnOffset(), column.getLength()));
              */

              column.setIndex(xa, blockBuffer, rowOffset, rowAddress, null);
            }
          } catch (Exception e) {
            log.log(Level.WARNING, e.toString(), e);
          }
        }
      }
    } finally {
      xa.commit();
    }
  }
View Full Code Here


   * Rebuilds the indexes
   */
  public void validateIndexes()
    throws IOException, SQLException
  {
    Transaction xa = Transaction.create();
    xa.setAutoCommit(true);

    try {
      TableIterator iter = createTableIterator();

      iter.init(xa);

      Column []columns = _row.getColumns();

      while (iter.nextBlock()) {
        iter.initRow();

        byte []blockBuffer = iter.getBuffer();

        while (iter.nextRow()) {
          try {
            long rowAddress = iter.getRowAddress();
            int rowOffset = iter.getRowOffset();

            for (int i = 0; i < columns.length; i++) {
              Column column = columns[i];

              column.validateIndex(xa, blockBuffer, rowOffset, rowAddress);
            }
          } catch (Exception e) {
            log.log(Level.WARNING, e.toString(), e);
          }
        }
      }
    } finally {
      xa.commit();
    }
  }
View Full Code Here

  }

  class IndexCacheWriter extends TaskWorker {
    public void runTask()
    {
      Transaction xa = Transaction.create();
     
      try {
        IndexKey key = null;

        Thread.interrupted();
View Full Code Here

  private java.sql.ResultSet executeQuery(Query query,
                                          QueryContext queryContext)
    throws SQLException
  {
    Transaction xa = _conn.getTransaction();

    boolean isOkay = false;
    try {
      query.execute(queryContext, xa);
      isOkay = true;
    } finally {
      if (! xa.isAutoCommit()) {
      }
      else if (isOkay)
        xa.commit();
      else
        xa.rollback();
    }

    _rs = new ResultSetImpl(this, queryContext.getResult());

    return _rs;
View Full Code Here

   * @return the number of rows modified
   */
  private int executeUpdate(Query query)
    throws SQLException
  {
    Transaction xa = _conn.getTransaction();
    boolean isOkay = false;

    int rowUpdateCount = 0;

    try {
      _queryContext.setTransaction(xa);

      query.execute(_queryContext, xa);

      rowUpdateCount = _queryContext.getRowUpdateCount();

      isOkay = true;
    } finally {
      if (! xa.isAutoCommit()) {
      }
      else if (isOkay)
        xa.commit();
      else
        xa.rollback();
    }

    return rowUpdateCount;
  }
View Full Code Here

  }

  public Transaction getTransaction()
  {
    if (_isAutoCommit) {
      Transaction xa = Transaction.create(this);
      // XXX: value?
      // xa.setTransactionTimeout(15000);
      xa.setAutoCommit(true);
      return xa;
    }
    else if (_xa == null) {
      _xa = Transaction.create(this);
     
View Full Code Here

    throws SQLException
  {
    if (log.isLoggable(Level.FINER))
      log.finer("commit " + this + " " + _xa);
   
    Transaction xa = _xa;
    _xa = null;
   
    if (xa != null)
      xa.commit();
  }
View Full Code Here

  }

  public void rollback()
    throws SQLException
  {
    Transaction xa = _xa;
    _xa = null;

    if (xa != null) {
      if (log.isLoggable(Level.FINER))
  log.finer("rollback " + this + " " + _xa);
   
      xa.rollback();
    }
  }
View Full Code Here

  public void setAutoCommit(boolean autoCommit)
    throws SQLException
  {
    if (! _isAutoCommit && autoCommit) {
      Transaction xa = _xa;
      _xa = null;
   
      if (xa != null)
  xa.commit();
    }
   
    _isAutoCommit = autoCommit;
  }
View Full Code Here

  public boolean execute()
    throws SQLException
  {
    _count++;

    Transaction xa = null;

    try {
      if (_count != 1)
        throw new IllegalStateException("Multithreading execute");

      xa = _conn.getTransaction();
      QueryContext queryContext = getQueryContext();

      if (_query.isSelect()) {
        _query.execute(queryContext, xa);

        _wasResultSet = true;
        _resultSet = new ResultSetImpl(this, queryContext.getResult());

        return true;
      }
      else {
        queryContext.setReturnGeneratedKeys(_isReturnGeneratedKeys);

        _query.execute(queryContext, xa);

        _wasResultSet = false;
        return false;
      }
    } finally {
      _count--;

      if (xa != null && xa.isAutoCommit())
        xa.rollback();
    }
  }
View Full Code Here

TOP

Related Classes of com.caucho.db.xa.Transaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.