예제 #1
0
void ProviderWindow::saveAction()
{

try
{
	if(record != NULL)
		dbwrite();

	if(record != NULL)
	{
		if(record->getType() == PROVIDER_NEW)
			emit newComplete();
		else
			emit editComplete();

		delete record;
		record = NULL;
	}
	close();
}
catch(pqxx::broken_connection)
{
		DBErrorWindow *dialog = new DBErrorWindow(this, database);
		dialog->setAttribute(Qt::WA_DeleteOnClose,true);

		connect(dialog,SIGNAL(reconnected()),this,SLOT(saveAction()));

		dialog->exec();
}



}
예제 #2
0
파일: db_lock.c 프로젝트: bagdxk/openafs
afs_int32
FreeLock(struct rx_call *call, afs_uint32 lockHandle)
{
    db_lockP lockPtr = 0;
    struct ubik_trans *ut;
    afs_int32 code;

    if (callPermitted(call) == 0)
	return (BUDB_NOTPERMITTED);

    code = InitRPC(&ut, LOCKWRITE, 1);
    if (code)
	return (code);

    if (checkLockHandle(ut, lockHandle) == 0)
	ABORT(BUDB_BADARGUMENT);

    lockPtr = &db.h.textLocks[lockHandle - 1];

    lockPtr->lockState = 0;	/* unlock it */
    lockPtr->lockTime = 0;
    lockPtr->expires = 0;
    lockPtr->instanceId = 0;
    dbwrite(ut, DBH_POS(lockPtr), (char *)lockPtr, sizeof(db_lockT));

    code = ubik_EndTrans(ut);
    return (code);

  abort_exit:
    ubik_AbortTrans(ut);
    return (code);
}
예제 #3
0
파일: db_lock.c 프로젝트: bagdxk/openafs
afs_int32
FreeAllLocks(struct rx_call *call, afs_uint32 instanceId)
{
    db_lockP startPtr, endPtr;
    struct ubik_trans *ut;
    afs_int32 code;

    if (callPermitted(call) == 0)
	return (BUDB_NOTPERMITTED);

    code = InitRPC(&ut, LOCKWRITE, 1);
    if (code)
	return (code);

    startPtr = &db.h.textLocks[0];
    endPtr = &db.h.textLocks[TB_NUM - 1];
    while (startPtr <= endPtr) {
	if ((ntohl(startPtr->lockState) == 1)
	    && (ntohl(startPtr->instanceId) == instanceId)
	    ) {
	    /* release the lock */
	    startPtr->lockState = 0;	/* unlock it */
	    startPtr->lockTime = 0;
	    startPtr->expires = 0;
	    startPtr->instanceId = 0;
	    dbwrite(ut, DBH_POS(startPtr), (char *)startPtr,
		    sizeof(db_lockT));
	}
	startPtr++;
    }
    code = ubik_EndTrans(ut);
    return (code);
}
예제 #4
0
파일: db-bench.c 프로젝트: yqingp/testness
void writerandom()
{
	char *name = "random write";
	struct timespec a, b;

	ngettime(&a);
	dbwrite(name, 1);
	ngettime(&b);
	report(name, a, b);
}
예제 #5
0
파일: db-bench.c 프로젝트: yqingp/testness
void writeseq()
{
	char *name = "seq write";
	struct timespec a, b;

	ngettime(&a);
	dbwrite(name, 0);
	ngettime(&b);
	report(name, a, b);
}
예제 #6
0
파일: db_lock.c 프로젝트: bagdxk/openafs
afs_int32
GetLock(struct rx_call *call, afs_uint32 instanceId, afs_int32 lockName,
	afs_int32 expiration, afs_uint32 *lockHandle)
{
    struct timeval tv;
    db_lockP lockPtr;
    struct ubik_trans *ut;

    afs_int32 code;

    if (callPermitted(call) == 0)
	return (BUDB_NOTPERMITTED);

    if ((lockName < 0) || (lockName >= TB_NUM))
	return (BUDB_BADARGUMENT);

    /* get the current time */
    gettimeofday(&tv, 0);

    code = InitRPC(&ut, LOCKWRITE, 1);
    if (code)
	return (code);

    lockPtr = &db.h.textLocks[lockName];

    if ((ntohl(lockPtr->lockState) != 0)	/* lock set */
	&&(ntohl(lockPtr->expires) > tv.tv_sec)	/* not expired */
	) {
	if (ntohl(lockPtr->instanceId) == instanceId)
	    code = BUDB_SELFLOCKED;
	else
	    code = BUDB_LOCKED;
	goto abort_exit;
    }

    lockPtr->lockState = htonl(1);	/* lock it */
    lockPtr->lockTime = htonl(tv.tv_sec);	/* when locked */
    lockPtr->expires = htonl(tv.tv_sec + expiration);
    lockPtr->instanceId = htonl(instanceId);
    code = dbwrite(ut, DBH_POS(lockPtr), (char *)lockPtr, sizeof(db_lockT));
    if (code)
	ABORT(code);

    *lockHandle = (afs_uint32) (lockName + 1);
    code = ubik_EndTrans(ut);
    return (code);

  abort_exit:
    ubik_AbortTrans(ut);
    return (code);
}
예제 #7
0
afs_int32
RestoreDbHeader(struct rx_call *call, struct DbHeader *header)
{
    struct ubik_trans *ut = 0;
    afs_int32 code = 0;

    extern struct memoryDB db;

    if (callPermitted(call) == 0)
        ERROR(BUDB_NOTPERMITTED);

    code = InitRPC(&ut, LOCKWRITE, 1);
    if (code)
        goto error_exit;

    if (header->dbversion != ntohl(db.h.version))
        ERROR(BUDB_VERSIONMISMATCH);

    /* merge rather than replace the header information */
    if (db.h.lastDumpId < htonl(header->lastDumpId))
        db.h.lastDumpId = htonl(header->lastDumpId);

    if (db.h.lastTapeId < htonl(header->lastTapeId))
        db.h.lastTapeId = htonl(header->lastTapeId);

    if (db.h.lastInstanceId < htonl(header->lastInstanceId))
        db.h.lastInstanceId = htonl(header->lastInstanceId);

    code = dbwrite(ut, 0, (char *)&db.h, sizeof(db.h));
    if (code)
        code = BUDB_IO;

error_exit:
    if (ut)
        ubik_EndTrans(ut);
    return (code);
}
예제 #8
0
afs_int32
SaveText(struct rx_call *call, afs_uint32 lockHandle, afs_int32 textType, 
	 afs_int32 offset, afs_int32 flags, charListT *charListPtr)
{
    struct ubik_trans *ut;
    struct block diskBlock;
    dbadr diskBlockAddr;
    afs_int32 remainingInBlock, chunkSize;
    struct textBlock *tbPtr;
    afs_int32 textLength = charListPtr->charListT_len;
    char *textptr = charListPtr->charListT_val;
    afs_int32 code;

    LogDebug(5, "SaveText: type %d, offset %d, length %d\n", textType, offset,
	     textLength);

    if (callPermitted(call) == 0)
	return (BUDB_NOTPERMITTED);

    if ((textLength > BLOCK_DATA_SIZE) || (offset < 0))
	return (BUDB_BADARGUMENT);

    code = InitRPC(&ut, LOCKWRITE, 1);
    if (code)
	return (code);

    /* fetch the lock state */
    if (checkLockHandle(ut, lockHandle) == 0)
	ABORT(BUDB_NOTLOCKED);

    if ((textType < 0) || (textType >= TB_NUM))
	ABORT(BUDB_BADARGUMENT);

    tbPtr = &db.h.textBlock[textType];

    LogDebug(5,
	     "SaveText: lockHandle %d textType %d offset %d flags %d txtlength %d\n",
	     lockHandle, textType, offset, flags, textLength);

    if (offset == 0) {
	/* release any blocks from previous transactions */
	diskBlockAddr = ntohl(tbPtr->newTextAddr);
	freeOldBlockChain(ut, diskBlockAddr);

	if (textLength) {
	    code = AllocBlock(ut, &diskBlock, &diskBlockAddr);
	    if (code)
		ABORT(code);

	    LogDebug(5, "allocated block %d\n", diskBlockAddr);

	    /* set block type */
	    diskBlock.h.type = text_BLOCK;

	    /* save it in the database header */
	    tbPtr->newsize = 0;
	    tbPtr->newTextAddr = htonl(diskBlockAddr);
	    dbwrite(ut, (char *)tbPtr - (char *)&db.h, (char *)tbPtr,
		    sizeof(struct textBlock));
	} else {
	    tbPtr->newsize = 0;
	    tbPtr->newTextAddr = 0;
	}
    } else {
	/* non-zero offset */
	int nblocks;

	if (offset != ntohl(tbPtr->newsize))
	    ABORT(BUDB_BADARGUMENT);

	/* locate the block to which offset refers */
	nblocks = offset / BLOCK_DATA_SIZE;

	diskBlockAddr = ntohl(tbPtr->newTextAddr);
	if (diskBlockAddr == 0)
	    ABORT(BUDB_BADARGUMENT);

	code =
	    dbread(ut, diskBlockAddr, (char *)&diskBlock, sizeof(diskBlock));
	if (code)
	    ABORT(code);

	while (nblocks--) {
	    diskBlockAddr = ntohl(diskBlock.h.next);
	    code =
		dbread(ut, diskBlockAddr, (char *)&diskBlock,
		       sizeof(diskBlock));
	    if (code)
		ABORT(code);
	}
    }

    /* diskBlock and diskBlockAddr now point to the last block in the chain */

    while (textLength) {
	/* compute the transfer size */
	remainingInBlock = (BLOCK_DATA_SIZE - (offset % BLOCK_DATA_SIZE));
	chunkSize = MIN(remainingInBlock, textLength);

	/* copy in the data */
	memcpy(&diskBlock.a[offset % BLOCK_DATA_SIZE], textptr, chunkSize);

	/* LogDebug(5, "text is %s\n", textptr); */

	textLength -= chunkSize;
	textptr += chunkSize;
	offset += chunkSize;
	tbPtr->newsize = htonl(ntohl(tbPtr->newsize) + chunkSize);

	if (textLength > 0) {
	    afs_int32 prevBlockAddr;
	    afs_int32 linkOffset;
	    afs_int32 linkValue;

	    /* have to add another block to the chain */

	    code =
		dbwrite(ut, diskBlockAddr, (char *)&diskBlock,
			sizeof(diskBlock));
	    if (code)
		ABORT(code);

	    prevBlockAddr = (afs_int32) diskBlockAddr;
	    code = AllocBlock(ut, &diskBlock, &diskBlockAddr);
	    if (code)
		ABORT(code);

	    LogDebug(5, "allocated block %d\n", diskBlockAddr);

	    /* set block type */
	    diskBlock.h.type = text_BLOCK;

	    /* now have to update the previous block's link */
	    linkOffset =
		(afs_int32) ((char*)& diskBlock.h.next - (char*)& diskBlock);
	    linkValue = htonl(diskBlockAddr);

	    code =
		dbwrite(ut, (afs_int32) prevBlockAddr + linkOffset,
			(char *)&linkValue, sizeof(afs_int32));
	    if (code)
		ABORT(code);
	} else {
	    /* just write the old block */
	    code =
		dbwrite(ut, diskBlockAddr, (char *)&diskBlock,
			sizeof(diskBlock));
	    if (code)
		ABORT(code);
	}
    }

    if (flags & BUDB_TEXT_COMPLETE) {	/* done */
	/* this was the last chunk of text */
	diskBlockAddr = ntohl(tbPtr->textAddr);
	freeOldBlockChain(ut, diskBlockAddr);

	tbPtr->textAddr = tbPtr->newTextAddr;
	tbPtr->newTextAddr = 0;
	tbPtr->size = tbPtr->newsize;
	tbPtr->newsize = 0;
	tbPtr->version = htonl(ntohl(tbPtr->version) + 1);

	/* saveTextToFile(ut, tbPtr); */
    }

    /* update size and other text header info */
    code =
	dbwrite(ut, (char *)tbPtr - (char *)&db.h, (char *)tbPtr,
		sizeof(struct textBlock));
    if (code)
	ABORT(code);

/*error_exit: */
    code = ubik_EndTrans(ut);
    return (code);

  abort_exit:
    ubik_AbortTrans(ut);
    return (code);
}