Persist blocks and transactions.

@param block
the block
179254
private void persistBlocksAndTransactions(EthBlock block)
    {
        Block blk = EtherObjectConverterUtil.convertEtherBlockToKunderaBlock(block, false);
        try
        {
            em.persist(blk);
            LOGGER.debug("Block number " + getBlockNumberWithRawData(blk.getNumber()) + " is stored!");
        }
        catch (Exception ex)
        {
            LOGGER.error("Block number " + getBlockNumberWithRawData(blk.getNumber()) + " is not stored. ", ex);
            throw new KunderaException("Block number " + getBlockNumberWithRawData(blk.getNumber())
                    + " is not stored. ", ex);
        }
        for (TransactionResult tx : block.getResult().getTransactions())
        {
            persistTransactions(EtherObjectConverterUtil.convertEtherTxToKunderaTx(tx), blk.getNumber());
        }
        em.clear();
    }
759100
private void addToSplitterQueue(Block<S, L> block) {
        ElementReference ref = splitters.referencedAdd(block);
        block.setSplitterQueueReference(ref);
    }
619101
protected Block visitBlock(Block block) {
        if (block == null) {
            return null;
        }

        Statement stmt = (Statement)block.accept(this);

        if (stmt instanceof Block) {
            return (Block)stmt;
        }
        else if (stmt != null) {
            return new Block(stmt);
        }
        else {
            return new Block(block.getSourceInfo());
        }
    }
753398
public void insertBlock(AbstractBaseDTNode<I, D> blockRoot) {
        blockRoot.removeFromBlockList();

        blockRoot.setNextElement(next);
        if (getNextElement() != null) {
            next.setPrevElement(blockRoot);
        }
        blockRoot.setPrevElement(this);
        next = blockRoot;
    }
412622
public void offer(StreamBlock streamBlock) throws IOException {
        m_persistentDeque.offer(streamBlock.asBBContainer());
        long unreleasedSeqNo = streamBlock.unreleasedSequenceNumber();
        if (m_memoryDeque.size() < 2) {
            StreamBlock fromPBD = pollPersistentDeque(false);
            if ((streamBlock.startSequenceNumber() == fromPBD.startSequenceNumber()) &&
                    (unreleasedSeqNo > streamBlock.startSequenceNumber())) {
                fromPBD.releaseTo(unreleasedSeqNo - 1);
            }
        }
    }
427734
@Override
	public void writeBlock(Buffer buffer) throws IOException {
		try {
			// if successfully added, the buffer will be recycled after the write operation
			addRequest(new BufferWriteRequest(this, buffer));
		} catch (Throwable e) {
			// if not added, we need to recycle here
			buffer.recycleBuffer();
			ExceptionUtils.rethrowIOException(e);
		}

	}
322624
@Override
	protected void writeDataBlock(byte[] data, int offset, int len, int blockHandle) throws DataStoreException
    {
    	byte[] blockData = new byte[blockSize];
    	System.arraycopy(data, offset, blockData, 0, len);
    	
    	dirtyBlockTable.markDirty(blockHandle, blockData);    	
    	journal.writeDataBlock(blockHandle, (long)blockHandle*blockSize, blockData);
    }
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)
544946
public void saveBlocks(BigInteger startBlockNumber, BigInteger endBlockNumber)
    {

        if (endBlockNumber.compareTo(startBlockNumber) < 1)
        {
            LOGGER.error("startBlockNumber must be smaller than endBlockNumer");
            throw new KunderaException("startBlockNumber must be smaller than endBlockNumer");
        }

        if (startBlockNumber.compareTo(getFirstBlockNumber()) < 0)
        {
            LOGGER.error("start block number can't be smaller than EARLIEST block");
            throw new KunderaException("starting block number can't be smaller than EARLIEST block");
        }

        if (endBlockNumber.compareTo(getLatestBlockNumber()) > 0)
        {
            LOGGER.error("end block number can't be larger than LATEST block");
            throw new KunderaException("end block number can't be larger than LATEST block");
        }

        long diff = endBlockNumber.subtract(startBlockNumber).longValue();

        for (long i = 0; i <= diff; i++)
        {
            EthBlock block = null;
            BigInteger currentBlockNum = null;
            try
            {
                currentBlockNum = startBlockNumber.add(BigInteger.valueOf(i));
                block = web3j.ethGetBlockByNumber(DefaultBlockParameter.valueOf(currentBlockNum), true).send();
            }
            catch (IOException ex)
            {
                LOGGER.error("Not able to find block" + currentBlockNum + ". ", ex);
                throw new KunderaException("Not able to find block" + currentBlockNum + ". ", ex);
            }
            persistBlocksAndTransactions(block);
        }

    }
222220
private static <S, L> void updateBlockReferences(Block<S, L> block) {
        UnorderedCollection<State<S, L>> states = block.getStates();
        for (ElementReference ref : states.references()) {
            State<S, L> state = states.get(ref);
            state.setBlockReference(ref);
            state.setBlock(block);
        }
    }
389105
public final void persist(BatchingContext batchingContext, TransactionState tranState)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "persist", new Object[] { batchingContext, tranState});

        if ((tranState == TransactionState.STATE_COMMITTED)
            || (tranState == TransactionState.STATE_COMMITTING_1PC)
            || (tranState == TransactionState.STATE_COMMITTING_2PC))
        {
            batchingContext.delete(getPersistable());
        }
        else if ((tranState == TransactionState.STATE_PREPARED)
                 || (tranState == TransactionState.STATE_PREPARING))
        {
            Persistable tuple = getPersistable();
            tuple.setLogicallyDeleted(true);
            batchingContext.updateLogicalDeleteAndXID(tuple);
        }
        else if ((tranState == TransactionState.STATE_ROLLEDBACK)
                 || (tranState == TransactionState.STATE_ROLLINGBACK))
        {
            Persistable tuple = getPersistable();
            tuple.setLogicallyDeleted(false);
            batchingContext.updateLogicalDeleteAndXID(tuple);
        }
        else
        {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "persist");
            throw new IllegalStateException(nls.getFormattedMessage("INVALID_TASK_OPERATION_SIMS1520", new Object[] {tranState}, null));
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "persist");
    }
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());
        }
    }
851955
public void visitBlockStatement(BlockStatement block) {
        pushState();
        block.setVariableScope(currentScope);
        super.visitBlockStatement(block);
        popState();
    }
116905
@Override
  public void addBlock(BlockInfo newblock) {
    if (this.blocks == null) {
      this.blocks = new BlockInfo[1];
      this.blocks[0] = newblock;
    } else {
      int size = this.blocks.length;
      BlockInfo[] newlist = new BlockInfo[size + 1];
      System.arraycopy(this.blocks, 0, newlist, 0, size);
      newlist[size] = newblock;
      this.blocks = newlist;
    }
  }
450583
void removeBlock(Block block) {
    BlockInfo blockInfo = removeBlockFromMap(block);
    if (blockInfo == null)
      return;
    blockInfo.inode = null;
    for(int idx = blockInfo.numNodes()-1; idx >= 0; idx--) {
      DatanodeDescriptor dn = blockInfo.getDatanode(idx);
      dn.removeBlock(blockInfo); // remove from the list and wipe the location
    }
  }
1333162
def write(self, block):
        
        self.fileobj.write(block)
        self.status.update(len(block))
808367
public void persist(Node node)
    {
        Object entity = node.getData();
        Object id = node.getEntityId();
        EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, node.getDataClass());
        isUpdate = node.isUpdate();
        List<RelationHolder> relationHolders = getRelationHolders(node);
        onPersist(metadata, entity, id, relationHolders);
        id = PropertyAccessorHelper.getId(entity, metadata);
        node.setEntityId(id);
        indexNode(node, metadata);
    }