Merge commit '12468c2'
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / AcornManagement.java
1 package org.simantics.acorn;
2
3 import java.nio.file.Path;
4 import java.util.Properties;
5
6 import org.simantics.db.Database;
7 import org.simantics.db.Driver.Management;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.server.ProCoreException;
10
11 public class AcornManagement implements Management {
12
13     private final Database db;
14     private final Properties properties;
15
16     AcornManagement(Path dbFolder, Properties properties) throws ProCoreException {
17         db = AcornDatabaseManager.getDatabase(dbFolder);
18         this.properties = properties;
19     }
20
21     @Override
22     public boolean exist() throws DatabaseException {
23         return db.isFolderOk();
24     }
25
26     @Override
27     public void delete() throws DatabaseException {
28         db.deleteFiles();
29         if (exist())
30             throw new DatabaseException("Failed to delete database. folder=" + db.getFolder());
31     }
32
33     @Override
34     public void create() throws DatabaseException {
35         db.initFolder(properties);
36         if (!exist())
37             throw new DatabaseException("Failed to create Acorn database. folder=" + db.getFolder());
38     }
39
40     @Override
41     public void purge() throws DatabaseException {
42         db.purgeDatabase();
43     }
44
45     @Override
46     public void shutdown() throws DatabaseException {
47         db.tryToStop();
48         db.disconnect();
49     }
50
51 }