本文整理汇总了C#中Microsoft.Isam.Esent.Interop.Update类的典型用法代码示例。如果您正苦于以下问题:C# Update类的具体用法?C# Update怎么用?C# Update使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Update类属于Microsoft.Isam.Esent.Interop命名空间,在下文中一共展示了Update类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddAttachment
public Etag AddAttachment(string key, Etag etag, Stream data, RavenJObject headers)
{
Api.JetSetCurrentIndex(session, Files, "by_name");
Api.MakeKey(session, Files, key, Encoding.Unicode, MakeKeyGrbit.NewKey);
var isUpdate = Api.TrySeek(session, Files, SeekGrbit.SeekEQ);
if (isUpdate)
{
var existingEtag = Etag.Parse(Api.RetrieveColumn(session, Files, tableColumnsCache.FilesColumns["etag"]));
if (existingEtag != etag && etag != null)
{
throw new ConcurrencyException("PUT attempted on attachment '" + key +
"' using a non current etag")
{
ActualETag = existingEtag,
ExpectedETag = etag
};
}
}
else
{
if (data == null)
throw new InvalidOperationException("When adding new attachment, the attachment data must be specified");
if (Api.TryMoveFirst(session, Details))
Api.EscrowUpdate(session, Details, tableColumnsCache.DetailsColumns["attachment_count"], 1);
}
Etag newETag = uuidGenerator.CreateSequentialUuid(UuidType.Attachments);
using (var update = new Update(session, Files, isUpdate ? JET_prep.Replace : JET_prep.Insert))
{
Api.SetColumn(session, Files, tableColumnsCache.FilesColumns["name"], key, Encoding.Unicode);
if (data != null)
{
long written;
using (var columnStream = new ColumnStream(session, Files, tableColumnsCache.FilesColumns["data"]))
{
if (isUpdate)
columnStream.SetLength(0);
using (var stream = new BufferedStream(columnStream))
{
data.CopyTo(stream);
written = stream.Position;
stream.Flush();
}
}
if (written == 0) // empty attachment
{
Api.SetColumn(session, Files, tableColumnsCache.FilesColumns["data"], new byte[0]);
}
}
Api.SetColumn(session, Files, tableColumnsCache.FilesColumns["etag"], newETag.TransformToValueForEsentSorting());
Api.SetColumn(session, Files, tableColumnsCache.FilesColumns["metadata"], headers.ToString(Formatting.None), Encoding.Unicode);
update.Save();
}
logger.Debug("Adding attachment {0}", key);
return newETag;
}
示例2: AddDocument
public Guid AddDocument(string key, Guid? etag, JObject data, JObject metadata)
{
Api.JetSetCurrentIndex(session, Documents, "by_key");
Api.MakeKey(session, Documents, key, Encoding.Unicode, MakeKeyGrbit.NewKey);
var isUpdate = Api.TrySeek(session, Documents, SeekGrbit.SeekEQ);
if (isUpdate)
{
EnsureNotLockedByTransaction(key, null);
EnsureDocumentEtagMatch(key, etag, "PUT");
}
else
{
EnsureDocumentIsNotCreatedInAnotherTransaction(key, Guid.NewGuid());
if (Api.TryMoveFirst(session, Details))
Api.EscrowUpdate(session, Details, tableColumnsCache.DetailsColumns["document_count"], 1);
}
Guid newEtag = DocumentDatabase.CreateSequentialUuid();
using (var update = new Update(session, Documents, isUpdate ? JET_prep.Replace : JET_prep.Insert))
{
Api.SetColumn(session, Documents, tableColumnsCache.DocumentsColumns["key"], key, Encoding.Unicode);
Api.SetColumn(session, Documents, tableColumnsCache.DocumentsColumns["data"], Encoding.UTF8.GetBytes(data.ToString()));
Api.SetColumn(session, Documents, tableColumnsCache.DocumentsColumns["etag"], newEtag.ToByteArray());
Api.SetColumn(session, Documents, tableColumnsCache.DocumentsColumns["metadata"], Encoding.UTF8.GetBytes(metadata.ToString()));
update.Save();
}
logger.DebugFormat("Inserted a new document with key '{0}', update: {1}, ",
key, isUpdate);
return newEtag;
}
示例3: Update
public void Update(Session session, JET_DBID dbid, Action<string> output)
{
using (var tbl = new Table(session, dbid, "tasks", OpenTableGrbit.None))
{
int rows = 0;
if (Api.TryMoveFirst(session, tbl))
{
var taskTypeColumnId = Api.GetTableColumnid(session, tbl, "task_type");
do
{
using (var update = new Update(session, tbl, JET_prep.Replace))
{
var taskType = Api.RetrieveColumnAsString(session, tbl, taskTypeColumnId, Encoding.Unicode);
Api.SetColumn(session, tbl, taskTypeColumnId, taskType, Encoding.ASCII);
update.Save();
}
if (rows++ % 10000 == 0)
{
output("Processed " + (rows) + " rows in tasks");
Api.JetCommitTransaction(session, CommitTransactionGrbit.LazyFlush);
Api.JetBeginTransaction2(session, BeginTransactionGrbit.None);
}
} while (Api.TryMoveNext(session, tbl));
}
SchemaCreator.UpdateVersion(session, dbid, "5.3");
}
}
示例4: PutReducedResult
public void PutReducedResult(string view, string reduceKey, int level, int sourceBucket, int bucket, RavenJObject data)
{
Guid etag = uuidGenerator.CreateSequentialUuid();
using (var update = new Update(session, ReducedResults, JET_prep.Insert))
{
Api.SetColumn(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["view"], view, Encoding.Unicode);
Api.SetColumn(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["level"], level);
Api.SetColumn(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["reduce_key"], reduceKey, Encoding.Unicode);
Api.SetColumn(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["hashed_reduce_key"], HashReduceKey(reduceKey));
Api.SetColumn(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["bucket"], bucket);
Api.SetColumn(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["source_bucket"], sourceBucket);
using (Stream stream = new BufferedStream(new ColumnStream(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["data"])))
{
using (var dataStream = documentCodecs.Aggregate(stream, (ds, codec) => codec.Value.Encode(reduceKey, data, null, ds)))
{
data.WriteTo(dataStream);
dataStream.Flush();
}
}
Api.SetColumn(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["etag"], etag.TransformToValueForEsentSorting());
Api.SetColumn(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["timestamp"], SystemTime.UtcNow);
update.Save();
}
}
示例5: SortDataWithJetOpenTempTable
public void SortDataWithJetOpenTempTable()
{
JET_TABLEID tableid;
var columns = new[]
{
new JET_COLUMNDEF { coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.TTKey },
new JET_COLUMNDEF { coltyp = JET_coltyp.Text, cp = JET_CP.Unicode },
};
var columnids = new JET_COLUMNID[columns.Length];
Api.JetOpenTempTable(this.session, columns, columns.Length, TempTableGrbit.Scrollable, out tableid, columnids);
for (int i = 5; i >= 0; --i)
{
using (var update = new Update(this.session, tableid, JET_prep.Insert))
{
Api.SetColumn(this.session, tableid, columnids[0], i);
Api.SetColumn(this.session, tableid, columnids[1], i.ToString(), Encoding.Unicode);
update.Save();
}
}
var expected = new[] { "0", "1", "2", "3", "4", "5" };
CollectionAssert.AreEqual(expected, this.RetrieveAllRecordsAsString(tableid, columnids[1]).ToArray());
Api.JetCloseTable(this.session, tableid);
}
示例6: Update
public void Update(Session session, JET_DBID dbid, Action<string> output)
{
using (var tbl = new Table(session, dbid, "lists", OpenTableGrbit.None))
{
JET_COLUMNID columnid;
Api.JetAddColumn(session, tbl, "created_at", new JET_COLUMNDEF
{
coltyp = JET_coltyp.DateTime,
grbit = ColumndefGrbit.ColumnMaybeNull,
}, null, 0, out columnid);
if (Api.TryMoveFirst(session, tbl))
{
do
{
using (var update = new Update(session, tbl, JET_prep.Replace))
{
var createdAt = Api.GetTableColumnid(session, tbl, "created_at");
Api.SetColumn(session, tbl, createdAt, SystemTime.UtcNow);
update.Save();
}
} while (Api.TryMoveNext(session, tbl));
}
SchemaCreator.CreateIndexes(session, tbl, new JET_INDEXCREATE
{
szIndexName = "by_name_and_created_at",
szKey = "+name\0+created_at\0\0",
grbit = CreateIndexGrbit.IndexDisallowNull
});
SchemaCreator.UpdateVersion(session, dbid, "5.1");
}
}
示例7: Update
public void Update(Session session, JET_DBID dbid)
{
using (var tx = new Transaction(session))
{
using (var files = new Table(session, dbid, "files", OpenTableGrbit.None))
{
const string indexDef = "+etag\0\0";
Api.JetCreateIndex(session, files, "by_etag", CreateIndexGrbit.IndexDisallowNull, indexDef, indexDef.Length,
100);
using (var details = new Table(session, dbid, "details", OpenTableGrbit.None))
{
Api.JetMove(session, details, JET_Move.First, MoveGrbit.None);
var columnids = Api.GetColumnDictionary(session, details);
using (var update = new Update(session, details, JET_prep.Replace))
{
Api.SetColumn(session, details, columnids["schema_version"], "2.7", Encoding.Unicode);
update.Save();
}
}
}
tx.Commit(CommitTransactionGrbit.None);
}
}
示例8: SetFileSize
/// <summary>
/// Установить размер.
/// </summary>
/// <param name="tt">Транзакция таблицы.</param>
/// <param name="item">Элемент.</param>
public void SetFileSize(TableTransaction tt, SizeCacheEsentItem item)
{
Api.JetSetCurrentIndex(tt.Session, tt.Table, null);
Api.MakeKey(tt.Session, tt.Table, item.FileId, Encoding.Unicode, MakeKeyGrbit.NewKey);
if (Api.TrySeek(tt.Session, tt.Table, SeekGrbit.SeekEQ))
{
Api.JetDelete(tt.Session, tt.Table);
}
using (var updater = new Update(tt.Session, tt.Table, JET_prep.Insert))
{
var columnId = Api.GetTableColumnid(tt.Session, tt.Table, "FileId");
Api.SetColumn(tt.Session, tt.Table, columnId, item.FileId, Encoding.Unicode);
var columnSize = Api.GetTableColumnid(tt.Session, tt.Table, "Size");
Api.SetColumn(tt.Session, tt.Table, columnSize, item.Size);
var columnDTicks = Api.GetTableColumnid(tt.Session, tt.Table, "DTicks");
Api.SetColumn(tt.Session, tt.Table, columnDTicks, item.DTicks);
var columnOTicks = Api.GetTableColumnid(tt.Session, tt.Table, "OTicks");
Api.SetColumn(tt.Session, tt.Table, columnOTicks, item.OTicks);
updater.Save();
}
}
示例9: CreateDetailsTable
private void CreateDetailsTable(JET_DBID dbid)
{
JET_TABLEID tableid;
Api.JetCreateTable(session, dbid, "details", 16, 100, out tableid);
JET_COLUMNID id;
Api.JetAddColumn(session, tableid, "id", new JET_COLUMNDEF
{
cbMax = 16,
coltyp = JET_coltyp.Binary,
grbit = ColumndefGrbit.ColumnNotNULL | ColumndefGrbit.ColumnFixed
}, null, 0, out id);
JET_COLUMNID schemaVersion;
Api.JetAddColumn(session, tableid, "schema_version", new JET_COLUMNDEF
{
cbMax = Encoding.Unicode.GetByteCount(SchemaVersion),
cp = JET_CP.Unicode,
coltyp = JET_coltyp.Text,
grbit = ColumndefGrbit.ColumnNotNULL | ColumndefGrbit.ColumnFixed
}, null, 0, out schemaVersion);
using (var update = new Update(session, tableid, JET_prep.Insert))
{
Api.SetColumn(session, tableid, id, Guid.NewGuid().ToByteArray());
Api.SetColumn(session, tableid, schemaVersion, SchemaVersion, Encoding.Unicode);
update.Save();
}
}
示例10: PutMappedResult
public void PutMappedResult(string view, string docId, string reduceKey, RavenJObject data)
{
Etag etag = uuidGenerator.CreateSequentialUuid(UuidType.MappedResults);
using (var update = new Update(session, MappedResults, JET_prep.Insert))
{
Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["view"], view, Encoding.Unicode);
Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["document_key"], docId, Encoding.Unicode);
Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["reduce_key"], reduceKey, Encoding.Unicode);
Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["hashed_reduce_key"], HashReduceKey(reduceKey));
var mapBucket = IndexingUtil.MapBucket(docId);
Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["bucket"], mapBucket);
using (Stream stream = new BufferedStream(new ColumnStream(session, MappedResults, tableColumnsCache.MappedResultsColumns["data"])))
{
using (var dataStream = documentCodecs.Aggregate(stream, (ds, codec) => codec.Value.Encode(reduceKey, data, null, ds)))
{
data.WriteTo(dataStream);
dataStream.Flush();
}
}
Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["etag"], etag.TransformToValueForEsentSorting());
Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["timestamp"], SystemTime.UtcNow.ToBinary());
update.Save();
}
}
示例11: Update
public void Update(Session session, JET_DBID dbid)
{
using (var tx = new Transaction(session))
{
using (var tasks = new Table(session, dbid, "tasks", OpenTableGrbit.None))
{
JET_COLUMNID columnid;
Api.JetAddColumn(session, tasks, "added_at",new JET_COLUMNDEF
{
coltyp = JET_coltyp.DateTime,
grbit = ColumndefGrbit.ColumnNotNULL
}, null, 0, out columnid);
using (var details = new Table(session, dbid, "details", OpenTableGrbit.None))
{
Api.JetMove(session, details, JET_Move.First, MoveGrbit.None);
var columnids = Api.GetColumnDictionary(session, details);
using (var update = new Update(session, details, JET_prep.Replace))
{
Api.SetColumn(session, details, columnids["schema_version"], "2.5", Encoding.Unicode);
update.Save();
}
}
}
tx.Commit(CommitTransactionGrbit.None);
}
}
示例12: Set
public void Set(string name, string key, RavenJObject data, UuidType uuidType)
{
Api.JetSetCurrentIndex(session, Lists, "by_name_and_key");
Api.MakeKey(session, Lists, name, Encoding.Unicode, MakeKeyGrbit.NewKey);
Api.MakeKey(session, Lists, key, Encoding.Unicode, MakeKeyGrbit.None);
var exists = Api.TrySeek(session, Lists, SeekGrbit.SeekEQ);
using (var update = new Update(session, Lists, exists ? JET_prep.Replace : JET_prep.Insert))
{
Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["name"], name, Encoding.Unicode);
Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["key"], key, Encoding.Unicode);
Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["etag"], uuidGenerator.CreateSequentialUuid(uuidType).TransformToValueForEsentSorting());
Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["created_at"], SystemTime.UtcNow);
using (var columnStream = new ColumnStream(session, Lists, tableColumnsCache.ListsColumns["data"]))
{
if (exists)
columnStream.SetLength(0);
using (Stream stream = new BufferedStream(columnStream))
{
data.WriteTo(stream);
stream.Flush();
}
}
update.Save();
}
}
示例13: Update
public void Update(Session session, JET_DBID dbid)
{
using(var tx = new Transaction(session))
{
using (var mappedResults = new Table(session, dbid, "mapped_results", OpenTableGrbit.None))
{
JET_COLUMNID columnid;
Api.JetAddColumn(session, mappedResults, "reduce_key_and_view_hashed", new JET_COLUMNDEF
{
cbMax = 32,
coltyp = JET_coltyp.Binary,
grbit = ColumndefGrbit.ColumnNotNULL
}, null, 0, out columnid);
const string indexDef = "+reduce_key_and_view_hashed\0\0";
Api.JetCreateIndex(session, mappedResults, "by_reduce_key_and_view_hashed",
CreateIndexGrbit.IndexDisallowNull, indexDef, indexDef.Length,
100);
Api.JetDeleteIndex(session, mappedResults, "by_view_and_reduce_key");
var columnDictionary = Api.GetColumnDictionary(session, mappedResults);
Api.MoveBeforeFirst(session, mappedResults);
while (Api.TryMoveNext(session, mappedResults))
{
using (var update = new Update(session, mappedResults, JET_prep.Replace))
{
var computeHash = MapReduceIndex.ComputeHash(
Api.RetrieveColumnAsString(session, mappedResults, columnDictionary["view"],
Encoding.Unicode),
Api.RetrieveColumnAsString(session, mappedResults, columnDictionary["reduce_key"],
Encoding.Unicode));
Api.SetColumn(session, mappedResults, columnDictionary["reduce_key_and_view_hashed"],
computeHash);
update.Save();
}
}
using (var details = new Table(session, dbid, "details", OpenTableGrbit.None))
{
Api.JetMove(session, details, JET_Move.First, MoveGrbit.None);
var columnids = Api.GetColumnDictionary(session, details);
using(var update = new Update(session, details, JET_prep.Replace))
{
Api.SetColumn(session, details, columnids["schema_version"], "2.2", Encoding.Unicode);
update.Save();
}
}
}
tx.Commit(CommitTransactionGrbit.None);
}
}
示例14: Update
public void Update(Session session, JET_DBID dbid, Action<string> output)
{
using (var table = new Table(session, dbid, "config", OpenTableGrbit.DenyRead | OpenTableGrbit.PermitDDL))
{
JET_COLUMNID newMetadataColumnId;
Api.JetAddColumn(session, table, "metadata_new", new JET_COLUMNDEF
{
cbMax = 1024*512,
coltyp = JET_coltyp.LongText,
cp = JET_CP.Unicode,
grbit = ColumndefGrbit.ColumnNotNULL
}, null, 0, out newMetadataColumnId);
}
using (var table = new Table(session, dbid, "config", OpenTableGrbit.None))
{
Api.MoveBeforeFirst(session, table);
var rows = 0;
var columnDictionary = Api.GetColumnDictionary(session, table);
var metadataColumn = columnDictionary["metadata"];
var nameColumn = columnDictionary["name"];
var newMetadataColumn = columnDictionary["metadata_new"];
while (Api.TryMoveNext(session, table))
{
using (var insert = new Update(session, table, JET_prep.Replace))
{
var name = Api.RetrieveColumnAsString(session, table, nameColumn, Encoding.Unicode);
var metadata = Api.RetrieveColumnAsString(session, table, metadataColumn, Encoding.Unicode);
var fixedMetadata = GuidToEtagMigrationInConfigurations(metadata, name);
Api.SetColumn(session, table, newMetadataColumn, fixedMetadata, Encoding.Unicode);
insert.Save();
}
if (rows++ % 100 == 0)
{
output("Processed " + (rows) + " rows from metadata column in config table");
Api.JetCommitTransaction(session, CommitTransactionGrbit.LazyFlush);
Api.JetBeginTransaction2(session, BeginTransactionGrbit.None);
}
}
Api.JetCommitTransaction(session, CommitTransactionGrbit.None);
// they cannot be run in transaction scope
Api.JetDeleteColumn(session, table, "metadata");
Api.JetRenameColumn(session, table, "metadata_new", "metadata", RenameColumnGrbit.None);
Api.JetBeginTransaction2(session, BeginTransactionGrbit.None);
}
SchemaCreator.UpdateVersion(session, dbid, "0.5");
}
示例15: Update
public void Update(Session session, JET_DBID dbid)
{
Transaction tx;
using (tx = new Transaction(session))
{
using ( var tbl = new Table(session, dbid, "indexes_stats",
OpenTableGrbit.PermitDDL | OpenTableGrbit.DenyRead | OpenTableGrbit.DenyWrite))
{
var columnDictionary = Api.GetColumnDictionary(session, tbl);
if (columnDictionary.ContainsKey("reduce_attempts"))
Api.JetDeleteColumn(session, tbl, "reduce_attempts");
if (columnDictionary.ContainsKey("reduce_errors"))
Api.JetDeleteColumn(session, tbl, "reduce_errors");
if (columnDictionary.ContainsKey("reduce_successes"))
Api.JetDeleteColumn(session, tbl, "reduce_successes");
}
CreateIndexesStatsReduce(session, dbid);
using (var stats = new Table(session, dbid, "indexes_stats",OpenTableGrbit.None))
using (var reduce = new Table(session, dbid, "indexes_stats_reduce", OpenTableGrbit.None))
{
var tblKeyColumn = Api.GetColumnDictionary(session, stats)["key"];
var reduceKeyCol = Api.GetColumnDictionary(session, reduce)["key"];
Api.MoveBeforeFirst(session, stats);
while (Api.TryMoveNext(session, stats))
{
using(var update = new Update(session, reduce, JET_prep.Insert))
{
var indexName = Api.RetrieveColumnAsString(session, stats, tblKeyColumn, Encoding.Unicode);
Api.SetColumn(session, reduce, reduceKeyCol, indexName, Encoding.Unicode);
update.Save();
}
}
}
tx.Commit(CommitTransactionGrbit.LazyFlush);
tx.Dispose();
tx = new Transaction(session);
}
using (var details = new Table(session, dbid, "details", OpenTableGrbit.None))
{
Api.JetMove(session, details, JET_Move.First, MoveGrbit.None);
var columnids = Api.GetColumnDictionary(session, details);
using (var update = new Update(session, details, JET_prep.Replace))
{
Api.SetColumn(session, details, columnids["schema_version"], "3.4", Encoding.Unicode);
update.Save();
}
}
tx.Commit(CommitTransactionGrbit.None);
tx.Dispose();
}