6 package com.vesoft.nebula.client.graph;
8 import com.vesoft.nebula.Value;
9 import com.vesoft.nebula.client.graph.data.ResultSet;
10 import com.vesoft.nebula.client.graph.exception.IOErrorException;
11 import com.vesoft.nebula.client.graph.net.Session;
12 import com.vesoft.nebula.client.graph.net.SessionState;
13 import com.vesoft.nebula.client.graph.net.SyncConnection;
14 import java.io.Serializable;
15 import java.util.Collections;
16 import java.util.HashMap;
18 import java.util.concurrent.atomic.AtomicBoolean;
19 import java.util.concurrent.atomic.AtomicReference;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
25 private static final long serialVersionUID = -88438249377120255L;
27 private final Logger log = LoggerFactory.getLogger(this.getClass());
29 private final long sessionID;
30 private final int timezoneOffset;
32 private final AtomicReference<SessionState> state =
new AtomicReference<>();
34 private final AtomicBoolean isReleased =
new AtomicBoolean(
false);
38 this.connection = connection;
39 this.sessionID = sessionID;
40 this.timezoneOffset = timezoneOffset;
41 this.state.set(state);
44 public long getSessionID() {
48 public Boolean isIdle() {
52 public Boolean isUsed() {
56 public boolean isUsedAndSetIdle() {
60 public boolean isIdleAndSetUsed() {
65 return new ResultSet(connection.execute(sessionID, stmt), timezoneOffset);
68 public ResultSet executeWithParameter(String stmt, Map<String, Object> parameterMap)
70 Map<byte[], Value> map =
new HashMap<>();
72 return new ResultSet(connection.executeWithParameter(sessionID, stmt, map), timezoneOffset);
76 return executeWithParameterTimeout(stmt,
77 (Map<String, Object>) Collections.EMPTY_MAP,
81 public ResultSet executeWithParameterTimeout(String stmt,
82 Map<String, Object> parameterMap,
84 Map<byte[], Value> map =
new HashMap<>();
86 return new ResultSet(connection.executeWithParameterTimeout(sessionID,
94 public String executeJsonWithParameter(String stmt, Map<String, Object> parameterMap)
96 Map<byte[], Value> map =
new HashMap<>();
98 return connection.executeJsonWithParameter(sessionID, stmt, map);
101 public void release() {
102 if (isReleased.get()) {
105 if (isReleased.compareAndSet(
false,
true)) {
107 connection.signout(sessionID);
109 }
catch (Exception e) {
The Session is an object that operates with nebula-graph.
static Value value2Nvalue(Object value)
convert java value type to nebula thrift value type