|
1 | 1 | /* |
2 | | - * Copyright 2017-2020 ObjectBox Ltd. All rights reserved. |
| 2 | + * Copyright 2017-2021 ObjectBox Ltd. All rights reserved. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -542,6 +542,7 @@ public boolean isClosed() { |
542 | 542 | * If true the schema is not updated and write transactions are not possible. |
543 | 543 | */ |
544 | 544 | public boolean isReadOnly() { |
| 545 | + checkOpen(); |
545 | 546 | return nativeIsReadOnly(handle); |
546 | 547 | } |
547 | 548 |
|
@@ -578,6 +579,7 @@ public void close() { |
578 | 579 | } |
579 | 580 | if (handle != 0) { // failed before native handle was created? |
580 | 581 | nativeDelete(handle); |
| 582 | + // TODO set handle to 0 and check in native methods |
581 | 583 | } |
582 | 584 |
|
583 | 585 | // When running the full unit test suite, we had 100+ threads before, hope this helps: |
@@ -721,6 +723,7 @@ public static boolean deleteAllFiles(@Nullable File baseDirectoryOrNull, @Nullab |
721 | 723 | * </ul> |
722 | 724 | */ |
723 | 725 | public void removeAllObjects() { |
| 726 | + checkOpen(); |
724 | 727 | nativeDropAllData(handle); |
725 | 728 | } |
726 | 729 |
|
@@ -1004,6 +1007,7 @@ public <R> void callInTxAsync(final Callable<R> callable, @Nullable final TxCall |
1004 | 1007 | * @return String that is typically logged by the application. |
1005 | 1008 | */ |
1006 | 1009 | public String diagnose() { |
| 1010 | + checkOpen(); |
1007 | 1011 | return nativeDiagnose(handle); |
1008 | 1012 | } |
1009 | 1013 |
|
@@ -1022,6 +1026,7 @@ public long validate(long pageLimit, boolean checkLeafLevel) { |
1022 | 1026 | if (pageLimit < 0) { |
1023 | 1027 | throw new IllegalArgumentException("pageLimit must be zero or positive"); |
1024 | 1028 | } |
| 1029 | + checkOpen(); |
1025 | 1030 | return nativeValidate(handle, pageLimit, checkLeafLevel); |
1026 | 1031 | } |
1027 | 1032 |
|
@@ -1086,6 +1091,7 @@ public String startObjectBrowser() { |
1086 | 1091 | @Nullable |
1087 | 1092 | public String startObjectBrowser(int port) { |
1088 | 1093 | verifyObjectBrowserNotRunning(); |
| 1094 | + checkOpen(); |
1089 | 1095 | String url = nativeStartObjectBrowser(handle, null, port); |
1090 | 1096 | if (url != null) { |
1091 | 1097 | objectBrowserPort = port; |
@@ -1097,6 +1103,7 @@ public String startObjectBrowser(int port) { |
1097 | 1103 | @Nullable |
1098 | 1104 | public String startObjectBrowser(String urlToBindTo) { |
1099 | 1105 | verifyObjectBrowserNotRunning(); |
| 1106 | + checkOpen(); |
1100 | 1107 | int port; |
1101 | 1108 | try { |
1102 | 1109 | port = new URL(urlToBindTo).getPort(); // Gives -1 if not available |
@@ -1116,6 +1123,7 @@ public synchronized boolean stopObjectBrowser() { |
1116 | 1123 | throw new IllegalStateException("ObjectBrowser has not been started before"); |
1117 | 1124 | } |
1118 | 1125 | objectBrowserPort = 0; |
| 1126 | + checkOpen(); |
1119 | 1127 | return nativeStopObjectBrowser(handle); |
1120 | 1128 | } |
1121 | 1129 |
|
@@ -1141,6 +1149,7 @@ private void verifyObjectBrowserNotRunning() { |
1141 | 1149 | * This for example allows central error handling or special logging for database-related exceptions. |
1142 | 1150 | */ |
1143 | 1151 | public void setDbExceptionListener(@Nullable DbExceptionListener dbExceptionListener) { |
| 1152 | + checkOpen(); |
1144 | 1153 | nativeSetDbExceptionListener(handle, dbExceptionListener); |
1145 | 1154 | } |
1146 | 1155 |
|
@@ -1179,10 +1188,12 @@ public TxCallback<?> internalFailedReadTxAttemptCallback() { |
1179 | 1188 | } |
1180 | 1189 |
|
1181 | 1190 | void setDebugFlags(int debugFlags) { |
| 1191 | + checkOpen(); |
1182 | 1192 | nativeSetDebugFlags(handle, debugFlags); |
1183 | 1193 | } |
1184 | 1194 |
|
1185 | 1195 | long panicModeRemoveAllObjects(int entityId) { |
| 1196 | + checkOpen(); |
1186 | 1197 | return nativePanicModeRemoveAllObjects(handle, entityId); |
1187 | 1198 | } |
1188 | 1199 |
|
|