diff --git a/docs/Drivers/Java/Reference/Database/ViewAccess.md b/docs/Drivers/Java/Reference/Database/ViewAccess.md new file mode 100644 index 000000000..e9708846c --- /dev/null +++ b/docs/Drivers/Java/Reference/Database/ViewAccess.md @@ -0,0 +1,64 @@ +# Accessing views + +These functions implement the +[HTTP API for accessing view](https://docs.arangodb.com/latest/HTTP/Views/Getting.html). + +## ArangoDatabase.view + +``` +ArangoDatabase.view(String name) : ArangoView +``` + +Returns a _ArangoView_ instance for the given view name. + +**Arguments** + +- **name**: `String` + + Name of the view + +**Examples** + +```Java +ArangoDB arango = new ArangoDB.Builder().build(); +ArangoDatabase db = arango.db("myDB"); +ArangoView view = db.view("myView"); +``` + +## ArangoDatabase.arangoSearch + +``` +ArangoDatabase.arangoSearch(String name) : ArangoSearch +``` + +Returns a _ArangoSearch_ instance for the given ArangoSearch view name. + +**Arguments** + +- **name**: `String` + + Name of the view + +**Examples** + +```Java +ArangoDB arango = new ArangoDB.Builder().build(); +ArangoDatabase db = arango.db("myDB"); +ArangoSearch view = db.arangoSearch("myArangoSearchView"); +``` + +## ArangoDatabase.getViews + +``` +ArangoDatabase.getViews() : Collection +``` + +Fetches all views from the database and returns an list of collection descriptions. + +**Examples** + +```Java +ArangoDB arango = new ArangoDB.Builder().build(); +ArangoDatabase db = arango.db("myDB"); +Collection infos = db.getViews(); +``` diff --git a/docs/Drivers/Java/Reference/README.md b/docs/Drivers/Java/Reference/README.md index 44bdd932e..c35bf9b2a 100644 --- a/docs/Drivers/Java/Reference/README.md +++ b/docs/Drivers/Java/Reference/README.md @@ -4,6 +4,7 @@ - [Database](Database/README.md) - [Database Manipulation](Database/DatabaseManipulation.md) - [Collection Access](Database/CollectionAccess.md) + - [View Access](Database/ViewAccess.md) - [Queries](Database/Queries.md) - [AQL User Functions](Database/AqlUserFunctions.md) - [Transactions](Database/Transactions.md) @@ -14,6 +15,9 @@ - [Document Manipulation](Collection/DocumentManipulation.md) - [Indexes](Collection/Indexes.md) - [Bulk Import](Collection/BulkImport.md) +- [View](View/README.md) + - [View Manipulation](View/ViewManipulation.md) + - [ArangoSearch Views](View/ArangoSearch.md) - [Cursor](Cursor.md) - [Graph](Graph/README.md) - [Vertex Collection](Graph/VertexCollection.md) diff --git a/docs/Drivers/Java/Reference/View/ArangoSearch.md b/docs/Drivers/Java/Reference/View/ArangoSearch.md new file mode 100644 index 000000000..b8904de3c --- /dev/null +++ b/docs/Drivers/Java/Reference/View/ArangoSearch.md @@ -0,0 +1,188 @@ +# ArangoSearch API + +These functions implement the +[HTTP API for ArangoSearch views](https://docs.arangodb.com/latest/HTTP/Views/ArangoSearch.html). + +## ArangoDatabase.createArangoSearch + +``` +ArangoDatabase.createArangoSearch(String name, ArangoSearchCreateOptions options) : ViewEntity +``` + +Creates a ArangoSearch view with the given _options_, then returns view information from the server. + +**Arguments** + +- **name**: `String` + + The name of the view + +- **options**: `ArangoSearchCreateOptions` + + - **locale**: `String` + + The default locale used for queries on analyzed string values (default: C). + + - **commitIntervalMsec**: `Long` + + Wait at least this many milliseconds between committing index data changes and making them visible to queries (default: 60000, to disable use: 0). For the case where there are a lot of inserts/updates, a lower value, until commit, will cause the index not to account for them and memory usage would continue to grow. For the case where there are a few inserts/updates, a higher value will impact performance and waste disk space for each commit call without any added benefits. + + - **cleanupIntervalStep**: `Long` + + Wait at least this many commits between removing unused files in data directory (default: 10, to disable use: 0). For the case where the consolidation policies merge segments often (i.e. a lot of commit+consolidate), a lower value will cause a lot of disk space to be wasted. For the case where the consolidation policies rarely merge segments (i.e. few inserts/deletes), a higher value will impact performance without any added benefits. + + - **threshold**: `ConsolidateThreshold[]` + + A list of consolidate thresholds + +**Examples** + +```Java +ArangoDB arango = new ArangoDB.Builder().build(); +ArangoDatabase db = arango.db("myDB"); +db.createArangoSearch("potatos", new ArangoSearchPropertiesOptions()); +// the ArangoSearch view "potatos" now exists +``` + +## ArangoSearch.create + +``` +ArangoSearch.create(ArangoSearchCreateOptions options) : ViewEntity +``` + +Creates a ArangoSearch view with the given _options_, then returns view information from the server. + +Alternative for [ArangoDatabase.createArangoSearch](#arangodatabasecreatearangosearch). + +**Arguments** + +- **options**: `ArangoSearchCreateOptions` + + - **locale**: `String` + + The default locale used for queries on analyzed string values (default: C). + + - **commitIntervalMsec**: `Long` + + Wait at least this many milliseconds between committing index data changes and making them visible to queries (default: 60000, to disable use: 0). For the case where there are a lot of inserts/updates, a lower value, until commit, will cause the index not to account for them and memory usage would continue to grow. For the case where there are a few inserts/updates, a higher value will impact performance and waste disk space for each commit call without any added benefits. + + - **cleanupIntervalStep**: `Long` + + Wait at least this many commits between removing unused files in data directory (default: 10, to disable use: 0). For the case where the consolidation policies merge segments often (i.e. a lot of commit+consolidate), a lower value will cause a lot of disk space to be wasted. For the case where the consolidation policies rarely merge segments (i.e. few inserts/deletes), a higher value will impact performance without any added benefits. + + - **threshold**: `ConsolidateThreshold[]` + + A list of consolidate thresholds + +**Examples** + +```Java +ArangoDB arango = new ArangoDB.Builder().build(); +ArangoDatabase db = arango.db("myDB"); +ArangoSearch view = db.arangoSearch("potatos"); + +view.create(new ArangoSearchPropertiesOptions()); +// the ArangoSearch view "potatos" now exists +``` + +## ArangoSearch.getProperties + +``` +ArangoSearch.getProperties() : ArangoSearchPropertiesEntity +``` + +Reads the properties of the specified view. + +**Examples** + +```Java +ArangoDB arango = new ArangoDB.Builder().build(); +ArangoDatabase db = arango.db("myDB"); +ArangoSearch view = db.arangoSearch("potatos"); + +ArangoSearchPropertiesEntity properties = view.getProperties(); +``` + +## ArangoSearch.updateProperties + +``` +ArangoSearch.updateProperties(ArangoSearchPropertiesOptions options) : ArangoSearchPropertiesEntity +``` + +Partially changes properties of the view. + +**Arguments** + +- **options**: `ArangoSearchPropertiesOptions` + + - **locale**: `String` + + The default locale used for queries on analyzed string values (default: C). + + - **commitIntervalMsec**: `Long` + + Wait at least this many milliseconds between committing index data changes and making them visible to queries (default: 60000, to disable use: 0). For the case where there are a lot of inserts/updates, a lower value, until commit, will cause the index not to account for them and memory usage would continue to grow. For the case where there are a few inserts/updates, a higher value will impact performance and waste disk space for each commit call without any added benefits. + + - **cleanupIntervalStep**: `Long` + + Wait at least this many commits between removing unused files in data directory (default: 10, to disable use: 0). For the case where the consolidation policies merge segments often (i.e. a lot of commit+consolidate), a lower value will cause a lot of disk space to be wasted. For the case where the consolidation policies rarely merge segments (i.e. few inserts/deletes), a higher value will impact performance without any added benefits. + + - **threshold**: `ConsolidateThreshold[]` + + A list of consolidate thresholds + + - **link**: `CollectionLink[]` + + A list of linked collections + +**Examples** + +```Java +ArangoDB arango = new ArangoDB.Builder().build(); +ArangoDatabase db = arango.db("myDB"); +ArangoSearch view = db.arangoSearch("some-view"); + +view.updateProperties(new ArangoSearchPropertiesOptions().link(CollectionLink.on("myCollection").fields(FieldLink.on("value").analyzers("identity")))); +``` + +## ArangoSearch.replaceProperties + +``` +ArangoSearch.replaceProperties(ArangoSearchPropertiesOptions options) : ArangoSearchPropertiesEntity +``` + +Changes properties of the view. + +**Arguments** + +- **options**: `ArangoSearchPropertiesOptions` + + - **locale**: `String` + + The default locale used for queries on analyzed string values (default: C). + + - **commitIntervalMsec**: `Long` + + Wait at least this many milliseconds between committing index data changes and making them visible to queries (default: 60000, to disable use: 0). For the case where there are a lot of inserts/updates, a lower value, until commit, will cause the index not to account for them and memory usage would continue to grow. For the case where there are a few inserts/updates, a higher value will impact performance and waste disk space for each commit call without any added benefits. + + - **cleanupIntervalStep**: `Long` + + Wait at least this many commits between removing unused files in data directory (default: 10, to disable use: 0). For the case where the consolidation policies merge segments often (i.e. a lot of commit+consolidate), a lower value will cause a lot of disk space to be wasted. For the case where the consolidation policies rarely merge segments (i.e. few inserts/deletes), a higher value will impact performance without any added benefits. + + - **threshold**: `ConsolidateThreshold[]` + + A list of consolidate thresholds + + - **link**: `CollectionLink[]` + + A list of linked collections + +**Examples** + +```Java +ArangoDB arango = new ArangoDB.Builder().build(); +ArangoDatabase db = arango.db("myDB"); +ArangoSearch view = db.arangoSearch("some-view"); + +view.replaceProperties(new ArangoSearchPropertiesOptions().link(CollectionLink.on("myCollection").fields(FieldLink.on("value").analyzers("identity")))); +``` diff --git a/docs/Drivers/Java/Reference/View/README.md b/docs/Drivers/Java/Reference/View/README.md new file mode 100644 index 000000000..c3690d856 --- /dev/null +++ b/docs/Drivers/Java/Reference/View/README.md @@ -0,0 +1,46 @@ +# View API + +These functions implement the +[HTTP API for views](https://docs.arangodb.com/latest/HTTP/Views/index.html). + +## Getting information about the view + +See +[the HTTP API documentation](https://docs.arangodb.com/latest/HTTP/Views/Getting.html) +for details. + +## ArangoView.exists + +``` +ArangoView.exists() : boolean +``` + +Checks whether the view exists + +**Examples** + +```Java +ArangoDB arango = new ArangoDB.Builder().build(); +ArangoDatabase db = arango.db("myDB"); +ArangoView view = db.view("potatos"); + +boolean exists = view.exists(); +``` + +## ArangoView.getInfo + +``` +ArangoView.getInfo() : ViewEntity +``` + +Returns information about the view. + +**Examples** + +```Java +ArangoDB arango = new ArangoDB.Builder().build(); +ArangoDatabase db = arango.db("myDB"); +ArangoView view = db.view("potatos"); + +ViewEntity info = view.getInfo(); +``` diff --git a/docs/Drivers/Java/Reference/View/ViewManipulation.md b/docs/Drivers/Java/Reference/View/ViewManipulation.md new file mode 100644 index 000000000..caefca465 --- /dev/null +++ b/docs/Drivers/Java/Reference/View/ViewManipulation.md @@ -0,0 +1,76 @@ +# Manipulating the view + +These functions implement +[the HTTP API for modifying views](https://docs.arangodb.com/latest/HTTP/Views/Modifying.html). + +## ArangoDatabase.createView + +``` +ArangoDatabase.createView(String name, ViewType type) : ViewEntity +``` + +Creates a view of the given _type_, then returns view information from the server. + +**Arguments** + +- **name**: `String` + + The name of the view + +- **type**: `ViewType` + + The type of the view + +**Examples** + +```Java +ArangoDB arango = new ArangoDB.Builder().build(); +ArangoDatabase db = arango.db("myDB"); +db.createView("myView", ViewType.ARANGO_SEARCH); +// the view "potatos" now exists +``` + +## ArangoView.rename + +``` +ArangoView.rename(String newName) : ViewEntity +``` + +Renames the view. + +**Arguments** + +- **newName**: `String` + + The new name + +**Examples** + +```Java +ArangoDB arango = new ArangoDB.Builder().build(); +ArangoDatabase db = arango.db("myDB"); +ArangoView view = db.view("some-view"); + +ViewEntity result = view.rename("new-view-name") +assertThat(result.getName(), is("new-view-name"); +// result contains additional information about the view +``` + +## ArangoView.drop + +``` +ArangoView.drop() : void +``` + +Deletes the view from the database. + +**Examples** + +```Java +ArangoDB arango = new ArangoDB.Builder().build(); +ArangoDatabase db = arango.db("myDB"); +ArangoView view = db.view("some-view"); + +view.drop(); +// the view "some-view" no longer exists +``` diff --git a/src/main/java/com/arangodb/ArangoDatabase.java b/src/main/java/com/arangodb/ArangoDatabase.java index dcf1683af..5f81d3421 100644 --- a/src/main/java/com/arangodb/ArangoDatabase.java +++ b/src/main/java/com/arangodb/ArangoDatabase.java @@ -37,6 +37,8 @@ import com.arangodb.entity.QueryEntity; import com.arangodb.entity.QueryTrackingPropertiesEntity; import com.arangodb.entity.TraversalEntity; +import com.arangodb.entity.ViewEntity; +import com.arangodb.entity.ViewType; import com.arangodb.model.AqlFunctionCreateOptions; import com.arangodb.model.AqlFunctionDeleteOptions; import com.arangodb.model.AqlFunctionGetOptions; @@ -48,6 +50,7 @@ import com.arangodb.model.GraphCreateOptions; import com.arangodb.model.TransactionOptions; import com.arangodb.model.TraversalOptions; +import com.arangodb.model.arangosearch.ArangoSearchCreateOptions; /** * Interface for operations on ArangoDB database level. @@ -682,4 +685,62 @@ TraversalEntity executeTraversal(Class vertexClass, Class edg */ ArangoRoute route(String... path); + /** + * Fetches all views from the database and returns an list of view descriptions. + * + * @see API Documentation + * @return list of information about all views + * @throws ArangoDBException + * @since ArangoDB 3.4.0 + */ + Collection getViews() throws ArangoDBException; + + /** + * Returns a {@code ArangoView} instance for the given view name. + * + * @param name + * Name of the view + * @return view handler + * @since ArangoDB 3.4.0 + */ + ArangoView view(String name); + + /** + * Returns a {@code ArangoSearch} instance for the given ArangoSearch view name. + * + * @param name + * Name of the view + * @return ArangoSearch view handler + * @since ArangoDB 3.4.0 + */ + ArangoSearch arangoSearch(String name); + + /** + * Creates a view of the given {@code type}, then returns view information from the server. + * + * @param name + * The name of the view + * @param type + * The type of the view + * @return information about the view + * @since ArangoDB 3.4.0 + * @throws ArangoDBException + */ + ViewEntity createView(String name, ViewType type) throws ArangoDBException; + + /** + * Creates a ArangoSearch view with the given {@code options}, then returns view information from the server. + * + * @see API + * Documentation + * @param name + * The name of the view + * @param options + * Additional options, can be null + * @return information about the view + * @since ArangoDB 3.4.0 + * @throws ArangoDBException + */ + ViewEntity createArangoSearch(String name, ArangoSearchCreateOptions options) throws ArangoDBException; + } diff --git a/src/main/java/com/arangodb/ArangoSearch.java b/src/main/java/com/arangodb/ArangoSearch.java new file mode 100644 index 000000000..14e775410 --- /dev/null +++ b/src/main/java/com/arangodb/ArangoSearch.java @@ -0,0 +1,95 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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; + +import com.arangodb.entity.ViewEntity; +import com.arangodb.entity.arangosearch.ArangoSearchPropertiesEntity; +import com.arangodb.model.arangosearch.ArangoSearchCreateOptions; +import com.arangodb.model.arangosearch.ArangoSearchPropertiesOptions; + +/** + * Interface for operations on ArangoDB view level for ArangoSearch views. + * + * @see View API Documentation + * @author Mark Vollmary + * @since ArangoDB 3.4.0 + */ +public interface ArangoSearch extends ArangoView { + + /** + * Creates a view, then returns view information from the server. + * + * @see API + * Documentation + * @return information about the view + * @throws ArangoDBException + */ + ViewEntity create() throws ArangoDBException; + + /** + * Creates a view with the given {@code options}, then returns view information from the server. + * + * @see API + * Documentation + * @param options + * Additional options, can be null + * @return information about the view + * @throws ArangoDBException + */ + ViewEntity create(ArangoSearchCreateOptions options) throws ArangoDBException; + + /** + * Reads the properties of the specified view. + * + * @see API + * Documentation + * @return properties of the view + * @throws ArangoDBException + */ + ArangoSearchPropertiesEntity getProperties() throws ArangoDBException; + + /** + * Partially changes properties of the view. + * + * @see API + * Documentation + * @param options + * properties to change + * @return properties of the view + * @throws ArangoDBException + */ + ArangoSearchPropertiesEntity updateProperties(ArangoSearchPropertiesOptions options) throws ArangoDBException; + + /** + * Changes properties of the view. + * + * @see API + * Documentation + * @param options + * properties to change + * @return properties of the view + * @throws ArangoDBException + */ + ArangoSearchPropertiesEntity replaceProperties(ArangoSearchPropertiesOptions options) throws ArangoDBException; + +} diff --git a/src/main/java/com/arangodb/ArangoView.java b/src/main/java/com/arangodb/ArangoView.java new file mode 100644 index 000000000..73fdd3a74 --- /dev/null +++ b/src/main/java/com/arangodb/ArangoView.java @@ -0,0 +1,85 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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; + +import com.arangodb.entity.ViewEntity; + +/** + * Interface for operations on ArangoDB view level. + * + * @see View API Documentation + * @author Mark Vollmary + * @since ArangoDB 3.4.0 + */ +public interface ArangoView extends ArangoSerializationAccessor { + + /** + * The the handler of the database the collection is within + * + * @return database handler + */ + public ArangoDatabase db(); + + /** + * The name of the view + * + * @return view name + */ + public String name(); + + /** + * Checks whether the view exists. + * + * @return true if the view exists, otherwise false + * @throws ArangoDBException + */ + boolean exists() throws ArangoDBException; + + /** + * Deletes the view from the database. + * + * @see API Documentation + * @throws ArangoDBException + */ + void drop() throws ArangoDBException; + + /** + * Renames the view. + * + * @see API Documentation + * @param newName + * The new name + * @return information about the view + * @throws ArangoDBException + */ + ViewEntity rename(String newName) throws ArangoDBException; + + /** + * Returns information about the view. + * + * @see API + * Documentation + * @return information about the view + * @throws ArangoDBException + */ + ViewEntity getInfo() throws ArangoDBException; + +} diff --git a/src/main/java/com/arangodb/entity/ViewEntity.java b/src/main/java/com/arangodb/entity/ViewEntity.java new file mode 100644 index 000000000..37d115f57 --- /dev/null +++ b/src/main/java/com/arangodb/entity/ViewEntity.java @@ -0,0 +1,56 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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 Mark Vollmary + * + */ +public class ViewEntity implements Entity { + + private String id; + private String name; + private ViewType type; + + public ViewEntity() { + super(); + } + + public ViewEntity(final String id, final String name, final ViewType type) { + super(); + this.id = id; + this.name = name; + this.type = type; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public ViewType getType() { + return type; + } + +} diff --git a/src/main/java/com/arangodb/entity/ViewType.java b/src/main/java/com/arangodb/entity/ViewType.java new file mode 100644 index 000000000..77397291d --- /dev/null +++ b/src/main/java/com/arangodb/entity/ViewType.java @@ -0,0 +1,31 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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 Mark Vollmary + * + */ +public enum ViewType { + + ARANGO_SEARCH + +} diff --git a/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchProperties.java b/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchProperties.java new file mode 100644 index 000000000..5b50f8b3a --- /dev/null +++ b/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchProperties.java @@ -0,0 +1,85 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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.arangosearch; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; + +/** + * @author Mark Vollmary + * + */ +public class ArangoSearchProperties { + + private String locale; + private Long commitIntervalMsec; + private Long cleanupIntervalStep; + private final Collection thresholds; + private final Collection links; + + public ArangoSearchProperties() { + super(); + thresholds = new ArrayList(); + links = new ArrayList(); + } + + public String getLocale() { + return locale; + } + + public void setLocale(final String locale) { + this.locale = locale; + } + + public Long getCommitIntervalMsec() { + return commitIntervalMsec; + } + + public void setCommitIntervalMsec(final Long commitIntervalMsec) { + this.commitIntervalMsec = commitIntervalMsec; + } + + public Long getCleanupIntervalStep() { + return cleanupIntervalStep; + } + + public void setCleanupIntervalStep(final Long cleanupIntervalStep) { + this.cleanupIntervalStep = cleanupIntervalStep; + } + + public Collection getThresholds() { + return thresholds; + } + + public void addThreshold(final ConsolidateThreshold... thresholds) { + this.thresholds.addAll(Arrays.asList(thresholds)); + } + + public Collection getLinks() { + return links; + } + + public void addLink(final CollectionLink... links) { + this.links.addAll(Arrays.asList(links)); + } + +} diff --git a/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchPropertiesEntity.java b/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchPropertiesEntity.java new file mode 100644 index 000000000..63c71a2a3 --- /dev/null +++ b/src/main/java/com/arangodb/entity/arangosearch/ArangoSearchPropertiesEntity.java @@ -0,0 +1,85 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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.arangosearch; + +import java.util.Collection; + +import com.arangodb.entity.ViewEntity; +import com.arangodb.entity.ViewType; + +/** + * @author Mark Vollmary + * + */ +public class ArangoSearchPropertiesEntity extends ViewEntity { + + private final ArangoSearchProperties properties; + + public ArangoSearchPropertiesEntity(final String id, final String name, final ViewType type, + final ArangoSearchProperties properties) { + super(id, name, type); + this.properties = properties; + } + + /** + * @return The default locale used for queries on analyzed string values (default: C). + */ + public String getLocale() { + return properties.getLocale(); + } + + /** + * @return Wait at least this many milliseconds between committing index data changes and making them visible to + * queries (default: 60000, to disable use: 0). For the case where there are a lot of inserts/updates, a + * lower value, until commit, will cause the index not to account for them and memory usage would continue + * to grow. For the case where there are a few inserts/updates, a higher value will impact performance and + * waste disk space for each commit call without any added benefits. + */ + public Long getCommitIntervalMsec() { + return properties.getCommitIntervalMsec(); + } + + /** + * @return Wait at least this many commits between removing unused files in data directory (default: 10, to disable + * use: 0). For the case where the consolidation policies merge segments often (i.e. a lot of + * commit+consolidate), a lower value will cause a lot of disk space to be wasted. For the case where the + * consolidation policies rarely merge segments (i.e. few inserts/deletes), a higher value will impact + * performance without any added benefits. + */ + public Long getCleanupIntervalStep() { + return properties.getCleanupIntervalStep(); + } + + /** + * @return A list of consolidate thresholds + */ + public Collection getThresholds() { + return properties.getThresholds(); + } + + /** + * @return A list of linked collections + */ + public Collection getLinks() { + return properties.getLinks(); + } + +} diff --git a/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java b/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java new file mode 100644 index 000000000..5ad712edb --- /dev/null +++ b/src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java @@ -0,0 +1,134 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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.arangosearch; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; + +/** + * @author Mark Vollmary + * + */ +public class CollectionLink { + + private final String name; + private final Collection analyzers; + private Boolean includeAllFields; + private Boolean trackListPositions; + private StoreValuesType storeValues; + private final Collection fields; + + private CollectionLink(final String name) { + super(); + this.name = name; + fields = new ArrayList(); + analyzers = new ArrayList(); + } + + /** + * Creates an instance of {@code CollectionLink} on the given collection name + * + * @param name + * Name of a collection + * @return new instance of {@code CollectionLink} + */ + public static CollectionLink on(final String name) { + return new CollectionLink(name); + } + + /** + * @param analyzers + * The list of analyzers to be used for indexing of string values (default: ["identity"]). + * @return link + */ + public CollectionLink analyzers(final String... analyzers) { + this.analyzers.addAll(Arrays.asList(analyzers)); + return this; + } + + /** + * @param includeAllFields + * The flag determines whether or not to index all fields on a particular level of depth (default: + * false). + * @return link + */ + public CollectionLink includeAllFields(final Boolean includeAllFields) { + this.includeAllFields = includeAllFields; + return this; + } + + /** + * @param trackListPositions + * The flag determines whether or not values in a lists should be treated separate (default: false). + * @return link + */ + public CollectionLink trackListPositions(final Boolean trackListPositions) { + this.trackListPositions = trackListPositions; + return this; + } + + /** + * @param storeValues + * How should the view track the attribute values, this setting allows for additional value retrieval + * optimizations (default "none"). + * @return link + */ + public CollectionLink storeValues(final StoreValuesType storeValues) { + this.storeValues = storeValues; + return this; + } + + /** + * @param fields + * A list of linked fields + * @return link + */ + public CollectionLink fields(final FieldLink... fields) { + this.fields.addAll(Arrays.asList(fields)); + return this; + } + + public String getName() { + return name; + } + + public Collection getAnalyzers() { + return analyzers; + } + + public Boolean getIncludeAllFields() { + return includeAllFields; + } + + public Boolean getTrackListPositions() { + return trackListPositions; + } + + public StoreValuesType getStoreValues() { + return storeValues; + } + + public Collection getFields() { + return fields; + } + +} \ No newline at end of file diff --git a/src/main/java/com/arangodb/entity/arangosearch/ConsolidateThreshold.java b/src/main/java/com/arangodb/entity/arangosearch/ConsolidateThreshold.java new file mode 100644 index 000000000..f198315bc --- /dev/null +++ b/src/main/java/com/arangodb/entity/arangosearch/ConsolidateThreshold.java @@ -0,0 +1,64 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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.arangosearch; + +/** + * @author Mark Vollmary + * + */ +public class ConsolidateThreshold { + + private final ConsolidateType type; + private Double threshold; + private Long segmentThreshold; + + private ConsolidateThreshold(final ConsolidateType type) { + super(); + this.type = type; + } + + public static ConsolidateThreshold of(final ConsolidateType type) { + return new ConsolidateThreshold(type); + } + + public ConsolidateThreshold threshold(final Double threshold) { + this.threshold = threshold; + return this; + } + + public ConsolidateThreshold segmentThreshold(final Long segmentThreshold) { + this.segmentThreshold = segmentThreshold; + return this; + } + + public ConsolidateType getType() { + return type; + } + + public Double getThreshold() { + return threshold; + } + + public Long getSegmentThreshold() { + return segmentThreshold; + } + +} diff --git a/src/main/java/com/arangodb/entity/arangosearch/ConsolidateType.java b/src/main/java/com/arangodb/entity/arangosearch/ConsolidateType.java new file mode 100644 index 000000000..29c42b089 --- /dev/null +++ b/src/main/java/com/arangodb/entity/arangosearch/ConsolidateType.java @@ -0,0 +1,7 @@ +package com.arangodb.entity.arangosearch; + +public enum ConsolidateType { + + COUNT, BYTES, BYTES_ACCUM, FILL + +} \ No newline at end of file diff --git a/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java b/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java new file mode 100644 index 000000000..51467212b --- /dev/null +++ b/src/main/java/com/arangodb/entity/arangosearch/FieldLink.java @@ -0,0 +1,110 @@ +package com.arangodb.entity.arangosearch; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; + +public class FieldLink { + + private final String name; + private final Collection analyzers; + private Boolean includeAllFields; + private Boolean trackListPositions; + private StoreValuesType storeValues; + private final Collection fields; + + private FieldLink(final String name) { + super(); + this.name = name; + fields = new ArrayList(); + analyzers = new ArrayList(); + } + + /** + * Creates an instance of {@code FieldLink} on the given field name + * + * @param name + * Name of a field + * @return new instance of {@code FieldLink} + */ + public static FieldLink on(final String name) { + return new FieldLink(name); + } + + /** + * @param analyzers + * The list of analyzers to be used for indexing of string values (default: ["identity"]). + * @return link + */ + public FieldLink analyzers(final String... analyzers) { + this.analyzers.addAll(Arrays.asList(analyzers)); + return this; + } + + /** + * @param includeAllFields + * The flag determines whether or not to index all fields on a particular level of depth (default: + * false). + * @return link + */ + public FieldLink includeAllFields(final Boolean includeAllFields) { + this.includeAllFields = includeAllFields; + return this; + } + + /** + * @param trackListPositions + * The flag determines whether or not values in a lists should be treated separate (default: false). + * @return link + */ + public FieldLink trackListPositions(final Boolean trackListPositions) { + this.trackListPositions = trackListPositions; + return this; + } + + /** + * @param storeValues + * How should the view track the attribute values, this setting allows for additional value retrieval + * optimizations (default "none"). + * @return link + */ + public FieldLink storeValues(final StoreValuesType storeValues) { + this.storeValues = storeValues; + return this; + } + + /** + * @param fields + * A list of linked fields + * @return link + */ + public FieldLink fields(final FieldLink... fields) { + this.fields.addAll(Arrays.asList(fields)); + return this; + } + + public String getName() { + return name; + } + + public Collection getAnalyzers() { + return analyzers; + } + + public Boolean getIncludeAllFields() { + return includeAllFields; + } + + public Boolean getTrackListPositions() { + return trackListPositions; + } + + public StoreValuesType getStoreValues() { + return storeValues; + } + + public Collection getFields() { + return fields; + } + +} \ No newline at end of file diff --git a/src/main/java/com/arangodb/entity/arangosearch/StoreValuesType.java b/src/main/java/com/arangodb/entity/arangosearch/StoreValuesType.java new file mode 100644 index 000000000..e879564fc --- /dev/null +++ b/src/main/java/com/arangodb/entity/arangosearch/StoreValuesType.java @@ -0,0 +1,39 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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.arangosearch; + +/** + * @author Mark Vollmary + * + */ +public enum StoreValuesType { + + /** + * Do not track values by the view + */ + NONE, + + /** + * Track only value presence, to allow use of the EXISTS() function. + */ + ID + +} diff --git a/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java b/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java index 92966f6ea..3bbafff0d 100644 --- a/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java @@ -30,6 +30,8 @@ import com.arangodb.ArangoDatabase; import com.arangodb.ArangoGraph; import com.arangodb.ArangoRoute; +import com.arangodb.ArangoSearch; +import com.arangodb.ArangoView; import com.arangodb.entity.AqlExecutionExplainEntity; import com.arangodb.entity.AqlFunctionEntity; import com.arangodb.entity.AqlParseEntity; @@ -45,6 +47,8 @@ import com.arangodb.entity.QueryEntity; import com.arangodb.entity.QueryTrackingPropertiesEntity; import com.arangodb.entity.TraversalEntity; +import com.arangodb.entity.ViewEntity; +import com.arangodb.entity.ViewType; import com.arangodb.internal.cursor.ArangoCursorImpl; import com.arangodb.internal.net.HostHandle; import com.arangodb.internal.util.DocumentUtil; @@ -59,6 +63,7 @@ import com.arangodb.model.GraphCreateOptions; import com.arangodb.model.TransactionOptions; import com.arangodb.model.TraversalOptions; +import com.arangodb.model.arangosearch.ArangoSearchCreateOptions; import com.arangodb.util.ArangoCursorInitializer; import com.arangodb.velocypack.Type; import com.arangodb.velocystream.Request; @@ -390,4 +395,30 @@ public ArangoRoute route(final String... path) { return new ArangoRouteImpl(this, createPath(path), Collections. emptyMap()); } + @Override + public Collection getViews() throws ArangoDBException { + return executor.execute(getViewsRequest(), getViewsResponseDeserializer()); + } + + @Override + public ArangoView view(final String name) { + return new ArangoViewImpl(this, name); + } + + @Override + public ArangoSearch arangoSearch(final String name) { + return new ArangoSearchImpl(this, name); + } + + @Override + public ViewEntity createView(final String name, final ViewType type) throws ArangoDBException { + return executor.execute(createViewRequest(name, type), ViewEntity.class); + } + + @Override + public ViewEntity createArangoSearch(final String name, final ArangoSearchCreateOptions options) + throws ArangoDBException { + return executor.execute(createArangoSearchRequest(name, options), ViewEntity.class); + } + } diff --git a/src/main/java/com/arangodb/internal/ArangoSearchImpl.java b/src/main/java/com/arangodb/internal/ArangoSearchImpl.java new file mode 100644 index 000000000..854569194 --- /dev/null +++ b/src/main/java/com/arangodb/internal/ArangoSearchImpl.java @@ -0,0 +1,98 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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.internal; + +import com.arangodb.ArangoDBException; +import com.arangodb.ArangoSearch; +import com.arangodb.entity.ViewEntity; +import com.arangodb.entity.arangosearch.ArangoSearchPropertiesEntity; +import com.arangodb.model.arangosearch.ArangoSearchCreateOptions; +import com.arangodb.model.arangosearch.ArangoSearchPropertiesOptions; + +/** + * @author Mark Vollmary + * + */ +public class ArangoSearchImpl extends InternalArangoSearch + implements ArangoSearch { + + protected ArangoSearchImpl(final ArangoDatabaseImpl db, final String name) { + super(db, name); + } + + @Override + public boolean exists() throws ArangoDBException { + try { + getInfo(); + return true; + } catch (final ArangoDBException e) { + if (ArangoErrors.ERROR_ARANGO_DATA_SOURCE_NOT_FOUND.equals(e.getErrorNum())) { + return false; + } + throw e; + } + } + + @Override + public void drop() throws ArangoDBException { + executor.execute(dropRequest(), Void.class); + } + + @Override + public synchronized ViewEntity rename(final String newName) throws ArangoDBException { + final ViewEntity result = executor.execute(renameRequest(newName), ViewEntity.class); + name = result.getName(); + return result; + } + + @Override + public ViewEntity getInfo() throws ArangoDBException { + return executor.execute(getInfoRequest(), ViewEntity.class); + } + + @Override + public ViewEntity create() throws ArangoDBException { + return create(new ArangoSearchCreateOptions()); + } + + @Override + public ViewEntity create(final ArangoSearchCreateOptions options) throws ArangoDBException { + return db().createArangoSearch(name(), options); + } + + @Override + public ArangoSearchPropertiesEntity getProperties() throws ArangoDBException { + return executor.execute(getPropertiesRequest(), ArangoSearchPropertiesEntity.class); + } + + @Override + public ArangoSearchPropertiesEntity updateProperties(final ArangoSearchPropertiesOptions options) + throws ArangoDBException { + return executor.execute(updatePropertiesRequest(options), ArangoSearchPropertiesEntity.class); + } + + @Override + public ArangoSearchPropertiesEntity replaceProperties(final ArangoSearchPropertiesOptions options) + throws ArangoDBException { + return executor.execute(replacePropertiesRequest(options), ArangoSearchPropertiesEntity.class); + } + +} diff --git a/src/main/java/com/arangodb/internal/ArangoViewImpl.java b/src/main/java/com/arangodb/internal/ArangoViewImpl.java new file mode 100644 index 000000000..00ff45f1e --- /dev/null +++ b/src/main/java/com/arangodb/internal/ArangoViewImpl.java @@ -0,0 +1,68 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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.internal; + +import com.arangodb.ArangoDBException; +import com.arangodb.ArangoView; +import com.arangodb.entity.ViewEntity; + +/** + * @author Mark Vollmary + * + */ +public class ArangoViewImpl extends InternalArangoView + implements ArangoView { + + protected ArangoViewImpl(final ArangoDatabaseImpl db, final String name) { + super(db, name); + } + + @Override + public boolean exists() throws ArangoDBException { + try { + getInfo(); + return true; + } catch (final ArangoDBException e) { + if (ArangoErrors.ERROR_ARANGO_DATA_SOURCE_NOT_FOUND.equals(e.getErrorNum())) { + return false; + } + throw e; + } + } + + @Override + public void drop() throws ArangoDBException { + executor.execute(dropRequest(), Void.class); + } + + @Override + public synchronized ViewEntity rename(final String newName) throws ArangoDBException { + final ViewEntity result = executor.execute(renameRequest(newName), ViewEntity.class); + name = result.getName(); + return result; + } + + @Override + public ViewEntity getInfo() throws ArangoDBException { + return executor.execute(getInfoRequest(), ViewEntity.class); + } + +} diff --git a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java index 3fcb3bce4..4f5d77ef7 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDatabase.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDatabase.java @@ -35,6 +35,8 @@ import com.arangodb.entity.QueryCachePropertiesEntity; import com.arangodb.entity.QueryTrackingPropertiesEntity; import com.arangodb.entity.TraversalEntity; +import com.arangodb.entity.ViewEntity; +import com.arangodb.entity.ViewType; import com.arangodb.internal.ArangoExecutor.ResponseDeserializer; import com.arangodb.internal.util.ArangoSerializationFactory.Serializer; import com.arangodb.model.AqlFunctionCreateOptions; @@ -50,6 +52,9 @@ import com.arangodb.model.TransactionOptions; import com.arangodb.model.TraversalOptions; import com.arangodb.model.UserAccessOptions; +import com.arangodb.model.ViewCreateOptions; +import com.arangodb.model.arangosearch.ArangoSearchCreateOptions; +import com.arangodb.model.arangosearch.ArangoSearchOptionsBuilder; import com.arangodb.util.ArangoSerializer; import com.arangodb.velocypack.Type; import com.arangodb.velocypack.VPackSlice; @@ -422,4 +427,29 @@ protected Collection deserializeEdges(final Class edgeClass, final VPa protected Request reloadRoutingRequest() { return request(name, RequestType.POST, PATH_API_ADMIN_ROUTING_RELOAD); } + + protected Request getViewsRequest() { + return request(name, RequestType.GET, InternalArangoView.PATH_API_VIEW); + } + + protected ResponseDeserializer> getViewsResponseDeserializer() { + return new ResponseDeserializer>() { + @Override + public Collection deserialize(final Response response) throws VPackException { + final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT); + return util().deserialize(result, new Type>() { + }.getType()); + } + }; + } + + protected Request createViewRequest(final String name, final ViewType type) { + return request(name(), RequestType.POST, InternalArangoView.PATH_API_VIEW) + .setBody(util().serialize(OptionsBuilder.build(new ViewCreateOptions(), name, type))); + } + + protected Request createArangoSearchRequest(final String name, final ArangoSearchCreateOptions options) { + return request(name(), RequestType.POST, InternalArangoView.PATH_API_VIEW).setBody(util().serialize( + ArangoSearchOptionsBuilder.build(options != null ? options : new ArangoSearchCreateOptions(), name))); + } } diff --git a/src/main/java/com/arangodb/internal/InternalArangoSearch.java b/src/main/java/com/arangodb/internal/InternalArangoSearch.java new file mode 100644 index 000000000..63ad01f89 --- /dev/null +++ b/src/main/java/com/arangodb/internal/InternalArangoSearch.java @@ -0,0 +1,54 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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.internal; + +import com.arangodb.model.arangosearch.ArangoSearchPropertiesOptions; +import com.arangodb.velocystream.Request; +import com.arangodb.velocystream.RequestType; + +/** + * @author Mark Vollmary + * + */ +public class InternalArangoSearch, D extends InternalArangoDatabase, E extends ArangoExecutor> + extends InternalArangoView { + + protected InternalArangoSearch(final D db, final String name) { + super(db, name); + } + + protected Request getPropertiesRequest() { + return request(db.name(), RequestType.GET, PATH_API_VIEW, name, "properties"); + } + + protected Request replacePropertiesRequest(final ArangoSearchPropertiesOptions options) { + final Request request = request(db.name(), RequestType.PUT, PATH_API_VIEW, name, "properties"); + request.setBody(util().serialize(options != null ? options : new ArangoSearchPropertiesOptions())); + return request; + } + + protected Request updatePropertiesRequest(final ArangoSearchPropertiesOptions options) { + final Request request = request(db.name(), RequestType.PATCH, PATH_API_VIEW, name, "properties"); + request.setBody(util().serialize(options != null ? options : new ArangoSearchPropertiesOptions())); + return request; + } + +} diff --git a/src/main/java/com/arangodb/internal/InternalArangoView.java b/src/main/java/com/arangodb/internal/InternalArangoView.java new file mode 100644 index 000000000..742d2dc10 --- /dev/null +++ b/src/main/java/com/arangodb/internal/InternalArangoView.java @@ -0,0 +1,68 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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.internal; + +import com.arangodb.model.OptionsBuilder; +import com.arangodb.model.ViewRenameOptions; +import com.arangodb.velocystream.Request; +import com.arangodb.velocystream.RequestType; + +/** + * @author Mark Vollmary + * + */ +public abstract class InternalArangoView, D extends InternalArangoDatabase, E extends ArangoExecutor> + extends ArangoExecuteable { + + protected static final String PATH_API_VIEW = "/_api/view"; + + protected final D db; + protected volatile String name; + + protected InternalArangoView(final D db, final String name) { + super(db.executor, db.util, db.context); + this.db = db; + this.name = name; + } + + public D db() { + return db; + } + + public String name() { + return name; + } + + protected Request dropRequest() { + return request(db.name(), RequestType.DELETE, PATH_API_VIEW, name); + } + + protected Request renameRequest(final String newName) { + final Request request = request(db.name(), RequestType.PUT, PATH_API_VIEW, name, "rename"); + request.setBody(util().serialize(OptionsBuilder.build(new ViewRenameOptions(), newName))); + return request; + } + + protected Request getInfoRequest() { + return request(db.name(), RequestType.GET, PATH_API_VIEW, name); + } + +} diff --git a/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java b/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java index d027d1195..98b17371f 100644 --- a/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java +++ b/src/main/java/com/arangodb/internal/velocypack/VPackDeserializers.java @@ -23,7 +23,9 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Iterator; import java.util.Map; +import java.util.Map.Entry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,6 +40,15 @@ import com.arangodb.entity.Permissions; import com.arangodb.entity.QueryExecutionState; import com.arangodb.entity.ReplicationFactor; +import com.arangodb.entity.ViewEntity; +import com.arangodb.entity.ViewType; +import com.arangodb.entity.arangosearch.ArangoSearchProperties; +import com.arangodb.entity.arangosearch.ArangoSearchPropertiesEntity; +import com.arangodb.entity.arangosearch.CollectionLink; +import com.arangodb.entity.arangosearch.ConsolidateThreshold; +import com.arangodb.entity.arangosearch.ConsolidateType; +import com.arangodb.entity.arangosearch.FieldLink; +import com.arangodb.entity.arangosearch.StoreValuesType; import com.arangodb.velocypack.VPackDeserializationContext; import com.arangodb.velocypack.VPackDeserializer; import com.arangodb.velocypack.VPackSlice; @@ -185,4 +196,143 @@ public ReplicationFactor deserialize( return replicationFactor; } }; + + public static final VPackDeserializer VIEW_TYPE = new VPackDeserializer() { + @Override + public ViewType deserialize( + final VPackSlice parent, + final VPackSlice vpack, + final VPackDeserializationContext context) throws VPackException { + return "arangosearch".equals(vpack.getAsString()) ? ViewType.ARANGO_SEARCH + : ViewType.valueOf(vpack.getAsString().toUpperCase()); + } + }; + + public static final VPackDeserializer ARANGO_SEARCH_PROPERTIES = new VPackDeserializer() { + @Override + public ArangoSearchProperties deserialize( + final VPackSlice parent, + final VPackSlice vpack, + final VPackDeserializationContext context) throws VPackException { + final ArangoSearchProperties properties = new ArangoSearchProperties(); + final VPackSlice locale = vpack.get("locale"); + if (locale.isString()) { + properties.setLocale(locale.getAsString()); + } + final VPackSlice commit = vpack.get("commit"); + if (commit.isObject()) { + final VPackSlice commitIntervalMsec = commit.get("commitIntervalMsec"); + if (commitIntervalMsec.isInteger()) { + properties.setCommitIntervalMsec(commitIntervalMsec.getAsLong()); + } + final VPackSlice cleanupIntervalStep = commit.get("cleanupIntervalStep"); + if (cleanupIntervalStep.isInteger()) { + properties.setCleanupIntervalStep(cleanupIntervalStep.getAsLong()); + } + final VPackSlice consolidate = commit.get("consolidate"); + if (consolidate.isObject()) { + for (final ConsolidateType type : ConsolidateType.values()) { + final VPackSlice consolidateThreshold = consolidate.get(type.name().toLowerCase()); + if (consolidateThreshold.isObject()) { + final ConsolidateThreshold t = ConsolidateThreshold.of(type); + final VPackSlice threshold = consolidateThreshold.get("threshold"); + if (threshold.isNumber()) { + t.threshold(threshold.getAsDouble()); + } + final VPackSlice segmentThreshold = consolidateThreshold.get("segmentThreshold"); + if (segmentThreshold.isInteger()) { + t.segmentThreshold(segmentThreshold.getAsLong()); + } + properties.addThreshold(t); + } + } + } + } + + final VPackSlice links = vpack.get("links"); + if (links.isObject()) { + final Iterator> collectionIterator = links.objectIterator(); + for (; collectionIterator.hasNext();) { + final Entry entry = collectionIterator.next(); + final VPackSlice value = entry.getValue(); + final CollectionLink link = CollectionLink.on(entry.getKey()); + final VPackSlice analyzers = value.get("analyzers"); + if (analyzers.isArray()) { + final Iterator analyzerIterator = analyzers.arrayIterator(); + for (; analyzerIterator.hasNext();) { + link.analyzers(analyzerIterator.next().getAsString()); + } + } + final VPackSlice includeAllFields = value.get("includeAllFields"); + if (includeAllFields.isBoolean()) { + link.includeAllFields(includeAllFields.getAsBoolean()); + } + final VPackSlice trackListPositions = value.get("trackListPositions"); + if (trackListPositions.isBoolean()) { + link.trackListPositions(trackListPositions.getAsBoolean()); + } + final VPackSlice storeValues = value.get("storeValues"); + if (storeValues.isString()) { + link.storeValues(StoreValuesType.valueOf(storeValues.getAsString().toUpperCase())); + } + final VPackSlice fields = value.get("fields"); + if (fields.isObject()) { + final Iterator> fieldsIterator = fields.objectIterator(); + for (; fieldsIterator.hasNext();) { + link.fields(deserializeField(fieldsIterator.next())); + } + } + properties.addLink(link); + } + } + return properties; + } + }; + + protected static FieldLink deserializeField(final Entry field) { + final VPackSlice value = field.getValue(); + final FieldLink link = FieldLink.on(field.getKey()); + final VPackSlice analyzers = value.get("analyzers"); + if (analyzers.isArray()) { + final Iterator analyzerIterator = analyzers.arrayIterator(); + for (; analyzerIterator.hasNext();) { + link.analyzers(analyzerIterator.next().getAsString()); + } + } + final VPackSlice includeAllFields = value.get("includeAllFields"); + if (includeAllFields.isBoolean()) { + link.includeAllFields(includeAllFields.getAsBoolean()); + } + final VPackSlice trackListPositions = value.get("trackListPositions"); + if (trackListPositions.isBoolean()) { + link.trackListPositions(trackListPositions.getAsBoolean()); + } + final VPackSlice storeValues = value.get("storeValues"); + if (storeValues.isString()) { + link.storeValues(StoreValuesType.valueOf(storeValues.getAsString().toUpperCase())); + } + final VPackSlice fields = value.get("fields"); + if (fields.isObject()) { + final Iterator> fieldsIterator = fields.objectIterator(); + for (; fieldsIterator.hasNext();) { + link.fields(deserializeField(fieldsIterator.next())); + } + } + return link; + } + + public static final VPackDeserializer ARANGO_SEARCH_PROPERTIES_ENTITY = new VPackDeserializer() { + @Override + public ArangoSearchPropertiesEntity deserialize( + final VPackSlice parent, + final VPackSlice vpack, + final VPackDeserializationContext context) throws VPackException { + final ViewEntity entity = context.deserialize(vpack, ViewEntity.class); + final ArangoSearchProperties properties = context.deserialize(vpack, ArangoSearchProperties.class); + final ArangoSearchPropertiesEntity result = new ArangoSearchPropertiesEntity(entity.getId(), + entity.getName(), entity.getType(), properties); + return result; + } + }; + } diff --git a/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java b/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java index ea85271f1..7ed1f2052 100644 --- a/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java +++ b/src/main/java/com/arangodb/internal/velocypack/VPackDriverModule.java @@ -34,6 +34,9 @@ import com.arangodb.entity.QueryEntity; import com.arangodb.entity.QueryExecutionState; import com.arangodb.entity.ReplicationFactor; +import com.arangodb.entity.ViewType; +import com.arangodb.entity.arangosearch.ArangoSearchProperties; +import com.arangodb.entity.arangosearch.ArangoSearchPropertiesEntity; import com.arangodb.internal.velocystream.internal.AuthenticationRequest; import com.arangodb.model.TraversalOptions; import com.arangodb.velocypack.VPackFieldNamingStrategy; @@ -71,6 +74,8 @@ public String translateName(final Field field) { context.registerSerializer(LogLevel.class, VPackSerializers.LOG_LEVEL); context.registerSerializer(Permissions.class, VPackSerializers.PERMISSIONS); context.registerSerializer(ReplicationFactor.class, VPackSerializers.REPLICATION_FACTOR); + context.registerSerializer(ViewType.class, VPackSerializers.VIEW_TYPE); + context.registerSerializer(ArangoSearchProperties.class, VPackSerializers.ARANGO_SEARCH_PROPERTIES); context.registerDeserializer(Response.class, VPackDeserializers.RESPONSE); context.registerDeserializer(CollectionType.class, VPackDeserializers.COLLECTION_TYPE); @@ -83,6 +88,10 @@ public String translateName(final Field field) { context.registerDeserializer(Permissions.class, VPackDeserializers.PERMISSIONS); context.registerDeserializer(QueryExecutionState.class, VPackDeserializers.QUERY_EXECUTION_STATE); context.registerDeserializer(ReplicationFactor.class, VPackDeserializers.REPLICATION_FACTOR); + context.registerDeserializer(ViewType.class, VPackDeserializers.VIEW_TYPE); + context.registerDeserializer(ArangoSearchProperties.class, VPackDeserializers.ARANGO_SEARCH_PROPERTIES); + context.registerDeserializer(ArangoSearchPropertiesEntity.class, + VPackDeserializers.ARANGO_SEARCH_PROPERTIES_ENTITY); } @Override diff --git a/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java b/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java index 3ff3507ab..f0628c044 100644 --- a/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java +++ b/src/main/java/com/arangodb/internal/velocypack/VPackSerializers.java @@ -20,6 +20,7 @@ package com.arangodb.internal.velocypack; +import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -31,6 +32,12 @@ import com.arangodb.entity.LogLevel; import com.arangodb.entity.Permissions; import com.arangodb.entity.ReplicationFactor; +import com.arangodb.entity.ViewType; +import com.arangodb.entity.arangosearch.ArangoSearchProperties; +import com.arangodb.entity.arangosearch.CollectionLink; +import com.arangodb.entity.arangosearch.ConsolidateThreshold; +import com.arangodb.entity.arangosearch.FieldLink; +import com.arangodb.entity.arangosearch.StoreValuesType; import com.arangodb.internal.velocystream.internal.AuthenticationRequest; import com.arangodb.model.TraversalOptions; import com.arangodb.model.TraversalOptions.Order; @@ -188,4 +195,131 @@ public void serialize( } } }; + + public static final VPackSerializer VIEW_TYPE = new VPackSerializer() { + @Override + public void serialize( + final VPackBuilder builder, + final String attribute, + final ViewType value, + final VPackSerializationContext context) throws VPackException { + final String type = value == ViewType.ARANGO_SEARCH ? "arangosearch" : value.name().toLowerCase(); + builder.add(attribute, type); + } + }; + + public static final VPackSerializer ARANGO_SEARCH_PROPERTIES = new VPackSerializer() { + @Override + public void serialize( + final VPackBuilder builder, + final String attribute, + final ArangoSearchProperties value, + final VPackSerializationContext context) throws VPackException { + final boolean wrap = !attribute.startsWith("_"); + if (wrap) { + builder.add("properties", ValueType.OBJECT); + } + final String locale = value.getLocale(); + if (locale != null) { + builder.add("locale", locale); + } + final Long commitIntervalMsec = value.getCommitIntervalMsec(); + final Long cleanupIntervalStep = value.getCleanupIntervalStep(); + final Collection thresholds = value.getThresholds(); + + if (commitIntervalMsec != null || cleanupIntervalStep != null || !thresholds.isEmpty()) { + builder.add("commit", ValueType.OBJECT); + if (commitIntervalMsec != null) { + builder.add("commitIntervalMsec", commitIntervalMsec); + } + if (cleanupIntervalStep != null) { + builder.add("cleanupIntervalStep", cleanupIntervalStep); + } + if (!thresholds.isEmpty()) { + builder.add("consolidate", ValueType.OBJECT); + for (final ConsolidateThreshold consolidateThreshold : thresholds) { + builder.add(consolidateThreshold.getType().name().toLowerCase(), ValueType.OBJECT); + final Double threshold = consolidateThreshold.getThreshold(); + if (threshold != null) { + builder.add("threshold", threshold); + } + final Long segmentThreshold = consolidateThreshold.getSegmentThreshold(); + if (segmentThreshold != null) { + builder.add("segmentThreshold", segmentThreshold); + } + builder.close(); + } + builder.close(); + } + builder.close(); + } + + final Collection links = value.getLinks(); + if (!links.isEmpty()) { + builder.add("links", ValueType.OBJECT); + for (final CollectionLink collectionLink : links) { + builder.add(collectionLink.getName(), ValueType.OBJECT); + final Collection analyzers = collectionLink.getAnalyzers(); + if (!analyzers.isEmpty()) { + builder.add("analyzers", ValueType.ARRAY); + for (final String analyzer : analyzers) { + builder.add(analyzer); + } + builder.close(); + } + final Boolean includeAllFields = collectionLink.getIncludeAllFields(); + if (includeAllFields != null) { + builder.add("includeAllFields", includeAllFields); + } + final Boolean trackListPositions = collectionLink.getTrackListPositions(); + if (trackListPositions != null) { + builder.add("trackListPositions", trackListPositions); + } + final StoreValuesType storeValues = collectionLink.getStoreValues(); + if (storeValues != null) { + builder.add("storeValues", storeValues.name().toLowerCase()); + } + serializeFieldLinks(builder, collectionLink.getFields()); + builder.close(); + } + builder.close(); + } + if (wrap) { + builder.close(); + } + } + }; + + private static void serializeFieldLinks(final VPackBuilder builder, final Collection links) { + if (!links.isEmpty()) { + builder.add("fields", ValueType.OBJECT); + for (final FieldLink fieldLink : links) { + builder.add(fieldLink.getName(), ValueType.OBJECT); + final Collection analyzers = fieldLink.getAnalyzers(); + if (!analyzers.isEmpty()) { + builder.add("analyzers", ValueType.ARRAY); + for (final String analyzer : analyzers) { + builder.add(analyzer); + } + builder.close(); + } + final Boolean includeAllFields = fieldLink.getIncludeAllFields(); + if (includeAllFields != null) { + builder.add("includeAllFields", includeAllFields); + } + final Boolean trackListPositions = fieldLink.getTrackListPositions(); + if (trackListPositions != null) { + builder.add("trackListPositions", trackListPositions); + } + final StoreValuesType storeValues = fieldLink.getStoreValues(); + if (storeValues != null) { + builder.add("storeValues", storeValues.name().toLowerCase()); + } + serializeFieldLinks(builder, fieldLink.getFields()); + builder.close(); + } + builder.close(); + } + } + } diff --git a/src/main/java/com/arangodb/model/OptionsBuilder.java b/src/main/java/com/arangodb/model/OptionsBuilder.java index 339356f2e..5c348cfb7 100644 --- a/src/main/java/com/arangodb/model/OptionsBuilder.java +++ b/src/main/java/com/arangodb/model/OptionsBuilder.java @@ -1,119 +1,128 @@ -/* - * 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.model; - -import java.util.Collection; -import java.util.Map; - -import com.arangodb.entity.EdgeDefinition; -import com.arangodb.entity.Permissions; -import com.arangodb.velocypack.VPackSlice; - -/** - * @author Mark Vollmary - * - */ -public class OptionsBuilder { - - private OptionsBuilder() { - super(); - } - - public static UserCreateOptions build(final UserCreateOptions options, final String user, final String passwd) { - return options.user(user).passwd(passwd); - } - - public static HashIndexOptions build(final HashIndexOptions options, final Iterable fields) { - return options.fields(fields); - } - - public static SkiplistIndexOptions build(final SkiplistIndexOptions options, final Iterable fields) { - return options.fields(fields); - } - - public static PersistentIndexOptions build(final PersistentIndexOptions options, final Iterable fields) { - return options.fields(fields); - } - - public static GeoIndexOptions build(final GeoIndexOptions options, final Iterable fields) { - return options.fields(fields); - } - - public static FulltextIndexOptions build(final FulltextIndexOptions options, final Iterable fields) { - return options.fields(fields); - } - - public static CollectionCreateOptions build(final CollectionCreateOptions options, final String name) { - return options.name(name); - } - - public static AqlQueryOptions build(final AqlQueryOptions options, final String query, final VPackSlice bindVars) { - return options.query(query).bindVars(bindVars); - } - - public static AqlQueryExplainOptions build( - final AqlQueryExplainOptions options, - final String query, - final Map bindVars) { - return options.query(query).bindVars(bindVars); - } - - public static AqlQueryParseOptions build(final AqlQueryParseOptions options, final String query) { - return options.query(query); - } - - public static GraphCreateOptions build( - final GraphCreateOptions options, - final String name, - final Collection edgeDefinitions) { - return options.name(name).edgeDefinitions(edgeDefinitions); - } - - public static TransactionOptions build(final TransactionOptions options, final String action) { - return options.action(action); - } - - public static CollectionRenameOptions build(final CollectionRenameOptions options, final String name) { - return options.name(name); - } - - public static DBCreateOptions build(final DBCreateOptions options, final String name) { - return options.name(name); - } - - public static UserAccessOptions build(final UserAccessOptions options, final Permissions grant) { - return options.grant(grant); - } - - public static AqlFunctionCreateOptions build( - final AqlFunctionCreateOptions options, - final String name, - final String code) { - return options.name(name).code(code); - } - - public static VertexCollectionCreateOptions build( - final VertexCollectionCreateOptions options, - final String collection) { - return options.collection(collection); - } - -} +/* + * 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.model; + +import java.util.Collection; +import java.util.Map; + +import com.arangodb.entity.EdgeDefinition; +import com.arangodb.entity.Permissions; +import com.arangodb.entity.ViewType; +import com.arangodb.velocypack.VPackSlice; + +/** + * @author Mark Vollmary + * + */ +public class OptionsBuilder { + + private OptionsBuilder() { + super(); + } + + public static UserCreateOptions build(final UserCreateOptions options, final String user, final String passwd) { + return options.user(user).passwd(passwd); + } + + public static HashIndexOptions build(final HashIndexOptions options, final Iterable fields) { + return options.fields(fields); + } + + public static SkiplistIndexOptions build(final SkiplistIndexOptions options, final Iterable fields) { + return options.fields(fields); + } + + public static PersistentIndexOptions build(final PersistentIndexOptions options, final Iterable fields) { + return options.fields(fields); + } + + public static GeoIndexOptions build(final GeoIndexOptions options, final Iterable fields) { + return options.fields(fields); + } + + public static FulltextIndexOptions build(final FulltextIndexOptions options, final Iterable fields) { + return options.fields(fields); + } + + public static CollectionCreateOptions build(final CollectionCreateOptions options, final String name) { + return options.name(name); + } + + public static AqlQueryOptions build(final AqlQueryOptions options, final String query, final VPackSlice bindVars) { + return options.query(query).bindVars(bindVars); + } + + public static AqlQueryExplainOptions build( + final AqlQueryExplainOptions options, + final String query, + final Map bindVars) { + return options.query(query).bindVars(bindVars); + } + + public static AqlQueryParseOptions build(final AqlQueryParseOptions options, final String query) { + return options.query(query); + } + + public static GraphCreateOptions build( + final GraphCreateOptions options, + final String name, + final Collection edgeDefinitions) { + return options.name(name).edgeDefinitions(edgeDefinitions); + } + + public static TransactionOptions build(final TransactionOptions options, final String action) { + return options.action(action); + } + + public static CollectionRenameOptions build(final CollectionRenameOptions options, final String name) { + return options.name(name); + } + + public static DBCreateOptions build(final DBCreateOptions options, final String name) { + return options.name(name); + } + + public static UserAccessOptions build(final UserAccessOptions options, final Permissions grant) { + return options.grant(grant); + } + + public static AqlFunctionCreateOptions build( + final AqlFunctionCreateOptions options, + final String name, + final String code) { + return options.name(name).code(code); + } + + public static VertexCollectionCreateOptions build( + final VertexCollectionCreateOptions options, + final String collection) { + return options.collection(collection); + } + + public static ViewCreateOptions build(final ViewCreateOptions options, final String name, final ViewType type) { + return options.name(name).type(type); + } + + public static ViewRenameOptions build(final ViewRenameOptions options, final String name) { + return options.name(name); + } + +} diff --git a/src/main/java/com/arangodb/model/ViewCreateOptions.java b/src/main/java/com/arangodb/model/ViewCreateOptions.java new file mode 100644 index 000000000..84c633870 --- /dev/null +++ b/src/main/java/com/arangodb/model/ViewCreateOptions.java @@ -0,0 +1,50 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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.model; + +import com.arangodb.entity.ViewType; + +/** + * @author Mark Vollmary + * + */ +public class ViewCreateOptions { + + @SuppressWarnings("unused") + private String name; + @SuppressWarnings("unused") + private ViewType type; + + public ViewCreateOptions() { + super(); + } + + protected ViewCreateOptions name(final String name) { + this.name = name; + return this; + } + + protected ViewCreateOptions type(final ViewType type) { + this.type = type; + return this; + } + +} diff --git a/src/main/java/com/arangodb/model/ViewRenameOptions.java b/src/main/java/com/arangodb/model/ViewRenameOptions.java new file mode 100644 index 000000000..6c9c4ff2f --- /dev/null +++ b/src/main/java/com/arangodb/model/ViewRenameOptions.java @@ -0,0 +1,49 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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.model; + +/** + * @author Mark Vollmary + * + */ +public class ViewRenameOptions { + + private String name; + + public ViewRenameOptions() { + super(); + } + + public String getName() { + return name; + } + + /** + * @param name + * The new name + * @return options + */ + protected ViewRenameOptions name(final String name) { + this.name = name; + return this; + } + +} diff --git a/src/main/java/com/arangodb/model/arangosearch/ArangoSearchCreateOptions.java b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchCreateOptions.java new file mode 100644 index 000000000..86f427125 --- /dev/null +++ b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchCreateOptions.java @@ -0,0 +1,98 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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.model.arangosearch; + +import com.arangodb.entity.ViewType; +import com.arangodb.entity.arangosearch.ArangoSearchProperties; +import com.arangodb.entity.arangosearch.ConsolidateThreshold; + +/** + * @author Mark Vollmary + * + */ +public class ArangoSearchCreateOptions { + + @SuppressWarnings("unused") + private String name; + @SuppressWarnings("unused") + private final ViewType type; + private final ArangoSearchProperties properties; + + public ArangoSearchCreateOptions() { + super(); + type = ViewType.ARANGO_SEARCH; + properties = new ArangoSearchProperties(); + } + + protected ArangoSearchCreateOptions name(final String name) { + this.name = name; + return this; + } + + /** + * @param locale + * The default locale used for queries on analyzed string values (default: C). + * @return options + */ + public ArangoSearchCreateOptions locale(final String locale) { + properties.setLocale(locale); + return this; + } + + /** + * @param commitIntervalMsec + * Wait at least this many milliseconds between committing index data changes and making them visible to + * queries (default: 60000, to disable use: 0). For the case where there are a lot of inserts/updates, a + * lower value, until commit, will cause the index not to account for them and memory usage would + * continue to grow. For the case where there are a few inserts/updates, a higher value will impact + * performance and waste disk space for each commit call without any added benefits. + * @return options + */ + public ArangoSearchCreateOptions commitIntervalMsec(final Long commitIntervalMsec) { + properties.setCommitIntervalMsec(commitIntervalMsec); + return this; + } + + /** + * @param cleanupIntervalStep + * Wait at least this many commits between removing unused files in data directory (default: 10, to + * disable use: 0). For the case where the consolidation policies merge segments often (i.e. a lot of + * commit+consolidate), a lower value will cause a lot of disk space to be wasted. For the case where the + * consolidation policies rarely merge segments (i.e. few inserts/deletes), a higher value will impact + * performance without any added benefits. + * @return options + */ + public ArangoSearchCreateOptions cleanupIntervalStep(final Long cleanupIntervalStep) { + properties.setCleanupIntervalStep(cleanupIntervalStep); + return this; + } + + /** + * @param thresholds + * A list of consolidate thresholds + * @return options + */ + public ArangoSearchCreateOptions threshold(final ConsolidateThreshold... thresholds) { + properties.addThreshold(thresholds); + return this; + } + +} diff --git a/src/main/java/com/arangodb/model/arangosearch/ArangoSearchOptionsBuilder.java b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchOptionsBuilder.java new file mode 100644 index 000000000..05018fa04 --- /dev/null +++ b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchOptionsBuilder.java @@ -0,0 +1,36 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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.model.arangosearch; + +/** + * @author Mark Vollmary + * + */ +public abstract class ArangoSearchOptionsBuilder { + + private ArangoSearchOptionsBuilder() { + super(); + } + + public static ArangoSearchCreateOptions build(final ArangoSearchCreateOptions options, final String name) { + return options.name(name); + } +} diff --git a/src/main/java/com/arangodb/model/arangosearch/ArangoSearchPropertiesOptions.java b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchPropertiesOptions.java new file mode 100644 index 000000000..cd68c6192 --- /dev/null +++ b/src/main/java/com/arangodb/model/arangosearch/ArangoSearchPropertiesOptions.java @@ -0,0 +1,98 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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.model.arangosearch; + +import com.arangodb.entity.arangosearch.ArangoSearchProperties; +import com.arangodb.entity.arangosearch.CollectionLink; +import com.arangodb.entity.arangosearch.ConsolidateThreshold; + +/** + * @author Mark Vollmary + * + */ +public class ArangoSearchPropertiesOptions { + + private final ArangoSearchProperties _properties; + + public ArangoSearchPropertiesOptions() { + super(); + _properties = new ArangoSearchProperties(); + } + + /** + * @param locale + * The default locale used for queries on analyzed string values (default: C). + * @return options + */ + public ArangoSearchPropertiesOptions locale(final String locale) { + _properties.setLocale(locale); + return this; + } + + /** + * @param commitIntervalMsec + * Wait at least this many milliseconds between committing index data changes and making them visible to + * queries (default: 60000, to disable use: 0). For the case where there are a lot of inserts/updates, a + * lower value, until commit, will cause the index not to account for them and memory usage would + * continue to grow. For the case where there are a few inserts/updates, a higher value will impact + * performance and waste disk space for each commit call without any added benefits. + * @return options + */ + public ArangoSearchPropertiesOptions commitIntervalMsec(final Long commitIntervalMsec) { + _properties.setCommitIntervalMsec(commitIntervalMsec); + return this; + } + + /** + * @param cleanupIntervalStep + * Wait at least this many commits between removing unused files in data directory (default: 10, to + * disable use: 0). For the case where the consolidation policies merge segments often (i.e. a lot of + * commit+consolidate), a lower value will cause a lot of disk space to be wasted. For the case where the + * consolidation policies rarely merge segments (i.e. few inserts/deletes), a higher value will impact + * performance without any added benefits. + * @return options + */ + public ArangoSearchPropertiesOptions cleanupIntervalStep(final Long cleanupIntervalStep) { + _properties.setCleanupIntervalStep(cleanupIntervalStep); + return this; + } + + /** + * @param thresholds + * A list of consolidate thresholds + * @return options + */ + public ArangoSearchPropertiesOptions threshold(final ConsolidateThreshold... thresholds) { + _properties.addThreshold(thresholds); + return this; + } + + /** + * @param links + * A list of linked collections + * @return options + */ + public ArangoSearchPropertiesOptions link(final CollectionLink... links) { + _properties.addLink(links); + return this; + } + +} diff --git a/src/test/java/com/arangodb/ArangoSearchTest.java b/src/test/java/com/arangodb/ArangoSearchTest.java new file mode 100644 index 000000000..795445a5c --- /dev/null +++ b/src/test/java/com/arangodb/ArangoSearchTest.java @@ -0,0 +1,186 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +import java.util.Collection; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import com.arangodb.ArangoDB.Builder; +import com.arangodb.entity.ViewEntity; +import com.arangodb.entity.ViewType; +import com.arangodb.entity.arangosearch.ArangoSearchPropertiesEntity; +import com.arangodb.entity.arangosearch.CollectionLink; +import com.arangodb.entity.arangosearch.ConsolidateThreshold; +import com.arangodb.entity.arangosearch.ConsolidateType; +import com.arangodb.entity.arangosearch.FieldLink; +import com.arangodb.entity.arangosearch.StoreValuesType; +import com.arangodb.model.arangosearch.ArangoSearchCreateOptions; +import com.arangodb.model.arangosearch.ArangoSearchPropertiesOptions; + +/** + * @author Mark Vollmary + * + */ +@RunWith(Parameterized.class) +public class ArangoSearchTest extends BaseTest { + + private static final String VIEW_NAME = "view_test"; + + public ArangoSearchTest(final Builder builder) { + super(builder); + db.createArangoSearch(VIEW_NAME, new ArangoSearchCreateOptions()); + } + + @Test + public void exists() { + assertThat(db.arangoSearch(VIEW_NAME).exists(), is(true)); + } + + @Test + public void getInfo() { + final ViewEntity info = db.arangoSearch(VIEW_NAME).getInfo(); + assertThat(info, is(not(nullValue()))); + assertThat(info.getId(), is(not(nullValue()))); + assertThat(info.getName(), is(VIEW_NAME)); + assertThat(info.getType(), is(ViewType.ARANGO_SEARCH)); + } + + @Test + public void drop() { + final String name = VIEW_NAME + "_droptest"; + db.createArangoSearch(name, new ArangoSearchCreateOptions()); + final ArangoView view = db.arangoSearch(name); + view.drop(); + assertThat(view.exists(), is(false)); + } + + @Test + public void rename() { + final String name = VIEW_NAME + "_renametest"; + final String newName = name + "_new"; + db.createArangoSearch(name, new ArangoSearchCreateOptions()); + db.arangoSearch(name).rename(newName); + assertThat(db.arangoSearch(name).exists(), is(false)); + assertThat(db.arangoSearch(newName).exists(), is(true)); + } + + @Test + public void create() { + final String name = VIEW_NAME + "_createtest"; + final ViewEntity info = db.arangoSearch(name).create(); + assertThat(info, is(not(nullValue()))); + assertThat(info.getId(), is(not(nullValue()))); + assertThat(info.getName(), is(name)); + assertThat(info.getType(), is(ViewType.ARANGO_SEARCH)); + assertThat(db.arangoSearch(name).exists(), is(true)); + } + + @Test + public void createWithOptions() { + final String name = VIEW_NAME + "_createtest"; + final ViewEntity info = db.arangoSearch(name).create(new ArangoSearchCreateOptions()); + assertThat(info, is(not(nullValue()))); + assertThat(info.getId(), is(not(nullValue()))); + assertThat(info.getName(), is(name)); + assertThat(info.getType(), is(ViewType.ARANGO_SEARCH)); + assertThat(db.arangoSearch(name).exists(), is(true)); + } + + @Test + public void getProperties() { + final String name = VIEW_NAME + "_getpropertiestest"; + final ArangoSearch view = db.arangoSearch(name); + view.create(new ArangoSearchCreateOptions()); + final ArangoSearchPropertiesEntity properties = view.getProperties(); + assertThat(properties, is(not(nullValue()))); + assertThat(properties.getId(), is(not(nullValue()))); + assertThat(properties.getName(), is(name)); + assertThat(properties.getType(), is(ViewType.ARANGO_SEARCH)); + assertThat(properties.getLocale(), is(not(nullValue()))); + assertThat(properties.getCommitIntervalMsec(), is(not(nullValue()))); + assertThat(properties.getCleanupIntervalStep(), is(not(nullValue()))); + final Collection thresholds = properties.getThresholds(); + assertThat(thresholds.size(), is(4)); + final Collection links = properties.getLinks(); + assertThat(links.isEmpty(), is(true)); + } + + @Test + public void updateProperties() { + db.createCollection("view_update_prop_test_collection"); + final String name = VIEW_NAME + "_updatepropertiestest"; + final ArangoSearch view = db.arangoSearch(name); + view.create(new ArangoSearchCreateOptions()); + final ArangoSearchPropertiesOptions options = new ArangoSearchPropertiesOptions(); + options.cleanupIntervalStep(15L); + options.commitIntervalMsec(65000L); + options.threshold(ConsolidateThreshold.of(ConsolidateType.COUNT).threshold(1.)); + options.link( + CollectionLink.on("view_update_prop_test_collection").fields(FieldLink.on("value").analyzers("identity") + .trackListPositions(true).includeAllFields(true).storeValues(StoreValuesType.ID))); + final ArangoSearchPropertiesEntity properties = view.updateProperties(options); + assertThat(properties, is(not(nullValue()))); + assertThat(properties.getCleanupIntervalStep(), is(15L)); + assertThat(properties.getCommitIntervalMsec(), is(65000L)); + assertThat(properties.getThresholds().size() >= 1, is(true)); + for (final ConsolidateThreshold t : properties.getThresholds()) { + if (t.getType() == ConsolidateType.COUNT) { + assertThat(t.getThreshold(), is(1.)); + } + } + assertThat(properties.getLinks().size(), is(1)); + final CollectionLink link = properties.getLinks().iterator().next(); + assertThat(link.getName(), is("view_update_prop_test_collection")); + assertThat(link.getFields().size(), is(1)); + final FieldLink next = link.getFields().iterator().next(); + assertThat(next.getName(), is("value")); + assertThat(next.getIncludeAllFields(), is(true)); + assertThat(next.getTrackListPositions(), is(true)); + assertThat(next.getStoreValues(), is(StoreValuesType.ID)); + } + + @Test + public void replaceProperties() { + db.createCollection("view_replace_prop_test_collection"); + final String name = VIEW_NAME + "_updatepropertiestest"; + final ArangoSearch view = db.arangoSearch(name); + view.create(new ArangoSearchCreateOptions()); + final ArangoSearchPropertiesOptions options = new ArangoSearchPropertiesOptions(); + options.link( + CollectionLink.on("view_replace_prop_test_collection").fields(FieldLink.on("value").analyzers("identity"))); + final ArangoSearchPropertiesEntity properties = view.replaceProperties(options); + assertThat(properties, is(not(nullValue()))); + assertThat(properties.getLinks().size(), is(1)); + final CollectionLink link = properties.getLinks().iterator().next(); + assertThat(link.getName(), is("view_replace_prop_test_collection")); + assertThat(link.getFields().size(), is(1)); + assertThat(link.getFields().iterator().next().getName(), is("value")); + } + +} diff --git a/src/test/java/com/arangodb/ArangoViewTest.java b/src/test/java/com/arangodb/ArangoViewTest.java new file mode 100644 index 000000000..d68f5eb86 --- /dev/null +++ b/src/test/java/com/arangodb/ArangoViewTest.java @@ -0,0 +1,83 @@ +/* + * DISCLAIMER + * + * Copyright 2018 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; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import com.arangodb.ArangoDB.Builder; +import com.arangodb.entity.ViewEntity; +import com.arangodb.entity.ViewType; + +/** + * @author Mark Vollmary + * + */ +@RunWith(Parameterized.class) +public class ArangoViewTest extends BaseTest { + + private static final String VIEW_NAME = "view_test"; + + public ArangoViewTest(final Builder builder) { + super(builder); + db.createView(VIEW_NAME, ViewType.ARANGO_SEARCH); + } + + @Test + public void exists() { + assertThat(db.view(VIEW_NAME).exists(), is(true)); + } + + @Test + public void getInfo() { + final ViewEntity info = db.view(VIEW_NAME).getInfo(); + assertThat(info, is(not(nullValue()))); + assertThat(info.getId(), is(not(nullValue()))); + assertThat(info.getName(), is(VIEW_NAME)); + assertThat(info.getType(), is(ViewType.ARANGO_SEARCH)); + } + + @Test + public void drop() { + final String name = VIEW_NAME + "_droptest"; + db.createView(name, ViewType.ARANGO_SEARCH); + final ArangoView view = db.view(name); + view.drop(); + assertThat(view.exists(), is(false)); + } + + @Test + public void rename() { + final String name = VIEW_NAME + "_renametest"; + final String newName = name + "_new"; + db.createView(name, ViewType.ARANGO_SEARCH); + db.view(name).rename(newName); + assertThat(db.view(name).exists(), is(false)); + assertThat(db.view(newName).exists(), is(true)); + } + +}