internal StatelessSessionImpl(SessionFactoryImpl factory, ISessionCreationOptions options) : base(factory, options) { // This context is disposed only on session own disposal. This greatly reduces the number of context switches // for most usual session usages. It may cause an irrelevant session id to be set back on disposal, but since all // session entry points are supposed to set it, it should not have any consequences. _context = SessionIdLoggingContext.CreateOrNull(SessionId); try { temporaryPersistenceContext = new StatefulPersistenceContext(this); if (log.IsDebugEnabled()) { log.Debug("[session-id={0}] opened session for session factory: [{1}/{2}]", SessionId, factory.Name, factory.Uuid); } CheckAndUpdateSessionStatus(); } catch { _context?.Dispose(); throw; } }
internal StatelessSessionImpl(IDbConnection connection, SessionFactoryImpl factory) : base(factory) { using (new SessionIdLoggingContext(SessionId)) { temporaryPersistenceContext = new StatefulPersistenceContext(this); connectionManager = new ConnectionManager(this, connection, ConnectionReleaseMode.AfterTransaction, new EmptyInterceptor()); CheckAndUpdateSessionStatus(); } }
/// <summary> /// Initializes a new instance of the <see cref="MultiCriteriaImpl"/> class. /// </summary> /// <param name="session">The session.</param> /// <param name="factory">The factory.</param> internal MultiCriteriaImpl(SessionImpl session, SessionFactoryImpl factory) { dialect = session.Factory.Dialect; if (!session.Factory.ConnectionProvider.Driver.SupportsMultipleQueries) { throw new NotSupportedException( string.Format("The dialect {0} does not support multiple queries.", dialect.GetType().FullName)); } this.session = session; this.factory = factory; }
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.GetEntityPersister(typeof(TestSaga).FullName); persisterForTestSaga.ShouldNotBeNull(); }
internal StatelessSessionImpl(SessionFactoryImpl factory, ISessionCreationOptions options) : base(factory, options) { using (BeginContext()) { temporaryPersistenceContext = new StatefulPersistenceContext(this); if (log.IsDebugEnabled()) { log.Debug("[session-id={0}] opened session for session factory: [{1}/{2}]", SessionId, factory.Name, factory.Uuid); } CheckAndUpdateSessionStatus(); } }
internal StatelessSessionImpl(DbConnection connection, SessionFactoryImpl factory) : base(factory) { using (new SessionIdLoggingContext(SessionId)) { temporaryPersistenceContext = new StatefulPersistenceContext(this); connectionManager = new ConnectionManager(this, connection, ConnectionReleaseMode.AfterTransaction, new EmptyInterceptor()); if (log.IsDebugEnabled) { log.DebugFormat("[session-id={0}] opened session for session factory: [{1}/{2}]", SessionId, factory.Name, factory.Uuid); } CheckAndUpdateSessionStatus(); } }
internal StatelessSessionImpl(SessionFactoryImpl factory, ISessionCreationOptions options) : base(factory, options) { using (BeginContext()) { temporaryPersistenceContext = new StatefulPersistenceContext(this); connectionManager = new ConnectionManager(this, options.UserSuppliedConnection, ConnectionReleaseMode.AfterTransaction, EmptyInterceptor.Instance, options.ShouldAutoJoinTransaction); if (log.IsDebugEnabled()) { log.Debug("[session-id={0}] opened session for session factory: [{1}/{2}]", SessionId, factory.Name, factory.Uuid); } CheckAndUpdateSessionStatus(); } }
/// <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); } }
/// <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; }
/// <summary> /// /// </summary> /// <param name="connection"></param> /// <param name="factory"></param> /// <param name="autoClose"></param> /// <param name="timestamp"></param> /// <param name="interceptor"></param> internal SessionImpl( IDbConnection connection, SessionFactoryImpl factory, bool autoClose, long timestamp, IInterceptor interceptor ) { if(interceptor == null) throw new ArgumentNullException("interceptor", "The interceptor can not be null"); this.connection = connection; connect = connection == null; this.interceptor = interceptor; this.autoClose = autoClose; this.timestamp = timestamp; this.factory = factory; entitiesByKey = new Hashtable( 50 ); proxiesByKey = new Hashtable( 10 ); nonExists = new HashedSet(); //TODO: hack with this cast entityEntries = ( IdentityMap ) IdentityMap.InstantiateSequenced( 50 ); collectionEntries = ( IdentityMap ) IdentityMap.InstantiateSequenced( 30 ); collectionsByKey = new Hashtable( 30 ); arrayHolders = ( IdentityMap ) IdentityMap.Instantiate( 10 ); insertions = new ArrayList( 20 ); deletions = new ArrayList( 20 ); updates = new ArrayList( 20 ); collectionCreations = new ArrayList( 20 ); collectionRemovals = new ArrayList( 20 ); collectionUpdates = new ArrayList( 20 ); InitTransientState(); log.Debug( "opened session" ); }
/// <summary> /// Constructor used to recreate the Session during the deserialization. /// </summary> /// <param name="info"></param> /// <param name="context"></param> /// <remarks> /// This is needed because we have to do some checking before the serialization process /// begins. I don't know how to add logic in ISerializable.GetObjectData and have .net /// write all of the serializable fields out. /// </remarks> protected SessionImpl( SerializationInfo info, StreamingContext context ) { this.autoClose = info.GetBoolean( "autoClose" ); this.timestamp = info.GetInt64( "timestamp" ); this.factory = ( SessionFactoryImpl ) info.GetValue( "factory", typeof( SessionFactoryImpl ) ); this.entitiesByKey = ( IDictionary ) info.GetValue( "entitiesByKey", typeof( IDictionary ) ); // we did not actually serializing the IDictionary but instead the proxies in an arraylist //this.proxiesByKey = (IDictionary)info.GetValue( "proxiesByKey", typeof(IDictionary) ); tmpProxiesKey = ( ArrayList ) info.GetValue( "tmpProxiesKey", typeof( ArrayList ) ); tmpProxiesProxy = ( ArrayList ) info.GetValue( "tmpProxiesProxy", typeof( ArrayList ) ); this.entityEntries = ( IdentityMap ) info.GetValue( "entityEntries", typeof( IdentityMap ) ); this.collectionEntries = ( IdentityMap ) info.GetValue( "collectionEntries", typeof( IdentityMap ) ); this.collectionsByKey = ( IDictionary ) info.GetValue( "collectionsByKey", typeof( IDictionary ) ); this.arrayHolders = ( IdentityMap ) info.GetValue( "arrayHolders", typeof( IdentityMap ) ); this.nonExists = ( ISet ) info.GetValue( "nonExists", typeof( ISet ) ); this.closed = info.GetBoolean( "closed" ); this.flushMode = ( FlushMode ) info.GetValue( "flushMode", typeof( FlushMode ) ); this.isCurrentTransaction = info.GetBoolean( "isCurrentTransaction" ); this.nullifiables = ( ISet ) info.GetValue( "nullifiables", typeof( ISet ) ); this.interceptor = ( IInterceptor ) info.GetValue( "interceptor", typeof( IInterceptor ) ); this.insertions = ( ArrayList ) info.GetValue( "insertions", typeof( ArrayList ) ); this.deletions = ( ArrayList ) info.GetValue( "deletions", typeof( ArrayList ) ); this.updates = ( ArrayList ) info.GetValue( "updates", typeof( ArrayList ) ); this.collectionCreations = ( ArrayList ) info.GetValue( "collectionCreations", typeof( ArrayList ) ); this.collectionUpdates = ( ArrayList ) info.GetValue( "collectionUpdates", typeof( ArrayList ) ); this.collectionRemovals = ( ArrayList ) info.GetValue( "collectionRemovals", typeof( ArrayList ) ); }