Ejemplo n.º 1
0
        public CollectionListeners(ISessionFactory sf)
        {
            preCollectionRecreateListener  = new PreCollectionRecreateListener(this);
            initializeCollectionListener   = new InitializeCollectionListener(this);
            preCollectionRemoveListener    = new PreCollectionRemoveListener(this);
            preCollectionUpdateListener    = new PreCollectionUpdateListener(this);
            postCollectionRecreateListener = new PostCollectionRecreateListener(this);
            postCollectionRemoveListener   = new PostCollectionRemoveListener(this);
            postCollectionUpdateListener   = new PostCollectionUpdateListener(this);
            SessionFactoryImpl impl = (SessionFactoryImpl)sf;

            impl.EventListeners.InitializeCollectionEventListeners = new IInitializeCollectionEventListener[]
            { initializeCollectionListener };

            impl.EventListeners.PreCollectionRecreateEventListeners = new IPreCollectionRecreateEventListener[]
            { preCollectionRecreateListener };
            impl.EventListeners.PostCollectionRecreateEventListeners = new IPostCollectionRecreateEventListener[]
            { postCollectionRecreateListener };
            impl.EventListeners.PreCollectionRemoveEventListeners = new IPreCollectionRemoveEventListener[]
            { preCollectionRemoveListener };
            impl.EventListeners.PostCollectionRemoveEventListeners = new IPostCollectionRemoveEventListener[]
            { postCollectionRemoveListener };
            impl.EventListeners.PreCollectionUpdateEventListeners = new IPreCollectionUpdateEventListener[]
            { preCollectionUpdateListener };
            impl.EventListeners.PostCollectionUpdateEventListeners = new IPostCollectionUpdateEventListener[]
            { postCollectionUpdateListener };
        }
        public void SetUp()
        {
            var builder    = new NHibernateSagaStorage();
            var properties = SQLiteConfiguration.InMemory();

            var configuration = new Configuration().AddProperties(properties);
            var settings      = new SettingsHolder();

            var metaModel = new SagaMetadataCollection();
            var types     = new [] { typeof(TestSaga), typeof(TestSagaData), typeof(TestComponent), typeof(PolymorphicPropertyBase),
                                     typeof(AlsoDerivedFromTestSagaWithTableNameAttributeActualSaga), typeof(AlsoDerivedFromTestSagaWithTableNameAttribute),
                                     typeof(DerivedFromTestSagaWithTableNameAttributeActualSaga), typeof(DerivedFromTestSagaWithTableNameAttribute),
                                     typeof(TestSagaWithTableNameAttributeActualSaga), typeof(TestSagaWithTableNameAttribute),
                                     typeof(SagaWithVersionedPropertyAttributeActualSaga), typeof(SagaWithVersionedPropertyAttribute),
                                     typeof(SagaWithoutVersionedPropertyAttributeActualSaga), typeof(SagaWithoutVersionedPropertyAttribute),
                                     typeof(object) };

            metaModel.Initialize(types);
            settings.Set <SagaMetadataCollection>(metaModel);

            settings.Set("TypesToScan", types);
            builder.ApplyMappings(settings, configuration);
            sessionFactory = configuration.BuildSessionFactory() as SessionFactoryImpl;

            persisterForTestSaga = sessionFactory.GetEntityPersisterFor <TestSagaData>();
        }
        static DbConnection OpenConnection(SessionFactoryImpl sessionFactoryImpl, Transaction ambientTransaction)
        {
            var connection = sessionFactoryImpl.ConnectionProvider.GetConnection();

            connection.EnlistTransaction(ambientTransaction);
            return(connection);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Find a join.  Return the name of the corresponding property.
 /// </summary>
 private static AbstractEntityPersister FindJoinedEntity(SessionFactoryImpl sf, AbstractEntityPersister root, string toTable, string fromField, out string propertyName)
 {
     //   root.ClassMetadata.PropertyTypes.First().Na
     for (int i = 0; i < root.PropertyTypes.Length; i++)
     {
         if (root.PropertyTypes[i].IsAssociationType &&
             !root.PropertyTypes[i].IsCollectionType)
         {
             String[] cols = root.ToColumns(root.PropertyNames[i]);
             if (cols.Length == 1 && cols[0] == fromField)
             {
                 propertyName = root.PropertyNames[i];
                 Type   t          = root.PropertyTypes[i].ReturnedClass;
                 String entityName = sf.TryGetGuessEntityName(t);
                 AbstractEntityPersister persister = (AbstractEntityPersister)sf.GetEntityPersister(entityName);
                 if (persister.TableName == toTable)
                 {
                     return(persister);
                 }
                 // special case for acct mgr
                 if (toTable == "USERINFO" && persister.TableName == "USERSECURITY")
                 {
                     propertyName = propertyName + ".UserInfo";
                     entityName   = "Sage.SalesLogix.Security.UserInfo";
                     return((AbstractEntityPersister)sf.GetEntityPersister(entityName));
                 }
             }
         }
     }
     propertyName = null;
     return(null);
 }
Ejemplo n.º 5
0
        public global::NHibernate.Cfg.Configuration GetCfg(string[] addAssemblies)
        {
            SessionFactoryImpl           sessionFactoryImpl = SpringHelper.ApplicationContext["NHibernateSessionFactory"] as SessionFactoryImpl;
            IDictionary                  springObjectDic    = getSpringObjectPropertyValue("NHibernateSessionFactory", "HibernateProperties") as IDictionary;
            IDictionary <string, string> dic = new Dictionary <string, string>();

            foreach (DictionaryEntry de in springObjectDic)
            {
                dic.Add(de.Key.ToString(), de.Value.ToString());
                //if (de.Key.ToString().Equals("hibernate.dialect"))
                //{
                //    dialectName = de.Value.ToString();
                //}
            }

            #region //真正抓取設定檔的內容
            ISession session       = sessionFactoryImpl.OpenSession();
            string   connectionStr = session.Connection.ConnectionString;
            #endregion

            dic.Add("connection.connection_string", connectionStr);
            Configuration cfg = new Configuration();
            cfg.AddProperties(dic);

            foreach (string assembly in addAssemblies)
            {
                cfg.AddAssembly(assembly);
            }

            return(cfg);
        }
Ejemplo n.º 6
0
        public void SetUp()
        {
            var builder = new NHibernateSagaStorage();

            var cfg = new Configuration()
                      .DataBaseIntegration(x =>
            {
                x.Dialect <MsSql2012Dialect>();
                x.ConnectionString = Consts.SqlConnectionString;
            });

            var types = new[] { typeof(SagaWithAbstractBaseClassActualSaga), typeof(SagaWithAbstractBaseClass), typeof(ContainSagaData), typeof(MyOwnAbstractBase) };

            var allMetadata = new SagaMetadataCollection();

            allMetadata.Initialize(types);

            var settings = new SettingsHolder();

            settings.Set("TypesToScan", types);
            settings.Set <SagaMetadataCollection>(allMetadata);

            builder.ApplyMappings(settings, cfg);
            sessionFactory = cfg.BuildSessionFactory() as SessionFactoryImpl;
        }
        public void SetUp()
        {
            var builder = new NHibernateSagaStorage();

            var cfg = new Configuration()
                      .DataBaseIntegration(x =>
            {
                x.Dialect <MsSql2012Dialect>();
                x.ConnectionString = Consts.SqlConnectionString;
            });

            var settings = new SettingsHolder();

            var metaModel = new SagaMetadataCollection();
            var types     = new [] { typeof(TestSaga), typeof(TestSagaData), typeof(TestComponent), typeof(PolymorphicPropertyBase),
                                     typeof(AlsoDerivedFromTestSagaWithTableNameAttributeActualSaga), typeof(AlsoDerivedFromTestSagaWithTableNameAttribute),
                                     typeof(DerivedFromTestSagaWithTableNameAttributeActualSaga), typeof(DerivedFromTestSagaWithTableNameAttribute),
                                     typeof(TestSagaWithTableNameAttributeActualSaga), typeof(TestSagaWithTableNameAttribute),
                                     typeof(SagaWithVersionedPropertyAttributeActualSaga), typeof(SagaWithVersionedPropertyAttribute),
                                     typeof(SagaWithoutVersionedPropertyAttributeActualSaga), typeof(SagaWithoutVersionedPropertyAttribute),
                                     typeof(object) };

            metaModel.Initialize(types);
            settings.Set <SagaMetadataCollection>(metaModel);

            settings.Set("TypesToScan", types);
            builder.ApplyMappings(settings, cfg);
            sessionFactory = cfg.BuildSessionFactory() as SessionFactoryImpl;

            persisterForTestSaga = sessionFactory.GetEntityPersisterFor <TestSagaData>();
        }
        public void SetUp()
        {
            var builder = new SessionFactoryBuilder(new[] { typeof(SagaWithAbstractBaseClass), typeof(ContainSagaData), typeof(MyOwnAbstractBase) });

            var properties = SQLiteConfiguration.InMemory();

            sessionFactory = builder.Build(new Configuration().AddProperties(properties)) as SessionFactoryImpl;
        }
Ejemplo n.º 9
0
        public void SetUp()
        {
            var builder = new SessionFactoryBuilder(new[] { typeof(SagaWithAbstractBaseClass), typeof(ContainSagaData), typeof(MyOwnAbstractBase) });

            var properties = SQLiteConfiguration.InMemory();

            sessionFactory = builder.Build(new Configuration().AddProperties(properties)) as SessionFactoryImpl;
        }
Ejemplo n.º 10
0
        public void SessionFactoryImpl_Can_Set_Connection_String()
        {
            var factory = new SessionFactoryImpl();

            Assert.IsNull(factory.ConnectionString);

            Assert.AreEqual(factory, factory.SetConnectionString("test"));
            Assert.AreEqual("test", factory.ConnectionString);
        }
Ejemplo n.º 11
0
        public void SessionFactoryImpl_Can_Set_Persistence_Adapter()
        {
            var fixture = new PersistenceAdapterFixture();
            var factory = new SessionFactoryImpl();

            Assert.IsNull(factory.Adapter);

            Assert.AreEqual(factory, factory.SetAdapter(fixture.PersistenceAdapter));
            Assert.AreEqual(fixture.PersistenceAdapter, factory.Adapter);
        }
        public void SetUp()
        {
            var builder = new NHibernateSagaStorage();
            var properties = SQLiteConfiguration.InMemory();

            var configuration = new Configuration().AddProperties(properties);
            var settings = new SettingsHolder();
            settings.Set("TypesToScan", new[] { typeof(SagaWithAbstractBaseClass), typeof(ContainSagaData), typeof(MyOwnAbstractBase) });
            builder.ApplyMappings(settings, configuration);
            sessionFactory = configuration.BuildSessionFactory() as SessionFactoryImpl;
        }
Ejemplo n.º 13
0
        public void TestFormatUserName()
        {
            String entityName = "Sage.SalesLogix.Entities.Contact";

            using (var sess = new SessionScopeWrapper())
            {
                SessionFactoryImpl      sf        = (SessionFactoryImpl)sess.SessionFactory;
                AbstractEntityPersister persister = (AbstractEntityPersister)(sf.GetEntityPersister(entityName));
                Assert.AreEqual("AccountManager.UserInfo.UserName", SimpleLookup.DecomposePath(sf, persister, "ACCOUNTMANAGERID", "6"));
            }
        }
Ejemplo n.º 14
0
        public void SessionFactoryImpl_Can_Open_Session()
        {
            var fixture = new PersistenceAdapterFixture();
            var session = new SessionFactoryImpl()
                          .SetConnectionString("test")
                          .SetAdapter(fixture.PersistenceAdapter)
                          .OpenSession();

            Assert.IsNotNull(session);
            Assert.AreEqual(fixture.Connection, session.Connection);
        }
Ejemplo n.º 15
0
        public void TestFormatOwner()
        {
            String entityName = "Sage.SalesLogix.Entities.Contact";

            using (var sess = new SessionScopeWrapper())
            {
                SessionFactoryImpl      sf        = (SessionFactoryImpl)sess.SessionFactory;
                AbstractEntityPersister persister = (AbstractEntityPersister)(sf.GetEntityPersister(entityName));
                Assert.AreEqual("Owner.OwnerDescription", SimpleLookup.DecomposePath(sf, persister, "SECCODEID", "8"));
            }
        }
Ejemplo n.º 16
0
        public void SetUp()
        {
            var builder    = new NHibernateSagaStorage();
            var properties = SQLiteConfiguration.InMemory();

            var configuration = new Configuration().AddProperties(properties);
            var settings      = new SettingsHolder();

            settings.Set("TypesToScan", new[] { typeof(SagaWithAbstractBaseClass), typeof(ContainSagaData), typeof(MyOwnAbstractBase) });
            builder.ApplyMappings(settings, configuration);
            sessionFactory = configuration.BuildSessionFactory() as SessionFactoryImpl;
        }
Ejemplo n.º 17
0
        public void SetUp()
        {
            var assemblyContainingSagas = typeof(TestSaga).Assembly;
            var types = assemblyContainingSagas.GetTypes().ToList();

            types.Add(typeof(ContainSagaData));

            var builder    = new SessionFactoryBuilder(types);
            var properties = SQLiteConfiguration.InMemory();

            sessionFactory = builder.Build(new Configuration().AddProperties(properties)) as SessionFactoryImpl;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Path represents path to a field, based at origin.
        /// Return the field object.
        /// A field path is normally of the form:
        /// Source Table:Path
        /// where Path is recursively defined as either:
        /// FieldName
        /// or
        /// From Field=To Field.To Table!Path
        /// </summary>
        /// <param name="sf"></param>
        /// <param name="root"></param>
        /// <param name="path"></param>
        /// <param name="format"></param>
        internal static String DecomposePath(SessionFactoryImpl sf, AbstractEntityPersister root, String path, String format)
        {
            String[] parts;

            parts = path.Split(new char[] { '!' }, 2);
            if (parts.Length == 1)
            {
                // field name
                // remove initial "@" (this is used to indicate calculated fields)
                if (parts[0][0] == '@')
                {
                    parts[0] = parts[0].Substring(1);
                }
                String fieldName = parts[0].ToUpper();
                for (int i = 0; i < root.PropertyTypes.Length; i++)
                {
                    IType propType = root.PropertyTypes[i];
                    if (propType.IsCollectionType)
                    {
                        continue;
                    }
                    String   propName = root.PropertyNames[i];
                    String[] columns  = root.ToColumns(propName);
                    if (columns.Length == 1 && columns[0].ToUpper() == fieldName)
                    {
                        return(FormatProperty(propName, propType, format));
                    }
                }

                LOG.Warn("Unable to locate property by column - " + parts[0]);
                return(null);
            }
            else
            {
                String newpath = parts[1];  // part after the exclamation mark
                Match  matches = _fieldPathRegexp.Match(parts[0]);
                if (!matches.Success)
                {
                    throw new ArgumentException("Path did not match field expression pattern: " + parts[0]);
                }
                System.Diagnostics.Debug.Assert(matches.Groups.Count == 5, "Number of Groups should have been 5, was " + matches.Groups.Count + " (path = " + parts[0] + ")");
                String toTable   = matches.Groups[4].Value;
                String fromField = matches.Groups[1].Value;
                String propertyName;
                root = FindJoinedEntity(sf, root, toTable, fromField, out propertyName);
                if (root == null)
                {
                    throw new ArgumentException("Unable to locate linked property " + toTable + " via " + fromField + "!");
                }
                return(propertyName + "." + DecomposePath(sf, root, newpath, format));
            }
        }
Ejemplo n.º 19
0
        public static void Open <TPersistenceAdapter>(string connectionString)
            where TPersistenceAdapter : IPersistenceAdapter, new()
        {
            SessionContext.SetContext(new WebSessionContext <ISession>());
            SessionFactoryContext.SetContext(new StaticContext <ISessionFactory>());
            TransactionContext.SetContext(new WebSessionContext <IDbTransaction>());

            var factory = new SessionFactoryImpl()
                          .SetAdapter(new TPersistenceAdapter())
                          .SetConnectionString(connectionString);

            SessionFactoryContext.Bind(factory);
        }
Ejemplo n.º 20
0
        public void TestDecomposePath()
        {
            String entityName = "Sage.SalesLogix.Entities.Contact";

            using (var sess = new SessionScopeWrapper())
            {
                SessionFactoryImpl      sf        = (SessionFactoryImpl)sess.SessionFactory;
                AbstractEntityPersister persister = (AbstractEntityPersister)(sf.GetEntityPersister(entityName));
                Assert.AreEqual("LastName", SimpleLookup.DecomposePath(sf, persister, "LASTNAME", "0"));
                Assert.AreEqual("Address.PostalCode", SimpleLookup.DecomposePath(sf, persister, "ADDRESSID=ADDRESSID.ADDRESS!POSTALCODE", "0"));
                Assert.AreEqual("AccountManager.UserInfo.UserName", SimpleLookup.DecomposePath(sf, persister, "ACCOUNTMANAGERID>USERID.USERINFO!USERNAME", "0"));
            }
        }
Ejemplo n.º 21
0
        public void SetUp()
        {
            var assemblyContainingSagas = typeof(TestSaga).Assembly;

            var builder = new SessionFactoryBuilder(assemblyContainingSagas.GetTypes());

            sessionFactory = builder.Build(SQLiteConfiguration.Standard
                                           .InMemory()
                                           .ProxyFactoryFactory(typeof(ProxyFactoryFactory).AssemblyQualifiedName)
                                           .ToProperties(), false) as SessionFactoryImpl;

            persisterForTestSaga = sessionFactory.GetEntityPersisterFor <TestSaga>();
        }
 public void SetUp()
 {
     sessionFactory = SessionFactoryHelper.Build(
         new[]
     {
         typeof(TestSaga2),
         typeof(TestSaga2ActualSaga),
         typeof(ContainSagaData),
         typeof(SagaWithNestedTypeActualSaga),
         typeof(SagaWithNestedType),
         typeof(SagaWithNestedType.Customer),
         typeof(SagaWithNestedSagaData),
         typeof(SagaWithNestedSagaData.NestedSagaData)
     });
 }
Ejemplo n.º 23
0
        public void SetUp()
        {
            var assemblyContainingSagas = typeof(TestSaga).Assembly;

            var builder = new SessionFactoryBuilder(assemblyContainingSagas.GetTypes());

            //var properties = SQLiteConfiguration.Standard
            //  .InMemory()
            //  .ToProperties();

            //File.WriteAllText("sqlite.txt", "");

            //foreach (var property in properties)
            //{
            //  File.AppendAllText("sqlite.txt", String.Format("{{ \"{0}\", \"{1}\" }}\n", property.Key, property.Value));

            //}

            var properties = SQLiteConfiguration.InMemory();

            sessionFactory = builder.Build(properties, false) as SessionFactoryImpl;

            persisterForTestSaga = sessionFactory.GetEntityPersisterFor <TestSaga>();
        }
Ejemplo n.º 24
0
 public void SetUp()
 {
     sessionFactory = SessionFactoryHelper.Build();
 }
        public void SetUp()
        {
            var assemblyContainingSagas = typeof(TestSaga).Assembly;
            var types = assemblyContainingSagas.GetTypes().ToList();
            types.Add(typeof (ContainSagaData));

            var builder = new SessionFactoryBuilder(types);
            var properties = SQLiteConfiguration.InMemory();

            sessionFactory = builder.Build(new Configuration().AddProperties(properties)) as SessionFactoryImpl;
        }
        public void SetUp()
        {
            sessionFactory = SessionFactoryHelper.Build();

            persisterForTestSaga = sessionFactory.GetEntityPersisterFor <TestSaga>();
        }
 public void SetUp()
 {
     sessionFactory = SessionFactoryHelper.Build();
 }
 public static IEntityPersister GetEntityPersisterFor <T>(this SessionFactoryImpl sessionFactory)
 {
     return(sessionFactory.GetEntityPersister(typeof(T).FullName));
 }
 public static void ShouldContainPersisterFor <T>(this SessionFactoryImpl sessionFactory)
 {
     Assert.NotNull(sessionFactory.GetEntityPersisterFor <T>());
 }