]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.application/src/org/simantics/application/db/DatabaseUtils.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.application / src / org / simantics / application / db / DatabaseUtils.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.application.db;\r
13 \r
14 import java.util.Properties;\r
15 \r
16 import org.simantics.db.Driver;\r
17 import org.simantics.db.Manager;\r
18 import org.simantics.db.Session;\r
19 import org.simantics.db.services.GlobalServiceInitializer;\r
20 \r
21 public final class DatabaseUtils {\r
22 \r
23 //    public static Session connect(String host, int port) throws Exception {\r
24 //        return connect(new ServerAddress(host, port));\r
25 //    }\r
26 //\r
27 //    public static Session connect(String host, int port, String dbid) throws Exception {\r
28 //        return connect(new ServerAddress(host, port, dbid));\r
29 //    }\r
30 \r
31     public static Session connect(String addr) throws Exception {\r
32         // Try to load and register the Driver instance with the driver manager\r
33         Class.forName("org.simantics.db.procore.ProCoreDriver");\r
34         Driver driver = Manager.getDriver("procore");\r
35 \r
36         // Connect to the server at the specified host and credentials.\r
37         // Note that we normally user authentication agent for user identification.\r
38         Properties props = new Properties();\r
39         props.setProperty("user", "Default User");\r
40         props.setProperty("password", "");\r
41 \r
42         Session session = driver.getSession(addr, props);\r
43 \r
44         new GlobalServiceInitializer().initialize(session);\r
45 \r
46         return session;\r
47     }\r
48 \r
49 }\r