Changeset 2139


Ignore:
Timestamp:
Mar 31, 2006, 2:56:55 PM (17 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #176: Running jobs with a project activated
INCLUDES DATABASE CHANGES. Please update the database.

Location:
trunk/src/core/net/sf/basedb/core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/InternalJobQueue.java

    r1886 r2139  
    413413        job = Job.getById(dc, jobId);
    414414       
     415        // Set the active project
     416        int projectId = job.getActiveProjectId();
     417        if (projectId != 0)
     418        {
     419          try
     420          {
     421            Project activeProject = Project.getById(dc, projectId);
     422            impersonated.setActiveProject(activeProject);
     423          }
     424          catch (Throwable t)
     425          {
     426            log.error("Exception while setting active project. Continuing with no active project.", t);
     427          }
     428        }
     429       
    415430        // Get an execution request and close the db connection
    416431        PluginExecutionRequest exec = null;
  • trunk/src/core/net/sf/basedb/core/Job.java

    r1924 r2139  
    2525package net.sf.basedb.core;
    2626
     27import net.sf.basedb.core.Transactional.Action;
    2728import net.sf.basedb.core.data.JobData;
    2829import net.sf.basedb.core.data.MessageData;
     
    221222    return getStatus() == Status.EXECUTING;
    222223  }
     224  /**
     225    Set's the project id to the currently active project.
     226  */
     227  @Override
     228  void onBeforeCommit(Action action)
     229    throws NotLoggedInException, BaseException
     230  {
     231    super.onBeforeCommit(action);
     232    int projectId = getSessionControl().getActiveProjectId();
     233    if (projectId != 0)
     234    {
     235      getData().setActiveProjectId(projectId);
     236    }
     237  }
    223238  // -------------------------------------------
    224239
     
    356371    if (priority < 1 || priority > 10) throw new NumberOutOfRangeException("priority", priority, 1, 10);
    357372    getData().setPriority(priority);
     373  }
     374 
     375  /**
     376    The ID of the project that should be made the active project while running
     377    this job. If the project can't be loaded the job should be executed without
     378    an active project.
     379    @return The ID of the active project, or 0 if no project should be active
     380   */
     381  public int getActiveProjectId()
     382  {
     383    return getData().getActiveProjectId();
    358384  }
    359385 
  • trunk/src/core/net/sf/basedb/core/data/JobData.java

    r1701 r2139  
    204204  }
    205205
     206  private int activeProjectId;
     207  /**
     208    The ID of the project that should be made active when running this job.
     209    @hibernate.property column="`project_id`" type="int" not-null="true"
     210  */
     211  public int getActiveProjectId()
     212  {
     213    return activeProjectId;
     214  }
     215  public void setActiveProjectId(int activeProjectId)
     216  {
     217    this.activeProjectId = activeProjectId;
     218  }
     219 
    206220  private Date created;
    207221  /**
Note: See TracChangeset for help on using the changeset viewer.