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); }
/// <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); }
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); }
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; }
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); }
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; }
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")); } }
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); }
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")); } }
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; }
/// <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)); } }
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); }
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")); } }
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) }); }
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>(); }
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 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>()); }