protected override object ProcessCollection(object collection, PersistentCollectionType type) { SessionImpl session = Session; object key = Key; ICollectionPersister persister = session.GetCollectionPersister(type.Role); session.RemoveCollection(persister, key); if (collection != null && (collection is PersistentCollection)) { PersistentCollection wrapper = collection as PersistentCollection; wrapper.SetCurrentSession(session); if (wrapper.WasInitialized) { session.AddNewCollection(wrapper, persister); } else { session.ReattachCollection(wrapper, wrapper.CollectionSnapshot); } } else { // otherwise a null or brand new collection // this will also (inefficiently) handle arrays, which // have no snapshot, so we can't do any better //processArrayOrNewCollection(collection, type); } return(null); }
/// <summary> /// Sets the specified collection view. /// </summary> /// <param name="key">The key.</param> /// <param name="collection">The collection.</param> /// <param name="persistence">The persistence.</param> public string Set(string key, List <Media> collection, Persistence persistence) { byte[] bytes = System.Text.Encoding.Default.GetBytes(key); string encodedKey = HexEncoding.ToString(bytes); IEnumerable <int> ids = collection.Select(m => m.MediaId); string idCollection = string.Join(",", ids); PersistentCollection collection1 = _persistentCollectionRepository.Get(key); if (collection1 == null || collection1.Value != idCollection) { PersistentCollection persistentCollection = new PersistentCollection { CollectionKey = key, Persistence = persistence, Value = idCollection }; _persistentCollectionRepository.Set(persistentCollection); } return(encodedKey); }
public static PersistentCollection <EmailTemplateTrigger> LoadForStoreEvent(StoreEvent storeEvent) { PersistentCollection <EmailTemplateTrigger> EmailTemplateTriggerCollection = new PersistentCollection <EmailTemplateTrigger>(); //CREATE THE DYNAMIC SQL TO LOAD OBJECT StringBuilder selectQuery = new StringBuilder(); //GET RECORDS STARTING AT FIRST ROW selectQuery.Append("SELECT StoreEventId, EmailTemplateId"); selectQuery.Append(" FROM ac_EmailTemplateTriggers"); selectQuery.Append(" WHERE StoreEventId = @storeEventId"); Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); database.AddInParameter(selectCommand, "@storeEventId", System.Data.DbType.Int32, (int)storeEvent); //EXECUTE THE COMMAND using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read()) { EmailTemplateTrigger storeEventTrigger = new EmailTemplateTrigger(); //SET FIELDS FROM ROW DATA storeEventTrigger.StoreEventId = dr.GetInt32(0); storeEventTrigger.EmailTemplateId = dr.GetInt32(1); storeEventTrigger.IsDirty = false; EmailTemplateTriggerCollection.Add(storeEventTrigger); } dr.Close(); } return(EmailTemplateTriggerCollection); }
private object ProcessArrayOrNewCollection(object collection, PersistentCollectionType collectionType) { if (collection == null) { return(null); } ICollectionPersister persister = Session.GetCollectionPersister(collectionType.Role); if (collectionType.IsArrayType) { ArrayHolder ah = Session.GetArrayHolder(collection); if (ah == null) { ah = new ArrayHolder(Session, collection); Session.AddNewCollection(ah, persister); Session.AddArrayHolder(ah); } return(null); } else { PersistentCollection persistentCollection = collectionType.Wrap(Session, collection); Session.AddNewCollection(persistentCollection, persister); if (log.IsDebugEnabled) { log.Debug("Wrapped collection in role: " + collectionType.Role); } return(persistentCollection); //Force a substitution! } }
/// <summary> /// Sets the dynamic collection. /// </summary> /// <param name="key">The key.</param> /// <param name="uploads">The uploads.</param> public string SetPersistentCollection(string key, List <RecentUploads> uploads) { List <Media> media = uploads.ConvertAll(o => (Media)o); PersistentCollection.SetBackUrl(string.Format("{0}/recent", Authorization.Owner.Username), Cookie); string setKey = PersistentCollection.Set(Authorization.Owner.Username + "_" + key + "_recent", media, Persistence.Permanent); return(setKey); }
/// <summary> /// Gets the specified collection key. /// </summary> /// <param name="collectionKey">The collection key.</param> /// <returns></returns> public string Get(string collectionKey) { byte[] bytes = HexEncoding.GetBytes(collectionKey); string encodedKey = System.Text.Encoding.Default.GetString(bytes); //string decryptHexEncoded = _cryptographyService.Decrypt(collectionKey); PersistentCollection collection = _persistentCollectionRepository.Get(encodedKey); return(collection != null ? collection.Value : string.Empty); }
public virtual PersistentDictionary <string, StoreSetting> LoadDictionaryForStore() { PersistentCollection <StoreSetting> settingCollection = StoreSettingDataSource.LoadForStore(); PersistentDictionary <string, StoreSetting> settingDictionary = new PersistentDictionary <string, StoreSetting>(); foreach (StoreSetting setting in settingCollection) { settingDictionary.Add(setting.FieldName, setting); } return(settingDictionary); }
private static void DeleteOrphans(PersistentCollection pc, ISessionImplementor session) { if (pc.WasInitialized) // can't be any orphans if it was not initialized { ICollection orphanColl = session.GetOrphans(pc); foreach (object obj in orphanColl) { session.Delete(obj); } } }
/// <summary> /// Gets a collection of all the users in the data source in pages of data. /// </summary> /// <param name="pageIndex">The index of the page of results to return. pageIndex is zero-based.</param> /// <param name="pageSize">The size of the page of results to return.</param> /// <param name="totalRecords">The total number of matched users.</param> /// <returns>A MembershipUserCollection collection that contains a page of pageSizeMembershipUser objects beginning at the page specified by pageIndex.</returns> public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) { MembershipUserCollection allUsers = new MembershipUserCollection(); PersistentCollection <User> users = UserDataSource.LoadForStore(pageSize, (pageSize * (pageIndex - 1)), string.Empty); foreach (User user in users) { allUsers.Add(new MembershipUser(this.Name, user.UserName, user.UserId, user.Email, user.PasswordQuestion, user.Comment, user.IsApproved, user.IsLockedOut, user.CreateDate, user.LastLoginDate, user.LastActivityDate, user.LastPasswordChangedDate, user.LastLockoutDate)); } totalRecords = UserDataSource.CountForStore(); return(allUsers); }
protected override object ProcessCollection(object collection, PersistentCollectionType collectionType) { if (collection != null && (collection is PersistentCollection)) { PersistentCollection coll = collection as PersistentCollection; if (coll.SetCurrentSession(Session)) { Session.ReattachCollection(coll, coll.CollectionSnapshot); } return(null); } else { return(ProcessArrayOrNewCollection(collection, collectionType)); } }
protected override object ProcessCollection(object collection, PersistentCollectionType type) { ICollectionPersister persister = Session.GetCollectionPersister(type.Role); if (collection == null) { // Do nothing } else if (collection is PersistentCollection) { PersistentCollection coll = (PersistentCollection)collection; if (coll.SetCurrentSession(Session)) { ICollectionSnapshot snapshot = coll.CollectionSnapshot; if (SessionImpl.IsOwnerUnchanged(snapshot, persister, this.Key)) { // a "detached" collection that originally belonged to the same entity if (snapshot.Dirty) { throw new HibernateException("reassociated object has dirty collection"); } Session.ReattachCollection(coll, snapshot); } else { // a "detached" collection that belonged to a different entity throw new HibernateException("reassociated object has dirty collection reference"); } } else { // a collection loaded in the current session // can not possibly be the collection belonging // to the entity passed to update() throw new HibernateException("reassociated object has dirty collection reference"); } } else { // brand new collection //TODO: or an array!! we can't lock objects with arrays now?? throw new HibernateException("reassociated object has dirty collection reference"); } return(null); }
/// <summary> /// Checks to see if the <see cref="PersistentCollection"/> has had any changes to the /// collections contents or if any of the elements in the collection have been modified. /// </summary> /// <param name="coll"></param> /// <returns><c>true</c> if the <see cref="PersistentCollection"/> is dirty.</returns> /// <remarks> /// default behavior; will be overridden in deep lazy collections /// </remarks> private bool IsDirty(PersistentCollection coll) { // if this has already been marked as dirty or the collection can not // be directly accessed (ie- we can guarantee that the NHibernate collection // wrappers are used) and the elements in the collection are not mutable // then return the dirty flag. if (dirty || ( !coll.IsDirectlyAccessible && !loadedPersister.ElementType.IsMutable )) { return(dirty); } else { // need to have the coll determine if it is the same as the snapshot // that was last taken. return(!coll.EqualsSnapshot(loadedPersister.ElementType)); } }
/// <summary> /// Processes emails for the given store event using the given parameters /// </summary> /// <param name="storeEvent">StoreEvent object for which to process the emails</param> /// <param name="parameters">The parameters to be used in nVelocity email templates</param> public static void ProcessEmails(StoreEvent storeEvent, Hashtable parameters) { parameters["store"] = Token.Instance.Store; //NEED TO GET THE EMAIL TEMPLATE FOR THE ORDER PersistentCollection <EmailTemplateTrigger> emailTriggers = EmailTemplateTriggerDataSource.LoadForStoreEvent(storeEvent); foreach (EmailTemplateTrigger trigger in emailTriggers) { EmailTemplate template = trigger.EmailTemplate; if (template != null) { foreach (string key in parameters.Keys) { template.Parameters[key] = parameters[key]; } template.Send(); } } }
/// <summary> /// Prepares this CollectionEntry for the Flush process. /// </summary> /// <param name="collection">The <see cref="PersistentCollection"/> that this CollectionEntry will be responsible for flushing.</param> internal void PreFlush(PersistentCollection collection) { // if the collection is initialized and it was previously persistent // initialize the dirty flag dirty = (initialized && loadedPersister != null && IsDirty(collection)) || (!initialized && dirty); //only need this so collection with queued adds will be removed from second-level cache if (log.IsDebugEnabled && dirty && loadedPersister != null) { log.Debug("Collection dirty: " + MessageHelper.InfoString(loadedPersister, loadedKey)); } // reset all of these values so any previous flush status // information is cleared from this CollectionEntry doupdate = false; doremove = false; dorecreate = false; reached = false; processed = false; }
protected override object ProcessCollection(object collection, PersistentCollectionType type) { ICollectionPersister persister = Session.GetCollectionPersister(type.Role); if (collection is PersistentCollection) { PersistentCollection wrapper = (PersistentCollection)collection; if (wrapper.SetCurrentSession(Session)) { //a "detached" collection! ICollectionSnapshot snapshot = wrapper.CollectionSnapshot; if (!SessionImpl.IsOwnerUnchanged(snapshot, persister, Key)) { // if the collection belonged to a different entity, // clean up the existing state of the collection Session.RemoveCollection(persister, Key); } Session.ReattachCollection(wrapper, snapshot); } else { // a collection loaded in the current session // can not possibly be the collection belonging // to the entity passed to update() Session.RemoveCollection(persister, Key); } } else { // null or brand new collection // this will also (inefficiently) handle arrays, which have // no snapshot, so we can't do any better Session.RemoveCollection(persister, Key); //processArrayOrNewCollection(collection, type); } return(null); }
/// <summary> /// Updates the CollectionEntry to reflect that it is has been successfully flushed to the database. /// </summary> /// <param name="collection">The <see cref="PersistentCollection"/> that was flushed.</param> /// <remarks> /// Called after a <em>successful</em> flush. /// </remarks> internal bool PostFlush(PersistentCollection collection) { if (ignore) { ignore = false; } else { // the CollectionEntry should be processed if we are in the PostFlush() if (!processed) { throw new AssertionFailure("collection was not processed by Flush()"); } // now that the flush has gone through move everything that is the current // over to the loaded fields and set dirty to false since the db & collection // are in synch. loadedKey = currentKey; SetLoadedPersister(currentPersister); dirty = false; // collection needs to know its' representation in memory and with // the db is now in synch - esp important for collections like a bag // that can add without initializing the collection. collection.PostFlush(); // if it was initialized or any of the scheduled actions were performed then // need to resnapshot the contents of the collection. if (initialized && (doremove || dorecreate || doupdate)) { InitSnapshot(collection, loadedPersister); } } return(loadedPersister == null); }
private static void SetDefaults() { LogPath = ""; KeyBindings = new KeyBindingCollection(new PersistentCollection<LuaKeyBinding>(Constants.KeyBindingCollectionSettingName)); CachedFiles = new PersistentCollection<SerializableFileInfo>(Constants.CachedFileCollectionSettingName); FavoritedLocations = new PersistentCollection<string>(Constants.FavoritedLocationsCollectionSettingName); }
/// <summary> /// Sets the specified collection. /// </summary> /// <param name="collection">The collection.</param> public void Set(PersistentCollection collection) { database.NonQuery("PersistentCollection_Set", collection); }
/// <summary> /// Updates the CollectionEntry to reflect that the <see cref="PersistentCollection"/> /// has been initialized. /// </summary> /// <param name="collection">The initialized <see cref="PersistentCollection"/> that this Entry is for.</param> internal void PostInitialize(PersistentCollection collection) { initialized = true; snapshot = collection.GetSnapshot(loadedPersister); }
internal void InitSnapshot(PersistentCollection collection, ICollectionPersister persister) { snapshot = collection.GetSnapshot(persister); }
/// <summary> /// Initializes a new instance of <see cref="ScheduledCollectionUpdate"/>. /// </summary> /// <param name="collection">The <see cref="PersistentCollection"/> to update.</param> /// <param name="persister">The <see cref="ICollectionPersister"/> that is responsible for the persisting the Collection.</param> /// <param name="id">The identifier of the Collection owner.</param> /// <param name="emptySnapshot">Indicates if the Collection was empty when it was loaded.</param> /// <param name="session">The <see cref="ISessionImplementor"/> that the Action is occuring in.</param> public ScheduledCollectionUpdate(PersistentCollection collection, ICollectionPersister persister, object id, bool emptySnapshot, ISessionImplementor session) : base(persister, id, session) { _collection = collection; _emptySnapshot = emptySnapshot; }
/// <summary> /// Initializes a new instance of <see cref="ScheduledCollectionRecreate"/>. /// </summary> /// <param name="collection">The <see cref="PersistentCollection"/> to recreate.</param> /// <param name="persister">The <see cref="ICollectionPersister"/> that is responsible for the persisting the Collection.</param> /// <param name="id">The identifier of the Collection owner.</param> /// <param name="session">The <see cref="ISessionImplementor"/> that the Action is occuring in.</param> public ScheduledCollectionRecreate(PersistentCollection collection, ICollectionPersister persister, object id, ISessionImplementor session) : base(persister, id, session) { _collection = collection; }