Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ public <S extends T> long count(final Example<S> example) {
final String filter = predicate.length() == 0 ? "" : " FILTER " + predicate;
final String query = String.format("FOR e IN %s%s COLLECT WITH COUNT INTO length RETURN length",
getCollectionName(), filter);
arangoOperations.collection(domainClass);
final ArangoCursor<Long> cursor = arangoOperations.query(query, bindVars, null, Long.class);
return cursor.next();
}
Expand All @@ -354,20 +355,19 @@ private <S extends T> ArangoCursor<T> findAllInternal(
final Sort sort,
@Nullable final Example<S> example,
final Map<String, Object> bindVars) {

final String query = String.format("FOR e IN %s %s %s RETURN e", getCollectionName(),
buildFilterClause(example, bindVars), buildSortClause(sort, "e"));
arangoOperations.collection(domainClass);
return arangoOperations.query(query, bindVars, null, domainClass);
}

private <S extends T> ArangoCursor<T> findAllInternal(
final Pageable pageable,
@Nullable final Example<S> example,
final Map<String, Object> bindVars) {

final String query = String.format("FOR e IN %s %s %s RETURN e", getCollectionName(),
buildFilterClause(example, bindVars), buildPageableClause(pageable, "e"));

arangoOperations.collection(domainClass);
return arangoOperations.query(query, bindVars,
pageable != null && pageable.isPaged() ? new AqlQueryOptions().fullCount(true) : null, domainClass);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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;

import java.util.ArrayList;
import java.util.Collection;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;

import com.arangodb.ArangoDB;
import com.arangodb.springframework.annotation.EnableArangoRepositories;
import com.arangodb.springframework.config.ArangoConfiguration;
import com.arangodb.springframework.core.mapping.CustomMappingTest;

/**
*
* @author Paulo Ferreira
*/
@Configuration
@ComponentScan("com.arangodb.springframework.component")
@EnableArangoRepositories(basePackages = {
"com.arangodb.springframework.repository",
"com.arangodb.springframework.example.polymorphic.repository",
"com.arangodb.springframework.debug.repository"},
namedQueriesLocation = "classpath*:arango-named-queries-test.properties")
public class ArangoMultiTenancyRepositoryTestConfiguration implements ArangoConfiguration {

public static final String DB = "spring-test-db";

@Override
public ArangoDB.Builder arango() {
return new ArangoDB.Builder();
}

@Override
public String database() {
return DB + "#{tenantProvider.getId()}";
}

@Override
public Collection<Converter<?, ?>> customConverters() {
final Collection<Converter<?, ?>> converters = new ArrayList<>();
converters.add(new CustomMappingTest.CustomVPackReadTestConverter());
converters.add(new CustomMappingTest.CustomVPackWriteTestConverter());
converters.add(new CustomMappingTest.CustomDBEntityReadTestConverter());
converters.add(new CustomMappingTest.CustomDBEntityWriteTestConverter());
return converters;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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.mapping;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

import java.util.Optional;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.arangodb.springframework.ArangoMultiTenancyRepositoryTestConfiguration;
import com.arangodb.springframework.component.TenantProvider;
import com.arangodb.springframework.core.ArangoOperations;
import com.arangodb.springframework.repository.IdTestRepository;
import com.arangodb.springframework.testdata.IdTestEntity;

/**
* @author Paulo Ferreira
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { ArangoMultiTenancyRepositoryTestConfiguration.class })
public class MultiTenancyDBLevelRepositoryTest {

private static final String TENANT00 = "tenant00";

@Autowired
protected ArangoOperations template;

@Autowired
TenantProvider tenantProvider;

@Autowired
IdTestRepository<String> idTestRepository;

/*
* For some reason, findAll already creates the collection by itself
*/

@Test
public void dbFindAll() {
tenantProvider.setId(TENANT00);
assertThat(idTestRepository.findAll().iterator().hasNext(), is(false));
}

@Test
public void dbFindOne() {
tenantProvider.setId(TENANT00);
IdTestEntity<String> entity = new IdTestEntity<>();
entity.setId("MyId");
Example<IdTestEntity<String>> example = Example.of(entity);
Optional<IdTestEntity<String>> result = idTestRepository.findOne(example);
assertThat(result.isPresent(), is(false));
}

@Before
@After
public void cleanup() {
tenantProvider.setId(TENANT00);
template.dropDatabase();
}

}