Skip to content

Commit d6f2ce1

Browse files
committed
Add Maven project template example
1 parent 9656720 commit d6f2ce1

File tree

4 files changed

+129
-0
lines changed

4 files changed

+129
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Maven project template for Couchbase Analytics
2+
3+
This directory contains an example Maven project for getting started with the Couchbase Analytics Java SDK.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.example</groupId>
8+
<artifactId>couchbase-analytics-java-example</artifactId>
9+
<version>1.0.0-SNAPSHOT</version>
10+
11+
<name>Couchbase Analytics Java SDK Project Template</name>
12+
<description>Examples project for Couchbase Analytics Java SDK</description>
13+
14+
<properties>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<maven.compiler.release>21</maven.compiler.release>
17+
</properties>
18+
19+
<!-- Required when using a *-SNAPSHOT version of the SDK. -->
20+
<repositories>
21+
<repository>
22+
<id>sonatype-snapshots</id>
23+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
24+
<releases>
25+
<enabled>false</enabled>
26+
</releases>
27+
<snapshots>
28+
<enabled>true</enabled>
29+
</snapshots>
30+
</repository>
31+
</repositories>
32+
33+
<dependencies>
34+
<dependency>
35+
<groupId>com.couchbase.client</groupId>
36+
<artifactId>couchbase-analytics-java-client</artifactId>
37+
<version>1.0.0-SNAPSHOT</version>
38+
</dependency>
39+
40+
<!-- Specify your favorite SLF4J 2 binding -->
41+
<dependency>
42+
<groupId>org.apache.logging.log4j</groupId>
43+
<artifactId>log4j-slf4j2-impl</artifactId>
44+
<version>2.24.3</version>
45+
</dependency>
46+
</dependencies>
47+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2025 Couchbase, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.couchbase.analytics;
18+
19+
import com.couchbase.analytics.client.java.Cluster;
20+
import com.couchbase.analytics.client.java.Credential;
21+
import com.couchbase.analytics.client.java.QueryResult;
22+
23+
import java.time.Duration;
24+
import java.util.List;
25+
26+
public class Example {
27+
public static void main(String[] args) {
28+
var connectionString = "https://...";
29+
var username = "...";
30+
var password = "...";
31+
32+
try (Cluster cluster = Cluster.newInstance(
33+
connectionString,
34+
Credential.of(username, password),
35+
// The third parameter is optional.
36+
// This example sets the default query timeout to 2 minutes.
37+
clusterOptions -> clusterOptions
38+
.timeout(it -> it.queryTimeout(Duration.ofMinutes(2)))
39+
)) {
40+
41+
// Buffered query. All rows must fit in memory.
42+
QueryResult result = cluster.executeQuery(
43+
"select ?=1",
44+
options -> options
45+
.readOnly(true)
46+
.parameters(List.of(1))
47+
);
48+
result.rows().forEach(row -> System.out.println("Got row: " + row));
49+
50+
// Alternatively --
51+
52+
// Streaming query. Rows are processed one-by-one
53+
// as they arrive from server.
54+
cluster.executeStreamingQuery(
55+
"select ?=1",
56+
row -> System.out.println("Got row: " + row),
57+
options -> options
58+
.readOnly(true)
59+
.parameters(List.of(1))
60+
);
61+
}
62+
}
63+
}
64+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="WARN">
3+
<Appenders>
4+
<Console name="Console" target="SYSTEM_OUT">
5+
<PatternLayout pattern="%d{ISO8601_OFFSET_DATE_TIME_HHCMM} %-5p [%c] %m%n"/>
6+
</Console>
7+
</Appenders>
8+
<Loggers>
9+
<Logger name="com.couchbase.client.core.deps.io.netty" level="warn"/>
10+
11+
<Root level="info">
12+
<AppenderRef ref="Console"/>
13+
</Root>
14+
</Loggers>
15+
</Configuration>

0 commit comments

Comments
 (0)