/** * Get the {@link MappingContext} to use in repositories. It is extracted from the default {@link CouchbaseOperations}. * * @return the mapping context. */ public MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> getMappingContext() { return defaultOperations.getConverter().getMappingContext(); }
/** * Get the {@link MappingContext} to use in repositories. It is extracted from the default {@link CouchbaseOperations}. * * @return the mapping context. */ public MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> getMappingContext() { return defaultOperations.getConverter().getMappingContext(); }
@Override public void deleteById(ID id) { Assert.notNull(id, "The given id must not be null!"); couchbaseOperations.remove(couchbaseOperations.getConverter().convertForWriteIfNeeded(id).toString()); }
@Override public boolean existsById(ID id) { Assert.notNull(id, "The given id must not be null!"); return couchbaseOperations.exists(couchbaseOperations.getConverter().convertForWriteIfNeeded(id).toString()); }
@Override public void deleteById(ID id) { Assert.notNull(id, "The given id must not be null!"); couchbaseOperations.remove(couchbaseOperations.getConverter().convertForWriteIfNeeded(id).toString()); }
@Override public boolean existsById(ID id) { Assert.notNull(id, "The given id must not be null!"); return couchbaseOperations.exists(couchbaseOperations.getConverter().convertForWriteIfNeeded(id).toString()); }
@Override public Optional<T> findById(ID id) { Assert.notNull(id, "The given id must not be null!"); return Optional.ofNullable(couchbaseOperations.findById(couchbaseOperations.getConverter().convertForWriteIfNeeded(id).toString(), entityInformation.getJavaType())); }
@Override public Optional<T> findById(ID id) { Assert.notNull(id, "The given id must not be null!"); return Optional.ofNullable(couchbaseOperations.findById(couchbaseOperations.getConverter().convertForWriteIfNeeded(id).toString(), entityInformation.getJavaType())); }
protected String getTypeField() { return getCouchbaseOperations().getConverter().getTypeKey(); }
protected String getTypeField() { return getCouchbaseOperations().getConverter().getTypeKey(); }
public StringN1qlBasedQuery(String statement, CouchbaseQueryMethod queryMethod, CouchbaseOperations couchbaseOperations, SpelExpressionParser spelParser, QueryMethodEvaluationContextProvider evaluationContextProvider) { super(queryMethod, couchbaseOperations); this.queryParser = new StringBasedN1qlQueryParser(statement, queryMethod, getCouchbaseOperations().getCouchbaseBucket().name(), getCouchbaseOperations().getConverter(), getTypeField(), getTypeValue()); this.parser = spelParser; this.evaluationContextProvider = evaluationContextProvider; }
public StringN1qlBasedQuery(String statement, CouchbaseQueryMethod queryMethod, CouchbaseOperations couchbaseOperations, SpelExpressionParser spelParser, QueryMethodEvaluationContextProvider evaluationContextProvider) { super(queryMethod, couchbaseOperations); this.queryParser = new StringBasedN1qlQueryParser(statement, queryMethod, getCouchbaseOperations().getCouchbaseBucket().name(), getCouchbaseOperations().getConverter(), getTypeField(), getTypeValue()); this.parser = spelParser; this.evaluationContextProvider = evaluationContextProvider; }
@Override public Iterable<T> findAll(Sort sort) { Assert.notNull(sort, "Sort must not be null!"); //prepare elements of the query WherePath selectFrom = N1qlUtils.createSelectFromForEntity(getCouchbaseOperations().getCouchbaseBucket().name()); Expression whereCriteria = N1qlUtils.createWhereFilterForEntity(null, getCouchbaseOperations().getConverter(), getEntityInformation()); //apply the sort com.couchbase.client.java.query.dsl.Sort[] orderings = N1qlUtils.createSort(sort, getCouchbaseOperations().getConverter()); Statement st = selectFrom.where(whereCriteria).orderBy(orderings); //fire the query ScanConsistency consistency = getCouchbaseOperations().getDefaultConsistency().n1qlConsistency(); N1qlQuery query = N1qlQuery.simple(st, N1qlParams.build().consistency(consistency)); return getCouchbaseOperations().findByN1QL(query, getEntityInformation().getJavaType()); }
@Override public Iterable<T> findAll(Sort sort) { Assert.notNull(sort, "Sort must not be null!"); //prepare elements of the query WherePath selectFrom = N1qlUtils.createSelectFromForEntity(getCouchbaseOperations().getCouchbaseBucket().name()); Expression whereCriteria = N1qlUtils.createWhereFilterForEntity(null, getCouchbaseOperations().getConverter(), getEntityInformation()); //apply the sort com.couchbase.client.java.query.dsl.Sort[] orderings = N1qlUtils.createSort(sort, getCouchbaseOperations().getConverter()); Statement st = selectFrom.where(whereCriteria).orderBy(orderings); //fire the query ScanConsistency consistency = getCouchbaseOperations().getDefaultConsistency().n1qlConsistency(); N1qlQuery query = N1qlQuery.simple(st, N1qlParams.build().consistency(consistency)); return getCouchbaseOperations().findByN1QL(query, getEntityInformation().getJavaType()); }
@Override protected Statement getCount(ParameterAccessor accessor, Object[] runtimeParameters) { Expression bucket = i(getCouchbaseOperations().getCouchbaseBucket().name()); WherePath countFrom = select(count("*").as(CountFragment.COUNT_ALIAS)).from(bucket); N1qlCountQueryCreator queryCountCreator = new N1qlCountQueryCreator(partTree, accessor, countFrom, getCouchbaseOperations().getConverter(), getQueryMethod()); Statement statement = queryCountCreator.createQuery(); this.placeHolderValues = queryCountCreator.getPlaceHolderValues(); return statement; }
@Override protected Statement getCount(ParameterAccessor accessor, Object[] runtimeParameters) { Expression bucket = i(getCouchbaseOperations().getCouchbaseBucket().name()); WherePath countFrom = select(count("*").as(CountFragment.COUNT_ALIAS)).from(bucket); N1qlCountQueryCreator queryCountCreator = new N1qlCountQueryCreator(partTree, accessor, countFrom, getCouchbaseOperations().getConverter(), getQueryMethod()); Statement statement = queryCountCreator.createQuery(); this.placeHolderValues = queryCountCreator.getPlaceHolderValues(); return statement; }
@Override public Iterable<T> findAllById(final Iterable<ID> ids) { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(false); query.stale(getCouchbaseOperations().getDefaultConsistency().viewConsistency()); JsonArray keys = JsonArray.create(); for (ID id : ids) { keys.add(couchbaseOperations.getConverter().convertForWriteIfNeeded(id)); } query.keys(keys); return couchbaseOperations.findByView(query, entityInformation.getJavaType()); }
@Override public Iterable<T> findAllById(final Iterable<ID> ids) { final ResolvedView resolvedView = determineView(); ViewQuery query = ViewQuery.from(resolvedView.getDesignDocument(), resolvedView.getViewName()); query.reduce(false); query.stale(getCouchbaseOperations().getDefaultConsistency().viewConsistency()); JsonArray keys = JsonArray.create(); for (ID id : ids) { keys.add(couchbaseOperations.getConverter().convertForWriteIfNeeded(id)); } query.keys(keys); return couchbaseOperations.findByView(query, entityInformation.getJavaType()); }
@Override public Object execute(Object[] runtimeParams) { String designDoc = method.getDimensionalAnnotation().designDocument(); String viewName = method.getDimensionalAnnotation().spatialViewName(); int dimensions = method.getDimensionalAnnotation().dimensions(); /* here contrary to the classical view query we don't support not including an attribute of the entity in the method name, those are mandatory and will result in a PropertyReferenceException if not used... */ PartTree tree = new PartTree(method.getName(), method.getEntityInformation().getJavaType()); //prepare a spatial view query to be used as a base for the query creator SpatialViewQuery baseSpatialQuery = SpatialViewQuery.from(designDoc, viewName) .stale(operations.getDefaultConsistency().viewConsistency()); //use the SpatialViewQueryCreator to complete it SpatialViewQueryCreator creator = new SpatialViewQueryCreator(dimensions, tree, new ParametersParameterAccessor(method.getParameters(), runtimeParams), baseSpatialQuery, operations.getConverter()); SpatialViewQueryCreator.SpatialViewQueryWrapper finalQuery = creator.createQuery(); //execute the spatial query return execute(finalQuery); }
@Override public Object execute(Object[] runtimeParams) { String designDoc = method.getDimensionalAnnotation().designDocument(); String viewName = method.getDimensionalAnnotation().spatialViewName(); int dimensions = method.getDimensionalAnnotation().dimensions(); /* here contrary to the classical view query we don't support not including an attribute of the entity in the method name, those are mandatory and will result in a PropertyReferenceException if not used... */ PartTree tree = new PartTree(method.getName(), method.getEntityInformation().getJavaType()); //prepare a spatial view query to be used as a base for the query creator SpatialViewQuery baseSpatialQuery = SpatialViewQuery.from(designDoc, viewName) .stale(operations.getDefaultConsistency().viewConsistency()); //use the SpatialViewQueryCreator to complete it SpatialViewQueryCreator creator = new SpatialViewQueryCreator(dimensions, tree, new ParametersParameterAccessor(method.getParameters(), runtimeParams), baseSpatialQuery, operations.getConverter()); SpatialViewQueryCreator.SpatialViewQueryWrapper finalQuery = creator.createQuery(); //execute the spatial query return execute(finalQuery); }