public byte[] getBytes(DataVal dataVal) { BinaryFormatter formatter = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); formatter.Serialize(ms, dataVal); return(ms.GetBuffer()); }
public DatabaseEntry SecondaryKeyGen( DatabaseEntry key, DatabaseEntry data) { byte[] firstStr = new byte[1]; DataVal dataVal = getDataVal(data.Data); firstStr[0] = ASCIIEncoding.ASCII.GetBytes(dataVal.DataString)[0]; return(new DatabaseEntry(firstStr)); }
/* Perform bulk update in primary db */ public void BulkUpdate() { Transaction txn = env.BeginTransaction(); try { if (this.dups == 0) { /* * Bulk insert non-duplicate key/data pairs. Those pairs * are filled into one single buffer. */ List <KeyValuePair <DatabaseEntry, DatabaseEntry> > pList = new List <KeyValuePair <DatabaseEntry, DatabaseEntry> >(); for (int i = 0; i < this.num; i++) { DataVal dataVal = new DataVal(i); pList.Add( new KeyValuePair <DatabaseEntry, DatabaseEntry>( new DatabaseEntry(BitConverter.GetBytes(i)), new DatabaseEntry(getBytes(dataVal)))); } pdb.Put(new MultipleKeyDatabaseEntry(pList, false), txn); } else { /* Bulk insert duplicate key/data pairs. All keys are * filled into a buffer, and their data is filled into * another buffer. */ List <DatabaseEntry> kList = new List <DatabaseEntry>(); List <DatabaseEntry> dList = new List <DatabaseEntry>(); for (int i = 0; i < this.num; i++) { int j = 0; DataVal dataVal = new DataVal(i); do { kList.Add( new DatabaseEntry(BitConverter.GetBytes(i))); dataVal.DataId = j; dList.Add(new DatabaseEntry(getBytes(dataVal))); } while (++j < this.dups); } pdb.Put(new MultipleDatabaseEntry(kList, false), new MultipleDatabaseEntry(dList, false), txn); } txn.Commit(); } catch (DatabaseException e1) { txn.Abort(); throw e1; } catch (IOException e2) { txn.Abort(); throw e2; } }
public byte[] getBytes(DataVal dataVal) { BinaryFormatter formatter = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); formatter.Serialize(ms, dataVal); return ms.GetBuffer(); }
/* Perform bulk update in primary db */ public void BulkUpdate() { Transaction txn = env.BeginTransaction(); try { if (this.dups == 0) { /* * Bulk insert non-duplicate key/data pairs. Those pairs * are filled into one single buffer. */ List<KeyValuePair<DatabaseEntry, DatabaseEntry>> pList = new List<KeyValuePair<DatabaseEntry, DatabaseEntry>>(); for (int i = 0; i < this.num; i++) { DataVal dataVal = new DataVal(i); pList.Add( new KeyValuePair<DatabaseEntry, DatabaseEntry>( new DatabaseEntry(BitConverter.GetBytes(i)), new DatabaseEntry(getBytes(dataVal)))); } pdb.Put(new MultipleKeyDatabaseEntry(pList, false), txn); } else { /* Bulk insert duplicate key/data pairs. All keys are * filled into a buffer, and their data is filled into * another buffer. */ List<DatabaseEntry> kList = new List<DatabaseEntry>(); List<DatabaseEntry> dList = new List<DatabaseEntry>(); for (int i = 0; i < this.num; i++) { int j = 0; DataVal dataVal = new DataVal(i); do { kList.Add( new DatabaseEntry(BitConverter.GetBytes(i))); dataVal.DataId = j; dList.Add(new DatabaseEntry(getBytes(dataVal))); } while (++j < this.dups); } pdb.Put(new MultipleDatabaseEntry(kList, false), new MultipleDatabaseEntry(dList, false), txn); } txn.Commit(); } catch (DatabaseException e1) { txn.Abort(); throw e1; } catch (IOException e2) { txn.Abort(); throw e2; } }