public void Store <TEntity>(TEntity entity) where TEntity : class { var record = new JellyRecord <TEntity>(entity); _jellyDatabase.OnStoreRecord <TEntity>(record); _flushRequired = true; }
internal void OnStoreRecord <TEntity>(JellyRecord <TEntity> record) where TEntity : class { Database database = null; var entityType = typeof(TEntity); var entityName = GetEntityName <TEntity>(); if (!_databases.TryGetValue(entityName, out database)) { database = CreateNewDatabase <long, TEntity>(true); RegisterIdentityProperty <TEntity, long>(null, true); } var dataKey = _keyGenerators[entityType].GenerateKey(record.Entity); database.Write(dataKey, record.GetSerializedData()); database.Flush(); }
private AutoGenIdentity <TKey> RetrieveAutoKeyState <TKey, TEntity>() { AutoGenIdentity <TKey> result; var database = _databases[GetEntityName <TEntity>()]; var typeComparer = TypeComparer <TKey> .GetTypeComparer(); var autoGenIndexKey = typeComparer.Increment(typeComparer.MinKey); var text = database.Read(DataKey.CreateKey(autoGenIndexKey)); if (!string.IsNullOrEmpty(text)) { var record = new JellyRecord <AutoGenIdentity <TKey> >(text); result = record.Entity; result.NextRetrieved += OnAutoGenIdentityRetrievedNextValue; return(result); } result = new AutoGenIdentity <TKey>() { CurrentUsedId = autoGenIndexKey, EntityTypeName = GetEntityName <TEntity>() }; result.NextRetrieved += OnAutoGenIdentityRetrievedNextValue; return(result); }