Persist transactions.

@param tx
the transaction
@param blockNumber
the block number
484248
private void persistTransactions(Transaction tx, String blockNumber)
    {

        LOGGER.debug("Going to save transactions for Block - " + getBlockNumberWithRawData(blockNumber) + "!");
        try
        {
            em.persist(tx);
            LOGGER.debug("Transaction with hash " + tx.getHash() + " is stored!");
        }
        catch (Exception ex)
        {
            LOGGER.error("Transaction with hash " + tx.getHash() + " is not stored. ", ex);
            throw new KunderaException("transaction with hash " + tx.getHash() + " is not stored. ", ex);
        }

    }
1206135
@Override
	public void onTxCommit(Transaction tx) {
		if (!tx.isReadOnly() && enableLogging) {
			LogSeqNum lsn = new CommitRecord(txNum).writeToLog();
			VanillaDb.logMgr().flush(lsn);
		}
	}
305227
def persist_block(self,
                      block: 'BaseBlock'
                      ) -> Tuple[Tuple[Hash32, ...], Tuple[Hash32, ...]]:
        
        with self.db.atomic_batch() as db:
            return self._persist_block(db, block)
255118
def tx_serialization_order(provider: Provider, blockhash: str, txid: str) -> int:
    ''''''

    return provider.getblock(blockhash)["tx"].index(txid)
77189
@Override
	public void commit() throws RemoteException {
		tx.commit();
		try {
			tx = VanillaDb.txMgr().newTransaction(isolationLevel, readOnly);
		} catch (Exception e) {
			throw new RemoteException("error creating transaction ", e);
		}
	}
197356
public void persist(Object e)
    {
        if (e == null)
        {
            throw new IllegalArgumentException(
                    "Entity object is invalid, operation failed. Please check previous log message for details");
        }

        // Create an object graph of the entity object.
        ObjectGraph graph = new GraphGenerator().generateGraph(e, this);
        // Call persist on each node in object graph.
        Node node = graph.getHeadNode();
        try
        {
            // Get write lock before writing object required for transaction.
            lock.writeLock().lock();

            node.setPersistenceDelegator(this);
            node.persist();

            // build flush stack.
            flushManager.buildFlushStack(node, com.impetus.kundera.persistence.context.EventLog.EventType.INSERT);

            // Flushing data.
            flush();

            // Add node to persistence context after successful flush.
            getPersistenceCache().getMainCache().addHeadNode(node);
        }
        finally
        {
            lock.writeLock().unlock();
        }

        // Unlocking object.
        graph.clear();
        graph = null;
        if (log.isDebugEnabled())
        {
            log.debug("Data persisted successfully for entity {}.", e.getClass());
        }
    }
45362
@Override
    public void chainUpdated(ChainData chainData) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "chainUpdated", chainData);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "chainUpdated");

    }
372491
@Override
    public final synchronized void commit(ContainerTx tx)
                    throws RemoteException
    {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "commit: " + getStateName(state),
                     new Object[] { tx, currentTx }); //123293

        if (removed) {
            if (isTraceOn && tc.isEntryEnabled())
                Tr.exit(tc, "commit: removed");
            return;
        }

        switch (state)
        {
            case COMMITTING_OUTSIDE_METHOD:
                setState(METHOD_READY);
                break;

            case COMMITTING_IN_METHOD:
                setState(IN_METHOD);
                break;

            default:
                if (isTraceOn && tc.isDebugEnabled()) // d144064
                    Tr.debug(tc, "invalid state: " + state); //123293
                throw new InvalidBeanOStateException(StateStrs[state],
                                "COMMITTING_IN_METHOD | " +
                                                "COMMITTING_OUTSIDE_METHOD");
        }

        if (tx.ivRemoveBeanO == this)
        {
            completeRemoveMethod(tx); // d647928
        }

        // currentTx is now reset in atCommit/atRollback AFTER the final pin
        // is undone.                                                      d258770
        // currentTx = null;                                            // PQ99986

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "commit: " + getStateName(state));
    }
813465
public void commitTransaction() throws SystemException
   {
      Long key = Long.valueOf(Thread.currentThread().getId());
      TransactionImpl tx = txs.get(key);
      if (tx != null)
      {
         try
         {
            tx.commit();
         }
         catch (Throwable t)
         {
            SystemException se = new SystemException("Error during commit");
            se.initCause(t);
            throw se;
         }
      }
      else
      {
         throw new IllegalStateException("No transaction to commit");
      }
   }
1189983
Block createNextBlock(@Nullable final Address to, final long version,
                          @Nullable TransactionOutPoint prevOut, final long time,
                          final byte[] pubKey, final Coin coinbaseValue,
                          final int height) {
        Block b = new Block(params, version);
        b.setDifficultyTarget(difficultyTarget);
        b.addCoinbaseTransaction(pubKey, coinbaseValue, height);

        if (to != null) {
            // Add a transaction paying 50 coins to the "to" address.
            Transaction t = new Transaction(params);
            t.addOutput(new TransactionOutput(params, t, FIFTY_COINS, to));
            // The input does not really need to be a valid signature, as long as it has the right general form.
            TransactionInput input;
            if (prevOut == null) {
                input = new TransactionInput(params, t, Script.createInputScript(EMPTY_BYTES, EMPTY_BYTES));
                // Importantly the outpoint hash cannot be zero as that's how we detect a coinbase transaction in isolation
                // but it must be unique to avoid 'different' transactions looking the same.
                byte[] counter = new byte[32];
                counter[0] = (byte) txCounter;
                counter[1] = (byte) (txCounter++ >> 8);
                input.getOutpoint().setHash(Sha256Hash.wrap(counter));
            } else {
                input = new TransactionInput(params, t, Script.createInputScript(EMPTY_BYTES, EMPTY_BYTES), prevOut);
            }
            t.addInput(input);
            b.addTransaction(t);
        }

        b.setPrevBlockHash(getHash());
        // Don't let timestamp go backwards
        if (getTimeSeconds() >= time)
            b.setTime(getTimeSeconds() + 1);
        else
            b.setTime(time);
        b.solve();
        try {
            b.verifyHeader();
        } catch (VerificationException e) {
            throw new RuntimeException(e); // Cannot happen.
        }
        if (b.getVersion() != version) {
            throw new RuntimeException();
        }
        return b;
    }
201564
@VisibleForTesting
    Block createNextBlockWithCoinbase(long version, byte[] pubKey, final int height) {
        return createNextBlock(null, version, (TransactionOutPoint) null,
                               Utils.currentTimeSeconds(), pubKey, FIFTY_COINS, height);
    }
296050
protected void modify(Transaction t) {
        try {
            this.lock.writeLock().lock();
            t.perform();
        } finally {
            this.lock.writeLock().unlock();
        }
    }
267781
public boolean setWriter(TransactionImpl tx, Object obj)
	{
		try
		{
			LockEntry lock = new LockEntry(new Identity(obj,getBroker()).toString(),
					tx.getGUID(),
					System.currentTimeMillis(),
					LockStrategyFactory.getIsolationLevel(obj),
					LockEntry.LOCK_WRITE);

			setWriterRemote(lock);
			return true;
		}
		catch (Throwable t)
		{
			log.error("Cannot set LockEntry for object " + obj + " in transaction " + tx);
			return false;
		}
	}
1128489
@Override
    public void commit()
    {
        if (!getRollbackOnly())
        {
            onTransaction(TxAction.COMMIT);
            ((EntityManagerImpl) entityManager).getPersistenceDelegator().commit();
        }
    }
131926
public final void commitInternal(final PersistentTransaction transaction)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "commitInternal", transaction);

        getLink().internalCommitAdd();

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "commitInternal");
    }
478130
protected int persist(Iterable<QueueEntry> entries, Transaction transaction) throws IOException {
    long writePointer = transaction.getWritePointer();
    byte[] rowKeyPrefix = Bytes.add(queueRowPrefix, Bytes.toBytes(writePointer));
    int count = 0;
    List<Put> puts = Lists.newArrayList();
    int bytes = 0;

    for (QueueEntry entry : entries) {
      // Row key = queue_name + writePointer + counter
      byte[] rowKey = Bytes.add(rowKeyPrefix, Bytes.toBytes(count++));
      rowKey = HBaseQueueAdmin.ROW_KEY_DISTRIBUTOR.getDistributedKey(rowKey);

      rollbackKeys.add(rowKey);
      // No need to write ts=writePointer, as the row key already contains the writePointer
      Put put = new Put(rowKey);
      put.add(QueueEntryRow.COLUMN_FAMILY,
              QueueEntryRow.DATA_COLUMN,
              entry.getData());
      put.add(QueueEntryRow.COLUMN_FAMILY,
              QueueEntryRow.META_COLUMN,
              QueueEntry.serializeHashKeys(entry.getHashKeys()));

      puts.add(put);

      bytes += entry.getData().length;
    }
    hTable.put(puts);
    hTable.flushCommits();

    return bytes;
  }
468304
synchronized void offer(TransactionTask task)
    {
        Iv2Trace.logTransactionTaskQueueOffer(task);
        TransactionState txnState = task.getTransactionState();
        if (!m_backlog.isEmpty()) {
            /*
             * This branch happens during regular execution when a multi-part is in progress.
             * The first task for the multi-part is the head of the queue, and all the single parts
             * are being queued behind it. The txnid check catches tasks that are part of the multi-part
             * and immediately queues them for execution. If any multi-part txn with smaller txnId shows up,
             * it must from repair process, just let it through.
             */
            if (txnState.isSinglePartition() ){
                m_backlog.addLast(task);
                return;
            }

            //It is possible a RO MP read with higher TxnId could be executed before a RO MP reader with lower TxnId
            //so do not offer them to the site task queue in the same time, place it in the backlog instead. However,
            //if it is an MP Write with a lower TxnId than the TxnId at the head of the backlog it could be a repair
            //task so put the MP Write task into the Scoreboard or the SiteTaskQueue
            TransactionTask headTask = m_backlog.getFirst();
            if (txnState.isReadOnly() && headTask.getTransactionState().isReadOnly() ?
                    TxnEgo.getSequence(task.getTxnId()) != TxnEgo.getSequence(headTask.getTxnId()) :
                    TxnEgo.getSequence(task.getTxnId()) > TxnEgo.getSequence(headTask.getTxnId())) {
                m_backlog.addLast(task);
            } else if (task.needCoordination() && m_scoreboardEnabled) {
                /*
                 * This branch coordinates FragmentTask or CompletedTransactionTask,
                 * holds the tasks until all the sites on the node receive the task.
                 * Task with newer spHandle will
                 */
                coordinatedTaskQueueOffer(task);
            } else {
                taskQueueOffer(task);
            }
        } else {
            /*
             * Base case nothing queued nothing in progress
             * If the task is a multipart then put an entry in the backlog which
             * will act as a barrier for single parts, queuing them for execution after the
             * multipart
             */
            if (!txnState.isSinglePartition()) {
                m_backlog.addLast(task);
            }
            /*
             * This branch coordinates FragmentTask or CompletedTransactionTask,
             * holds the tasks until all the sites on the node receive the task.
             * Task with newer spHandle will
             */
            if (task.needCoordination() && m_scoreboardEnabled) {
                coordinatedTaskQueueOffer(task);
            } else {
                taskQueueOffer(task);
            }
        }
    }