- Created by user-1a1b1, last modified by Shared Doc User on Jul 07, 2023
CAST supports Couchbase via its NoSQL for Java extension. Details about the support provided for Java with Spring Data source code is discussed below.
Supported Client Libraries
Library | Versions | Supported |
up to: 3.1.10 | |
Supported Operations
Operation | Methods Supported |
---|---|
Insert | Insert API's support by couchbase spring framework
|
Select | Select API's support by couchbase spring framework
|
Delete | Delete API's support by couchbase spring framework
|
Update | Update API's support by couchbase spring framework
|
Objects
Icon | Description |
---|---|
Java Couchbase Cluster | |
Java Couchbase Bucket | |
Java Couchbase Collection | |
Java Couchbase Unknown Cluster | |
| Java Couchbase Unknown Bucket |
Java Couchbase Unknown Collection |
Links
Links are created for transaction and function point needs:
Link type | Source and destination of link | Methods supported |
---|---|---|
parentLink | Between Couchbase Cluster object, Couchbase Bucket object and Couchbase Collection object | |
useLink | Between the caller Spring Data Java Method objects and Couchbase Collection objects |
|
useSelectLink | Select methods supported
| |
useUpdateLink |
| |
useDeleteLink |
| |
useInsertLink |
|
What results can you expect?
Once the analysis/snapshot generation is completed, you can view the results in the normal manner (for example via CAST Enlighten). Some examples are shown below.
Cluster and Bucket Identification
Cluster and bucket from properties file
Bucket identification from proporties file
spring.couchbase.bootstrap-hosts=localhost spring.couchbase.bucket.name=test
Multiple bucket
@Bean public Bucket campusBucket() throws Exception { return couchbaseCluster().openBucket("test2", "pwd"); } @Bean public CouchbaseTemplate campusTemplate() throws Exception { CouchbaseTemplate template = new CouchbaseTemplate( couchbaseClusterInfo(), campusBucket(), mappingCouchbaseConverter(), translationService()); template.setDefaultConsistency(getDefaultConsistency()); return template; } @Override public void configureRepositoryOperationsMapping( RepositoryOperationsMapping baseMapping) { try { baseMapping.mapEntity(Campus.class, campusTemplate()); } catch (Exception e) { } }
Cluster and Bucket Identification using Java Configuration
Cluster and bucket info from java configuration
public class dbConfig extends AbstractCouchbaseConfiguration { @Value("${couchbase.bucketname}") private String bucketName; @Value("${couchbase.node}") private String node; @Value("${couchbase.password}") private String pswd; @Override protected String getBucketName() { this.bucketName = bucketName; return this.bucketName; } @Override protected String getBucketPassword() { this.pswd = pswd; return this.pswd; } @Override protected List<String> getBootstrapHosts(String x,String y) { // TODO Auto-generated method stub. this.node = node; List<String> nodes = new ArrayList<String>("one","two","three"); nodes.add(this.node); return nodes; } }
Marking a Cluster and Bucket Unknown
Unknown cluster and bucket
When no Cluster or Bucket Object can be identified, but there are Couchbase Operations detected from the Source Code. Then an Unknown Couchbase Cluster and Unknown Couchbase Bucket is Created.
Couchbase Insert Operation
Insert
@GetMapping("/insert") public void insert() { CouchbaseOperations cop= context.getBean(campusRepo.class).getCouchbaseOperations(); List<Campus> campus = new ArrayList<Campus>(); campus.add(new Campus("SP234","Chennai",new Point(67.456,78.987))); campus.add(new Campus("SP456","Hyderabad",new Point(56.274,108.943))); cop.insert(campus); }
@GetMapping("/execute") public book executeAct() { CouchbaseOperations cop = context.getBean(bookRepo.class).getCouchbaseOperations(); return cop.execute(new BucketCallback<book>() { public book doInBucket() throws java.util.concurrent.TimeoutException,ExecutionException, InterruptedException { book bk1 = new book("789UV","Spring-data","framework","Deepak Vohra"); cop.save(bk1); return bk1; }});
insert op in another bucket
@GetMapping("/insertObj") public void insertObj() { CouchbaseOperations cop= context.getBean(campusRepo.class).getCouchbaseOperations(); Campus campus = new Campus("SP678","Trivandrum",new Point(67.456,78.987)); cop.insert(campus); }
Couchbase Update Operation
Update
@PostMapping("/update") public void updateCustomer(@RequestBody Customer customer) { CouchbaseOperations cOperations = repository.getCouchbaseOperations(); cOperations.update(customer); }
Couchbase Select Operation
Select
@GetMapping("/squery") public List<book> SVquery() { CouchbaseOperations cop = context.getBean(bookRepo.class).getCouchbaseOperations(); return cop.findBySpatialView(SpatialViewQuery.from("book","all"),book.class ); }
@GetMapping("/Vquery") public List<book> Vquery() { CouchbaseOperations cop = context.getBean(bookRepo.class).getCouchbaseOperations(); return cop.findByView(ViewQuery.from("book","all"),book.class); }
Couchbase Delete Operation
Delete
@GetMapping("/removeC") public void remC() { CouchbaseOperations cop= context.getBean(campusRepo.class).getCouchbaseOperations(); List<Campus> campus = new ArrayList<Campus>(); campus.add(new Campus("SP89A","Mumbai",new Point(32.456,160.987))); campus.add(new Campus("SPABC","Kolkata",new Point(90.274,186.943))); cop.remove(campus); }
@GetMapping("/deletebyname/{name}") public void deletebyname(@PathVariable(required = true) String name) { List<Customer> customers = repository.findByName(name); repository.deleteAll(customers); }
@GetMapping("/delete/{id}") public void delete(@PathVariable(required = true) int id) { Optional<Customer> customer = repository.findById(id); repository.delete(customer.get()); }
Couchbase N1QL Query and Custom Methods
N1QL Query and Custom Methods
@N1qlPrimaryIndexed @ViewIndexed(designDoc = "building") public interface BuildingRepository extends CouchbaseRepository<Building, String> { List<Building> findByCompanyId(String companyId); Page<Building> findByCompanyIdAndNameLikeOrderByName(String companyId, String name, Pageable pageable); }
Couchbase N1QL Query and Custom Methods
Query Annotations
code
@N1qlPrimaryIndexed @ViewIndexed(designDoc = "building") public interface BuildingRepository extends CouchbaseRepository<Building, String> { List<Building> findByCompanyId(String companyId); Page<Building> findByCompanyIdAndNameLikeOrderByName(String companyId, String name, Pageable pageable); @Query("#{#n1ql.selectEntity} where #{#n1ql.filter} and companyId = $1 and $2 within #{#n1ql.bucket}") Building findByCompanyAndAreaId(String companyId, String areaId); @Query("#{#n1ql.selectEntity} where #{#n1ql.filter} AND ANY phone IN phoneNumbers SATISFIES phone = $1 END") List<Building> findByPhoneNumber(String telephoneNumber); @Query("SELECT COUNT(*) AS count FROM #{#n1ql.bucket} WHERE #{#n1ql.filter} and companyId = $1") Long countBuildings(String companyId); }
Limitations
- Resolution of Database and Collection is limited, "Unknown" is used when not resolved.
- No labels