ObjectStreamClass classFormat)
throws DbException, ClassNotFoundException {
// an intent-to-write cursor is needed for CDB
Dbc cursor = db.openCursor(true);
try {
// get and lock the record containing the last assigned ID
DataThang key = newDbt();
key.setBytes(LAST_CLASS_ID_KEY);
DataThang data = newDbt();
int putFlag = Db.DB_CURRENT;
int err = cursor.get(key, data,
Db.DB_SET | env.getWriteLockFlag());
if (err != 0) {
// if this is a new database, set the initial ID record
data.setBytes(new byte[1]); // zero ID
putFlag = Db.DB_KEYLAST;
}
byte[] idBytes = data.getBytes();
// check one last time to see if another thread
// wrote the information before this thread
Object anotherClassInfo = classMap.get(className);
if (anotherClassInfo != null)
return (ClassInfo) anotherClassInfo;
// increment the ID by one and write the updated record
idBytes = incrementID(idBytes);
data.setBytes(idBytes);
cursor.put(key, data, putFlag);
// write the new class format record whose key is the ID just
// assigned
byte[] keyBytes = new byte[1 + idBytes.length];