Exemple #1
0
        internal object closeTable <tRow>(SerializerSession thisSession) where tRow : new()
        {
            TableInSession res = new TableInSession();

            lock ( syncRoot )
            {
                foreach (SerializerSession sess in m_allSessions)
                {
                    if (sess == thisSession)
                    {
                        continue;
                    }
                    res.add(sess, sess.closeTable <tRow>());
                }
            }
            return(res);
        }
Exemple #2
0
 public void add(SerializerSession s, SerializerSession.eTableState t)
 {
     m_list.Add(s, t);
 }
Exemple #3
0
        iSerializerSession GetSessionImpl(eSessionCooperativeLevel coopLevel)
        {
            if (singleSessionPerThread && null != threadSession)
            {
                if (threadSession.cooperativeLevel != coopLevel)
                {
                    throw new Exception("You can't get sessions with different cooperative levels on the same thread at the same time");
                }
                threadSession.AddRef();
                return(threadSession);
            }

            if (null != m_semaphore)
            {
                if (!m_semaphore.WaitOne(tsWaitForFreeSession))
                {
                    throw new TimeoutException("SessionPool.tsWaitForFreeSession timeout exceeded.");
                }
            }

            SerializerSession nativeSession = null;
            bool bNewSession = false;

            lock (this.syncRoot)
            {
                if (m_freeSessions.Count > 0)
                {
                    nativeSession = m_freeSessions.Pop();
                }
                else
                {
                    m_serializer.EnsureDatabaseExists();

                    nativeSession = new SerializerSession(m_serializer);
                    m_allSessions.Add(nativeSession);
                    bNewSession = true;

                    if (m_bFirstSession)
                    {
                        m_bFirstSession = false;

                        if (null != this.updateSchema)
                        {
                            DatabaseSchemaUpdater updater = new DatabaseSchemaUpdater(nativeSession);
                            this.updateSchema(updater);
                        }
                    }
                }
            }

            if (bNewSession)
            {
                foreach (var t in m_recordTypes)
                {
                    nativeSession.AddType(t);
                }
                TraceInfo("GetSessionImpl: constructed a new session");
            }

            SerializerSessionImpl sessionWrapper = new SerializerSessionImpl(nativeSession, this, coopLevel);

            sessionCooperativeLockEnter(sessionWrapper);
            sessionWrapper.AddRef();

            if (singleSessionPerThread)
            {
                threadSession = sessionWrapper;
            }

            // Bind new session to the current thread
            nativeSession.setThread();

            return(sessionWrapper);
        }