1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics;
14 import org.eclipse.core.runtime.jobs.IJobManager;
15 import org.eclipse.core.runtime.jobs.Job;
18 * An Eclipse job that inherently belongs to the
19 * {@link Simantics#DATABASE_JOB_FAMILY} job family.
22 * Use {@link #inProgress()} to check whether there are currently any
23 * {@link DatabaseJob}s running in the platform's job manager. Checks should be
24 * performed if any synchronous database requests must be initiated in the UI
25 * thread but it is not 100% necessary to return an accurate result right at
26 * that moment. Performing too much synchronous requests in the UI thread will
27 * currently inevitably get the UI completely stuck and therefore offloading
28 * database work to database job worker threads is highly recommended.
30 * @author Tuukka Lehtonen
32 public abstract class DatabaseJob extends Job {
34 public static final String DATABASE_JOB_FAMILY = "org.simantics.db.inDatabaseJob";
36 public DatabaseJob(String name) {
41 public boolean belongsTo(Object family) {
42 if (DATABASE_JOB_FAMILY.equals(family))
44 return super.belongsTo(family);
47 public static boolean inProgress() {
48 IJobManager manager = Job.getJobManager();
49 Job[] jobs = manager.find(DATABASE_JOB_FAMILY);
51 if (job.getState() == Job.RUNNING)