c#

位置:IT落伍者 >> c# >> 浏览文章

C#使用BerkeleyDB操作简介[5]


发布日期:2021年10月31日
 
C#使用BerkeleyDB操作简介[5]

keyStreamPosition = ;

formatterSerialize(keyStream putKey);

DbEntry key = DbEntryInOut(keyStreamGetBuffer() (int)keyStreamPosition);

dataStreamPosition = ;

formatterSerialize(dataStream put);

DbEntry data = DbEntryInOut(dataStreamGetBuffer() (int)dataStreamPosition);

WriteStatus status = btreePut(txn ref key ref data);

switch (status)

{

case WriteStatusSuccess:

return true;

case WriteStatusNotFound:

case WriteStatusKeyExist:

default:

return false;

}

}

private bool iscomit = false;

public void Commit()

{

txnCommit(TxnCommitModeNone);

iscomit = true;

}

public List<IPut> Find()

{

List<IPut> custList = new List<IPut>();

using (DbBTreeCursor cursor = btreeOpenCursor(txn DbFileCursorCreateFlagsNone))

{

IPut cust = null;

while (GetNextRecord(cursor ref cust))

custListAdd(cust);

}

return custList;

}

public bool Get(ref IPut put)

{

keyStreamPosition = ;

formatterSerialize(keyStream putKey);

DbEntry key = DbEntryInOut(keyStreamGetBuffer() (int)keyStreamPosition);

dataStreamSetLength(dataStreamCapacity);

DbEntry data = DbEntryOut(dataStreamGetBuffer());

while (true)

{

ReadStatus status = btreeGet(txn ref key ref data DbFileReadFlagsNone);

switch (status)

{

case ReadStatusSuccess:

dataStreamPosition = ;

dataStreamSetLength(dataSize);

put = (IPut)formatterDeserialize(dataStream);

return true;

case ReadStatusBufferSmall: //扩容

if (keyBufferLength < keySize)

{

keyStreamSetLength(keySize);

key = DbEntryOut(keyStreamGetBuffer());

}

if (dataBufferLength < dataSize)

{

dataStreamSetLength(dataSize);

data = DbEntryOut(dataStreamGetBuffer());

}

continue;

case ReadStatusNotFound:

case ReadStatusKeyEmpty:

default:

return false;

}

}

}

[] [] [] [] [] [] []

               

上一篇:C#使用BerkeleyDB操作简介[1]

下一篇:C#使用BerkeleyDB操作简介[4]