StringCursor::StringCursor(
	TransactionContext &txn, ObjectManager &objectManager, OId oId)
	: BaseObject(txn.getPartitionId(), objectManager, oId),
	  zeroLengthStr_(ZERO_LENGTH_STR_BINARY_) {
	length_ = ValueProcessor::decodeVarSize(getBaseAddr());
	moveCursor(ValueProcessor::getEncodedVarSize(length_));  
}
Beispiel #2
0
BaseContainer::RowCache::RowCache(TransactionContext &txn, BaseContainer *container)
	: fieldCacheList_(txn.getDefaultAllocator()) {
	ObjectManager &objectManager = *(container->getObjectManager());
	new (frontFieldCache_.addr())
			FieldCache(txn.getPartitionId(), objectManager);

	const uint32_t varCount = container->getVariableColumnNum();

	lastCachedField_ = 0;

	if (varCount > 0) {
		assert(fieldCacheList_.empty());
		fieldCacheList_.resize(varCount);
		for (uint32_t i = varCount; i > 0; i--) {
			void *addr = &fieldCacheList_[i - 1];
			new (addr) FieldCache(txn.getPartitionId(), objectManager);
		}
	}
}
VariableArrayCursor::VariableArrayCursor(TransactionContext &txn,
	ObjectManager &objectManager, OId oId, AccessMode accessMode)
	: BaseObject(txn.getPartitionId(), objectManager),
	  curObject_(*this),
	  elemCursor_(UNDEF_CURSOR_POS),
	  accessMode_(accessMode) {
	BaseObject::load(oId, accessMode_);
	rootOId_ = getBaseOId();
	elemNum_ = ValueProcessor::decodeVarSize(curObject_.getBaseAddr());
	curObject_.moveCursor(
		ValueProcessor::getEncodedVarSize(elemNum_));  
}
Beispiel #4
0
BaseContainer::RowArray::RowArray(TransactionContext &txn, BaseContainer *container) 
	: rowArrayImplList_(txn.getDefaultAllocator()),
	rowArrayStorage_(txn.getPartitionId(), *container->getObjectManager()),
	rowCache_(txn, container), defaultImpl_(NULL) {

	if (container->getContainerType() == COLLECTION_CONTAINER) {
		latestParam_.rowDataOffset_ = getColFixedOffset();
		latestParam_.rowIdOffset_ = getColRowIdOffset();
		latestParam_.rowHeaderOffset_ = COL_ROW_HEADER_OFFSET;
	} else if (container->getContainerType() == TIME_SERIES_CONTAINER) {
		latestParam_.rowDataOffset_ = sizeof(RowHeader);
		latestParam_.rowIdOffset_ = latestParam_.rowDataOffset_ +
		   container->getColumnInfo(ColumnInfo::ROW_KEY_COLUMN_ID)
		   .getColumnOffset();
		latestParam_.rowHeaderOffset_ = TIM_ROW_HEADER_OFFSET;
	} else {
		assert(false);
		GS_THROW_USER_ERROR(GS_ERROR_DS_DS_CONTAINER_TYPE_INVALID, "");
	}

	latestParam_.varColumnNum_ = container->getVariableColumnNum();
	latestParam_.varHeaderSize_ = ValueProcessor::getEncodedVarSize(latestParam_.varColumnNum_);
	latestParam_.columnNum_ = container->getColumnNum();
	latestParam_.nullOffsetDiff_ = 0;
	latestParam_.columnOffsetDiff_ = 0;

	latestParam_.rowSize_ = container->getRowSize();
	latestParam_.rowFixedColumnSize_ = container->getRowFixedColumnSize();
	latestParam_.nullbitsSize_ = container->getNullbitsSize();
	latestParam_.nullsOffset_ = latestParam_.rowSize_ - (latestParam_.nullbitsSize_ + latestParam_.rowFixedColumnSize_);

	typedef BaseContainer::RowArrayImpl<BaseContainer, BaseContainer::ROW_ARRAY_GENERAL> GeneralRowArrayImpl;
	typedef BaseContainer::RowArrayImpl<BaseContainer, BaseContainer::ROW_ARRAY_PLAIN> PlainRowArrayImpl;

	util::StackAllocator &alloc = txn.getDefaultAllocator();
	GeneralRowArrayImpl *generalImpl = ALLOC_NEW(alloc) GeneralRowArrayImpl(
		txn, container, rowArrayStorage_, rowCache_, latestParam_);
	PlainRowArrayImpl *plainImpl = reinterpret_cast<PlainRowArrayImpl *>(generalImpl);
	rowArrayImplList_.push_back(generalImpl);
	rowArrayImplList_.push_back(plainImpl);
	defaultImpl_ = getImpl<BaseContainer, BaseContainer::ROW_ARRAY_GENERAL>();
}
/*!
	@brief Clone
*/
OId VariableArrayCursor::clone(TransactionContext &txn,
	const AllocateStrategy &allocateStrategy, OId neighborOId) {
	if (UNDEF_OID == getBaseOId()) {
		return UNDEF_OID;
	}
	OId currentNeighborOId = neighborOId;
	OId linkOId = UNDEF_OID;

	uint32_t srcDataLength = getArrayLength();
	if (srcDataLength == 0) {
		uint8_t *srcObj = getBaseAddr();
		Size_t srcObjSize = getObjectManager()->getSize(srcObj);
		BaseObject destObject(txn.getPartitionId(), *getObjectManager());
		OId destOId = UNDEF_OID;
		if (currentNeighborOId != UNDEF_OID) {
			destObject.allocateNeighbor<uint8_t>(srcObjSize, allocateStrategy,
				destOId, currentNeighborOId, OBJECT_TYPE_VARIANT);
		}
		else {
			destObject.allocate<uint8_t>(
				srcObjSize, allocateStrategy, destOId, OBJECT_TYPE_VARIANT);
		}
		memcpy(destObject.getBaseAddr(), srcObj, srcObjSize);
		linkOId = destOId;
	}
	else {
		OId srcOId = UNDEF_OID;
		OId destOId = UNDEF_OID;
		OId prevOId = UNDEF_OID;
		uint8_t *srcObj = NULL;
		BaseObject destObject(txn.getPartitionId(), *getObjectManager());

		uint8_t *srcElem;
		uint32_t srcElemSize;
		uint32_t srcCount;
		uint8_t *lastElem = NULL;
		uint32_t lastElemSize = 0;
		while (nextElement()) {
			srcObj = data();
			srcOId = getElementOId();
			srcElem = getElement(srcElemSize, srcCount);
			if (srcOId != prevOId) {
				Size_t srcObjSize = getObjectManager()->getSize(srcObj);
				if (currentNeighborOId != UNDEF_OID) {
					destObject.allocateNeighbor<uint8_t>(srcObjSize,
						allocateStrategy, destOId, currentNeighborOId,
						OBJECT_TYPE_VARIANT);
				}
				else {
					destObject.allocate<uint8_t>(srcObjSize, allocateStrategy,
						destOId, OBJECT_TYPE_VARIANT);
				}
				currentNeighborOId =
					destOId;  

				memcpy(destObject.getBaseAddr(), srcObj, srcObjSize);
				if (UNDEF_OID == linkOId) {
					linkOId = destOId;
				}
				else {
					assert(lastElem > 0);
					uint8_t *linkOIdAddr =
						lastElem + lastElemSize +
						ValueProcessor::getEncodedVarSize(lastElemSize);
					uint64_t encodedOId =
						ValueProcessor::encodeVarSizeOId(destOId);
					memcpy(linkOIdAddr, &encodedOId, sizeof(uint64_t));
				}
				prevOId = srcOId;
			}
			lastElem = destObject.getBaseAddr() + (srcElem - srcObj);
			lastElemSize = srcElemSize;
		}
	}
	return linkOId;
}