X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.application%2Fsrc%2Forg%2Fsimantics%2Fapplication%2Fdb%2FHeadlessDatabaseApplication.java;h=355476e62512356643a6204fc5eabd9294bc9af3;hp=2f13280ff86fd44d04075d659522bdd4c2cdae74;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.application/src/org/simantics/application/db/HeadlessDatabaseApplication.java b/bundles/org.simantics.application/src/org/simantics/application/db/HeadlessDatabaseApplication.java index 2f13280ff..355476e62 100644 --- a/bundles/org.simantics.application/src/org/simantics/application/db/HeadlessDatabaseApplication.java +++ b/bundles/org.simantics.application/src/org/simantics/application/db/HeadlessDatabaseApplication.java @@ -1,99 +1,99 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.application.db; - -import org.eclipse.equinox.app.IApplication; -import org.eclipse.equinox.app.IApplicationContext; -import org.simantics.application.arguments.SimanticsArguments; -import org.simantics.application.template.TemplateDatabaseApplication; -import org.simantics.db.Session; - -/** - * A headless (non-ui) application base class for one-shot connection to and - * usage of a Simantics database. - * - *

- * The simplest way to use this application class is to override the - * {@link #afterConnect(DatabaseHandle)} method to do your own stuff with the - * database in question. Use {@link #getSession()} to get a hold of the database - * session. - *

- * - *

- * The application expects at least the {@link SimanticsArguments#SERVER} and - * supports the {@link SimanticsArguments#CHECKOUT}. - *

- * - * @see TemplateDatabaseApplication for a usage example - */ -public abstract class HeadlessDatabaseApplication implements IApplication { - - private DatabaseHandle database; - - @Override - public Object start(IApplicationContext context) throws Exception { - try { - beforeConnect(context); - connectToServer(context); - afterConnect(); - - return IApplication.EXIT_OK; - } finally { - if (database != null) { - try { - database.dispose(); - } catch (Throwable t) { - t.printStackTrace(); - } - } - } - } - - @Override - public void stop() { - // TODO: force the application to stop - } - - protected IDatabaseHandle connectToServer(IApplicationContext context) throws Exception { - String[] args = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS); - database = new DatabaseHandle(args, deleteLocalCopyAtExit()); - return database; - } - - protected Session getSession() { - if (database == null) - throw new IllegalStateException("null database session"); - return database.getSession(); - } - - /** - * Override this method to perform actions before the application - * attempts to connect to the database specified by the command line - * arguments. - * - * @param context the application startup context - */ - protected void beforeConnect(IApplicationContext context) { - } - - /** - * Override this method to perform actions after the application - * has connected to the database specified by the command line arguments. - */ - protected void afterConnect() { - } - - protected boolean deleteLocalCopyAtExit() { - return false; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.application.db; + +import org.eclipse.equinox.app.IApplication; +import org.eclipse.equinox.app.IApplicationContext; +import org.simantics.application.arguments.SimanticsArguments; +import org.simantics.application.template.TemplateDatabaseApplication; +import org.simantics.db.Session; + +/** + * A headless (non-ui) application base class for one-shot connection to and + * usage of a Simantics database. + * + *

+ * The simplest way to use this application class is to override the + * {@link #afterConnect(DatabaseHandle)} method to do your own stuff with the + * database in question. Use {@link #getSession()} to get a hold of the database + * session. + *

+ * + *

+ * The application expects at least the {@link SimanticsArguments#SERVER} and + * supports the {@link SimanticsArguments#CHECKOUT}. + *

+ * + * @see TemplateDatabaseApplication for a usage example + */ +public abstract class HeadlessDatabaseApplication implements IApplication { + + private DatabaseHandle database; + + @Override + public Object start(IApplicationContext context) throws Exception { + try { + beforeConnect(context); + connectToServer(context); + afterConnect(); + + return IApplication.EXIT_OK; + } finally { + if (database != null) { + try { + database.dispose(); + } catch (Throwable t) { + t.printStackTrace(); + } + } + } + } + + @Override + public void stop() { + // TODO: force the application to stop + } + + protected IDatabaseHandle connectToServer(IApplicationContext context) throws Exception { + String[] args = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS); + database = new DatabaseHandle(args, deleteLocalCopyAtExit()); + return database; + } + + protected Session getSession() { + if (database == null) + throw new IllegalStateException("null database session"); + return database.getSession(); + } + + /** + * Override this method to perform actions before the application + * attempts to connect to the database specified by the command line + * arguments. + * + * @param context the application startup context + */ + protected void beforeConnect(IApplicationContext context) { + } + + /** + * Override this method to perform actions after the application + * has connected to the database specified by the command line arguments. + */ + protected void afterConnect() { + } + + protected boolean deleteLocalCopyAtExit() { + return false; + } + +}