Exemple #1
0
        // Creates new connection or gets previously used from the session
        public DataConnection GetConnection(EntitySession session,
                                            ConnectionLifetime connLifetime = ConnectionLifetime.Operation, bool admin = false)
        {
            if (admin)
            {
                return(new DataConnection(session, this, connLifetime, true));
            }
            var conn = session.CurrentConnection;

            if (conn != null)
            {
                if (conn.Lifetime < connLifetime)
                {
                    conn.Lifetime = connLifetime;
                }
                return(conn);
            }
            // if we have KeepOpen mode (recommended in Web app), then make Lifetime explicit -
            // i.e. until explicitly called to close; web call context handler will do it after completing
            // processing requests
            if (session.Context.DbConnectionMode == DbConnectionReuseMode.KeepOpen)
            {
                connLifetime = ConnectionLifetime.Explicit;
            }
            conn = new DataConnection(session, this, connLifetime, admin: admin);
            session.CurrentConnection = conn; //it will register it in disposables
            return(conn);
        }
Exemple #2
0
 public DataConnection(EntitySession session, Database database, ConnectionLifetime lifetime, bool admin = false)
 {
     Session = session;
       Database = database;
       Lifetime = lifetime;
       var connString = admin ? database.Settings.SchemaManagementConnectionString : database.Settings.ConnectionString;
       DbConnection = database.DbModel.Driver.CreateConnection(connString);
 }
Exemple #3
0
        public DataConnection(EntitySession session, Database database, ConnectionLifetime lifetime, bool admin = false)
        {
            Session  = session;
            Database = database;
            Lifetime = lifetime;
            var connString = admin ? database.Settings.SchemaManagementConnectionString : database.Settings.ConnectionString;

            DbConnection = database.DbModel.Driver.CreateConnection(connString);
        }
Exemple #4
0
 // Creates new connection or gets previously used from the session
 public DataConnection GetConnection(EntitySession session, 
     ConnectionLifetime minLifetime = ConnectionLifetime.Operation, bool admin = false)
 {
     if (admin)
     return new DataConnection(session, this, minLifetime, true);
       var conn = session.CurrentConnection;
       if(conn != null) {
     if (conn.Lifetime < minLifetime)
       conn.Lifetime = minLifetime;
     return conn;
       }
       if (session.Context.DbConnectionMode == DbConnectionReuseMode.KeepOpen)
     minLifetime = ConnectionLifetime.Explicit;
       conn = new DataConnection(session, this, minLifetime, admin: admin);
       session.CurrentConnection = conn; //it will register it in disposables
       return conn;
 }
Exemple #5
0
 public override void RequestClose()
 {
     ConnectionLifetime.RequestClose();
 }