8000 Fix `ArangoCollection#rename(String)` · MladenMitev/arangodb-java-driver@7558e13 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7558e13

Browse files
author
mpv1989
committed
Fix ArangoCollection#rename(String)
1 parent b6edaec commit 7558e13

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- fixed `ArangoCollection#rename(String)`
12+
13+
Change field `name` in `ArangoCollection` after rename so that future requests through the instance will be made with the new collection name.
14+
915
## [4.6.0] - 2018-07-02
1016

1117
### Added

src/main/java/com/arangodb/internal/ArangoCollectionImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,10 @@ public CollectionPropertiesEntity changeProperties(final CollectionPropertiesOpt
382382
}
383383

384384
@Override
385-
public CollectionEntity rename(final String newName) throws ArangoDBException {
386-
return executor.execute(renameRequest(newName), CollectionEntity.class);
385+
public synchronized CollectionEntity rename(final String newName) throws ArangoDBException {
386+
final CollectionEntity result = executor.execute(renameRequest(newName), CollectionEntity.class);
387+
name = result.getName();
388+
return result;
387389
}
388390

389391
@Override

src/main/java/com/arangodb/internal/InternalArangoCollection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public abstract class InternalArangoCollection<A extends InternalArangoDB<E>, D
8787
private static final String SILENT = "silent";
8888

8989
private final D db;
90-
private final String name;
90+
protected volatile String name;
9191

9292
protected InternalArangoCollection(final D db, final String name) {
9393
super(db.executor, db.util, db.context);

src/test/java/com/arangodb/ArangoCollectionTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,20 @@ public void rename() {
20042004
}
20052005
}
20062006

2007+
@Test
2008+
public void renameDontBreaksCollectionHandler() {
2009+
if (arangoDB.getRole() != ServerRole.SINGLE) {
2010+
return;
2011+
}
2012+
try {
2013+
final ArangoCollection collection = db.collection(COLLECTION_NAME);
2014+
collection.rename(COLLECTION_NAME + "1");
2015+
assertThat(collection.getInfo(), is(notNullValue()));
2016+
} finally {
2017+
db.collection(COLLECTION_NAME + "1").rename(COLLECTION_NAME);
2018+
}
2019+
}
2020+
20072021
@Test
20082022
public void getRevision() {
20092023
final CollectionRevisionEntity result = db.collection(COLLECTION_NAME).getRevision();

0 commit comments

Comments
 (0)
0