Skip to content

Commit 3429a50

Browse files
author
mpv1989
committed
Fix db, collection creation
1 parent 9d0c9f2 commit 3429a50

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,8 @@ private ArangoDatabase db() {
125125
return db;
126126
}
127127
db = arango.db(databaseName);
128-
try {
129-
db.getInfo();
130-
} catch (final ArangoDBException e) {
131-
if (new Integer(404).equals(e.getResponseCode())) {
132-
try {
133-
arango.createDatabase(databaseName);
134-
} catch (final ArangoDBException e1) {
135-
throw translateExceptionIfPossible(e1);
136-
}
137-
} else {
138-
throw translateExceptionIfPossible(e);
139-
}
128+
if (!db.exists()) {
129+
db.create();
140130
}
141131
database = db;
142132
return db;
@@ -169,18 +159,8 @@ private ArangoCollection _collection(
169159

170160
return collectionCache.computeIfAbsent(name, collName -> {
171161
final ArangoCollection collection = db().collection(collName);
172-
try {
173-
collection.getInfo();
174-
} catch (final ArangoDBException e) {
175-
if (new Integer(404).equals(e.getResponseCode())) {
176-
try {
177-
db().createCollection(collName, options);
178-
} catch (final ArangoDBException e1) {
179-
throw translateExceptionIfPossible(e1);
180-
}
181-
} else {
182-
throw translateExceptionIfPossible(e);
183-
}
162+
if (!collection.exists()) {
163+
collection.create(options);
184164
}
185165
if (persistentEntity != null) {
186166
ensureCollectionIndexes(collection(collection), persistentEntity);

0 commit comments

Comments
 (0)