]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.acorn/src/org/simantics/acorn/AcornDatabaseManager.java
ListIndexRoots request
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / AcornDatabaseManager.java
1 package org.simantics.acorn;
2
3 import java.io.IOException;
4 import java.nio.file.Files;
5 import java.nio.file.Path;
6 import java.util.HashMap;
7 import java.util.Map;
8
9 import org.simantics.acorn.internal.AcornDatabase;
10 import org.simantics.db.Database;
11 import org.simantics.db.server.ProCoreException;
12
13 /**
14  * @author Tuukka Lehtonen
15  */
16 public class AcornDatabaseManager {
17
18     private static Map<String, Database> dbs = new HashMap<String, Database>();
19
20     public static synchronized Database getDatabase(Path folder) throws ProCoreException {
21         Path canonical;
22         try {
23             if (!Files.exists(folder))
24                 Files.createDirectories(folder);
25             canonical = folder.toRealPath();
26         } catch (IOException e) {
27             throw new ProCoreException("Could not get canonical path.", e);
28         }
29
30         String canonicalPath = canonical.toString();
31         Database db = dbs.get(canonicalPath);
32         if (null != db)
33             return db;
34
35         db = new AcornDatabase(canonical);
36         dbs.put(canonicalPath, db);
37         return db;
38     }
39
40 }