]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db/src/org/simantics/db/Database.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / Database.java
1 package org.simantics.db;
2
3 import java.io.File;
4 import java.nio.ByteBuffer;
5 import java.nio.file.Path;
6 import java.util.Properties;
7
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.exception.SDBException;
10 import org.simantics.db.service.ClusterUID;
11
12 public interface Database {
13     static public enum Status {
14         NoDatabase { @Override public String getString() { return "NoDatabase"; }},
15         NotRunning { @Override public String getString() { return "NotRunning"; }},
16         Standalone { @Override public String getString() { return "Standalone"; }},
17         Local { @Override public String getString() { return "Local"; }},
18         Remote { @Override public String getString() { return "Remote";}};
19         public abstract String getString();
20         @Override
21         public String toString() {
22             return message;
23         }
24         public String message = "";
25     }
26     public DatabaseUserAgent getUserAgent();
27     public void setUserAgent(DatabaseUserAgent dbUserAgent);
28     public Status getStatus();
29
30     public File getFolder();
31     public boolean isFolderOk();
32     public boolean isFolderOk(File aFolder);
33     public boolean isFolderEmpty();
34     public boolean isFolderEmpty(File aFolder);
35     public void initFolder(Properties properties) throws SDBException;
36     public void deleteFiles() throws SDBException;
37
38     public void start() throws SDBException;
39     public boolean isRunning() throws SDBException;
40     public boolean tryToStop() throws SDBException;
41
42     public void connect() throws SDBException;
43     public boolean isConnected() throws SDBException;
44     public String execute(String command) throws SDBException;
45     public void disconnect() throws SDBException;
46
47     public void clone(File to, int revision, boolean saveHistory) throws SDBException;
48     public Path createFromChangeSets(int revision) throws SDBException;
49     public void deleteGuard() throws SDBException;
50     public Path dumpChangeSets() throws SDBException;
51     public void purgeDatabase() throws SDBException;
52     public long serverGetTailChangeSetId() throws SDBException;
53
54     public interface Session {
55         public Database getDatabase(); // Convenience method.
56         public void close() throws SDBException;
57         public void open() throws SDBException;
58         public boolean isClosed() throws SDBException;
59         public interface ChangeSetData {
60             public boolean isOk();
61         }
62         public interface ChangeSetIds {
63             public long getFirstChangeSetId();
64             public int getCount();
65         }
66         public interface Cluster {
67             public int getInflateSize();
68             public ByteBuffer getDeflated();
69         }
70         public interface ClusterChanges {
71             public long getHeadChangeSetId();
72             public int[] getResourceIndex();
73             public int[] getPredicateIndex();
74             public long[] getPredicateFirst();
75             public long[] getPredicateSecond();
76             public int[] getValueIndex();
77         }
78         public interface ClusterIds {
79             public int getStatus();
80             public long[] getFirst();
81             public long[] getSecond();
82         }
83         public interface Information {
84             public String getServerId();
85             public String getProtocolId();
86             public String getDatabaseId();
87             public long getFirstChangeSetId();
88         }
89         public interface Refresh {
90             public long getHeadChangeSetId();
91             public long[] getFirst();
92             public long[] getSecond();
93         }
94         public interface ResourceSegment {
95             public byte[] getClusterId();
96             public int getResourceIndex();
97             public long getValueSize(); // Size of whole value.
98             public byte[] getSegment(); // Bytes of asked segment.
99             public long getOffset(); // Segment offset.
100         }
101         public interface Transaction {
102             public long getHeadChangeSetId();
103             public long getTransactionId();
104         }
105         interface OnChangeSetUpdate {
106             public void onChangeSetUpdate(ChangeSetUpdate changeSetUpdate) throws SDBException;
107         }
108         public void acceptCommit(long transactionId, long changeSetId, byte[] metadata) throws SDBException;
109         public long cancelCommit(long transactionId, long changeSetId, byte[] metadata, OnChangeSetUpdate onChangeSetUpdate) throws SDBException;
110         public Transaction askReadTransaction() throws SDBException;
111         public Transaction askWriteTransaction(long transactionId) throws SDBException;
112         public long endTransaction(long transactionId) throws SDBException; // Return head change set id.
113         public String execute(String command) throws SDBException;
114         public byte[] getChangeSetMetadata(long changeSetId) throws SDBException;
115         public ChangeSetData getChangeSetData(long minChangeSetId, long  maxChangeSetId, OnChangeSetUpdate onChangeSetupate) throws SDBException;
116         public ChangeSetIds getChangeSetIds() throws SDBException;
117         public Cluster getCluster(byte[] clusterId) throws SDBException;
118         public ClusterChanges getClusterChanges(long changeSetId, byte[] clusterId) throws SDBException;
119         public ClusterIds getClusterIds() throws SDBException;
120         public Information getInformation() throws SDBException;
121         public Refresh getRefresh(long changeSetId) throws SDBException;
122         public ResourceSegment getResourceSegment(byte[] clusterUID, int resourceIndex, long offset, short size) throws SDBException;
123         public long reserveIds(int count) throws SDBException;
124         public void updateCluster(byte[] operations) throws SDBException;
125         public interface ChangeSetUpdate {
126             public long getChangeSetId();
127             public int getChangeSetIndex();
128             public int getNumberOfClusterChangeSets();
129             public int getIndexOfClusterChangeSet();
130             public byte[] getClusterId();
131             public boolean getNewCluster();
132             public byte[] getData();
133         }
134         public boolean undo(long[] changeSetIds, OnChangeSetUpdate onChangeSetUpdate) throws SDBException;
135         
136         public <T> T clone(ClusterUID clusterUID, ClusterCreator clusterCreator) throws DatabaseException;
137         public boolean refreshEnabled();
138         public boolean rolledback();
139     }
140     public Session newSession(ServiceLocator locator) throws SDBException;
141     interface Journal {
142         public class Line {
143             public boolean status;
144             public String request;
145             public String comment;
146         }
147         public boolean canRead();
148         public int count();
149         public int read(int index, Line line) throws SDBException;
150     }
151     public Journal getJournal() throws SDBException;
152     public String getCompression();
153 }