]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/internal/SimanticsInternal.java
DB and Layer0 modifications for related issues
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / internal / SimanticsInternal.java
index 8ae309e6825c9d01af3ded4c754db378a42d55e9..d30be8ffcd21fc9f8ff3dae4a5713e5328270b31 100644 (file)
 package org.simantics.db.layer0.internal;
 
 import java.io.File;
-import java.util.concurrent.TimeUnit;
 
 import org.eclipse.core.runtime.Platform;
 import org.simantics.db.Resource;
-import org.simantics.db.Session;
-import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.util.SimanticsClipboard;
 import org.simantics.db.layer0.util.SimanticsKeys;
 import org.simantics.db.management.ISessionContext;
-import org.simantics.db.management.ISessionContextProvider;
-import org.simantics.db.management.ISessionContextProviderSource;
-import org.simantics.db.request.ReadInterface;
-import org.simantics.db.request.WriteInterface;
-import org.simantics.layer0.Layer0;
-import org.simantics.operation.Layer0X;
-import org.simantics.utils.threads.ThreadUtils;
 
 /**
  * An internal facade for accessing basic Simantics platform services.
@@ -35,112 +25,7 @@ import org.simantics.utils.threads.ThreadUtils;
  * 
  * Use org.simantics.Simantics instead where ever possible.
  */
-public class SimanticsInternal {
-
-    private static ISessionContextProviderSource providerSource = null;
-
-    /**
-     * Queue execution of a runnable. 
-     * 
-     * @param runnable
-     */
-    public static void async(Runnable runnable) {
-        ThreadUtils.getBlockingWorkExecutor().execute(runnable);
-    }
-
-    public static void async(Runnable runnable, int delay, TimeUnit unit) {
-        ThreadUtils.getTimer().schedule(runnable, delay, unit);
-    }
-    
-    /**
-     * Queue execution of a non-blocking runnable. Use this method with caution. 
-     * A non-blocking runnable nevers locks anything, No Locks, No semaphores,
-     * No Object.wait(), No synchronized() {} blocks.   
-     * 
-     * @param runnable a non-blocking runnable
-     */
-    public static void asyncNonblocking(Runnable runnable) {
-        ThreadUtils.getNonBlockingWorkExecutor().execute(runnable);
-    }
-
-    /**
-     * Schedule execution of a non-blocking runnable. Use this method with caution. 
-     * A non-blocking runnable never locks anything, No Locks, No semaphores,
-     * No Object,wait(), No synchronized() {} blocks.   
-     * 
-     * @param runnable a non-blocking runnable
-     * @param initialDelay
-     * @param period
-     */
-    public static void asyncNonblocking(Runnable runnable, int initialDelay, int period) {
-        ThreadUtils.getNonBlockingWorkExecutor().scheduleAtFixedRate(runnable, initialDelay, period, TimeUnit.MILLISECONDS);
-    }
-    
-    public static synchronized ISessionContext setSessionContext(ISessionContext ctx) {
-        return getSessionContextProvider().setSessionContext(ctx);
-    }
-
-    public static void setSessionContextProviderSource(ISessionContextProviderSource source) {
-        if (source == null)
-            throw new IllegalArgumentException("null provider source");
-        providerSource = source;
-    }
-
-    public static ISessionContextProviderSource getProviderSource() {
-        if (providerSource == null)
-            throw new IllegalStateException(
-            "providerSource must be initialized by the application before using class Simantics");
-        return providerSource;
-    }
-
-    public static ISessionContextProvider getSessionContextProvider() {
-        return getProviderSource().getActive();
-    }
-
-    /**
-     * Returns the database session context associated with the currently active
-     * context. This method should be used to retrieve session contexts only
-     * when the client is sure that the correct context is active.
-     * 
-     * @return the session context associated with the currently active context
-     *         or <code>null</code> if the context has no session context
-     */
-    public static ISessionContext getSessionContext() {
-        ISessionContextProvider provider = getSessionContextProvider();
-        return provider != null ? provider.getSessionContext() : null;
-    }
-
-    /**
-     * Returns the database Session bound to the currently active context.
-     * 
-     * <p>
-     * The method always returns a non-null Session or produces an
-     * IllegalStateException if a Session was not attainable.
-     * </p>
-     * 
-     * @return the Session bound to the currently active workbench window
-     * @throws IllegalStateException if no Session was available
-     */
-    public static Session getSession() {
-        ISessionContext ctx = getSessionContext();
-        if (ctx == null)
-            throw new IllegalStateException("Session unavailable, no database session open");
-        return ctx.getSession();
-    }
-
-    /**
-     * Returns the database Session bound to the currently active context.
-     * Differently from {@link #getSession()}, this method returns
-     * <code>null</code> if there is no current Session available.
-     * 
-     * @see #getSession()
-     * @return the Session bound to the currently active context or
-     *         <code>null</code>
-     */
-    public static Session peekSession() {
-        ISessionContext ctx = getSessionContext();
-        return ctx == null ? null : ctx.peekSession();
-    }
+public class SimanticsInternal extends org.simantics.db.common.SimanticsInternal {
 
     /**
      * @return the currently open and active project as an IProject
@@ -179,23 +64,6 @@ public class SimanticsInternal {
         return clipboard;
     }
 
-    public static Layer0 getLayer0() throws DatabaseException {
-        return Layer0.getInstance(getSession());
-    }
-
-    public static Layer0X getLayer0X() throws DatabaseException {
-        return Layer0X.getInstance(getSession());
-    }
-
-    
-    public static <T> T sync(ReadInterface<T> r) throws DatabaseException {
-       return getSession().sync(r);
-    }
-    
-    public static <T> T sync(WriteInterface<T> r) throws DatabaseException {
-       return getSession().sync(r);
-    }
-    
     public static File getTemporaryDirectory() {
         File workspace = Platform.getLocation().toFile();
         File temp = new File(workspace, "tempFiles");