/// <summary> /// Generates the specified entity. /// </summary> /// <param name="entity">The entity.</param> /// <param name="mongoSession">The mongo session.</param> /// <returns></returns> /// <remarks> /// This code was taken from NHibernate. /// </remarks> public object Generate(object entity, IMongoSessionImplementor mongoSession) { byte[] guidArray = Guid.NewGuid().ToByteArray(); DateTime baseDate = new DateTime(1900, 1, 1); DateTime now = DateTime.Now; // Get the days and milliseconds which will be used to build the byte string TimeSpan days = new TimeSpan(now.Ticks - baseDate.Ticks); TimeSpan msecs = now.TimeOfDay; // Convert to a byte array // Note that SQL Server is accurate to 1/300th of a millisecond so we divide by 3.333333 byte[] daysArray = BitConverter.GetBytes(days.Days); byte[] msecsArray = BitConverter.GetBytes((long)(msecs.TotalMilliseconds / 3.333333)); // Reverse the bytes to match SQL Servers ordering Array.Reverse(daysArray); Array.Reverse(msecsArray); // Copy the bytes into the guid Array.Copy(daysArray, daysArray.Length - 2, guidArray, guidArray.Length - 6, 2); Array.Copy(msecsArray, msecsArray.Length - 4, guidArray, guidArray.Length - 4, 4); return new Guid(guidArray); }
public DeleteDocumentMapper(IMongoSessionImplementor mongoSession) { if (mongoSession == null) throw new ArgumentNullException("mongoSession"); this.mongoSession = mongoSession; }
public IdGenerator(IMongoSessionImplementor mongoSession) { if (mongoSession == null) throw new ArgumentNullException("mongoSession"); this.mongoSession = mongoSession; }
/// <summary> /// Initializes a new instance of the <see cref="ChangeTracker"/> class. /// </summary> /// <param name="mongoSession">The mongo session.</param> public ChangeTracker(IMongoSessionImplementor mongoSession) { if (mongoSession == null) throw new ArgumentNullException("mongoSession"); this.mongoSession = mongoSession; this.trackedEntities = new List<TrackedEntity>(); }
public object Generate(object entity, IMongoSessionImplementor mongoSession) { var classMap = mongoSession.MappingStore.GetClassMapFor(entity.GetType()); object id = classMap.IdMap.MemberGetter(entity); if (Object.Equals(id, classMap.IdMap.UnsavedValue)) throw new IdGenerationException(string.Format("Ids for {0} must be manually assigned before saving.", classMap.Type)); return id; }
/// <summary> /// Creates the mongo query specification. /// </summary> /// <param name="mappingStore">The mapping store.</param> /// <param name="hydrator">The hydrator.</param> /// <param name="queryModel">The query model.</param> /// <returns></returns> public static MongoQuerySpecification CreateMongoQuerySpecification(IMongoSessionImplementor mongoSession, QueryModel queryModel) { if (mongoSession == null) throw new ArgumentNullException("mongoSession"); if (queryModel == null) throw new ArgumentNullException("queryModel"); var visitor = new CollectionQueryModelVisitor(mongoSession); visitor.VisitQueryModel(queryModel); return visitor.querySpec; }
/// <summary> /// Initializes a new instance of the <see cref="PersistenceAction"/> class. /// </summary> /// <param name="mongoSession">The mongo session.</param> /// <param name="mongoSessionCache">The mongo session cache.</param> /// <param name="changeTracker">The change tracker.</param> public PersistenceAction(IMongoSessionImplementor mongoSession, IMongoSessionCache mongoSessionCache, IChangeTracker changeTracker) { if (mongoSession == null) throw new ArgumentNullException("mongoSession"); if (mongoSessionCache == null) throw new ArgumentNullException("mongoSessionCache"); if (changeTracker == null) throw new ArgumentNullException("changeTracker"); this.ChangeTracker = changeTracker; this.MongoSessionCache = mongoSessionCache; this.MongoSession = mongoSession; }
/// <summary> /// Initializes a new instance of the <see cref="AbstractLazyInitializer"/> class. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="id">The id.</param> /// <param name="mongoSession">The mongo session.</param> protected AbstractLazyInitializer(Type entityType, object id, IMongoSessionImplementor mongoSession) { if (entityType == null) throw new ArgumentNullException("rootClassType"); if (id == null) throw new ArgumentNullException("id"); if (mongoSession == null) throw new ArgumentNullException("mongoSession"); this.EntityType = entityType; this.Id = id; this.IsInitialized = false; this.mongoSession = mongoSession; }
/// <summary> /// Gets the proxy. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="id">The id.</param> /// <param name="mongoSession">The mongo session.</param> /// <returns></returns> public IMongoProxy GetProxy(Type entityType, object id, IMongoSessionImplementor mongoSession) { try { var initializer = new CastleLazyInitializer(entityType, id, mongoSession); object generatedProxy = generator.CreateClassProxy(entityType, new[] { typeof(IMongoProxy) }, initializer); initializer.constructed = true; return (IMongoProxy)generatedProxy; } catch (Exception ex) { throw new Exception("Unable to create a proxy.", ex); } }
/// <summary> /// Converts to document value. /// </summary> /// <param name="value">The value.</param> /// <returns></returns> public object ConvertToDocumentValue(object value, IMongoSessionImplementor mongoSession) { var lastMemberMap = this.memberMaps[this.memberMaps.Count - 1]; var mapper = new ValueToDocumentValueMapper(mongoSession); return mapper.CreateDocumentValue(lastMemberMap, value); }
/// <summary> /// Gets the implementation. /// </summary> /// <param name="mongoSession">The mongo session.</param> /// <returns></returns> public object GetImplementation(IMongoSessionImplementor mongoSession) { return mongoSession.GetById(this.EntityType, this.Id); }
public void SetUp() { mongoSession = new Mock<IMongoSessionImplementor>().Object; }
/// <summary> /// Generates the specified entity. /// </summary> /// <param name="entity">The entity.</param> /// <param name="mongoSession">The mongo session.</param> /// <returns></returns> public object Generate(object entity, IMongoSessionImplementor mongoSession) { return this.IdGenerator.Generate(entity, mongoSession); }
/// <summary> /// Initializes a new instance of the <see cref="MongoQueryModelVisitor"/> class. /// </summary> /// <param name="mongoSession">The mongo session.</param> public ScalarQueryModelVisitor(IMongoSessionImplementor mongoSession) { this.mongoSession = mongoSession; this.Query = new Document(); }
/// <summary> /// Generates the specified entity. /// </summary> /// <param name="entity">The entity.</param> /// <param name="mongoSession">The mongo session.</param> /// <returns></returns> public object Generate(object entity, IMongoSessionImplementor mongoSession) { return Guid.NewGuid(); }
/// <summary> /// Initializes a new instance of the <see cref="MongoQueryModelVisitor"/> class. /// </summary> /// <param name="mongoSession">The mongo session.</param> private CollectionQueryModelVisitor(IMongoSessionImplementor mongoSession) { this.mongoSession = mongoSession; this.querySpec = new MongoQuerySpecification(); }
/// <summary> /// Initializes a new instance of the <see cref="CastleLazyInitializer"/> class. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="id">The id.</param> /// <param name="mongoSession">The mongo session.</param> public CastleLazyInitializer(Type entityType, object id, IMongoSessionImplementor mongoSession) : base(entityType, id, mongoSession) { }
/// <summary> /// Initializes a new instance of the <see cref="FindOneAction"/> class. /// </summary> /// <param name="mongoSession">The mongoSession.</param> /// <param name="mongoSessionCache">The mongo session cache.</param> /// <param name="changeTracker">The change tracker.</param> public FindOneAction(IMongoSessionImplementor mongoSession, IMongoSessionCache mongoSessionCache, IChangeTracker changeTracker) : base(mongoSession, mongoSessionCache, changeTracker) { }
/// <summary> /// Initializes a new instance of the <see cref="BasicLazyInitializer"/> class. /// </summary> /// <param name="entityType">Type of the entity.</param> /// <param name="id">The id.</param> /// <param name="mongoSession">The mongo session.</param> protected BasicLazyInitializer(Type entityType, object id, IMongoSessionImplementor mongoSession) : base(entityType, id, mongoSession) { this.idMemberName = mongoSession.MappingStore.GetClassMapFor(entityType).IdMap.MemberName; this.overridesEquals = entityType.Overrides("Equals", new[] { typeof(object) }); }