Skip to content

Commit

Permalink
Merge branch 'master' of github.com:arangodb/arangodb-java-driver
Browse files Browse the repository at this point in the history
  • Loading branch information
hkernbach committed Aug 19, 2019
2 parents 0af2e3c + c05c3b7 commit 92a6749
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 8 deletions.
7 changes: 7 additions & 0 deletions docs/Drivers/Java/Reference/Database/StreamTransactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ Gets information about a Stream Transaction.
transaction id


## ArangoDatabase.getStreamTransactions

`ArangoDatabase.getStreamTransactions() : Collection<TransactionEntity>`

Gets all the currently running Stream Transactions.


## ArangoDatabase.commitStreamTransaction

`ArangoDatabase.commitStreamTransaction(String id) : StreamTransactionEntity`
Expand Down
2 changes: 2 additions & 0 deletions docs/Drivers/Java/Reference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [Queries](Database/Queries.md)
- [AQL User Functions](Database/AqlUserFunctions.md)
- [Transactions](Database/Transactions.md)
- [Stream Transactions](Database/StreamTransactions.md)
- [Graph Access](Database/GraphAccess.md)
- [HTTP Routes](Database/HttpRoutes.md)
- [Collection](Collection/README.md)
Expand All @@ -18,6 +19,7 @@
- [View](View/README.md)
- [View Manipulation](View/ViewManipulation.md)
- [ArangoSearch Views](View/ArangoSearch.md)
- [Analyzers](View/Analyzers.md)
- [Cursor](Cursor.md)
- [Graph](Graph/README.md)
- [Vertex Collection](Graph/VertexCollection.md)
Expand Down
84 changes: 84 additions & 0 deletions docs/Drivers/Java/Reference/View/Analyzers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Analyzers

[HTTP Interface for Analyzers](https://www.arangodb.com/docs/devel/http/analyzers.html).


## Types

- **AnalyzerEntity**

- **name**: `String`

The analyzer name.

- **type**: `AnalyzerType`

The analyzer type. Can be one of: `identity`, `delimiter`, `stem`, `norm`, `ngram`, `text`

- **properties**: `Map<String, Object>`

The properties used to configure the specified type. Value may be a string, an object or null. The default value is null.

- **features**: `Set<AnalyzerFeature>`

The set of features to set on the analyzer generated fields. The default value is an empty array.
Values can be: `frequency`, `norm`, `position`


## ArangoDatabase.createArangoSearch

`ArangoDatabase.createAnalyzer(AnalyzerEntity options) : AnalyzerEntity`

Creates an Analyzer.


## ArangoDatabase.getAnalyzer

`ArangoDatabase.getAnalyzer(String name) : AnalyzerEntity`

Gets information about an Analyzer

**Arguments**

- **name**: `String`

The name of the analyzer


## ArangoDatabase.getAnalyzers

`ArangoDatabase.getAnalyzers() : Collection<AnalyzerEntity>`

Retrieves all analyzers definitions.


## ArangoDatabase.deleteAnalyzer

`ArangoDatabase.deleteAnalyzer(String name) : void`

Deletes an Analyzer.

**Arguments**

- **name**: `String`

The name of the analyzer


## ArangoDatabase.deleteAnalyzer

`ArangoDatabase.deleteAnalyzer(String name, AnalyzerDeleteOptions options) : void`

Deletes an Analyzer.

**Arguments**

- **name**: `String`

The name of the analyzer

- **options**: `AnalyzerDeleteOptions`

- **force**: `Boolean`

The analyzer configuration should be removed even if it is in-use. The default value is false.
11 changes: 11 additions & 0 deletions src/main/java/com/arangodb/ArangoDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,17 @@ GraphEntity createGraph(String name, Collection<EdgeDefinition> edgeDefinitions,
*/
StreamTransactionEntity getStreamTransaction(String id) throws ArangoDBException;

/**
* Gets all the currently running Stream Transactions.
*
* @return all the currently running Stream Transactions
* @throws ArangoDBException
* @see <a href="https://docs.arangodb.com/current/HTTP/transaction-stream-transaction.html#list-currently-ongoing-transactions">
* API Documentation</a>
* @since ArangoDB 3.5.0
*/
Collection<TransactionEntity> getStreamTransactions() throws ArangoDBException;

/**
* Commits a Stream Transaction.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ public class StreamTransactionEntity implements Entity {
private String id;
private StreamTransactionStatus status;

public enum StreamTransactionStatus {
running, committed, aborted
}

public String getId() {
return id;
}
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/arangodb/entity/StreamTransactionStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* DISCLAIMER
*
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright holder is ArangoDB GmbH, Cologne, Germany
*/

package com.arangodb.entity;

/**
* @author Michele Rastelli
*/
public enum StreamTransactionStatus {
running, committed, aborted
}
42 changes: 42 additions & 0 deletions src/main/java/com/arangodb/entity/TransactionEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* DISCLAIMER
*
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright holder is ArangoDB GmbH, Cologne, Germany
*/

package com.arangodb.entity;

/**
* @author Michele Rastelli
* @see <a href=
* "https://docs.arangodb.com/current/HTTP/transaction-stream-transaction.html#list-currently-ongoing-transactions</a>
* @since ArangoDB 3.5.0
*/
public class TransactionEntity implements Entity {

private String id;
private StreamTransactionStatus state;

public String getId() {
return id;
}

public StreamTransactionStatus getStatus() {
return state;
}

}
5 changes: 5 additions & 0 deletions src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ public StreamTransactionEntity getStreamTransaction(String id) throws ArangoDBEx
return executor.execute(getStreamTransactionRequest(id), streamTransactionResponseDeserializer());
}

@Override
public Collection<TransactionEntity> getStreamTransactions() throws ArangoDBException {
return executor.execute(getStreamTransactionsRequest(), transactionsResponseDeserializer());
}

@Override
public StreamTransactionEntity commitStreamTransaction(String id) throws ArangoDBException {
return executor.execute(commitStreamTransactionRequest(id), streamTransactionResponseDeserializer());
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/arangodb/internal/InternalArangoDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,25 @@ protected Request abortStreamTransactionRequest(String id) {
return request(name, RequestType.DELETE, PATH_API_TRANSACTION, id);
}

protected Request getStreamTransactionsRequest() {
return request(name, RequestType.GET, PATH_API_TRANSACTION);
}

protected Request getStreamTransactionRequest(String id) {
return request(name, RequestType.GET, PATH_API_TRANSACTION, id);
}

protected ResponseDeserializer<Collection<TransactionEntity>> transactionsResponseDeserializer() {
return new ResponseDeserializer<Collection<TransactionEntity>>() {
@Override
public Collection<TransactionEntity> deserialize(final Response response) throws VPackException {
final VPackSlice result = response.getBody().get("transactions");
return util().deserialize(result, new Type<Collection<TransactionEntity>>() {
}.getType());
}
};
}

protected Request commitStreamTransactionRequest(String id) {
return request(name, RequestType.PUT, PATH_API_TRANSACTION, id);
}
Expand Down
29 changes: 25 additions & 4 deletions src/test/java/com/arangodb/StreamTransactionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void beginStreamTransaction() {

StreamTransactionEntity tx = db.beginStreamTransaction(null);
assertThat(tx.getId(), is(notNullValue()));
assertThat(tx.getStatus(), is(StreamTransactionEntity.StreamTransactionStatus.running));
assertThat(tx.getStatus(), is(StreamTransactionStatus.running));
db.abortStreamTransaction(tx.getId());
}

Expand All @@ -97,7 +97,7 @@ public void abortStreamTransaction() {

assertThat(abortedTx.getId(), is(notNullValue()));
assertThat(abortedTx.getId(), is(begunTx.getId()));
assertThat(abortedTx.getStatus(), is(StreamTransactionEntity.StreamTransactionStatus.aborted));
assertThat(abortedTx.getStatus(), is(StreamTransactionStatus.aborted));
}

@Test
Expand Down Expand Up @@ -151,7 +151,7 @@ public void getStreamTransaction() {

assertThat(gotTx.getId(), is(notNullValue()));
assertThat(gotTx.getId(), is(createdTx.getId()));
assertThat(gotTx.getStatus(), is(StreamTransactionEntity.StreamTransactionStatus.running));
assertThat(gotTx.getStatus(), is(StreamTransactionStatus.running));

db.abortStreamTransaction(createdTx.getId());
}
Expand Down Expand Up @@ -185,7 +185,7 @@ public void commitStreamTransaction() {

assertThat(committedTx.getId(), is(notNullValue()));
assertThat(committedTx.getId(), is(createdTx.getId()));
assertThat(committedTx.getStatus(), is(StreamTransactionEntity.StreamTransactionStatus.committed));
assertThat(committedTx.getStatus(), is(StreamTransactionStatus.committed));
}

@Test
Expand Down Expand Up @@ -705,4 +705,25 @@ public void nextCursor() {
db.abortStreamTransaction(tx.getId());
}

@Test
public void getStreamTransactions() {
assumeTrue(requireSingleServer());
assumeTrue(requireVersion(3, 5));
assumeTrue(requireStorageEngine(ArangoDBEngine.StorageEngineName.rocksdb));

StreamTransactionEntity tx1 = db.beginStreamTransaction(null);
StreamTransactionEntity tx2 = db.beginStreamTransaction(null);

List<String> createdIds = Arrays.asList(tx1.getId(), tx2.getId());
Set<TransactionEntity> gotTxs = db.getStreamTransactions().stream().
filter(it -> createdIds.contains(it.getId())).collect(Collectors.toSet());

assertThat(gotTxs.size(), is(createdIds.size()));
assertThat(gotTxs.stream()
.allMatch(it -> it.getStatus() == StreamTransactionStatus.running), is(true));

db.abortStreamTransaction(tx1.getId());
db.abortStreamTransaction(tx2.getId());
}

}

0 comments on commit 92a6749

Please sign in to comment.