keyStream
Position =
;
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;
}
}
}
[] [] [] [] [] [] []