]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestHandler.java
Minor fix and optimization for exporting TG and Pgraph with sharedlib
[simantics/platform.git] / bundles / org.simantics.db.testing / src / org / simantics / db / testing / common / TestHandler.java
1 package org.simantics.db.testing.common;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.Properties;
6
7 import org.eclipse.core.runtime.Platform;
8 import org.simantics.db.Driver;
9 import org.simantics.db.Driver.Management;
10 import org.simantics.db.Manager;
11 import org.simantics.db.ServerI;
12 import org.simantics.db.Session;
13 import org.simantics.db.SessionManager;
14 import org.simantics.db.SessionReference;
15 import org.simantics.db.exception.DatabaseException;
16
17 import fi.vtt.simantics.procore.ProCoreServerReference;
18 import fi.vtt.simantics.procore.ProCoreSessionReference;
19 import fi.vtt.simantics.procore.SessionManagerSource;
20
21 /**
22  * ProCore specific test handler.
23  *
24  */
25 public class TestHandler {
26 //    private final TestSettings testSettings;
27     private final Driver driver;
28     private final File dbFolder;
29     TestHandler(TestSettings testSettings, String dbFolderName) throws DatabaseException {
30 //        this.testSettings = testSettings;
31         driver = Manager.getDriver("procore");
32         if (null == dbFolderName)
33             dbFolder = Platform.getLocation().append("db").toFile();
34       else
35           dbFolder = new File(dbFolderName);
36     }
37     void initNew() throws DatabaseException {
38         Management m = getManagement();
39         if (m.exist())
40             m.delete();
41         m.create();
42     }
43     void initIfNeccessary() throws DatabaseException {
44         Management m = getManagement();
45         if (!m.exist())
46             m.create();
47     }
48     public Session getSession() throws DatabaseException {
49         // Note that we normally user authentication agent for user identification.
50         Properties props = new Properties();
51         props.setProperty("user", "Default User");
52         props.setProperty("password", "");
53         return driver.getSession(dbFolder.getAbsolutePath(), props);
54     }
55     public ServerI getServer() throws DatabaseException {
56         return driver.getServer(dbFolder.getAbsolutePath(), null);
57     }
58     public Management getManagement() throws DatabaseException {
59       return driver.getManagement(dbFolder.getAbsolutePath(), null);
60   }
61     public Session regSession(long sessionId) throws DatabaseException, IOException {
62         SessionManager sm = SessionManagerSource.getSessionManager();
63         ProCoreServerReference ser = new ProCoreServerReference(dbFolder.toPath());
64         SessionReference ses = new ProCoreSessionReference(ser, sessionId);
65         return sm.createSession(ses, null);
66     }
67
68 }