All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arangodb.springframework.repository.query.DerivedArangoQuery Maven / Gradle / Ivy

There is a newer version: 4.5.0
Show newest version
/*
 * 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.repository.query;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.repository.query.parser.PartTree;

import com.arangodb.entity.IndexEntity;
import com.arangodb.entity.IndexType;
import com.arangodb.model.AqlQueryOptions;
import com.arangodb.springframework.core.ArangoOperations;
import com.arangodb.springframework.core.mapping.ArangoPersistentEntity;
import com.arangodb.springframework.core.mapping.ArangoPersistentProperty;
import com.arangodb.springframework.repository.query.derived.BindParameterBinding;
import com.arangodb.springframework.repository.query.derived.DerivedQueryCreator;

/**
 *
 * @author Audrius Malele
 * @author Mark McCormick
 * @author Mark Vollmary
 * @author Christian Lechner
 */
public class DerivedArangoQuery extends AbstractArangoQuery {

	private final PartTree tree;
	private final MappingContext, ArangoPersistentProperty> context;
	private final List geoFields;

	public DerivedArangoQuery(final ArangoQueryMethod method, final ArangoOperations operations) {
		super(method, operations);
		tree = new PartTree(method.getName(), domainClass);
		context = operations.getConverter().getMappingContext();
		geoFields = getGeoFields();
	}

	@Override
	protected String createQuery(
		final ArangoParameterAccessor accessor,
		final Map bindVars,
		final AqlQueryOptions options) {

		return new DerivedQueryCreator(context, domainClass, tree, accessor, new BindParameterBinding(bindVars),
				geoFields).createQuery();
	}

	@Override
	protected boolean isCountQuery() {
		return tree.isCountProjection();
	}

	@Override
	protected boolean isExistsQuery() {
		return tree.isExistsProjection();
	}

	private List getGeoFields() {
		final List geoFields = new LinkedList<>();
		if (method.isGeoQuery()) {
			for (final IndexEntity index : operations.collection(domainClass).getIndexes()) {
				final IndexType type = index.getType();
				if (type == IndexType.geo || type == IndexType.geo1 || type == IndexType.geo2) {
					geoFields.addAll(index.getFields());
				}
			}
		}
		return geoFields;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy