Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions docs/UserGuide/API/Programming-Java-Native-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,21 @@ Here we show the commonly used interfaces and their parameters in the Native API
* Initialize a Session

```java
Session(String host, int rpcPort)

Session(String host, String rpcPort, String username, String password)

Session(String host, int rpcPort, String username, String password)
// use default configuration
session = new Session.Builder.build();

// configure all fields
session =
new Session.Builder()
.host(String host)
.port(int port)
.fetchSize(int fetchSize)
.username(String username)
.password(String password)
.thriftDefaultBufferSize(int thriftDefaultBufferSize)
.thriftMaxFrameSize(int thriftMaxFrameSize)
.enableCacheLeader(boolean enableCacheLeader)
.build();
```

* Open a Session
Expand Down
18 changes: 15 additions & 3 deletions docs/zh/UserGuide/API/Programming-Java-Native-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,21 @@ mvn clean install -pl session -am -Dmaven.test.skip=true
* 初始化Session

```java
Session(String host, int rpcPort)
Session(String host, String rpcPort, String username, String password)
Session(String host, int rpcPort, String username, String password)
// 全部使用默认配置
session = new Session.Builder.build();

// 自行配置参数
session =
new Session.Builder()
.host(String host)
.port(int port)
.fetchSize(int fetchSize)
.username(String username)
.password(String password)
.thriftDefaultBufferSize(int thriftDefaultBufferSize)
.thriftMaxFrameSize(int thriftMaxFrameSize)
.enableCacheLeader(boolean enableCacheLeader)
.build();
```

* 开启Session
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public class SessionExample {

public static void main(String[] args)
throws IoTDBConnectionException, StatementExecutionException {
session = new Session(LOCAL_HOST, 6667, "root", "root");
session =
new Session.Builder().host(LOCAL_HOST).port(6667).username("root").password("root").build();
session.open(false);

// set session fetchSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ public class SessionPoolExample {

public static void main(String[] args)
throws StatementExecutionException, IoTDBConnectionException, InterruptedException {
pool = new SessionPool("127.0.0.1", 6667, "root", "root", 3);
pool =
new SessionPool.Builder()
.host("127.0.0.1")
.port(6667)
.user("root")
.password("root")
.maxSize(3)
.build();
service = Executors.newFixedThreadPool(10);

insertRecord();
Expand Down
4 changes: 4 additions & 0 deletions session/src/main/java/org/apache/iotdb/session/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

public class Config {

public static final String DEFAULT_HOST = "localhost";
public static final int DEFAULT_PORT = 6667;
public static final String DEFAULT_USER = "root";
public static final String DEFAULT_PASSWORD = "root";
public static final int DEFAULT_FETCH_SIZE = 5000;
Expand All @@ -34,4 +36,6 @@ public class Config {

/** thrift max frame size (16384000 bytes by default), we change it to 64MB */
public static final int DEFAULT_MAX_FRAME_SIZE = 67108864;

public static final int DEFAULT_SESSION_POOL_MAX_SIZE = 5;
}
65 changes: 65 additions & 0 deletions session/src/main/java/org/apache/iotdb/session/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -1833,4 +1833,69 @@ public boolean isEnableQueryRedirection() {
public void setEnableQueryRedirection(boolean enableQueryRedirection) {
this.enableQueryRedirection = enableQueryRedirection;
}

public static class Builder {
private String host = Config.DEFAULT_HOST;
private int rpcPort = Config.DEFAULT_PORT;
private String username = Config.DEFAULT_USER;
private String password = Config.DEFAULT_PASSWORD;
private int fetchSize = Config.DEFAULT_FETCH_SIZE;
private ZoneId zoneId = null;
private int thriftDefaultBufferSize = Config.DEFAULT_INITIAL_BUFFER_CAPACITY;
private int thriftMaxFrameSize = Config.DEFAULT_MAX_FRAME_SIZE;
private boolean enableCacheLeader = Config.DEFAULT_CACHE_LEADER_MODE;

public Builder host(String host) {
this.host = host;
return this;
}

public Builder port(int port) {
this.rpcPort = port;
return this;
}

public Builder username(String username) {
this.username = username;
return this;
}

public Builder password(String password) {
this.password = password;
return this;
}

public Builder fetchSize(int fetchSize) {
this.fetchSize = fetchSize;
return this;
}

public Builder thriftDefaultBufferSize(int thriftDefaultBufferSize) {
this.thriftDefaultBufferSize = thriftDefaultBufferSize;
return this;
}

public Builder thriftMaxFrameSize(int thriftMaxFrameSize) {
this.thriftMaxFrameSize = thriftMaxFrameSize;
return this;
}

public Builder enableCacheLeader(boolean enableCacheLeader) {
this.enableCacheLeader = enableCacheLeader;
return this;
}

public Session build() {
return new Session(
host,
rpcPort,
username,
password,
fetchSize,
zoneId,
thriftDefaultBufferSize,
thriftMaxFrameSize,
enableCacheLeader);
}
}
}
Loading