]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics/src/org/simantics/internal/SessionUtil.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics / src / org / simantics / internal / SessionUtil.java
index f106244368c5841200de0cbac0c75580511ec378..86bc764673fbc5319fa2d6292f30501c76407317 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     Semantum Oy - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.internal;\r
-\r
-import java.io.File;\r
-import java.util.Properties;\r
-import java.util.UUID;\r
-\r
-import org.eclipse.core.runtime.IProduct;\r
-import org.eclipse.core.runtime.Platform;\r
-import org.simantics.db.ServerEx;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.service.LifecycleSupport;\r
-import org.simantics.db.service.XSupport;\r
-import org.simantics.project.management.ServerManager;\r
-import org.simantics.project.management.ServerManagerFactory;\r
-\r
-/**\r
- * An as-simple-as-possible utility class for starting a Simantics database\r
- * instance and opening a connection ({@link Session}) to it.\r
- *\r
- * <p>\r
- * To get up and running, simply invoke:\r
- * <pre>\r
- *     SessionUtil util = new SessionUtil("my-client-id");\r
- *     try {\r
- *         File workspaceLocation = ...;\r
- *         Session session = util.openSession(workspaceLocation);\r
- *         // do something with the database session\r
- *     } finally {\r
- *         util.close();\r
- *     }\r
- * </pre>\r
- *\r
- * <p>\r
- * This class is a provisional utility, pending for public inclusion.\r
- *\r
- * @author Tuukka Lehtonen\r
- * @see Session\r
- */\r
-public class SessionUtil {\r
-\r
-       private String clientId;\r
-       @SuppressWarnings("unused")\r
-       private File workspace;\r
-\r
-       private ServerManager serverManager;\r
-       private ServerEx server;\r
-       private Session session;\r
-\r
-       public static String getApplicationClientId() {\r
-               IProduct product = Platform.getProduct();\r
-               if(product == null) return "noProduct";\r
-               String application = product.getApplication();\r
-               return application != null ? application : UUID.randomUUID().toString();\r
-       }\r
-\r
-       public SessionUtil() {\r
-               this(UUID.randomUUID().toString());\r
-       }\r
-\r
-       public SessionUtil(String clientId) {\r
-               serverManager = ServerManagerFactory.getServerManager();\r
-               this.clientId = clientId;\r
-       }\r
-\r
-       public void close() throws DatabaseException {\r
-               if (session != null) {\r
-                       session.getService(LifecycleSupport.class).close();\r
-               }\r
-               serverManager.close();\r
-       }\r
-\r
-//     public Session open(File workspace) throws IOException, DatabaseException {\r
-//             File dbDir = new File(workspace, "db");\r
-//             if (!dbDir.exists() || !dbDir.isDirectory())\r
-//                     throw new FileNotFoundException("database directory " + dbDir + " not found");\r
-//             server = serverManager.getServer(dbDir);\r
-//             server.start(null);\r
-//             session = openSession(server, dbDir);\r
-//             this.workspace = workspace;\r
-//             return session;\r
-//     }\r
-\r
-       private Session openSession(ServerEx server, File dbDir) throws DatabaseException {\r
-               Properties info = new Properties(ServerManager.DEFAULT);\r
-               session = server.createSession(info);\r
-               session.getService(XSupport.class).setServiceMode(true, true);\r
-               return session;\r
-       }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2013 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:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.internal;
+
+import java.io.File;
+import java.util.Properties;
+import java.util.UUID;
+
+import org.eclipse.core.runtime.IProduct;
+import org.eclipse.core.runtime.Platform;
+import org.simantics.db.ServerEx;
+import org.simantics.db.Session;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.service.LifecycleSupport;
+import org.simantics.db.service.XSupport;
+import org.simantics.project.management.ServerManager;
+import org.simantics.project.management.ServerManagerFactory;
+
+/**
+ * An as-simple-as-possible utility class for starting a Simantics database
+ * instance and opening a connection ({@link Session}) to it.
+ *
+ * <p>
+ * To get up and running, simply invoke:
+ * <pre>
+ *     SessionUtil util = new SessionUtil("my-client-id");
+ *     try {
+ *         File workspaceLocation = ...;
+ *         Session session = util.openSession(workspaceLocation);
+ *         // do something with the database session
+ *     } finally {
+ *         util.close();
+ *     }
+ * </pre>
+ *
+ * <p>
+ * This class is a provisional utility, pending for public inclusion.
+ *
+ * @author Tuukka Lehtonen
+ * @see Session
+ */
+public class SessionUtil {
+
+       private String clientId;
+       @SuppressWarnings("unused")
+       private File workspace;
+
+       private ServerManager serverManager;
+       private ServerEx server;
+       private Session session;
+
+       public static String getApplicationClientId() {
+               IProduct product = Platform.getProduct();
+               if(product == null) return "noProduct";
+               String application = product.getApplication();
+               return application != null ? application : UUID.randomUUID().toString();
+       }
+
+       public SessionUtil() {
+               this(UUID.randomUUID().toString());
+       }
+
+       public SessionUtil(String clientId) {
+               serverManager = ServerManagerFactory.getServerManager();
+               this.clientId = clientId;
+       }
+
+       public void close() throws DatabaseException {
+               if (session != null) {
+                       session.getService(LifecycleSupport.class).close();
+               }
+               serverManager.close();
+       }
+
+//     public Session open(File workspace) throws IOException, DatabaseException {
+//             File dbDir = new File(workspace, "db");
+//             if (!dbDir.exists() || !dbDir.isDirectory())
+//                     throw new FileNotFoundException("database directory " + dbDir + " not found");
+//             server = serverManager.getServer(dbDir);
+//             server.start(null);
+//             session = openSession(server, dbDir);
+//             this.workspace = workspace;
+//             return session;
+//     }
+
+       private Session openSession(ServerEx server, File dbDir) throws DatabaseException {
+               Properties info = new Properties(ServerManager.DEFAULT);
+               session = server.createSession(info);
+               session.getService(XSupport.class).setServiceMode(true, true);
+               return session;
+       }
+
+}