public void ConvertFrom_WhenLongAsObject_ValuesAreReflected() { long value = 42; var id = StructureId.ConvertFrom(value); Assert.IsFalse(id.IsEmpty); Assert.AreEqual(value, id.Value); Assert.AreEqual(typeof(long), id.DataType); Assert.AreEqual(StructureIdTypes.BigIdentity, id.IdType); }
public void ConvertFrom_WhenGuidAsObject_ValuesAreReflected() { var value = Guid.Parse("925DE70F-03F4-4FC6-B372-FAA344CA8C90"); var id = StructureId.ConvertFrom(value); Assert.IsFalse(id.IsEmpty); Assert.AreEqual(value, id.Value); Assert.AreEqual(typeof(Guid), id.DataType); Assert.AreEqual(StructureIdTypes.Guid, id.IdType); }
public void ConvertFrom_WhenStringAsObject_ValuesAreReflected() { var value = "My string id."; var id = StructureId.ConvertFrom(value); Assert.IsFalse(id.IsEmpty); Assert.AreEqual(value, id.Value); Assert.AreEqual(typeof(string), id.DataType); Assert.AreEqual(StructureIdTypes.String, id.IdType); }
protected virtual void OnDeleteById(Type structureType, object id) { Ensure.That(id, "id").IsNotNull(); var structureId = StructureId.ConvertFrom(id); var structureSchema = OnUpsertStructureSchema(structureType); CacheConsumeMode = CacheConsumeModes.DoNotUpdateCacheWithDbResult; Db.CacheProvider.Remove(structureSchema, structureId); DbClient.DeleteById(structureId, structureSchema); InternalEvents.NotifyDeleted(this, structureSchema, structureId); }
protected virtual T OnCheckoutById <T>(object id) where T : class { Ensure.That(id, "id").IsNotNull(); var structureId = StructureId.ConvertFrom(id); var structureSchema = OnUpsertStructureSchema <T>(); return(Db.CacheProvider.Consume( structureSchema, structureId, sid => Db.Serializer.Deserialize <T>(DbClient.GetJsonByIdWithLock(sid, structureSchema)), CacheConsumeMode)); }
protected virtual object OnGetById(Type structureType, object id) { Ensure.That(structureType, "structureType").IsNotNull(); Ensure.That(id, "id").IsNotNull(); var structureId = StructureId.ConvertFrom(id); var structureSchema = OnUpsertStructureSchema(structureType); return(Db.CacheProvider.Consume( structureSchema, structureId, sid => Db.Serializer.Deserialize(DbClient.GetJsonById(sid, structureSchema), structureType), CacheConsumeMode)); }
protected virtual bool OnExists(Type structureType, object id) { return(Try(() => { Ensure.That(structureType, "structureType").IsNotNull(); Ensure.That(id, "id").IsNotNull(); var structureId = StructureId.ConvertFrom(id); var structureSchema = OnUpsertStructureSchema(structureType); return Db.CacheProvider.Exists( structureSchema, structureId, sid => DbClient.Exists(structureSchema, sid)); })); }
protected virtual ISession OnUpdate <TContract, TImpl>(object id, Action <TImpl> modifier, Func <TImpl, bool> proceed = null) where TContract : class where TImpl : class { Try(() => { Ensure.That(id, "id").IsNotNull(); Ensure.That(modifier, "modifier").IsNotNull(); var structureSchema = OnUpsertStructureSchema <TContract>(); var structureId = StructureId.ConvertFrom(id); var existingJson = DbClient.GetJsonByIdWithLock(structureId, structureSchema); if (string.IsNullOrWhiteSpace(existingJson)) { throw new SisoDbException(ExceptionMessages.WriteSession_NoItemExistsForUpdate.Inject(structureSchema.Name, structureId.Value)); } var item = Db.Serializer.Deserialize <TImpl>(existingJson); modifier.Invoke(item); if (proceed != null && !proceed.Invoke(item)) { return; } if (structureSchema.HasConcurrencyToken) { OnEnsureConcurrencyTokenIsValid(structureSchema, structureId, item, typeof(TImpl)); } CacheConsumeMode = CacheConsumeModes.DoNotUpdateCacheWithDbResult; Db.CacheProvider.CleanQueriesFor(structureSchema); Db.CacheProvider.Remove(structureSchema, structureId); DbClient.DeleteIndexesAndUniquesById(structureId, structureSchema); var structureBuilder = Db.StructureBuilders.ResolveBuilderForUpdate(structureSchema); var updatedStructure = structureBuilder.CreateStructure(item, structureSchema); var bulkInserter = Db.ProviderFactory.GetStructureInserter(DbClient); bulkInserter.Replace(structureSchema, updatedStructure); InternalEvents.NotifyUpdated(this, structureSchema, updatedStructure, item); }); return(this); }
protected virtual string OnGetByIdAsJson(Type structureType, object id) { Ensure.That(structureType, "structureType").IsNotNull(); Ensure.That(id, "id").IsNotNull(); var structureId = StructureId.ConvertFrom(id); var structureSchema = OnUpsertStructureSchema(structureType); if (!Db.CacheProvider.IsEnabledFor(structureSchema)) { return(DbClient.GetJsonById(structureId, structureSchema)); } var item = Db.CacheProvider.Consume( structureSchema, structureId, sid => Db.Serializer.Deserialize( DbClient.GetJsonById(sid, structureSchema), structureSchema.Type.Type), CacheConsumeMode); return(Db.Serializer.Serialize(item)); }