@@ -225,47 +225,52 @@ public static boolean isObjectBrowserAvailable() { |
225 | 225 | canonicalPath = getCanonicalPath(directory); |
226 | 226 | verifyNotAlreadyOpen(canonicalPath); |
227 | 227 |
|
228 | | - handle = nativeCreateWithFlatOptions(builder.buildFlatStoreOptions(canonicalPath), builder.model); |
229 | | - int debugFlags = builder.debugFlags; |
230 | | - if (debugFlags != 0) { |
231 | | - debugTxRead = (debugFlags & DebugFlags.LOG_TRANSACTIONS_READ) != 0; |
232 | | - debugTxWrite = (debugFlags & DebugFlags.LOG_TRANSACTIONS_WRITE) != 0; |
233 | | - } else { |
234 | | - debugTxRead = debugTxWrite = false; |
235 | | - } |
236 | | - debugRelations = builder.debugRelations; |
| 228 | + try { |
| 229 | + handle = nativeCreateWithFlatOptions(builder.buildFlatStoreOptions(canonicalPath), builder.model); |
| 230 | + int debugFlags = builder.debugFlags; |
| 231 | + if (debugFlags != 0) { |
| 232 | + debugTxRead = (debugFlags & DebugFlags.LOG_TRANSACTIONS_READ) != 0; |
| 233 | + debugTxWrite = (debugFlags & DebugFlags.LOG_TRANSACTIONS_WRITE) != 0; |
| 234 | + } else { |
| 235 | + debugTxRead = debugTxWrite = false; |
| 236 | + } |
| 237 | + debugRelations = builder.debugRelations; |
237 | 238 |
|
238 | | - for (EntityInfo<?> entityInfo : builder.entityInfoList) { |
239 | | - try { |
240 | | - dbNameByClass.put(entityInfo.getEntityClass(), entityInfo.getDbName()); |
241 | | - int entityId = nativeRegisterEntityClass(handle, entityInfo.getDbName(), entityInfo.getEntityClass()); |
242 | | - entityTypeIdByClass.put(entityInfo.getEntityClass(), entityId); |
243 | | - classByEntityTypeId.put(entityId, entityInfo.getEntityClass()); |
244 | | - propertiesByClass.put(entityInfo.getEntityClass(), entityInfo); |
245 | | - for (Property<?> property : entityInfo.getAllProperties()) { |
246 | | - if (property.customType != null) { |
247 | | - if (property.converterClass == null) { |
248 | | - throw new RuntimeException("No converter class for custom type of " + property); |
| 239 | + for (EntityInfo<?> entityInfo : builder.entityInfoList) { |
| 240 | + try { |
| 241 | + dbNameByClass.put(entityInfo.getEntityClass(), entityInfo.getDbName()); |
| 242 | + int entityId = nativeRegisterEntityClass(handle, entityInfo.getDbName(), entityInfo.getEntityClass()); |
| 243 | + entityTypeIdByClass.put(entityInfo.getEntityClass(), entityId); |
| 244 | + classByEntityTypeId.put(entityId, entityInfo.getEntityClass()); |
| 245 | + propertiesByClass.put(entityInfo.getEntityClass(), entityInfo); |
| 246 | + for (Property<?> property : entityInfo.getAllProperties()) { |
| 247 | + if (property.customType != null) { |
| 248 | + if (property.converterClass == null) { |
| 249 | + throw new RuntimeException("No converter class for custom type of " + property); |
| 250 | + } |
| 251 | + nativeRegisterCustomType(handle, entityId, 0, property.dbName, property.converterClass, |
| 252 | + property.customType); |
249 | 253 | } |
250 | | - nativeRegisterCustomType(handle, entityId, 0, property.dbName, property.converterClass, |
251 | | - property.customType); |
252 | 254 | } |
| 255 | + } catch (RuntimeException e) { |
| 256 | + throw new RuntimeException("Could not setup up entity " + entityInfo.getEntityClass(), e); |
253 | 257 | } |
254 | | - } catch (RuntimeException e) { |
255 | | - throw new RuntimeException("Could not setup up entity " + entityInfo.getEntityClass(), e); |
256 | 258 | } |
257 | | - } |
258 | | - int size = classByEntityTypeId.size(); |
259 | | - allEntityTypeIds = new int[size]; |
260 | | - long[] entityIdsLong = classByEntityTypeId.keys(); |
261 | | - for (int i = 0; i < size; i++) { |
262 | | - allEntityTypeIds[i] = (int) entityIdsLong[i]; |
263 | | - } |
| 259 | + int size = classByEntityTypeId.size(); |
| 260 | + allEntityTypeIds = new int[size]; |
| 261 | + long[] entityIdsLong = classByEntityTypeId.keys(); |
| 262 | + for (int i = 0; i < size; i++) { |
| 263 | + allEntityTypeIds[i] = (int) entityIdsLong[i]; |
| 264 | + } |
264 | 265 |
|
265 | | - objectClassPublisher = new ObjectClassPublisher(this); |
| 266 | + objectClassPublisher = new ObjectClassPublisher(this); |
266 | 267 |
|
267 | | - failedReadTxAttemptCallback = builder.failedReadTxAttemptCallback; |
268 | | - queryAttempts = Math.max(builder.queryAttempts, 1); |
| 268 | + failedReadTxAttemptCallback = builder.failedReadTxAttemptCallback; |
| 269 | + queryAttempts = Math.max(builder.queryAttempts, 1); |
| 270 | + } catch (RuntimeException runtimeException) { |
| 271 | + close(); // Proper clean up, e.g. delete native handle, remove this path from openFiles |
| 272 | + throw runtimeException; |
| 273 | + } |
269 | 274 | } |
270 | 275 |
|
271 | 276 | static String getCanonicalPath(File directory) { |
|