public void HiLo_Async_MultiDb() { using (var store = GetDocumentStore()) { using (var session = store.OpenSession()) { session.Store(new HiloDoc { Max = 64 }, "Raven/Hilo/users"); session.Store(new HiloDoc { Max = 128 }, "Raven/Hilo/products"); session.Store(new PrefixHiloDoc() { ServerPrefix = "4," }, "Raven/ServerPrefixForHilo"); session.SaveChanges(); var multiDbHiLo = new AsyncMultiDatabaseHiLoKeyGenerator(store, store.Conventions); var generateDocumentKey = multiDbHiLo.GenerateDocumentKeyAsync(null, new User()).GetAwaiter().GetResult(); Assert.Equal("users/4,65", generateDocumentKey); generateDocumentKey = multiDbHiLo.GenerateDocumentKeyAsync(null, new Product()).GetAwaiter().GetResult(); Assert.Equal("products/4,129", generateDocumentKey); } } }
/// <summary> /// Initializes this instance. /// </summary> /// <returns></returns> public IDocumentStore Initialize(bool ensureDatabaseExists) { if (initialized) { return(this); } AssertValidConfiguration(); //jsonRequestFactory = new HttpJsonRequestFactory(MaxNumberOfCachedRequests, HttpMessageHandlerFactory, Conventions.AcceptGzipContent, Conventions.AuthenticationScheme); try { if (string.IsNullOrEmpty(ApiKey) == false) { Credentials = null; } // TODO iftah //SecurityExtensions.InitializeSecurity(Conventions, jsonRequestFactory, Url, Credentials); InitializeInternal(); if (Conventions.AsyncDocumentKeyGenerator == null) // don't overwrite what the user is doing { var generator = new AsyncMultiDatabaseHiLoKeyGenerator(this, Conventions); _asyncMultiDbHiLo = generator; Conventions.AsyncDocumentKeyGenerator = (dbName, entity) => generator.GenerateDocumentKeyAsync(dbName, entity); } Smuggler = new DatabaseSmuggler(this); initialized = true; } catch (Exception) { Dispose(); throw; } return(this); }
public Global() { var store = new DocumentStore(); DocumentConvention Conventions = store.Conventions; #region key_generator_hilo MultiDatabaseHiLoGenerator hiLoGenerator = new MultiDatabaseHiLoGenerator(32); Conventions.DocumentKeyGenerator = (dbName, databaseCommands, entity) => hiLoGenerator.GenerateDocumentKey(dbName, databaseCommands, Conventions, entity); AsyncMultiDatabaseHiLoKeyGenerator asyncHiLoGenerator = new AsyncMultiDatabaseHiLoKeyGenerator(32); Conventions.AsyncDocumentKeyGenerator = (dbName, commands, entity) => asyncHiLoGenerator.GenerateDocumentKeyAsync(dbName, commands, Conventions, entity); #endregion #region key_generator_identityKeys Conventions.DocumentKeyGenerator = (dbname, commands, entity) => store.Conventions.GetTypeTagName(entity.GetType()) + "/"; #endregion #region find_type_name Conventions.FindClrTypeName = type => // use reflection to determine the type; #endregion string.Empty; #region find_clr_type Conventions.FindClrType = (id, doc, metadata) => metadata.Value <string>(Abstractions.Data.Constants.RavenClrType); #endregion #region find_type_tagname Conventions.FindTypeTagName = type => // function that provides the collection name based on the entity type #endregion string.Empty; #region find_dynamic_tag_name Conventions.FindDynamicTagName = dynamicObject => // function to determine the collection name for the given dynamic object #endregion string.Empty; #region transform_tag_name_to_prefix Conventions.TransformTypeTagNameToDocumentKeyPrefix = tagName => // transform the tag name to the prefix of a key, e.g. [prefix]/12 #endregion string.Empty; #region find_identity_property Conventions.FindIdentityProperty = memberInfo => memberInfo.Name == "Id"; #endregion #region find_iden_propn_name_from_entity_name Conventions.FindIdentityPropertyNameFromEntityName = entityName => "Id"; #endregion #region identity_part_separator Conventions.IdentityPartsSeparator = "/"; #endregion #region identity_type_convertors Conventions.IdentityTypeConvertors = new List <ITypeConverter> { new GuidConverter(), new Int32Converter(), new Int64Converter() }; #endregion #region identity_type_convertors_2 Conventions.IdentityTypeConvertors.Add(new UInt32Converter()); #endregion #region find_id_value_part_for_value_type_conversion Conventions.FindIdValuePartForValueTypeConversion = (entity, id) => id.Split(new[] { Conventions.IdentityPartsSeparator }, StringSplitOptions.RemoveEmptyEntries).Last(); #endregion #region find_full_doc_key_from_non_string_identifier Conventions.FindFullDocumentKeyFromNonStringIdentifier = (id, type, allowNull) => // by default returns [tagName]/[identityValue]; #endregion string.Empty; }
public Global() { var store = new DocumentStore(); DocumentConvention Conventions = store.Conventions; #region key_generator_hilo MultiDatabaseHiLoGenerator hiLoGenerator = new MultiDatabaseHiLoGenerator(32); Conventions.DocumentKeyGenerator = (dbName, databaseCommands, entity) => hiLoGenerator.GenerateDocumentKey(dbName, databaseCommands, Conventions, entity); AsyncMultiDatabaseHiLoKeyGenerator asyncHiLoGenerator = new AsyncMultiDatabaseHiLoKeyGenerator(32); Conventions.AsyncDocumentKeyGenerator = (dbName, commands, entity) => asyncHiLoGenerator.GenerateDocumentKeyAsync(dbName, commands, Conventions, entity); #endregion #region key_generator_identityKeys Conventions.DocumentKeyGenerator = (dbname, commands, entity) => store.Conventions.GetTypeTagName(entity.GetType()) + "/"; #endregion #region find_type_name Conventions.FindClrTypeName = type => // use reflection to determine the type; #endregion string.Empty; #region find_clr_type Conventions.FindClrType = (id, doc, metadata) => metadata.Value<string>(Abstractions.Data.Constants.RavenClrType); #endregion #region find_type_tagname Conventions.FindTypeTagName = type => // function that provides the collection name based on the entity type #endregion string.Empty; #region find_dynamic_tag_name Conventions.FindDynamicTagName = dynamicObject => // function to determine the collection name for the given dynamic object #endregion string.Empty; #region transform_tag_name_to_prefix Conventions.TransformTypeTagNameToDocumentKeyPrefix = tagName => // transform the tag name to the prefix of a key, e.g. [prefix]/12 #endregion string.Empty; #region find_identity_property Conventions.FindIdentityProperty = memberInfo => memberInfo.Name == "Id"; #endregion #region find_iden_propn_name_from_entity_name Conventions.FindIdentityPropertyNameFromEntityName = entityName => "Id"; #endregion #region identity_part_separator Conventions.IdentityPartsSeparator = "/"; #endregion #region identity_type_convertors Conventions.IdentityTypeConvertors = new List<ITypeConverter> { new GuidConverter(), new Int32Converter(), new Int64Converter() }; #endregion #region identity_type_convertors_2 Conventions.IdentityTypeConvertors.Add(new UInt32Converter()); #endregion #region find_id_value_part_for_value_type_conversion Conventions.FindIdValuePartForValueTypeConversion = (entity, id) => id.Split(new[] { Conventions.IdentityPartsSeparator }, StringSplitOptions.RemoveEmptyEntries).Last(); #endregion #region find_full_doc_key_from_non_string_identifier Conventions.FindFullDocumentKeyFromNonStringIdentifier = (id, type, allowNull) => // by default returns [tagName]/[identityValue]; #endregion string.Empty; }