Java tutorial
/* * Copyright (c) 2016 Couchbase, Inc. * * 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. */ package com.couchbase.trombi.data; import java.util.List; import com.couchbase.trombi.domain.Coworker; import org.springframework.data.couchbase.core.query.Dimensional; import org.springframework.data.couchbase.core.query.N1qlPrimaryIndexed; import org.springframework.data.couchbase.core.query.Query; import org.springframework.data.couchbase.core.query.ViewIndexed; import org.springframework.data.couchbase.repository.CouchbaseRepository; import org.springframework.data.geo.Circle; import org.springframework.data.geo.Distance; import org.springframework.data.geo.Point; import org.springframework.data.geo.Polygon; import org.springframework.data.repository.Repository; import org.springframework.data.repository.query.Param; /** * A Spring Data {@link CouchbaseRepository repository} of {@link Coworker}. * * @author Simon Basl */ @ViewIndexed(designDoc = "coworker", viewName = "all") @N1qlPrimaryIndexed public interface CoworkerRepository extends CouchbaseRepository<Coworker, String> { public static final String PREFIX = "coworker"; Coworker findOneByName(String name); List<Coworker> findByTeamIs(String team); List<Coworker> findAllByTeamIsAndDescriptionContains(String team, String description); @Query("#{#n1ql.selectEntity} WHERE" + " #{#n1ql.filter} AND ANY im " + "IN OBJECT_VALUES(imHandles) " + "SATISFIES im LIKE \"%#{[0]}%\" END") List<Coworker> findAllByIm(@Param("im") String im); @Dimensional(designDocument = "coworkerGeo", spatialViewName = "byLocationOrCheckin") List<Coworker> findAllByMainLocationCoordinatesWithin(@Param("area") Polygon area); @Dimensional(designDocument = "coworkerGeo", spatialViewName = "byLocationOrCheckin") List<Coworker> findAllByMainLocationCoordinatesWithin(@Param("area") Circle area); @Dimensional(designDocument = "coworkerGeo", spatialViewName = "byLocationOrCheckin") List<Coworker> findAllByMainLocationCoordinatesNear(@Param("center") Point center, @Param("distance") Distance distance); }