From a907d96ced647cec95b38cd461ac517b20a84945 Mon Sep 17 00:00:00 2001 From: mpv1989 Date: Wed, 4 Jul 2018 09:57:47 +0200 Subject: [PATCH 01/14] Remove stupid stuff --- .../config/TypeKeyStrategy.java | 30 ------------------- 1 file changed, 30 deletions(-) delete mode 100644 src/main/java/com/arangodb/springframework/config/TypeKeyStrategy.java diff --git a/src/main/java/com/arangodb/springframework/config/TypeKeyStrategy.java b/src/main/java/com/arangodb/springframework/config/TypeKeyStrategy.java deleted file mode 100644 index 1a9ebf570..000000000 --- a/src/main/java/com/arangodb/springframework/config/TypeKeyStrategy.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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.springframework.config; - -/** - * @author Mark Vollmary - * - */ -public enum TypeKeyStrategy { - - ALWAYS, ONLY_IF_NECESSARY, NEVER -} From 181a9f13fff3fa6fb36706f4564e80f49af6e4f8 Mon Sep 17 00:00:00 2001 From: mpv1989 Date: Thu, 5 Jul 2018 14:56:57 +0200 Subject: [PATCH 02/14] Fix `ArangoOperations#getVersion()` use configured database instead of _system --- ChangeLog.md | 1 + .../arangodb/springframework/core/template/ArangoTemplate.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 8ee5ad1c8..8e7dc379e 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - Check `Persistable#isNew` - fixed `ArangoOperations#upsert(Iterable, UpsertStrategy)` (issue #92) - Check `Persistable#isNew` +- fixed `ArangoOperations#getVersion()` use configured database instead of _system ## [2.2.0] - 2018-07-02 diff --git a/src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java b/src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java index b3d4d6240..60dc4eada 100644 --- a/src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java +++ b/src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java @@ -294,7 +294,7 @@ public ArangoDB driver() { public ArangoDBVersion getVersion() throws DataAccessException { try { if (version == null) { - version = arango.getVersion(); + version = db().getVersion(); } return version; } catch (final ArangoDBException e) { From 8e15560a3c5d8550e2b035a867607e36573074f8 Mon Sep 17 00:00:00 2001 From: mpv1989 Date: Mon, 9 Jul 2018 14:17:13 +0200 Subject: [PATCH 03/14] Prepare release 2.2.2 --- ChangeLog.md | 7 +++++-- pom.xml | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 8e7dc379e..cf3f114d9 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [2.2.2] - 2018-07-09 + +### Fixed + +- fixed `ArangoOperations#getVersion()` use configured database instead of \_system ## [2.2.1] - 2018-07-03 @@ -14,7 +18,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a - Check `Persistable#isNew` - fixed `ArangoOperations#upsert(Iterable, UpsertStrategy)` (issue #92) - Check `Persistable#isNew` -- fixed `ArangoOperations#getVersion()` use configured database instead of _system ## [2.2.0] - 2018-07-02 diff --git a/pom.xml b/pom.xml index 8c43df9f3..6815f70c0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.arangodb arangodb-spring-data - 2.2.1 + 2.2.2 2017 jar From 357c5998cf6a4a2fa6d715c0f2054c2ed466e22b Mon Sep 17 00:00:00 2001 From: mpv1989 Date: Tue, 17 Jul 2018 10:50:00 +0200 Subject: [PATCH 04/14] Deprecate Key, DBEntity, DBCollectionEntity - deprecated `com.arangodb.springframework.annotation.Key` - deprecated `com.arangodb.springframework.core.convert.DBEntity` - deprecated `com.arangodb.springframework.core.convert.DBCollectionEntity` --- ChangeLog.md | 8 + .../springframework/annotation/Key.java | 75 +- .../springframework/annotation/Param.java | 2 +- .../core/convert/ArangoConverter.java | 87 +- .../core/convert/ArangoEntityReader.java | 63 +- .../core/convert/ArangoEntityWriter.java | 63 +- .../core/convert/ArangoTypeMapper.java | 67 +- .../core/convert/DBCollectionEntity.java | 106 +-- .../core/convert/DBDocumentEntity.java | 99 ++- .../core/convert/DBEntity.java | 75 +- .../core/convert/DBEntityDeserializer.java | 87 +- .../core/convert/DBEntityModule.java | 124 +-- .../core/convert/DefaultArangoConverter.java | 1 + .../core/convert/DefaultArangoTypeMapper.java | 211 ++--- .../core/mapping/ArangoSimpleTypes.java | 1 + .../DefaultArangoPersistentProperty.java | 297 +++---- .../template/ArangoExtCursorIterator.java | 1 + .../core/template/ArangoTemplate.java | 1 + .../mapping/testdata/BasicTestEntity.java | 1 + .../core/template/ArangoTemplateTest.java | 817 +++++++++--------- .../springframework/testdata/Customer.java | 495 +++++------ .../testdata/IncompleteCustomer.java | 1 + .../springframework/testdata/Material.java | 36 +- .../springframework/testdata/Product.java | 265 +++--- 24 files changed, 1512 insertions(+), 1471 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index cf3f114d9..e2adee442 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Deprecated + +- deprecated `com.arangodb.springframework.annotation.Key` +- deprecated `com.arangodb.springframework.core.convert.DBEntity` +- deprecated `com.arangodb.springframework.core.convert.DBCollectionEntity` + ## [2.2.2] - 2018-07-09 ### Fixed diff --git a/src/main/java/com/arangodb/springframework/annotation/Key.java b/src/main/java/com/arangodb/springframework/annotation/Key.java index e2bb130f9..10cfaddc7 100644 --- a/src/main/java/com/arangodb/springframework/annotation/Key.java +++ b/src/main/java/com/arangodb/springframework/annotation/Key.java @@ -1,36 +1,39 @@ -/* - * DISCLAIMER - * - * Copyright 2017 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.springframework.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * @author Mark Vollmary - * - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.FIELD }) -public @interface Key { - -} +/* + * DISCLAIMER + * + * Copyright 2017 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.springframework.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @deprecated Represents the document field {@code _key}. Will be removed in 3.0.0, please use + * {@link org.springframework.data.annotation.Id} then instead. + * + * @author Mark Vollmary + */ +@Deprecated +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.FIELD }) +public @interface Key { + +} diff --git a/src/main/java/com/arangodb/springframework/annotation/Param.java b/src/main/java/com/arangodb/springframework/annotation/Param.java index 0384b78b6..36208a546 100644 --- a/src/main/java/com/arangodb/springframework/annotation/Param.java +++ b/src/main/java/com/arangodb/springframework/annotation/Param.java @@ -26,7 +26,7 @@ import java.lang.annotation.Target; /** - * Deprecated. Please use {@link org.springframework.data.repository.query.Param} instead. + * @deprecated. Will be removed in 3.0.0, please use {@link org.springframework.data.repository.query.Param} instead. * * @author Audrius Malele * @author Mark McCormick diff --git a/src/main/java/com/arangodb/springframework/core/convert/ArangoConverter.java b/src/main/java/com/arangodb/springframework/core/convert/ArangoConverter.java index 9ed20e331..3f09042c2 100644 --- a/src/main/java/com/arangodb/springframework/core/convert/ArangoConverter.java +++ b/src/main/java/com/arangodb/springframework/core/convert/ArangoConverter.java @@ -1,43 +1,44 @@ -/* - * DISCLAIMER - * - * Copyright 2017 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.springframework.core.convert; - -import org.springframework.data.convert.EntityConverter; - -import com.arangodb.springframework.core.mapping.ArangoPersistentEntity; -import com.arangodb.springframework.core.mapping.ArangoPersistentProperty; - -/** - * @author Mark Vollmary - * @author Christian Lechner - * - */ -public interface ArangoConverter - extends EntityConverter, ArangoPersistentProperty, Object, DBEntity>, - ArangoEntityReader, ArangoEntityWriter { - - boolean isCollectionType(Class type); - - boolean isEntityType(Class type); - - ArangoTypeMapper getTypeMapper(); - -} +/* + * DISCLAIMER + * + * Copyright 2017 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.springframework.core.convert; + +import org.springframework.data.convert.EntityConverter; + +import com.arangodb.springframework.core.mapping.ArangoPersistentEntity; +import com.arangodb.springframework.core.mapping.ArangoPersistentProperty; + +/** + * @author Mark Vollmary + * @author Christian Lechner + * + */ +@SuppressWarnings("deprecation") +public interface ArangoConverter + extends EntityConverter, ArangoPersistentProperty, Object, DBEntity>, + ArangoEntityReader, ArangoEntityWriter { + + boolean isCollectionType(Class type); + + boolean isEntityType(Class type); + + ArangoTypeMapper getTypeMapper(); + +} diff --git a/src/main/java/com/arangodb/springframework/core/convert/ArangoEntityReader.java b/src/main/java/com/arangodb/springframework/core/convert/ArangoEntityReader.java index 19c1b0a54..98be945d4 100644 --- a/src/main/java/com/arangodb/springframework/core/convert/ArangoEntityReader.java +++ b/src/main/java/com/arangodb/springframework/core/convert/ArangoEntityReader.java @@ -1,31 +1,32 @@ -/* - * DISCLAIMER - * - * Copyright 2017 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.springframework.core.convert; - -import org.springframework.data.convert.EntityReader; - -/** - * @author Mark Vollmary - * - */ -public interface ArangoEntityReader extends EntityReader { - -} +/* + * DISCLAIMER + * + * Copyright 2017 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.springframework.core.convert; + +import org.springframework.data.convert.EntityReader; + +/** + * @author Mark Vollmary + * + */ +@SuppressWarnings("deprecation") +public interface ArangoEntityReader extends EntityReader { + +} diff --git a/src/main/java/com/arangodb/springframework/core/convert/ArangoEntityWriter.java b/src/main/java/com/arangodb/springframework/core/convert/ArangoEntityWriter.java index 0adde9b2f..5ebb92b8a 100644 --- a/src/main/java/com/arangodb/springframework/core/convert/ArangoEntityWriter.java +++ b/src/main/java/com/arangodb/springframework/core/convert/ArangoEntityWriter.java @@ -1,31 +1,32 @@ -/* - * DISCLAIMER - * - * Copyright 2017 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.springframework.core.convert; - -import org.springframework.data.convert.EntityWriter; - -/** - * @author Mark Vollmary - * - */ -public interface ArangoEntityWriter extends EntityWriter { - -} +/* + * DISCLAIMER + * + * Copyright 2017 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.springframework.core.convert; + +import org.springframework.data.convert.EntityWriter; + +/** + * @author Mark Vollmary + * + */ +@SuppressWarnings("deprecation") +public interface ArangoEntityWriter extends EntityWriter { + +} diff --git a/src/main/java/com/arangodb/springframework/core/convert/ArangoTypeMapper.java b/src/main/java/com/arangodb/springframework/core/convert/ArangoTypeMapper.java index 942a9b2b4..a82caadd2 100644 --- a/src/main/java/com/arangodb/springframework/core/convert/ArangoTypeMapper.java +++ b/src/main/java/com/arangodb/springframework/core/convert/ArangoTypeMapper.java @@ -1,33 +1,34 @@ -/* - * 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.springframework.core.convert; - -import org.springframework.data.convert.TypeMapper; - -/** - * @author Christian Lechner - * - */ -public interface ArangoTypeMapper extends TypeMapper { - - boolean isTypeKey(String key); - -} +/* + * 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.springframework.core.convert; + +import org.springframework.data.convert.TypeMapper; + +/** + * @author Christian Lechner + * + */ +@SuppressWarnings("deprecation") +public interface ArangoTypeMapper extends TypeMapper { + + boolean isTypeKey(String key); + +} diff --git a/src/main/java/com/arangodb/springframework/core/convert/DBCollectionEntity.java b/src/main/java/com/arangodb/springframework/core/convert/DBCollectionEntity.java index ba8194807..ab28adc43 100644 --- a/src/main/java/com/arangodb/springframework/core/convert/DBCollectionEntity.java +++ b/src/main/java/com/arangodb/springframework/core/convert/DBCollectionEntity.java @@ -1,52 +1,54 @@ -/* - * DISCLAIMER - * - * Copyright 2017 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.springframework.core.convert; - -import java.util.ArrayList; -import java.util.Collection; - -/** - * @author Mark Vollmary - * - */ -public class DBCollectionEntity extends ArrayList implements DBEntity { - - private static final long serialVersionUID = -2068955559598596722L; - - public DBCollectionEntity() { - super(); - } - - public DBCollectionEntity(final Collection c) { - super(c); - } - - @Override - public Object put(final String key, final Object value) { - throw new UnsupportedOperationException(); - } - - @Override - public Object get(final Object key) { - throw new UnsupportedOperationException(); - } - -} +/* + * DISCLAIMER + * + * Copyright 2017 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.springframework.core.convert; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * @deprecated Will be removed in 3.0.0 + * + * @author Mark Vollmary + */ +@Deprecated +public class DBCollectionEntity extends ArrayList implements DBEntity { + + private static final long serialVersionUID = -2068955559598596722L; + + public DBCollectionEntity() { + super(); + } + + public DBCollectionEntity(final Collection c) { + super(c); + } + + @Override + public Object put(final String key, final Object value) { + throw new UnsupportedOperationException(); + } + + @Override + public Object get(final Object key) { + throw new UnsupportedOperationException(); + } + +} diff --git a/src/main/java/com/arangodb/springframework/core/convert/DBDocumentEntity.java b/src/main/java/com/arangodb/springframework/core/convert/DBDocumentEntity.java index 0f2a3f062..525279458 100644 --- a/src/main/java/com/arangodb/springframework/core/convert/DBDocumentEntity.java +++ b/src/main/java/com/arangodb/springframework/core/convert/DBDocumentEntity.java @@ -1,47 +1,52 @@ -/* - * DISCLAIMER - * - * Copyright 2017 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.springframework.core.convert; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author Mark Vollmary - * - */ -public class DBDocumentEntity extends HashMap implements DBEntity { - - private static final long serialVersionUID = -7251842887063588024L; - - public DBDocumentEntity() { - super(); - } - - public DBDocumentEntity(final Map m) { - super(m); - } - - @Override - public boolean add(final Object value) { - throw new UnsupportedOperationException(); - } - -} +/* + * DISCLAIMER + * + * Copyright 2017 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.springframework.core.convert; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Mark Vollmary + * + */ +@SuppressWarnings("deprecation") +public class DBDocumentEntity extends HashMap implements DBEntity { + + private static final long serialVersionUID = -7251842887063588024L; + + public DBDocumentEntity() { + super(); + } + + public DBDocumentEntity(final Map m) { + super(m); + } + + /** + * @deprecated Will be removed in 3.0.0 + */ + @Deprecated + @Override + public boolean add(final Object value) { + throw new UnsupportedOperationException(); + } + +} diff --git a/src/main/java/com/arangodb/springframework/core/convert/DBEntity.java b/src/main/java/com/arangodb/springframework/core/convert/DBEntity.java index 2107750f4..96fe69f25 100644 --- a/src/main/java/com/arangodb/springframework/core/convert/DBEntity.java +++ b/src/main/java/com/arangodb/springframework/core/convert/DBEntity.java @@ -1,35 +1,40 @@ -/* - * DISCLAIMER - * - * Copyright 2017 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.springframework.core.convert; - -/** - * @author Mark Vollmary - * - */ -public interface DBEntity { - - Object put(String key, Object value); - - Object get(Object key); - - boolean add(Object value); - -} +/* + * DISCLAIMER + * + * Copyright 2017 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.springframework.core.convert; + +import com.arangodb.entity.DocumentEntity; + +/** + * @deprecated Will be removed in 3.0.0, please use {@link DocumentEntity} instead + * + * @author Mark Vollmary + * + */ +@Deprecated +public interface DBEntity { + + Object put(String key, Object value); + + Object get(Object key); + + boolean add(Object value); + +} diff --git a/src/main/java/com/arangodb/springframework/core/convert/DBEntityDeserializer.java b/src/main/java/com/arangodb/springframework/core/convert/DBEntityDeserializer.java index 131d0e7c0..f2dad0587 100644 --- a/src/main/java/com/arangodb/springframework/core/convert/DBEntityDeserializer.java +++ b/src/main/java/com/arangodb/springframework/core/convert/DBEntityDeserializer.java @@ -1,43 +1,44 @@ -/* - * DISCLAIMER - * - * Copyright 2017 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.springframework.core.convert; - -import com.arangodb.velocypack.VPackDeserializationContext; -import com.arangodb.velocypack.VPackDeserializer; -import com.arangodb.velocypack.VPackSlice; -import com.arangodb.velocypack.exception.VPackException; - -/** - * @author Mark Vollmary - * - */ -public class DBEntityDeserializer implements VPackDeserializer { - - @Override - public DBEntity deserialize( - final VPackSlice parent, - final VPackSlice vpack, - final VPackDeserializationContext context) throws VPackException { - final Class type = vpack.isObject() ? DBDocumentEntity.class : DBCollectionEntity.class; - return (DBEntity) context.deserialize(vpack, type); - } - -} +/* + * DISCLAIMER + * + * Copyright 2017 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.springframework.core.convert; + +import com.arangodb.velocypack.VPackDeserializationContext; +import com.arangodb.velocypack.VPackDeserializer; +import com.arangodb.velocypack.VPackSlice; +import com.arangodb.velocypack.exception.VPackException; + +/** + * @author Mark Vollmary + * + */ +@SuppressWarnings("deprecation") +public class DBEntityDeserializer implements VPackDeserializer { + + @Override + public DBEntity deserialize( + final VPackSlice parent, + final VPackSlice vpack, + final VPackDeserializationContext context) throws VPackException { + final Class type = vpack.isObject() ? DBDocumentEntity.class : DBCollectionEntity.class; + return (DBEntity) context.deserialize(vpack, type); + } + +} diff --git a/src/main/java/com/arangodb/springframework/core/convert/DBEntityModule.java b/src/main/java/com/arangodb/springframework/core/convert/DBEntityModule.java index 907a3c653..687655208 100644 --- a/src/main/java/com/arangodb/springframework/core/convert/DBEntityModule.java +++ b/src/main/java/com/arangodb/springframework/core/convert/DBEntityModule.java @@ -1,61 +1,63 @@ -/* - * 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.springframework.core.convert; - -import java.util.Collection; -import java.util.Map; - -import com.arangodb.velocypack.VPackInstanceCreator; -import com.arangodb.velocypack.VPackModule; -import com.arangodb.velocypack.VPackSetupContext; - -/** - * @author Christian Lechner - * - */ -public class DBEntityModule implements VPackModule { - - @Override - public > void setup(C context) { - context.registerInstanceCreator(Map.class, new DBDocumentEntityInstantiator()) - .registerInstanceCreator(Collection.class, new DBCollectionEntityInstantiator()) - .registerDeserializer(DBEntity.class, new DBEntityDeserializer()); - } - - public static class DBDocumentEntityInstantiator implements VPackInstanceCreator> { - - @Override - public Map createInstance() { - return new DBDocumentEntity(); - } - - } - - public static class DBCollectionEntityInstantiator implements VPackInstanceCreator> { - - @Override - public Collection createInstance() { - return new DBCollectionEntity(); - } - - } - -} +/* + * 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.springframework.core.convert; + +import java.util.Collection; +import java.util.Map; + +import com.arangodb.velocypack.VPackInstanceCreator; +import com.arangodb.velocypack.VPackModule; +import com.arangodb.velocypack.VPackSetupContext; + +/** + * @author Christian Lechner + * + */ +public class DBEntityModule implements VPackModule { + + @SuppressWarnings("deprecation") + @Override + public > void setup(final C context) { + context.registerInstanceCreator(Map.class, new DBDocumentEntityInstantiator()) + .registerInstanceCreator(Collection.class, new DBCollectionEntityInstantiator()) + .registerDeserializer(DBEntity.class, new DBEntityDeserializer()); + } + + public static class DBDocumentEntityInstantiator implements VPackInstanceCreator> { + + @Override + public Map createInstance() { + return new DBDocumentEntity(); + } + + } + + public static class DBCollectionEntityInstantiator implements VPackInstanceCreator> { + + @SuppressWarnings("deprecation") + @Override + public Collection createInstance() { + return new DBCollectionEntity(); + } + + } + +} diff --git a/src/main/java/com/arangodb/springframework/core/convert/DefaultArangoConverter.java b/src/main/java/com/arangodb/springframework/core/convert/DefaultArangoConverter.java index f450b3314..46a8efb67 100644 --- a/src/main/java/com/arangodb/springframework/core/convert/DefaultArangoConverter.java +++ b/src/main/java/com/arangodb/springframework/core/convert/DefaultArangoConverter.java @@ -62,6 +62,7 @@ * @author Christian Lechner * @author Reşat SABIQ */ +@SuppressWarnings("deprecation") public class DefaultArangoConverter implements ArangoConverter { private static final String _ID = "_id"; diff --git a/src/main/java/com/arangodb/springframework/core/convert/DefaultArangoTypeMapper.java b/src/main/java/com/arangodb/springframework/core/convert/DefaultArangoTypeMapper.java index 7e96f1ef2..879c53ebd 100644 --- a/src/main/java/com/arangodb/springframework/core/convert/DefaultArangoTypeMapper.java +++ b/src/main/java/com/arangodb/springframework/core/convert/DefaultArangoTypeMapper.java @@ -1,105 +1,106 @@ -/* - * 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.springframework.core.convert; - -import java.util.Arrays; -import java.util.List; - -import org.springframework.data.convert.DefaultTypeMapper; -import org.springframework.data.convert.SimpleTypeInformationMapper; -import org.springframework.data.convert.TypeAliasAccessor; -import org.springframework.data.convert.TypeInformationMapper; -import org.springframework.data.mapping.Alias; -import org.springframework.data.mapping.PersistentEntity; -import org.springframework.data.mapping.context.MappingContext; - -/** - * @author Christian Lechner - * - */ -public class DefaultArangoTypeMapper extends DefaultTypeMapper implements ArangoTypeMapper { - - public static final String DEFAULT_TYPE_KEY = "_class"; - - private final String typeKey; - - public DefaultArangoTypeMapper() { - this(DEFAULT_TYPE_KEY); - } - - public DefaultArangoTypeMapper(final String typeKey) { - this(typeKey, Arrays.asList(new SimpleTypeInformationMapper())); - } - - public DefaultArangoTypeMapper(final String typeKey, - final MappingContext, ?> mappingContext) { - this(typeKey, new DocumentTypeAliasAccessor(typeKey), mappingContext, - Arrays.asList(new SimpleTypeInformationMapper())); - } - - public DefaultArangoTypeMapper(final String typeKey, final List mappers) { - this(typeKey, new DocumentTypeAliasAccessor(typeKey), null, mappers); - } - - private DefaultArangoTypeMapper(final String typeKey, final TypeAliasAccessor accessor, - final MappingContext, ?> mappingContext, - final List mappers) { - - super(accessor, mappingContext, mappers); - this.typeKey = typeKey; - } - - @Override - public boolean isTypeKey(final String key) { - return typeKey == null ? false : typeKey.equals(key); - } - - public static final class DocumentTypeAliasAccessor implements TypeAliasAccessor { - - private final String typeKey; - - public DocumentTypeAliasAccessor(final String typeKey) { - this.typeKey = typeKey; - } - - @Override - public Alias readAliasFrom(final DBEntity source) { - if (source instanceof DBCollectionEntity) { - return Alias.NONE; - } - - if (source instanceof DBDocumentEntity) { - return Alias.ofNullable(source.get(this.typeKey)); - } - - throw new IllegalArgumentException("Cannot read alias from " + source.getClass()); - } - - @Override - public void writeTypeTo(final DBEntity sink, final Object alias) { - if (this.typeKey != null && sink instanceof DBDocumentEntity) { - sink.put(this.typeKey, alias); - } - } - - } - -} +/* + * 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.springframework.core.convert; + +import java.util.Arrays; +import java.util.List; + +import org.springframework.data.convert.DefaultTypeMapper; +import org.springframework.data.convert.SimpleTypeInformationMapper; +import org.springframework.data.convert.TypeAliasAccessor; +import org.springframework.data.convert.TypeInformationMapper; +import org.springframework.data.mapping.Alias; +import org.springframework.data.mapping.PersistentEntity; +import org.springframework.data.mapping.context.MappingContext; + +/** + * @author Christian Lechner + * + */ +@SuppressWarnings("deprecation") +public class DefaultArangoTypeMapper extends DefaultTypeMapper implements ArangoTypeMapper { + + public static final String DEFAULT_TYPE_KEY = "_class"; + + private final String typeKey; + + public DefaultArangoTypeMapper() { + this(DEFAULT_TYPE_KEY); + } + + public DefaultArangoTypeMapper(final String typeKey) { + this(typeKey, Arrays.asList(new SimpleTypeInformationMapper())); + } + + public DefaultArangoTypeMapper(final String typeKey, + final MappingContext, ?> mappingContext) { + this(typeKey, new DocumentTypeAliasAccessor(typeKey), mappingContext, + Arrays.asList(new SimpleTypeInformationMapper())); + } + + public DefaultArangoTypeMapper(final String typeKey, final List mappers) { + this(typeKey, new DocumentTypeAliasAccessor(typeKey), null, mappers); + } + + private DefaultArangoTypeMapper(final String typeKey, final TypeAliasAccessor accessor, + final MappingContext, ?> mappingContext, + final List mappers) { + + super(accessor, mappingContext, mappers); + this.typeKey = typeKey; + } + + @Override + public boolean isTypeKey(final String key) { + return typeKey == null ? false : typeKey.equals(key); + } + + public static final class DocumentTypeAliasAccessor implements TypeAliasAccessor { + + private final String typeKey; + + public DocumentTypeAliasAccessor(final String typeKey) { + this.typeKey = typeKey; + } + + @Override + public Alias readAliasFrom(final DBEntity source) { + if (source instanceof DBCollectionEntity) { + return Alias.NONE; + } + + if (source instanceof DBDocumentEntity) { + return Alias.ofNullable(source.get(this.typeKey)); + } + + throw new IllegalArgumentException("Cannot read alias from " + source.getClass()); + } + + @Override + public void writeTypeTo(final DBEntity sink, final Object alias) { + if (this.typeKey != null && sink instanceof DBDocumentEntity) { + sink.put(this.typeKey, alias); + } + } + + } + +} diff --git a/src/main/java/com/arangodb/springframework/core/mapping/ArangoSimpleTypes.java b/src/main/java/com/arangodb/springframework/core/mapping/ArangoSimpleTypes.java index 213702112..e7d663c28 100644 --- a/src/main/java/com/arangodb/springframework/core/mapping/ArangoSimpleTypes.java +++ b/src/main/java/com/arangodb/springframework/core/mapping/ArangoSimpleTypes.java @@ -47,6 +47,7 @@ * @author Christian Lechner * */ +@SuppressWarnings("deprecation") public abstract class ArangoSimpleTypes { private static final Set> ARANGO_SIMPLE_TYPES; diff --git a/src/main/java/com/arangodb/springframework/core/mapping/DefaultArangoPersistentProperty.java b/src/main/java/com/arangodb/springframework/core/mapping/DefaultArangoPersistentProperty.java index 715d8e4dd..a25b72283 100644 --- a/src/main/java/com/arangodb/springframework/core/mapping/DefaultArangoPersistentProperty.java +++ b/src/main/java/com/arangodb/springframework/core/mapping/DefaultArangoPersistentProperty.java @@ -1,148 +1,149 @@ -/* - * DISCLAIMER - * - * Copyright 2017 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.springframework.core.mapping; - -import java.util.Optional; - -import org.springframework.data.mapping.Association; -import org.springframework.data.mapping.PersistentEntity; -import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty; -import org.springframework.data.mapping.model.FieldNamingStrategy; -import org.springframework.data.mapping.model.Property; -import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy; -import org.springframework.data.mapping.model.SimpleTypeHolder; -import org.springframework.util.StringUtils; - -import com.arangodb.springframework.annotation.Field; -import com.arangodb.springframework.annotation.From; -import com.arangodb.springframework.annotation.FulltextIndexed; -import com.arangodb.springframework.annotation.GeoIndexed; -import com.arangodb.springframework.annotation.HashIndexed; -import com.arangodb.springframework.annotation.Key; -import com.arangodb.springframework.annotation.PersistentIndexed; -import com.arangodb.springframework.annotation.Ref; -import com.arangodb.springframework.annotation.Relations; -import com.arangodb.springframework.annotation.Rev; -import com.arangodb.springframework.annotation.SkiplistIndexed; -import com.arangodb.springframework.annotation.To; - -/** - * @author Mark Vollmary - * - */ -public class DefaultArangoPersistentProperty extends AnnotationBasedPersistentProperty - implements ArangoPersistentProperty { - - private final FieldNamingStrategy fieldNamingStrategy; - - public DefaultArangoPersistentProperty(final Property property, - final PersistentEntity owner, final SimpleTypeHolder simpleTypeHolder, - final FieldNamingStrategy fieldNamingStrategy) { - super(property, owner, simpleTypeHolder); - this.fieldNamingStrategy = fieldNamingStrategy != null ? fieldNamingStrategy - : PropertyNameFieldNamingStrategy.INSTANCE; - } - - @Override - protected Association createAssociation() { - return new Association<>(this, null); - } - - @Override - public boolean isKeyProperty() { - return findAnnotation(Key.class) != null; - } - - @Override - public boolean isRevProperty() { - return findAnnotation(Rev.class) != null; - } - - @Override - public Optional getRef() { - return Optional.ofNullable(findAnnotation(Ref.class)); - } - - @Override - public Optional getRelations() { - return Optional.ofNullable(findAnnotation(Relations.class)); - } - - @Override - public Optional getFrom() { - return Optional.ofNullable(findAnnotation(From.class)); - } - - @Override - public Optional getTo() { - return Optional.ofNullable(findAnnotation(To.class)); - } - - @Override - public String getFieldName() { - final String fieldName; - if (isIdProperty()) { - fieldName = "_id"; - } else if (isKeyProperty()) { - fieldName = "_key"; - } else if (isRevProperty()) { - fieldName = "_rev"; - } else if (getFrom().isPresent()) { - fieldName = "_from"; - } else if (getTo().isPresent()) { - fieldName = "_to"; - } else { - fieldName = getAnnotatedFieldName().orElse(fieldNamingStrategy.getFieldName(this)); - } - return fieldName; - } - - private Optional getAnnotatedFieldName() { - return Optional.ofNullable(findAnnotation(Field.class)) - .map(f -> StringUtils.hasText(f.value()) ? f.value() : null); - } - - @Override - public Optional getHashIndexed() { - return Optional.ofNullable(findAnnotation(HashIndexed.class)); - } - - @Override - public Optional getSkiplistIndexed() { - return Optional.ofNullable(findAnnotation(SkiplistIndexed.class)); - } - - @Override - public Optional getPersistentIndexed() { - return Optional.ofNullable(findAnnotation(PersistentIndexed.class)); - } - - @Override - public Optional getGeoIndexed() { - return Optional.ofNullable(findAnnotation(GeoIndexed.class)); - } - - @Override - public Optional getFulltextIndexed() { - return Optional.ofNullable(findAnnotation(FulltextIndexed.class)); - } - -} +/* + * DISCLAIMER + * + * Copyright 2017 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.springframework.core.mapping; + +import java.util.Optional; + +import org.springframework.data.mapping.Association; +import org.springframework.data.mapping.PersistentEntity; +import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty; +import org.springframework.data.mapping.model.FieldNamingStrategy; +import org.springframework.data.mapping.model.Property; +import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy; +import org.springframework.data.mapping.model.SimpleTypeHolder; +import org.springframework.util.StringUtils; + +import com.arangodb.springframework.annotation.Field; +import com.arangodb.springframework.annotation.From; +import com.arangodb.springframework.annotation.FulltextIndexed; +import com.arangodb.springframework.annotation.GeoIndexed; +import com.arangodb.springframework.annotation.HashIndexed; +import com.arangodb.springframework.annotation.Key; +import com.arangodb.springframework.annotation.PersistentIndexed; +import com.arangodb.springframework.annotation.Ref; +import com.arangodb.springframework.annotation.Relations; +import com.arangodb.springframework.annotation.Rev; +import com.arangodb.springframework.annotation.SkiplistIndexed; +import com.arangodb.springframework.annotation.To; + +/** + * @author Mark Vollmary + * + */ +@SuppressWarnings("deprecation") +public class DefaultArangoPersistentProperty extends AnnotationBasedPersistentProperty + implements ArangoPersistentProperty { + + private final FieldNamingStrategy fieldNamingStrategy; + + public DefaultArangoPersistentProperty(final Property property, + final PersistentEntity owner, final SimpleTypeHolder simpleTypeHolder, + final FieldNamingStrategy fieldNamingStrategy) { + super(property, owner, simpleTypeHolder); + this.fieldNamingStrategy = fieldNamingStrategy != null ? fieldNamingStrategy + : PropertyNameFieldNamingStrategy.INSTANCE; + } + + @Override + protected Association createAssociation() { + return new Association<>(this, null); + } + + @Override + public boolean isKeyProperty() { + return findAnnotation(Key.class) != null; + } + + @Override + public boolean isRevProperty() { + return findAnnotation(Rev.class) != null; + } + + @Override + public Optional getRef() { + return Optional.ofNullable(findAnnotation(Ref.class)); + } + + @Override + public Optional getRelations() { + return Optional.ofNullable(findAnnotation(Relations.class)); + } + + @Override + public Optional getFrom() { + return Optional.ofNullable(findAnnotation(From.class)); + } + + @Override + public Optional getTo() { + return Optional.ofNullable(findAnnotation(To.class)); + } + + @Override + public String getFieldName() { + final String fieldName; + if (isIdProperty()) { + fieldName = "_id"; + } else if (isKeyProperty()) { + fieldName = "_key"; + } else if (isRevProperty()) { + fieldName = "_rev"; + } else if (getFrom().isPresent()) { + fieldName = "_from"; + } else if (getTo().isPresent()) { + fieldName = "_to"; + } else { + fieldName = getAnnotatedFieldName().orElse(fieldNamingStrategy.getFieldName(this)); + } + return fieldName; + } + + private Optional getAnnotatedFieldName() { + return Optional.ofNullable(findAnnotation(Field.class)) + .map(f -> StringUtils.hasText(f.value()) ? f.value() : null); + } + + @Override + public Optional getHashIndexed() { + return Optional.ofNullable(findAnnotation(HashIndexed.class)); + } + + @Override + public Optional getSkiplistIndexed() { + return Optional.ofNullable(findAnnotation(SkiplistIndexed.class)); + } + + @Override + public Optional getPersistentIndexed() { + return Optional.ofNullable(findAnnotation(PersistentIndexed.class)); + } + + @Override + public Optional getGeoIndexed() { + return Optional.ofNullable(findAnnotation(GeoIndexed.class)); + } + + @Override + public Optional getFulltextIndexed() { + return Optional.ofNullable(findAnnotation(FulltextIndexed.class)); + } + +} diff --git a/src/main/java/com/arangodb/springframework/core/template/ArangoExtCursorIterator.java b/src/main/java/com/arangodb/springframework/core/template/ArangoExtCursorIterator.java index 0c227a609..29c56daa7 100644 --- a/src/main/java/com/arangodb/springframework/core/template/ArangoExtCursorIterator.java +++ b/src/main/java/com/arangodb/springframework/core/template/ArangoExtCursorIterator.java @@ -36,6 +36,7 @@ * @param * */ +@SuppressWarnings("deprecation") class ArangoExtCursorIterator extends ArangoCursorIterator { private ArangoConverter converter; diff --git a/src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java b/src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java index 60dc4eada..6e1484db4 100644 --- a/src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java +++ b/src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java @@ -84,6 +84,7 @@ * @author Christian Lechner * @author Reşat SABIQ */ +@SuppressWarnings("deprecation") public class ArangoTemplate implements ArangoOperations, CollectionCallback { private volatile ArangoDBVersion version; diff --git a/src/test/java/com/arangodb/springframework/core/mapping/testdata/BasicTestEntity.java b/src/test/java/com/arangodb/springframework/core/mapping/testdata/BasicTestEntity.java index 016482d94..6be8f5ba2 100644 --- a/src/test/java/com/arangodb/springframework/core/mapping/testdata/BasicTestEntity.java +++ b/src/test/java/com/arangodb/springframework/core/mapping/testdata/BasicTestEntity.java @@ -30,6 +30,7 @@ * @author Mark Vollmary * */ +@SuppressWarnings("deprecation") @Document public class BasicTestEntity { diff --git a/src/test/java/com/arangodb/springframework/core/template/ArangoTemplateTest.java b/src/test/java/com/arangodb/springframework/core/template/ArangoTemplateTest.java index 559ea2427..7a548979d 100644 --- a/src/test/java/com/arangodb/springframework/core/template/ArangoTemplateTest.java +++ b/src/test/java/com/arangodb/springframework/core/template/ArangoTemplateTest.java @@ -1,409 +1,408 @@ -/* - * DISCLAIMER - * - * Copyright 2017 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.springframework.core.template; - -import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.StreamSupport; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.Transient; -import org.springframework.data.domain.Persistable; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import com.arangodb.ArangoCursor; -import com.arangodb.entity.ArangoDBVersion; -import com.arangodb.entity.BaseDocument; -import com.arangodb.entity.DocumentEntity; -import com.arangodb.entity.MultiDocumentEntity; -import com.arangodb.model.AqlQueryOptions; -import com.arangodb.springframework.AbstractArangoTest; -import com.arangodb.springframework.ArangoTestConfiguration; -import com.arangodb.springframework.annotation.Key; -import com.arangodb.springframework.core.ArangoOperations.UpsertStrategy; -import com.arangodb.springframework.testdata.Address; -import com.arangodb.springframework.testdata.Customer; -import com.arangodb.springframework.testdata.Product; -import com.arangodb.util.MapBuilder; -import com.arangodb.velocypack.VPackSlice; - -/** - * @author Mark Vollmary - * - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { ArangoTestConfiguration.class }) -public class ArangoTemplateTest extends AbstractArangoTest { - - @Test - public void template() { - final ArangoDBVersion version = template.getVersion(); - assertThat(version, is(notNullValue())); - assertThat(version.getLicense(), is(notNullValue())); - assertThat(version.getServer(), is(notNullValue())); - assertThat(version.getVersion(), is(notNullValue())); - } - - @Test - public void insertDocument() { - final DocumentEntity res = template.insert(new Customer("John", "Doe", 30)); - assertThat(res, is(notNullValue())); - assertThat(res.getId(), is(notNullValue())); - } - - @Test - public void insertDocuments() { - final Customer c1 = new Customer(); - final Customer c2 = new Customer(); - final Customer c3 = new Customer(); - c3.setKey("3"); - final Customer c4 = new Customer(); - c4.setKey("3"); - final MultiDocumentEntity res = template.insert(Arrays.asList(c1, c2, c3, c4), - Customer.class); - assertThat(res, is(notNullValue())); - assertThat(res.getDocuments().size(), is(3)); - assertThat(res.getErrors().size(), is(1)); - assertThat(c1.getId(), is(notNullValue())); - assertThat(c2.getId(), is(notNullValue())); - assertThat(c3.getId(), is(notNullValue())); - } - - @Test - public void insertDocumentWithCollName() { - final DocumentEntity res = template.insert("customer", new Customer("John", "Doe", 30)); - assertThat(res, is(notNullValue())); - assertThat(res.getId(), is(notNullValue())); - } - - @Test - public void upsertReplace() { - final Customer customer = new Customer("John", "Doe", 30); - template.upsert(customer, UpsertStrategy.REPLACE); - assertThat(template.find(customer.getId(), Customer.class).get().getAge(), is(30)); - customer.setAge(35); - template.upsert(customer, UpsertStrategy.REPLACE); - assertThat(template.find(customer.getId(), Customer.class).get().getAge(), is(35)); - } - - @Test - public void upsertUpdate() { - final Customer customer = new Customer("John", "Doe", 30); - template.upsert(customer, UpsertStrategy.UPDATE); - assertThat(template.find(customer.getId(), Customer.class).get().getAge(), is(30)); - customer.setAge(35); - template.upsert(customer, UpsertStrategy.UPDATE); - assertThat(template.find(customer.getId(), Customer.class).get().getAge(), is(35)); - } - - @Test - public void upsertReplaceMultiple() { - final Customer c1 = new Customer("John", "Doe", 30); - final Customer c2 = new Customer("John2", "Doe2", 30); - template.upsert(Arrays.asList(c1, c2), UpsertStrategy.REPLACE); - assertThat(template.find(c1.getId(), Customer.class).get().getAge(), is(30)); - assertThat(template.find(c2.getId(), Customer.class).get().getAge(), is(30)); - c1.setAge(35); - c2.setAge(35); - final Customer c3 = new Customer("John3", "Doe2", 30); - template.upsert(Arrays.asList(c1, c2, c3), UpsertStrategy.REPLACE); - assertThat(template.find(c1.getId(), Customer.class).get().getAge(), is(35)); - assertThat(template.find(c2.getId(), Customer.class).get().getAge(), is(35)); - assertThat(template.find(c3.getId(), Customer.class).get().getAge(), is(30)); - } - - @Test - public void upsertUpdateMultiple() { - final Customer c1 = new Customer("John", "Doe", 30); - final Customer c2 = new Customer("John2", "Doe2", 30); - template.upsert(Arrays.asList(c1, c2), UpsertStrategy.UPDATE); - assertThat(template.find(c1.getId(), Customer.class).get().getAge(), is(30)); - assertThat(template.find(c2.getId(), Customer.class).get().getAge(), is(30)); - c1.setAge(35); - c2.setAge(35); - final Customer c3 = new Customer("John3", "Doe2", 30); - template.upsert(Arrays.asList(c1, c2, c3), UpsertStrategy.UPDATE); - assertThat(template.find(c1.getId(), Customer.class).get().getAge(), is(35)); - assertThat(template.find(c2.getId(), Customer.class).get().getAge(), is(35)); - assertThat(template.find(c3.getId(), Customer.class).get().getAge(), is(30)); - } - - @Test - public void getDocument() { - final DocumentEntity res = template.insert(new Customer("John", "Doe", 30, new Address("22162–1010"))); - final Customer customer = template.find(res.getId(), Customer.class).get(); - assertThat(customer, is(notNullValue())); - assertThat(customer.getName(), is("John")); - assertThat(customer.getSurname(), is("Doe")); - assertThat(customer.getAge(), is(30)); - assertThat(customer.getAddress(), is(notNullValue())); - assertThat(customer.getAddress().getZipCode(), is("22162–1010")); - } - - @Test - public void getDocuments() { - final Customer c1 = new Customer("John", "Doe", 30); - final Customer c2 = new Customer("John2", "Doe", 30); - template.insert(Arrays.asList(c1, c2), Customer.class); - final Iterable customers = template.find(Arrays.asList(c1.getId(), c2.getId()), Customer.class); - assertThat(customers, is(notNullValue())); - assertThat( - StreamSupport.stream(customers.spliterator(), false).map((e) -> e.getId()).collect(Collectors.toList()), - hasItems(c1.getId(), c2.getId())); - } - - @Test - public void getAllDocuments() { - final Customer c1 = new Customer("John", "Doe", 30); - final Customer c2 = new Customer("John2", "Doe", 30); - template.insert(Arrays.asList(c1, c2), Customer.class); - final Iterable customers = template.findAll(Customer.class); - assertThat(customers, is(notNullValue())); - assertThat( - StreamSupport.stream(customers.spliterator(), false).map((e) -> e.getId()).collect(Collectors.toList()), - hasItems(c1.getId(), c2.getId())); - } - - @Test - public void replaceDocument() { - final DocumentEntity res = template.insert(new Customer("John", "Doe", 30)); - final DocumentEntity replaceDocument = template.replace(res.getId(), new Customer("Jane", "Doe", 26)); - assertThat(replaceDocument, is(notNullValue())); - final Customer customer = template.find(res.getId(), Customer.class).get(); - assertThat(customer, is(notNullValue())); - assertThat(customer.getName(), is("Jane")); - assertThat(customer.getSurname(), is("Doe")); - assertThat(customer.getAge(), is(26)); - } - - @Test - public void replaceDocuments() { - final DocumentEntity a = template.insert(new Product("a")); - final DocumentEntity b = template.insert(new Product("b")); - - final Product documentA = template.find(a.getId(), Product.class).get(); - documentA.setName("aa"); - final Product documentB = template.find(b.getId(), Product.class).get(); - documentB.setName("bb"); - - final MultiDocumentEntity res = template.replace(Arrays.asList(documentA, documentB), - Product.class); - assertThat(res, is(notNullValue())); - assertThat(res.getDocuments().size(), is(2)); - - final Product newA = template.find(a.getId(), Product.class).get(); - assertThat(newA.getName(), is("aa")); - final Product newB = template.find(b.getId(), Product.class).get(); - assertThat(newB.getName(), is("bb")); - } - - @Test - public void updateDocument() { - final DocumentEntity res = template.insert(new Customer("John", "Doe", 30)); - template.update(res.getId(), new Customer("Jane", "Doe", 26)); - final Customer customer = template.find(res.getId(), Customer.class).get(); - assertThat(customer, is(notNullValue())); - assertThat(customer.getName(), is("Jane")); - assertThat(customer.getSurname(), is("Doe")); - assertThat(customer.getAge(), is(26)); - } - - @Test - public void updateDocuments() { - final DocumentEntity a = template.insert(new Product("a")); - final DocumentEntity b = template.insert(new Product("b")); - - final Product documentA = template.find(a.getId(), Product.class).get(); - documentA.setName("aa"); - final Product documentB = template.find(b.getId(), Product.class).get(); - documentB.setName("bb"); - - final MultiDocumentEntity res = template.update(Arrays.asList(documentA, documentB), - Product.class); - assertThat(res, is(notNullValue())); - assertThat(res.getDocuments().size(), is(2)); - - final Product newA = template.find(a.getId(), Product.class).get(); - assertThat(newA.getName(), is("aa")); - final Product newB = template.find(b.getId(), Product.class).get(); - assertThat(newB.getName(), is("bb")); - } - - @Test - public void deleteDocument() { - final DocumentEntity res = template.insert(new Customer("John", "Doe", 30)); - template.delete(res.getId(), Customer.class); - final Optional customer = template.find(res.getId(), Customer.class); - assertThat(customer.isPresent(), is(false)); - } - - @Test - public void deleteDocuments() { - final DocumentEntity a = template.insert(new Product("a")); - final DocumentEntity b = template.insert(new Product("b")); - - final Product documentA = template.find(a.getId(), Product.class).get(); - final Product documentB = template.find(b.getId(), Product.class).get(); - - final MultiDocumentEntity res = template.delete(Arrays.asList(documentA, documentB), - Product.class); - assertThat(res, is(notNullValue())); - assertThat(res.getDocuments().size(), is(2)); - - final Optional deletedA = template.find(a.getId(), Product.class); - assertThat(deletedA.isPresent(), is(false)); - final Optional deletedB = template.find(b.getId(), Product.class); - assertThat(deletedB.isPresent(), is(false)); - } - - @Test - public void query() { - template.insert(new Customer("John", "Doe", 30)); - final ArangoCursor cursor = template.query("FOR c IN @@coll FILTER c.name == @name RETURN c", - new MapBuilder().put("@coll", "customer").put("name", "John").get(), new AqlQueryOptions(), Customer.class); - assertThat(cursor, is(notNullValue())); - final List customers = cursor.asListRemaining(); - assertThat(customers.size(), is(1)); - assertThat(customers.get(0).getName(), is("John")); - assertThat(customers.get(0).getSurname(), is("Doe")); - assertThat(customers.get(0).getAge(), is(30)); - } - - @Test - public void queryWithoutBindParams() { - template.insert(new Customer("John", "Doe", 30)); - final ArangoCursor cursor = template.query("FOR c IN customer FILTER c.name == 'John' RETURN c", null, - new AqlQueryOptions(), Customer.class); - assertThat(cursor, is(notNullValue())); - final List customers = cursor.asListRemaining(); - assertThat(customers.size(), is(1)); - assertThat(customers.get(0).getName(), is("John")); - assertThat(customers.get(0).getSurname(), is("Doe")); - assertThat(customers.get(0).getAge(), is(30)); - } - - @SuppressWarnings("rawtypes") - @Test - public void queryMap() { - template.insert(new Customer("John", "Doe", 30)); - final ArangoCursor cursor = template.query("FOR c IN @@coll FILTER c.name == @name RETURN c", - new MapBuilder().put("@coll", "customer").put("name", "John").get(), new AqlQueryOptions(), Map.class); - assertThat(cursor, is(notNullValue())); - final List customers = cursor.asListRemaining(); - assertThat(customers.size(), is(1)); - assertThat(customers.get(0).get("name"), is("John")); - assertThat(customers.get(0).get("surname"), is("Doe")); - assertThat(customers.get(0).get("age"), is(30L)); - } - - @Test - public void queryBaseDocument() { - template.insert(new Customer("John", "Doe", 30)); - final ArangoCursor cursor = template.query("FOR c IN @@coll FILTER c.name == @name RETURN c", - new MapBuilder().put("@coll", "customer").put("name", "John").get(), new AqlQueryOptions(), - BaseDocument.class); - assertThat(cursor, is(notNullValue())); - final List customers = cursor.asListRemaining(); - assertThat(customers.size(), is(1)); - assertThat(customers.get(0).getAttribute("name"), is("John")); - assertThat(customers.get(0).getAttribute("surname"), is("Doe")); - assertThat(customers.get(0).getAttribute("age"), is(30L)); - } - - @Test - public void queryVPackSlice() { - template.insert(new Customer("John", "Doe", 30)); - final ArangoCursor cursor = template.query("FOR c IN @@coll FILTER c.name == @name RETURN c", - new MapBuilder().put("@coll", "customer").put("name", "John").get(), new AqlQueryOptions(), - VPackSlice.class); - assertThat(cursor, is(notNullValue())); - final List customers = cursor.asListRemaining(); - assertThat(customers.size(), is(1)); - assertThat(customers.get(0).get("name").getAsString(), is("John")); - assertThat(customers.get(0).get("surname").getAsString(), is("Doe")); - assertThat(customers.get(0).get("age").getAsInt(), is(30)); - } - - public static class NewEntityTest implements Persistable { - - @Id - private String id; - @Key - private final String key; - @Transient - private transient boolean persisted; - - public NewEntityTest(final String key) { - super(); - this.key = key; - } - - public void setPersisted(final boolean persisted) { - this.persisted = persisted; - } - - @Override - public boolean isNew() { - return !persisted; - } - - @Override - public String getId() { - return key; - } - } - - @SuppressWarnings("deprecation") - @Test - public void upsertWithUserGeneratedKey() { - final NewEntityTest entity = new NewEntityTest("test"); - template.upsert(entity, UpsertStrategy.REPLACE); - assertThat(template.collection(NewEntityTest.class).count(), is(1L)); - entity.setPersisted(true); - template.upsert(entity, UpsertStrategy.REPLACE); - assertThat(template.collection(NewEntityTest.class).count(), is(1L)); - } - - @SuppressWarnings("deprecation") - @Test - public void mutliUpsertWithUserGeneratedKey() { - final NewEntityTest entity1 = new NewEntityTest("test1"); - final NewEntityTest entity2 = new NewEntityTest("test2"); - template.upsert(Arrays.asList(entity1, entity2), UpsertStrategy.REPLACE); - assertThat(template.collection(NewEntityTest.class).count(), is(2L)); - entity1.setPersisted(true); - entity2.setPersisted(true); - template.upsert(Arrays.asList(entity1, entity2), UpsertStrategy.REPLACE); - assertThat(template.collection(NewEntityTest.class).count(), is(2L)); - } - -} +/* + * DISCLAIMER + * + * Copyright 2017 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.springframework.core.template; + +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertThat; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.data.annotation.Id; +import org.springframework.data.annotation.Transient; +import org.springframework.data.domain.Persistable; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.arangodb.ArangoCursor; +import com.arangodb.entity.ArangoDBVersion; +import com.arangodb.entity.BaseDocument; +import com.arangodb.entity.DocumentEntity; +import com.arangodb.entity.MultiDocumentEntity; +import com.arangodb.model.AqlQueryOptions; +import com.arangodb.springframework.AbstractArangoTest; +import com.arangodb.springframework.ArangoTestConfiguration; +import com.arangodb.springframework.annotation.Key; +import com.arangodb.springframework.core.ArangoOperations.UpsertStrategy; +import com.arangodb.springframework.testdata.Address; +import com.arangodb.springframework.testdata.Customer; +import com.arangodb.springframework.testdata.Product; +import com.arangodb.util.MapBuilder; +import com.arangodb.velocypack.VPackSlice; + +/** + * @author Mark Vollmary + * + */ +@SuppressWarnings("deprecation") +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { ArangoTestConfiguration.class }) +public class ArangoTemplateTest extends AbstractArangoTest { + + @Test + public void template() { + final ArangoDBVersion version = template.getVersion(); + assertThat(version, is(notNullValue())); + assertThat(version.getLicense(), is(notNullValue())); + assertThat(version.getServer(), is(notNullValue())); + assertThat(version.getVersion(), is(notNullValue())); + } + + @Test + public void insertDocument() { + final DocumentEntity res = template.insert(new Customer("John", "Doe", 30)); + assertThat(res, is(notNullValue())); + assertThat(res.getId(), is(notNullValue())); + } + + @Test + public void insertDocuments() { + final Customer c1 = new Customer(); + final Customer c2 = new Customer(); + final Customer c3 = new Customer(); + c3.setKey("3"); + final Customer c4 = new Customer(); + c4.setKey("3"); + final MultiDocumentEntity res = template.insert(Arrays.asList(c1, c2, c3, c4), + Customer.class); + assertThat(res, is(notNullValue())); + assertThat(res.getDocuments().size(), is(3)); + assertThat(res.getErrors().size(), is(1)); + assertThat(c1.getId(), is(notNullValue())); + assertThat(c2.getId(), is(notNullValue())); + assertThat(c3.getId(), is(notNullValue())); + } + + @Test + public void insertDocumentWithCollName() { + final DocumentEntity res = template.insert("customer", new Customer("John", "Doe", 30)); + assertThat(res, is(notNullValue())); + assertThat(res.getId(), is(notNullValue())); + } + + @Test + public void upsertReplace() { + final Customer customer = new Customer("John", "Doe", 30); + template.upsert(customer, UpsertStrategy.REPLACE); + assertThat(template.find(customer.getId(), Customer.class).get().getAge(), is(30)); + customer.setAge(35); + template.upsert(customer, UpsertStrategy.REPLACE); + assertThat(template.find(customer.getId(), Customer.class).get().getAge(), is(35)); + } + + @Test + public void upsertUpdate() { + final Customer customer = new Customer("John", "Doe", 30); + template.upsert(customer, UpsertStrategy.UPDATE); + assertThat(template.find(customer.getId(), Customer.class).get().getAge(), is(30)); + customer.setAge(35); + template.upsert(customer, UpsertStrategy.UPDATE); + assertThat(template.find(customer.getId(), Customer.class).get().getAge(), is(35)); + } + + @Test + public void upsertReplaceMultiple() { + final Customer c1 = new Customer("John", "Doe", 30); + final Customer c2 = new Customer("John2", "Doe2", 30); + template.upsert(Arrays.asList(c1, c2), UpsertStrategy.REPLACE); + assertThat(template.find(c1.getId(), Customer.class).get().getAge(), is(30)); + assertThat(template.find(c2.getId(), Customer.class).get().getAge(), is(30)); + c1.setAge(35); + c2.setAge(35); + final Customer c3 = new Customer("John3", "Doe2", 30); + template.upsert(Arrays.asList(c1, c2, c3), UpsertStrategy.REPLACE); + assertThat(template.find(c1.getId(), Customer.class).get().getAge(), is(35)); + assertThat(template.find(c2.getId(), Customer.class).get().getAge(), is(35)); + assertThat(template.find(c3.getId(), Customer.class).get().getAge(), is(30)); + } + + @Test + public void upsertUpdateMultiple() { + final Customer c1 = new Customer("John", "Doe", 30); + final Customer c2 = new Customer("John2", "Doe2", 30); + template.upsert(Arrays.asList(c1, c2), UpsertStrategy.UPDATE); + assertThat(template.find(c1.getId(), Customer.class).get().getAge(), is(30)); + assertThat(template.find(c2.getId(), Customer.class).get().getAge(), is(30)); + c1.setAge(35); + c2.setAge(35); + final Customer c3 = new Customer("John3", "Doe2", 30); + template.upsert(Arrays.asList(c1, c2, c3), UpsertStrategy.UPDATE); + assertThat(template.find(c1.getId(), Customer.class).get().getAge(), is(35)); + assertThat(template.find(c2.getId(), Customer.class).get().getAge(), is(35)); + assertThat(template.find(c3.getId(), Customer.class).get().getAge(), is(30)); + } + + @Test + public void getDocument() { + final DocumentEntity res = template.insert(new Customer("John", "Doe", 30, new Address("22162–1010"))); + final Customer customer = template.find(res.getId(), Customer.class).get(); + assertThat(customer, is(notNullValue())); + assertThat(customer.getName(), is("John")); + assertThat(customer.getSurname(), is("Doe")); + assertThat(customer.getAge(), is(30)); + assertThat(customer.getAddress(), is(notNullValue())); + assertThat(customer.getAddress().getZipCode(), is("22162–1010")); + } + + @Test + public void getDocuments() { + final Customer c1 = new Customer("John", "Doe", 30); + final Customer c2 = new Customer("John2", "Doe", 30); + template.insert(Arrays.asList(c1, c2), Customer.class); + final Iterable customers = template.find(Arrays.asList(c1.getId(), c2.getId()), Customer.class); + assertThat(customers, is(notNullValue())); + assertThat( + StreamSupport.stream(customers.spliterator(), false).map((e) -> e.getId()).collect(Collectors.toList()), + hasItems(c1.getId(), c2.getId())); + } + + @Test + public void getAllDocuments() { + final Customer c1 = new Customer("John", "Doe", 30); + final Customer c2 = new Customer("John2", "Doe", 30); + template.insert(Arrays.asList(c1, c2), Customer.class); + final Iterable customers = template.findAll(Customer.class); + assertThat(customers, is(notNullValue())); + assertThat( + StreamSupport.stream(customers.spliterator(), false).map((e) -> e.getId()).collect(Collectors.toList()), + hasItems(c1.getId(), c2.getId())); + } + + @Test + public void replaceDocument() { + final DocumentEntity res = template.insert(new Customer("John", "Doe", 30)); + final DocumentEntity replaceDocument = template.replace(res.getId(), new Customer("Jane", "Doe", 26)); + assertThat(replaceDocument, is(notNullValue())); + final Customer customer = template.find(res.getId(), Customer.class).get(); + assertThat(customer, is(notNullValue())); + assertThat(customer.getName(), is("Jane")); + assertThat(customer.getSurname(), is("Doe")); + assertThat(customer.getAge(), is(26)); + } + + @Test + public void replaceDocuments() { + final DocumentEntity a = template.insert(new Product("a")); + final DocumentEntity b = template.insert(new Product("b")); + + final Product documentA = template.find(a.getId(), Product.class).get(); + documentA.setName("aa"); + final Product documentB = template.find(b.getId(), Product.class).get(); + documentB.setName("bb"); + + final MultiDocumentEntity res = template.replace(Arrays.asList(documentA, documentB), + Product.class); + assertThat(res, is(notNullValue())); + assertThat(res.getDocuments().size(), is(2)); + + final Product newA = template.find(a.getId(), Product.class).get(); + assertThat(newA.getName(), is("aa")); + final Product newB = template.find(b.getId(), Product.class).get(); + assertThat(newB.getName(), is("bb")); + } + + @Test + public void updateDocument() { + final DocumentEntity res = template.insert(new Customer("John", "Doe", 30)); + template.update(res.getId(), new Customer("Jane", "Doe", 26)); + final Customer customer = template.find(res.getId(), Customer.class).get(); + assertThat(customer, is(notNullValue())); + assertThat(customer.getName(), is("Jane")); + assertThat(customer.getSurname(), is("Doe")); + assertThat(customer.getAge(), is(26)); + } + + @Test + public void updateDocuments() { + final DocumentEntity a = template.insert(new Product("a")); + final DocumentEntity b = template.insert(new Product("b")); + + final Product documentA = template.find(a.getId(), Product.class).get(); + documentA.setName("aa"); + final Product documentB = template.find(b.getId(), Product.class).get(); + documentB.setName("bb"); + + final MultiDocumentEntity res = template.update(Arrays.asList(documentA, documentB), + Product.class); + assertThat(res, is(notNullValue())); + assertThat(res.getDocuments().size(), is(2)); + + final Product newA = template.find(a.getId(), Product.class).get(); + assertThat(newA.getName(), is("aa")); + final Product newB = template.find(b.getId(), Product.class).get(); + assertThat(newB.getName(), is("bb")); + } + + @Test + public void deleteDocument() { + final DocumentEntity res = template.insert(new Customer("John", "Doe", 30)); + template.delete(res.getId(), Customer.class); + final Optional customer = template.find(res.getId(), Customer.class); + assertThat(customer.isPresent(), is(false)); + } + + @Test + public void deleteDocuments() { + final DocumentEntity a = template.insert(new Product("a")); + final DocumentEntity b = template.insert(new Product("b")); + + final Product documentA = template.find(a.getId(), Product.class).get(); + final Product documentB = template.find(b.getId(), Product.class).get(); + + final MultiDocumentEntity res = template.delete(Arrays.asList(documentA, documentB), + Product.class); + assertThat(res, is(notNullValue())); + assertThat(res.getDocuments().size(), is(2)); + + final Optional deletedA = template.find(a.getId(), Product.class); + assertThat(deletedA.isPresent(), is(false)); + final Optional deletedB = template.find(b.getId(), Product.class); + assertThat(deletedB.isPresent(), is(false)); + } + + @Test + public void query() { + template.insert(new Customer("John", "Doe", 30)); + final ArangoCursor cursor = template.query("FOR c IN @@coll FILTER c.name == @name RETURN c", + new MapBuilder().put("@coll", "customer").put("name", "John").get(), new AqlQueryOptions(), Customer.class); + assertThat(cursor, is(notNullValue())); + final List customers = cursor.asListRemaining(); + assertThat(customers.size(), is(1)); + assertThat(customers.get(0).getName(), is("John")); + assertThat(customers.get(0).getSurname(), is("Doe")); + assertThat(customers.get(0).getAge(), is(30)); + } + + @Test + public void queryWithoutBindParams() { + template.insert(new Customer("John", "Doe", 30)); + final ArangoCursor cursor = template.query("FOR c IN customer FILTER c.name == 'John' RETURN c", null, + new AqlQueryOptions(), Customer.class); + assertThat(cursor, is(notNullValue())); + final List customers = cursor.asListRemaining(); + assertThat(customers.size(), is(1)); + assertThat(customers.get(0).getName(), is("John")); + assertThat(customers.get(0).getSurname(), is("Doe")); + assertThat(customers.get(0).getAge(), is(30)); + } + + @SuppressWarnings("rawtypes") + @Test + public void queryMap() { + template.insert(new Customer("John", "Doe", 30)); + final ArangoCursor cursor = template.query("FOR c IN @@coll FILTER c.name == @name RETURN c", + new MapBuilder().put("@coll", "customer").put("name", "John").get(), new AqlQueryOptions(), Map.class); + assertThat(cursor, is(notNullValue())); + final List customers = cursor.asListRemaining(); + assertThat(customers.size(), is(1)); + assertThat(customers.get(0).get("name"), is("John")); + assertThat(customers.get(0).get("surname"), is("Doe")); + assertThat(customers.get(0).get("age"), is(30L)); + } + + @Test + public void queryBaseDocument() { + template.insert(new Customer("John", "Doe", 30)); + final ArangoCursor cursor = template.query("FOR c IN @@coll FILTER c.name == @name RETURN c", + new MapBuilder().put("@coll", "customer").put("name", "John").get(), new AqlQueryOptions(), + BaseDocument.class); + assertThat(cursor, is(notNullValue())); + final List customers = cursor.asListRemaining(); + assertThat(customers.size(), is(1)); + assertThat(customers.get(0).getAttribute("name"), is("John")); + assertThat(customers.get(0).getAttribute("surname"), is("Doe")); + assertThat(customers.get(0).getAttribute("age"), is(30L)); + } + + @Test + public void queryVPackSlice() { + template.insert(new Customer("John", "Doe", 30)); + final ArangoCursor cursor = template.query("FOR c IN @@coll FILTER c.name == @name RETURN c", + new MapBuilder().put("@coll", "customer").put("name", "John").get(), new AqlQueryOptions(), + VPackSlice.class); + assertThat(cursor, is(notNullValue())); + final List customers = cursor.asListRemaining(); + assertThat(customers.size(), is(1)); + assertThat(customers.get(0).get("name").getAsString(), is("John")); + assertThat(customers.get(0).get("surname").getAsString(), is("Doe")); + assertThat(customers.get(0).get("age").getAsInt(), is(30)); + } + + public static class NewEntityTest implements Persistable { + + @Id + private String id; + @Key + private final String key; + @Transient + private transient boolean persisted; + + public NewEntityTest(final String key) { + super(); + this.key = key; + } + + public void setPersisted(final boolean persisted) { + this.persisted = persisted; + } + + @Override + public boolean isNew() { + return !persisted; + } + + @Override + public String getId() { + return key; + } + } + + @Test + public void upsertWithUserGeneratedKey() { + final NewEntityTest entity = new NewEntityTest("test"); + template.upsert(entity, UpsertStrategy.REPLACE); + assertThat(template.collection(NewEntityTest.class).count(), is(1L)); + entity.setPersisted(true); + template.upsert(entity, UpsertStrategy.REPLACE); + assertThat(template.collection(NewEntityTest.class).count(), is(1L)); + } + + @Test + public void mutliUpsertWithUserGeneratedKey() { + final NewEntityTest entity1 = new NewEntityTest("test1"); + final NewEntityTest entity2 = new NewEntityTest("test2"); + template.upsert(Arrays.asList(entity1, entity2), UpsertStrategy.REPLACE); + assertThat(template.collection(NewEntityTest.class).count(), is(2L)); + entity1.setPersisted(true); + entity2.setPersisted(true); + template.upsert(Arrays.asList(entity1, entity2), UpsertStrategy.REPLACE); + assertThat(template.collection(NewEntityTest.class).count(), is(2L)); + } + +} diff --git a/src/test/java/com/arangodb/springframework/testdata/Customer.java b/src/test/java/com/arangodb/springframework/testdata/Customer.java index 28c12cf94..b8979f080 100644 --- a/src/test/java/com/arangodb/springframework/testdata/Customer.java +++ b/src/test/java/com/arangodb/springframework/testdata/Customer.java @@ -1,247 +1,248 @@ -/* - * DISCLAIMER - * - * Copyright 2017 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.springframework.testdata; - -import java.util.Collection; - -import org.springframework.data.annotation.Id; - -import com.arangodb.springframework.annotation.Document; -import com.arangodb.springframework.annotation.GeoIndexed; -import com.arangodb.springframework.annotation.Key; -import com.arangodb.springframework.annotation.Ref; -import com.arangodb.springframework.annotation.Relations; -import com.arangodb.springframework.annotation.Rev; - -/** - * @author Mark Vollmary - * - */ -@Document -public class Customer { - - @Id - private String id; - @Key - private String key; - @Rev - private String rev; - private String name; - private String surname; - private int age; - private Address address; - - private boolean alive; - @GeoIndexed - private int[] location; - private Iterable integerList; - private String[] stringArray; - private Iterable stringList; - private Customer nestedCustomer; - private Iterable nestedCustomers; - - @Ref - private ShoppingCart shoppingCart; - @Relations(edges = { Owns.class }) - private Collection owns; - - public Customer() { - super(); - } - - public Customer(final String name, final String surname, final int age) { - super(); - this.name = name; - this.surname = surname; - this.age = age; - } - - public Customer(final String name, final String surname, final int age, final boolean alive) { - super(); - this.name = name; - this.surname = surname; - this.age = age; - this.alive = alive; - } - - public Customer(final String name, final String surname, final int age, final Address address) { - super(); - this.name = name; - this.surname = surname; - this.age = age; - this.address = address; - } - - public String getId() { - return id; - } - - public void setId(final String id) { - this.id = id; - } - - public String getKey() { - return key; - } - - public void setKey(final String key) { - this.key = key; - } - - public String getRev() { - return rev; - } - - public void setRev(final String rev) { - this.rev = rev; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - public String getSurname() { - return surname; - } - - public void setSurname(final String surname) { - this.surname = surname; - } - - public int getAge() { - return age; - } - - public void setAge(final int age) { - this.age = age; - } - - public Address getAddress() { - return address; - } - - public void setAddress(final Address address) { - this.address = address; - } - - public ShoppingCart getShoppingCart() { - return shoppingCart; - } - - public void setShoppingCart(final ShoppingCart shoppingCart) { - this.shoppingCart = shoppingCart; - } - - public Collection getOwns() { - return owns; - } - - public void setOwns(final Collection owns) { - this.owns = owns; - } - - public boolean isAlive() { - return alive; - } - - public void setAlive(final boolean alive) { - this.alive = alive; - } - - public int[] getLocation() { - return location; - } - - public void setLocation(final int[] location) { - this.location = location; - } - - public Iterable getIntegerList() { - return integerList; - } - - public void setIntegerList(final Iterable integerList) { - this.integerList = integerList; - } - - public String[] getStringArray() { - return stringArray; - } - - public void setStringArray(final String[] stringArray) { - this.stringArray = stringArray; - } - - public void setStringList(final Iterable stringList) { - this.stringList = stringList; - } - - public Customer getNestedCustomer() { - return nestedCustomer; - } - - public void setNestedCustomer(final Customer nestedCustomer) { - this.nestedCustomer = nestedCustomer; - } - - public Iterable getNestedCustomers() { - return nestedCustomers; - } - - public void setNestedCustomers(final Iterable nestedCustomers) { - this.nestedCustomers = nestedCustomers; - } - - public Iterable getStringList() { - return stringList; - } - - @Override - public boolean equals(final Object o) { - if (!(o instanceof Customer)) { - return false; - } - final Customer customer = (Customer) o; - if (!customer.getId().equals(this.getId())) { - return false; - } - if (!customer.getName().equals(this.getName())) { - return false; - } - if (!customer.getSurname().equals(this.getSurname())) { - return false; - } - if (customer.getAge() != this.getAge()) { - return false; - } - return true; - } - - @Override - public String toString() { - return "Customer {id: " + id + ", name: " + name + ", surname: " + surname + ", age: " + age + "}"; - } - -} +/* + * DISCLAIMER + * + * Copyright 2017 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.springframework.testdata; + +import java.util.Collection; + +import org.springframework.data.annotation.Id; + +import com.arangodb.springframework.annotation.Document; +import com.arangodb.springframework.annotation.GeoIndexed; +import com.arangodb.springframework.annotation.Key; +import com.arangodb.springframework.annotation.Ref; +import com.arangodb.springframework.annotation.Relations; +import com.arangodb.springframework.annotation.Rev; + +/** + * @author Mark Vollmary + * + */ +@SuppressWarnings("deprecation") +@Document +public class Customer { + + @Id + private String id; + @Key + private String key; + @Rev + private String rev; + private String name; + private String surname; + private int age; + private Address address; + + private boolean alive; + @GeoIndexed + private int[] location; + private Iterable integerList; + private String[] stringArray; + private Iterable stringList; + private Customer nestedCustomer; + private Iterable nestedCustomers; + + @Ref + private ShoppingCart shoppingCart; + @Relations(edges = { Owns.class }) + private Collection owns; + + public Customer() { + super(); + } + + public Customer(final String name, final String surname, final int age) { + super(); + this.name = name; + this.surname = surname; + this.age = age; + } + + public Customer(final String name, final String surname, final int age, final boolean alive) { + super(); + this.name = name; + this.surname = surname; + this.age = age; + this.alive = alive; + } + + public Customer(final String name, final String surname, final int age, final Address address) { + super(); + this.name = name; + this.surname = surname; + this.age = age; + this.address = address; + } + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + public String getKey() { + return key; + } + + public void setKey(final String key) { + this.key = key; + } + + public String getRev() { + return rev; + } + + public void setRev(final String rev) { + this.rev = rev; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getSurname() { + return surname; + } + + public void setSurname(final String surname) { + this.surname = surname; + } + + public int getAge() { + return age; + } + + public void setAge(final int age) { + this.age = age; + } + + public Address getAddress() { + return address; + } + + public void setAddress(final Address address) { + this.address = address; + } + + public ShoppingCart getShoppingCart() { + return shoppingCart; + } + + public void setShoppingCart(final ShoppingCart shoppingCart) { + this.shoppingCart = shoppingCart; + } + + public Collection getOwns() { + return owns; + } + + public void setOwns(final Collection owns) { + this.owns = owns; + } + + public boolean isAlive() { + return alive; + } + + public void setAlive(final boolean alive) { + this.alive = alive; + } + + public int[] getLocation() { + return location; + } + + public void setLocation(final int[] location) { + this.location = location; + } + + public Iterable getIntegerList() { + return integerList; + } + + public void setIntegerList(final Iterable integerList) { + this.integerList = integerList; + } + + public String[] getStringArray() { + return stringArray; + } + + public void setStringArray(final String[] stringArray) { + this.stringArray = stringArray; + } + + public void setStringList(final Iterable stringList) { + this.stringList = stringList; + } + + public Customer getNestedCustomer() { + return nestedCustomer; + } + + public void setNestedCustomer(final Customer nestedCustomer) { + this.nestedCustomer = nestedCustomer; + } + + public Iterable getNestedCustomers() { + return nestedCustomers; + } + + public void setNestedCustomers(final Iterable nestedCustomers) { + this.nestedCustomers = nestedCustomers; + } + + public Iterable getStringList() { + return stringList; + } + + @Override + public boolean equals(final Object o) { + if (!(o instanceof Customer)) { + return false; + } + final Customer customer = (Customer) o; + if (!customer.getId().equals(this.getId())) { + return false; + } + if (!customer.getName().equals(this.getName())) { + return false; + } + if (!customer.getSurname().equals(this.getSurname())) { + return false; + } + if (customer.getAge() != this.getAge()) { + return false; + } + return true; + } + + @Override + public String toString() { + return "Customer {id: " + id + ", name: " + name + ", surname: " + surname + ", age: " + age + "}"; + } + +} diff --git a/src/test/java/com/arangodb/springframework/testdata/IncompleteCustomer.java b/src/test/java/com/arangodb/springframework/testdata/IncompleteCustomer.java index 9a208ff4e..ae515a2f8 100644 --- a/src/test/java/com/arangodb/springframework/testdata/IncompleteCustomer.java +++ b/src/test/java/com/arangodb/springframework/testdata/IncompleteCustomer.java @@ -8,6 +8,7 @@ import com.arangodb.springframework.annotation.Key; import com.arangodb.springframework.annotation.Rev; +@SuppressWarnings("deprecation") @Document("customer") public class IncompleteCustomer { @Id diff --git a/src/test/java/com/arangodb/springframework/testdata/Material.java b/src/test/java/com/arangodb/springframework/testdata/Material.java index d7f0dbed7..2f78229a9 100644 --- a/src/test/java/com/arangodb/springframework/testdata/Material.java +++ b/src/test/java/com/arangodb/springframework/testdata/Material.java @@ -1,31 +1,33 @@ package com.arangodb.springframework.testdata; +import org.springframework.data.annotation.Id; + import com.arangodb.springframework.annotation.Key; import com.arangodb.springframework.annotation.Rev; -import org.springframework.data.annotation.Id; /** * Created by markmccormick on 24/08/2017. */ +@SuppressWarnings("deprecation") public class Material { - @Id - private String id; - @Key - private String key; - @Rev - private String rev; - private String name; + @Id + private String id; + @Key + private String key; + @Rev + private String rev; + private String name; - public Material(String name) { - this.name = name; - } + public Material(final String name) { + this.name = name; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(final String name) { + this.name = name; + } } diff --git a/src/test/java/com/arangodb/springframework/testdata/Product.java b/src/test/java/com/arangodb/springframework/testdata/Product.java index a81bd9daa..d1aaff4e8 100644 --- a/src/test/java/com/arangodb/springframework/testdata/Product.java +++ b/src/test/java/com/arangodb/springframework/testdata/Product.java @@ -1,132 +1,133 @@ -/* - * DISCLAIMER - * - * Copyright 2017 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.springframework.testdata; - -import org.springframework.data.annotation.Id; - -import com.arangodb.springframework.annotation.Field; -import com.arangodb.springframework.annotation.GeoIndex; -import com.arangodb.springframework.annotation.Key; -import com.arangodb.springframework.annotation.Relations; -import com.arangodb.springframework.annotation.Rev; - -/** - * @author Mark Vollmary - * - */ -@GeoIndex(fields = { "location" }) -public class Product { - - @Id - private String id; - @Key - private String key; - @Rev - private String rev; - private String name; - @Field("description") - private String desc; - private double[] location; - - private Product nested; - - @Relations(edges = { Contains.class }) - private Material contains; - - public Product() { - super(); - } - - public Product(final String name) { - super(); - this.name = name; - } - - public Product(final String name, final double[] location) { - this(name); - this.location = location; - } - - public String getId() { - return id; - } - - public void setId(final String id) { - this.id = id; - } - - public String getKey() { - return key; - } - - public void setKey(final String key) { - this.key = key; - } - - public String getRev() { - return rev; - } - - public void setRev(final String rev) { - this.rev = rev; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - public String getDesc() { - return desc; - } - - public void setDesc(final String desc) { - this.desc = desc; - } - - public Material getContains() { - return contains; - } - - public void setContains(final Material contains) { - this.contains = contains; - } - - public double[] getLocation() { - return location; - } - - public void setLocation(final double[] location) { - this.location = location; - } - - public Product getNested() { - return nested; - } - - public void setNested(final Product nested) { - this.nested = nested; - } - -} +/* + * DISCLAIMER + * + * Copyright 2017 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.springframework.testdata; + +import org.springframework.data.annotation.Id; + +import com.arangodb.springframework.annotation.Field; +import com.arangodb.springframework.annotation.GeoIndex; +import com.arangodb.springframework.annotation.Key; +import com.arangodb.springframework.annotation.Relations; +import com.arangodb.springframework.annotation.Rev; + +/** + * @author Mark Vollmary + * + */ +@SuppressWarnings("deprecation") +@GeoIndex(fields = { "location" }) +public class Product { + + @Id + private String id; + @Key + private String key; + @Rev + private String rev; + private String name; + @Field("description") + private String desc; + private double[] location; + + private Product nested; + + @Relations(edges = { Contains.class }) + private Material contains; + + public Product() { + super(); + } + + public Product(final String name) { + super(); + this.name = name; + } + + public Product(final String name, final double[] location) { + this(name); + this.location = location; + } + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + public String getKey() { + return key; + } + + public void setKey(final String key) { + this.key = key; + } + + public String getRev() { + return rev; + } + + public void setRev(final String rev) { + this.rev = rev; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getDesc() { + return desc; + } + + public void setDesc(final String desc) { + this.desc = desc; + } + + public Material getContains() { + return contains; + } + + public void setContains(final Material contains) { + this.contains = contains; + } + + public double[] getLocation() { + return location; + } + + public void setLocation(final double[] location) { + this.location = location; + } + + public Product getNested() { + return nested; + } + + public void setNested(final Product nested) { + this.nested = nested; + } + +} From 4a94398dc2c87d798f04806e1fe7997822a6ec42 Mon Sep 17 00:00:00 2001 From: mpv1989 Date: Tue, 17 Jul 2018 11:17:21 +0200 Subject: [PATCH 05/14] Prepare snapshot --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6815f70c0..d0e4a3824 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.arangodb arangodb-spring-data - 2.2.2 + 2.3.0-SNAPSHOT 2017 jar From a2a3110a094cf4a0d468b84d5f3989028b72211f Mon Sep 17 00:00:00 2001 From: mpv1989 Date: Wed, 18 Jul 2018 15:26:16 +0200 Subject: [PATCH 06/14] Prepare release 2.3.0 --- ChangeLog.md | 2 ++ pom.xml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index e2adee442..5d5a66832 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [Unreleased] +## [2.3.0] - 2018-07-18 + ### Deprecated - deprecated `com.arangodb.springframework.annotation.Key` diff --git a/pom.xml b/pom.xml index d0e4a3824..da3bbe63c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.arangodb arangodb-spring-data - 2.3.0-SNAPSHOT + 2.3.0 2017 jar From 9c00fa963b9cf6fff3c86663de1e6d25aa022ec3 Mon Sep 17 00:00:00 2001 From: mpv1989 Date: Wed, 18 Jul 2018 15:47:57 +0200 Subject: [PATCH 07/14] Prepare snapshot --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index da3bbe63c..6b60630c3 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.arangodb arangodb-spring-data - 2.3.0 + 2.3.1-SNAPSHOT 2017 jar From 81ea1290689d0cbcda81e37aad4fed7b3a021054 Mon Sep 17 00:00:00 2001 From: mpv1989 Date: Fri, 10 Aug 2018 09:49:03 +0200 Subject: [PATCH 08/14] Fix a bug in derived queries when using two times `@relations` in one entity --- ChangeLog.md | 4 +++ .../query/derived/DerivedQueryCreator.java | 29 +++++++++--------- .../repository/CustomerRepository.java | 2 ++ .../derived/DerivedQueryCreatorTest.java | 30 +++++++++++++++++++ .../springframework/testdata/Customer.java | 11 +++++++ 5 files changed, 62 insertions(+), 14 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 5d5a66832..b0fc197da 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [Unreleased] +### Fixed + +- fixed a bug in derived queries when using two times `@Relations` in one entity + ## [2.3.0] - 2018-07-18 ### Deprecated diff --git a/src/main/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreator.java b/src/main/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreator.java index 1510a74fa..00e9afdf7 100644 --- a/src/main/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreator.java +++ b/src/main/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreator.java @@ -87,7 +87,6 @@ public class DerivedQueryCreator extends AbstractQueryCreator are lowered - * + * * @param part * @param property * @return @@ -236,7 +235,7 @@ private String ignorePropertyCase(final Part part, final String property) { /** * Returns a String representing a full propertyPath e.g. "e.product.name" - * + * * @param part * @return */ @@ -249,11 +248,12 @@ private String getProperty(final Part part) { * Creates a predicate template with one String placeholder for a Part-specific predicate expression from properties * in PropertyPath which represent references or collections, and, also, returns a 2nd String representing property * to be used in a Part-specific predicate expression - * + * * @param part + * @param varsUsed * @return */ - private String[] createPredicateTemplateAndPropertyString(final Part part) { + private String[] createPredicateTemplateAndPropertyString(final Part part, int varsUsed) { final String PREDICATE_TEMPLATE = "(%s FILTER %%s RETURN 1)[0] == 1"; final PersistentPropertyPath persistentPropertyPath = context.getPersistentPropertyPath(part.getProperty()); StringBuilder simpleProperties = new StringBuilder(); @@ -345,7 +345,7 @@ private String[] createPredicateTemplateAndPropertyString(final Part part) { /** * Lowers case of a given argument if its type is String, Iterable or String[] if shouldIgnoreCase is true - * + * * @param argument * @param shouldIgnoreCase * @return @@ -376,7 +376,7 @@ private Object ignoreArgumentCase(final Object argument, final boolean shouldIgn /** * Determines whether the case for a Part should be ignored based on property type and IgnoreCase keywords in the * method name - * + * * @param part * @return */ @@ -394,7 +394,7 @@ private boolean shouldIgnoreCase(final Part part) { /** * Puts actual arguments in bindVars Map based on Part-specific information and types of arguments. - * + * * @param iterator * @param shouldIgnoreCase * @param arguments @@ -487,7 +487,7 @@ private ArgumentProcessingResult bindArguments( /** * Ensures that Points used in geospatial parts of non-nested properties are the same in case geospatial return type * is expected - * + * * @param point */ private void checkUniquePoint(final Point point) { @@ -524,7 +524,7 @@ private double convertDistanceToMeters(final Distance distance) { /** * Ensures that the same geo fields are used in geospatial parts of non-nested properties are the same in case * geospatial return type is expected - * + * * @param part */ private void checkUniqueLocation(final Part part) { @@ -542,13 +542,14 @@ private void checkUniqueLocation(final Part part) { /** * Creates a PartInformation containing a String representing either a predicate or array expression, and binds * arguments from Iterator for a given Part - * + * * @param part * @param iterator * @return */ private PartInformation createPartInformation(final Part part, final Iterator iterator) { - final String[] templateAndProperty = createPredicateTemplateAndPropertyString(part); + int varsUsed = 0; + final String[] templateAndProperty = createPredicateTemplateAndPropertyString(part, varsUsed); final String template = templateAndProperty[0]; final String property = templateAndProperty[1]; boolean isArray = false; diff --git a/src/test/java/com/arangodb/springframework/repository/CustomerRepository.java b/src/test/java/com/arangodb/springframework/repository/CustomerRepository.java index ef516663d..69d1257ab 100644 --- a/src/test/java/com/arangodb/springframework/repository/CustomerRepository.java +++ b/src/test/java/com/arangodb/springframework/repository/CustomerRepository.java @@ -196,6 +196,8 @@ List findByNestedCustomersNestedCustomerShoppingCartProductsLocationWi List getByOwnsName(String name); + List getByOwnsNameAndOwns2Name(String name, String name2); + List getByOwnsContainsName(String name); // Count query diff --git a/src/test/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreatorTest.java b/src/test/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreatorTest.java index 12dde13e3..7371e721a 100644 --- a/src/test/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreatorTest.java +++ b/src/test/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreatorTest.java @@ -737,6 +737,36 @@ public void relationsSingleLevelTest() { assertTrue(equals(toBeRetrieved, retrieved, cmp, eq, false)); } + @Test + public void twoRelationsSingleLevelTest() { + final List toBeRetrieved = new LinkedList<>(); + final List customers = new LinkedList<>(); + List retrieved; + final Customer john = new Customer("John", "Smith", 52); + final Customer adam = new Customer("Adam", "Smith", 294); + final Customer matt = new Customer("Matt", "Smith", 34); + final Product phone = new Product("phone"); + final Product car = new Product("car"); + final Product chair = new Product("chair"); + template.insert(phone); + template.insert(car); + template.insert(chair); + customers.add(john); + customers.add(matt); + customers.add(adam); + repository.save(customers); + template.insert(new Owns(john, phone)); + template.insert(new Owns(john, car)); + template.insert(new Owns(adam, chair)); + template.insert(new Owns(matt, phone)); + template.insert(new Owns(matt, car)); + template.insert(new Owns(matt, chair)); + toBeRetrieved.add(john); + toBeRetrieved.add(matt); + retrieved = repository.getByOwnsNameAndOwns2Name(phone.getName(), phone.getName()); + assertTrue(equals(toBeRetrieved, retrieved, cmp, eq, false)); + } + @Test public void relationsMultiLevelTest() { final List toBeRetrieved = new LinkedList<>(); diff --git a/src/test/java/com/arangodb/springframework/testdata/Customer.java b/src/test/java/com/arangodb/springframework/testdata/Customer.java index b8979f080..162b9261a 100644 --- a/src/test/java/com/arangodb/springframework/testdata/Customer.java +++ b/src/test/java/com/arangodb/springframework/testdata/Customer.java @@ -64,6 +64,9 @@ public class Customer { @Relations(edges = { Owns.class }) private Collection owns; + @Relations(edges = { Owns.class }) + private Collection owns2; + public Customer() { super(); } @@ -163,6 +166,14 @@ public void setOwns(final Collection owns) { this.owns = owns; } + public Collection getOwns2() { + return owns2; + } + + public void setOwns2(final Collection owns2) { + this.owns2 = owns2; + } + public boolean isAlive() { return alive; } From 5f28cacb2bf5f0e9ad5cb777439d09cd122484c3 Mon Sep 17 00:00:00 2001 From: mpv1989 Date: Fri, 10 Aug 2018 09:52:59 +0200 Subject: [PATCH 09/14] Fix test --- .../repository/query/derived/DerivedQueryCreatorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreatorTest.java b/src/test/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreatorTest.java index 7371e721a..f944257ed 100644 --- a/src/test/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreatorTest.java +++ b/src/test/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreatorTest.java @@ -754,7 +754,7 @@ public void twoRelationsSingleLevelTest() { customers.add(john); customers.add(matt); customers.add(adam); - repository.save(customers); + repository.saveAll(customers); template.insert(new Owns(john, phone)); template.insert(new Owns(john, car)); template.insert(new Owns(adam, chair)); From 8f1df1cc7691dd9ae02d060591bcb0e01ddf8202 Mon Sep 17 00:00:00 2001 From: mpv1989 Date: Mon, 13 Aug 2018 07:34:46 +0200 Subject: [PATCH 10/14] Prepare release 2.3.1 --- ChangeLog.md | 2 ++ pom.xml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index b0fc197da..e244d28f6 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [Unreleased] +## [2.3.1] - 2018-08-13 + ### Fixed - fixed a bug in derived queries when using two times `@Relations` in one entity diff --git a/pom.xml b/pom.xml index 6b60630c3..9ebeba0df 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.arangodb arangodb-spring-data - 2.3.1-SNAPSHOT + 2.3.1 2017 jar From 306d147a60c2ffce59333bcadf7a31315800de15 Mon Sep 17 00:00:00 2001 From: mpv1989 Date: Mon, 13 Aug 2018 07:37:19 +0200 Subject: [PATCH 11/14] Prepare snapshot --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9ebeba0df..ee25a5bdf 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.arangodb arangodb-spring-data - 2.3.1 + 2.3.2-SNAPSHOT 2017 jar From 909a08acc69f52ee9bdf20b605a8a06d0bd9fb5a Mon Sep 17 00:00:00 2001 From: mpv1989 Date: Mon, 13 Aug 2018 10:34:52 +0200 Subject: [PATCH 12/14] Fix repository methods with `Example` using `StringMatcher.CONTAINING` (issue #113) --- ChangeLog.md | 4 ++++ .../repository/ArangoExampleConverter.java | 3 +++ .../repository/ArangoRepositoryTest.java | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index e244d28f6..398b8c647 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [Unreleased] +### Fixed + +- fixed repository methods with `Example` using `StringMatcher.CONTAINING` (issue #113) + ## [2.3.1] - 2018-08-13 ### Fixed diff --git a/src/main/java/com/arangodb/springframework/repository/ArangoExampleConverter.java b/src/main/java/com/arangodb/springframework/repository/ArangoExampleConverter.java index a8a40729f..06bc123e8 100644 --- a/src/main/java/com/arangodb/springframework/repository/ArangoExampleConverter.java +++ b/src/main/java/com/arangodb/springframework/repository/ArangoExampleConverter.java @@ -115,6 +115,9 @@ private void addPredicate( case ENDING: value = escape(string) + "$"; break; + case CONTAINING: + value = escape(string); + break; case DEFAULT: case EXACT: default: diff --git a/src/test/java/com/arangodb/springframework/repository/ArangoRepositoryTest.java b/src/test/java/com/arangodb/springframework/repository/ArangoRepositoryTest.java index d172f68ea..1e4e3e43a 100644 --- a/src/test/java/com/arangodb/springframework/repository/ArangoRepositoryTest.java +++ b/src/test/java/com/arangodb/springframework/repository/ArangoRepositoryTest.java @@ -1,7 +1,9 @@ package com.arangodb.springframework.repository; +import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import java.util.ArrayList; @@ -13,6 +15,7 @@ import org.junit.runner.RunWith; import org.springframework.data.domain.Example; import org.springframework.data.domain.ExampleMatcher; +import org.springframework.data.domain.ExampleMatcher.StringMatcher; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; @@ -326,4 +329,19 @@ public void endingWithByExampleNestedIncludeNullTest() { final Customer retrieved = repository.findOne(example).get(); assertEquals(check, retrieved); } + + @Test + public void containingExampleTest() { + final Customer entity = new Customer("name", "surname", 10); + repository.save(entity); + + final Customer probe = new Customer(); + probe.setName("am"); + final Example example = Example.of(probe, + ExampleMatcher.matching().withStringMatcher(StringMatcher.CONTAINING).withIgnorePaths("arangoId", "id", + "key", "rev", "surname", "age")); + final Optional retrieved = repository.findOne(example); + assertThat(retrieved.isPresent(), is(true)); + assertThat(retrieved.get().getName(), is("name")); + } } From 7d628df3bd4f233351414156d2a5fee44506a475 Mon Sep 17 00:00:00 2001 From: mpv1989 Date: Tue, 4 Sep 2018 09:53:22 +0200 Subject: [PATCH 13/14] Prepare release 2.3.2 --- ChangeLog.md | 2 ++ pom.xml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 398b8c647..15e2e2b09 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [Unreleased] +## [2.3.2] - 2018-09-04 + ### Fixed - fixed repository methods with `Example` using `StringMatcher.CONTAINING` (issue #113) diff --git a/pom.xml b/pom.xml index ee25a5bdf..8aa07e390 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.arangodb arangodb-spring-data - 2.3.2-SNAPSHOT + 2.3.2 2017 jar From a876b53ea598c751b3522ca265956cd46d2ed84a Mon Sep 17 00:00:00 2001 From: mpv1989 Date: Tue, 4 Sep 2018 10:03:51 +0200 Subject: [PATCH 14/14] Prepare snapshot --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8aa07e390..b3e7098af 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.arangodb arangodb-spring-data - 2.3.2 + 2.3.3-SNAPSHOT 2017 jar