1 package org.simantics.acorn;
3 import java.nio.file.Path;
4 import java.nio.file.Paths;
5 import java.util.Properties;
7 import org.simantics.db.DatabaseUserAgent;
8 import org.simantics.db.Driver;
9 import org.simantics.db.ServerI;
10 import org.simantics.db.ServerReference;
11 import org.simantics.db.Session;
12 import org.simantics.db.SessionReference;
13 import org.simantics.db.exception.DatabaseException;
15 public class AcornDriver implements Driver {
17 public static final String AcornDriverName = "acorn";
20 public String getName() {
21 return AcornDriverName;
25 public DatabaseUserAgent getDatabaseUserAgent(String address) throws DatabaseException {
26 Path dbFolder = Paths.get(address);
27 return AcornDatabaseManager.getDatabase(dbFolder).getUserAgent();
31 public void setDatabaseUserAgent(String address, DatabaseUserAgent dbUserAgent) throws DatabaseException {
32 Path dbFolder = Paths.get(address);
33 AcornDatabaseManager.getDatabase(dbFolder).setUserAgent(dbUserAgent);
37 public Session getSession(String address, Properties properties) throws DatabaseException {
38 Path dbFolder = Paths.get(address);
39 Session session = AcornSessionManagerImpl.getInstance().createSession(new SessionReference() {
42 public ServerReference getServerReference() {
43 return new ServerReference() {
46 public Path getDBFolder() {
53 public long getSessionId() {
57 if (!properties.containsKey("clientId"))
58 properties.put("clientId", dbFolder.toFile().getAbsolutePath());
59 session.registerService(Properties.class, properties);
60 Session s = session.peekService(Session.class);
62 session.registerService(Session.class, session);
67 public ServerI getServer(String address, Properties properties) throws DatabaseException {
68 return new ServerI() {
71 public void stop() throws DatabaseException {
76 public void start() throws DatabaseException {
81 public boolean isActive() throws DatabaseException {
86 public String getAddress() throws DatabaseException {
91 public String executeAndDisconnect(String command) throws DatabaseException {
96 public String execute(String command) throws DatabaseException {
103 public Management getManagement(String address, Properties properties) throws DatabaseException {
104 Path dbFolder = Paths.get(address);
105 return new AcornManagement(dbFolder, properties);