/// <summary> /// Generates the document key. /// </summary> /// <param name="conventions">The conventions.</param> /// <param name="entity">The entity.</param> /// <returns></returns> public string GenerateDocumentKey(IDatabaseCommands databaseCommands, DocumentConvention conventions, object entity) { var typeTagName = conventions.GetDynamicTagName(entity); if (string.IsNullOrEmpty(typeTagName)) //ignore empty tags return null; var tag = conventions.TransformTypeTagNameToDocumentKeyPrefix(typeTagName); HiLoKeyGenerator value; if (keyGeneratorsByTag.TryGetValue(tag, out value)) return value.GenerateDocumentKey(databaseCommands, conventions, entity); lock(generatorLock) { if (keyGeneratorsByTag.TryGetValue(tag, out value)) return value.GenerateDocumentKey(databaseCommands, conventions, entity); value = new HiLoKeyGenerator(tag, capacity); // doing it this way for thread safety keyGeneratorsByTag = new Dictionary<string, HiLoKeyGenerator>(keyGeneratorsByTag) { {tag, value} }; } return value.GenerateDocumentKey(databaseCommands, conventions, entity); }
/// <summary> /// Generates the document key. /// </summary> /// <param name="conventions">The conventions.</param> /// <param name="entity">The entity.</param> /// <param name="databaseCommands">Low level database commands.</param> /// <returns></returns> public string GenerateDocumentKey(IDatabaseCommands databaseCommands, DocumentConvention conventions, object entity) { var typeTagName = conventions.GetDynamicTagName(entity); if (string.IsNullOrEmpty(typeTagName)) //ignore empty tags { return(null); } var tag = conventions.TransformTypeTagNameToDocumentKeyPrefix(typeTagName); HiLoKeyGenerator value; if (keyGeneratorsByTag.TryGetValue(tag, out value)) { return(value.GenerateDocumentKey(databaseCommands, conventions, entity)); } lock (generatorLock) { if (keyGeneratorsByTag.TryGetValue(tag, out value)) { return(value.GenerateDocumentKey(databaseCommands, conventions, entity)); } value = new HiLoKeyGenerator(tag, capacity); // doing it this way for thread safety keyGeneratorsByTag = new Dictionary <string, HiLoKeyGenerator>(keyGeneratorsByTag) { { tag, value } }; } return(value.GenerateDocumentKey(databaseCommands, conventions, entity)); }
public Task <string> GenerateDocumentKeyAsync(IAsyncDatabaseCommands databaseCommands, DocumentConvention conventions, object entity) { var typeTagName = conventions.GetDynamicTagName(entity); if (string.IsNullOrEmpty(typeTagName)) //ignore empty tags { return(CompletedTask.With <string>(null)); } var tag = conventions.TransformTypeTagNameToDocumentKeyPrefix(typeTagName); AsyncHiLoKeyGenerator value; if (keyGeneratorsByTag.TryGetValue(tag, out value)) { return(value.GenerateDocumentKeyAsync(databaseCommands, conventions, entity)); } lock (generatorLock) { if (keyGeneratorsByTag.TryGetValue(tag, out value)) { return(value.GenerateDocumentKeyAsync(databaseCommands, conventions, entity)); } value = new AsyncHiLoKeyGenerator(tag, capacity); keyGeneratorsByTag.TryAdd(tag, value); } return(value.GenerateDocumentKeyAsync(databaseCommands, conventions, entity)); }
public Task<string> GenerateDocumentKeyAsync(IAsyncDatabaseCommands databaseCommands, DocumentConvention conventions, object entity) { var typeTagName = conventions.GetDynamicTagName(entity); if (string.IsNullOrEmpty(typeTagName)) //ignore empty tags return CompletedTask.With<string>(null); var tag = conventions.TransformTypeTagNameToDocumentKeyPrefix(typeTagName); AsyncHiLoKeyGenerator value; if (keyGeneratorsByTag.TryGetValue(tag, out value)) return value.GenerateDocumentKeyAsync(databaseCommands, conventions, entity); lock(generatorLock) { if (keyGeneratorsByTag.TryGetValue(tag, out value)) return value.GenerateDocumentKeyAsync(databaseCommands, conventions, entity); value = new AsyncHiLoKeyGenerator(tag, capacity); keyGeneratorsByTag.TryAdd(tag, value); } return value.GenerateDocumentKeyAsync(databaseCommands, conventions, entity); }
/// <summary> /// Generates the document key using identity. /// </summary> /// <param name="conventions">The conventions.</param> /// <param name="entity">The entity.</param> /// <returns></returns> public static string GenerateDocumentKeyUsingIdentity(DocumentConvention conventions, object entity) { return(conventions.GetDynamicTagName(entity) + "/"); }