private IDbCommand CommandGetAndGetLock(IDbConnection conn, bool getAndLock, string sessionId)
        {
            var getSql     = "TempGetStateItem";
            var getLockSql = "TempGetStateItemExclusive";
            var e          = DatabaseServices.ExecutionService;

            var cmd = e.CreateCommand(conn, getAndLock ? getLockSql : getSql);

            cmd.CommandType    = CommandType.StoredProcedure;
            cmd.CommandTimeout = queryTimeout;

            e.CreateParameter(cmd, P.P("id"), DbType.StringFixedLength, sessionId).Size = SessionConstants.ID_LENGTH;
            var p = e.CreateParameter(cmd, P.P("item"), DbType.Binary, System.DBNull.Value);

            MySQLParams.SetBlobType(p);
            p.Direction = ParameterDirection.Output;
            p           = e.CreateParameter(cmd, P.P("locked"), DbType.Boolean, System.DBNull.Value);
            p.Direction = ParameterDirection.Output;
            p           = e.CreateParameter(cmd, P.P("lockAge"), DbType.Int32, System.DBNull.Value);
            p.Direction = ParameterDirection.Output;
            p           = e.CreateParameter(cmd, P.P("lockCookie"), DbType.Int32, System.DBNull.Value);
            p.Direction = ParameterDirection.Output;
            p           = e.CreateParameter(cmd, P.P("actionFlags"), DbType.Int32, System.DBNull.Value);
            p.Direction = ParameterDirection.Output;

            return(cmd);
        }
        private IDbCommand InsertCommand(IDbConnection conn)
        {
            var e   = DatabaseServices.ExecutionService;
            var sql = "TempInsertStateItem";
            var cmd = e.CreateCommand(conn, sql);

            cmd.CommandType    = CommandType.StoredProcedure;
            cmd.CommandTimeout = queryTimeout;
            e.CreateParameter(cmd, P.P("id"), DbType.StringFixedLength, null).Size = SessionConstants.ID_LENGTH;
            var p = e.CreateParameter(cmd, P.P("item"), DbType.Binary, null);

            MySQLParams.SetBlobType(p);
            e.CreateParameter(cmd, P.P("timeout"), DbType.Int32, null);

            return(cmd);
        }
 public void InsertOrUpdate(string sessionId, int lockId, byte[] data, TimeSpan timeout)
 {
     try {
         using (var con = DatabaseServices.TransactionService.CreateConnection()) {
             var e = DatabaseServices.ExecutionService;
             using (var cmd = e.CreateCommand(con, "TempCreateOrUpdateStateItem")) {
                 cmd.CommandTimeout = queryTimeout;
                 cmd.CommandType    = CommandType.StoredProcedure;
                 e.CreateParameter(cmd, P.P("id"), DbType.StringFixedLength, sessionId).Size = SessionConstants.ID_LENGTH;
                 var p = e.CreateParameter(cmd, P.P("item"), DbType.Binary, data);
                 MySQLParams.SetBlobType(p);
                 e.CreateParameter(cmd, P.P("timeout"), DbType.Int32, Convert.ToInt32(timeout.TotalMinutes));
                 e.CreateParameter(cmd, P.P("lockCookie"), DbType.Int32, lockId);
                 cmd.ExecuteNonQuery();
             }
         }
     } catch (Exception e) {
         throw new SessionStoreException(e.Message, e);
     }
 }