]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.application/src/org/simantics/application/db/DatabaseUtils.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.application / src / org / simantics / application / db / DatabaseUtils.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.application.db;
13
14 import java.util.Properties;
15
16 import org.simantics.db.Driver;
17 import org.simantics.db.Manager;
18 import org.simantics.db.Session;
19 import org.simantics.db.services.GlobalServiceInitializer;
20
21 public final class DatabaseUtils {
22
23 //    public static Session connect(String host, int port) throws Exception {
24 //        return connect(new ServerAddress(host, port));
25 //    }
26 //
27 //    public static Session connect(String host, int port, String dbid) throws Exception {
28 //        return connect(new ServerAddress(host, port, dbid));
29 //    }
30
31     public static Session connect(String addr) throws Exception {
32         // Try to load and register the Driver instance with the driver manager
33         Class.forName("org.simantics.db.procore.ProCoreDriver");
34         Driver driver = Manager.getDriver("procore");
35
36         // Connect to the server at the specified host and credentials.
37         // Note that we normally user authentication agent for user identification.
38         Properties props = new Properties();
39         props.setProperty("user", "Default User");
40         props.setProperty("password", "");
41
42         Session session = driver.getSession(addr, props);
43
44         new GlobalServiceInitializer().initialize(session);
45
46         return session;
47     }
48
49 }