UltipaConfiguration
UltipaConfiguration
defines the information of server needed when connecting to an Ultipa graph database.
Item | Type | Default Value | Description |
---|---|---|---|
hosts | String | Ultipa server hosts, separated with comma | |
username | String | username of server | |
password | String | password of server | |
timeout | Integer | 15 | timeout seconds for any request |
connectTimeout | Integer | 2000 | timeout milliseconds for connection, by default each host will be tried 3 times |
consistency | Boolean | false | if use leader host to guarantee Consistency Read |
crt | String | crt file path, provided when establishing ssl connection, and overrideAuthority should be set. Set value using a local cert file, or set to 'https' in which case a public cert file is used and the host should be an url starting with 'https' |
|
overrideAuthority | String | use 'ultipa' to override 'hostname' and match server certificate | |
maxRecvSize | Integer | 4MB | max byte when receiving data |
defaultGraph | String | default | name of graphset to use |
heartBeat | Integer | 10000 | heartbeat milliseconds for all instances, set 0 to turn off heartbeat |
poolConfig | PoolConfig | configuration of connection pool |
Example: Create a server connection, use graphset 'default' when configuring the server, and use 'amz' when instantiating UltipaClientDriver
public class Main {
public static void main(String[] args) {
UltipaConfiguration configuration = UltipaConfiguration.config()
.hosts("192.168.1.85:60061,192.168.1.86:60061,192.168.1.87:60061")
.username("***")
.password("***");
UltipaClientDriver driver = null;
try {
driver = new UltipaClientDriver(configuration);
Connection conn = driver.getConnection("amz");
String reply = conn.sayHello("Hi");
System.out.println(reply);
} finally {
if (driver != null) {
driver.close();
}
}
}
}
PoolConfig
PoolConfig
defines the information of Apache Common-Pool needed when connecting to an Ultipa graph database.
Item | Type | Default Value | Description |
---|---|---|---|
maxIdle | int | 8 | maximum number of idle connections |
minIdle | int | 0 | minimum number of idle connections |
maxTotal | int | 8 | maximum number of total connections |
minEvictableIdleTimeMillis | long | 1800000 | minimum idle milliseconds of an evictable connection |
timeBetweenEvictionRunsMillis | long | -1 | test interval milliseconds for evictable connections, set negative to turn off scan |
maxWaitMillis | long | -1 | maximum wait milliseconds, set negative to wait forever |
testOnBorrow | boolean | false | if test connections when borrow |
testOnReturn | boolean | false | if test connections when return |
testWhileIdle | boolean | false | if test connections when idle |
lifo | bool | true | if last in first out |
blockWhenExhausted | boolean | true | if block new request until timeout when connections are exhausted, set false and popup error |
numTestsPerEvictionRun | int | 3 | maximum number of connections to evict each time |
Example: Create a server connection, use graphset 'default' and configure the connection pool
public class Main {
public static void main(String[] args) {
UltipaConfiguration configuration = UltipaConfiguration.config()
.hosts("192.168.1.85:60061,192.168.1.86:60061,192.168.1.87:60061")
.username("***")
.password("***");
PoolConfig poolConfig = configuration.getPoolConfig();
poolConfig.setMaxIdle(50);
poolConfig.setMinIdle(2);
poolConfig.setMaxTotal(200);
UltipaClientDriver driver = null;
try {
driver = new UltipaClientDriver(configuration);
Connection conn = driver.getConnection();
String reply = conn.sayHello("Hi");
System.out.println(reply);
} finally {
if (driver != null) {
driver.close();
}
}
}
}
ultipa.properties
ultipa.properties
is a configuration file that stores the information of server and connection pool, needed when connecting to an Ultipa graph database.
ultipa.properties should be placed under the 'classpath' of Java project, which is by default './src/main/resources'
When ultipa.properties
is provided while UltipaClientDriver
is instantiated using UltipaConfiguration
:
- server configurations in the
ultipa.properties
will take precedence over those defined byUltipaConfiguration
; - connection pool configurations defined by
PoolConfig
will be ignored, and only those in theultipa.properties
will be considered.
Example: Create a server connection using configuration file
ultipa.hosts=192.168.1.85:60061,192.168.1.86:60061,192.168.1.87:60061
ultipa.username=root
ultipa.password=root
ultipa.defaultGraph=amz
# ultipa.crt=F:\\ultipa.crt
# ultipa.overrideAuthority=ultipa
ultipa.pool.maxIdle=50
ultipa.pool.minIdle=20
ultipa.pool.maxTotal=200
ultipa.pool.timeBetweenEvictionRunsMillis=3600000
ultipa.pool.testOnBorrow=true
public class Main {
public static void main(String[] args) {
UltipaClientDriver driver = null;
try {
driver = new UltipaClientDriver();
Connection conn = driver.getConnection();
String reply = conn.sayHello("Hi");
System.out.println(reply);
} finally {
if (driver != null) {
driver.close();
}
}
}
}
DataSource
DataSrouce
defines the information of server and connection pool needed when connecting to an Ultipa graph database.
When ultipa.properties
is provided while UltipaClientDriver
is instantiated using DataSrouce
:
- both server and connection pool configurations will be defined by
DataSrouce
, and theultipa.properties
will be ignored.
Example: Create a server connection using DataSource
public class Main {
public static void main(String[] args) {
UltipaConfiguration configuration = UltipaConfiguration.config()
.hosts("192.168.1.85:60061,192.168.1.86:60061,192.168.1.87:60061")
.username("***")
.password("***");
PoolConfig poolConfig = configuration.getPoolConfig();
poolConfig.setMaxIdle(50);
poolConfig.setMinIdle(2);
poolConfig.setMaxTotal(200);
DataSource dataSource = new DataSource();
dataSource.setUltipaConfiguration(configuration);
dataSource.setDefaultGraph("amz");
UltipaClientDriver driver = null;
try {
driver = new UltipaClientDriver(dataSource);
Connection conn = driver.getConnection();
String reply = conn.sayHello("Hi");
System.out.println(reply);
} finally {
if (driver != null) {
driver.close();
}
}
}
}
RequestConfig
RequestConfig
defines the information needed when sending non-insert type of requests to an Ultipa graph database.
Item | Type | Default Value | Description |
---|---|---|---|
graphName | String | name of graphset to use, or use defaultGraph configured when establishing server connection if not set |
|
timeout | int | 15 | timeout seconds for the request, or use timeout configured when establishing server connection if not set |
host | String | send the request to a designated host, or sent to a random host if not set | |
useMaster | boolean | False | if send the request to the leader to guarantee Consistency Read |
threadNum | int | number of thread |
Example: Create a server connection using graphset 'default', send a uql to graphset 'amz' and send the request to leader
public class Main {
public static void main(String[] args) {
UltipaConfiguration configuration = UltipaConfiguration.config()
.hosts("192.168.1.85:60061,192.168.1.86:60061,192.168.1.87:60061")
.username("***")
.password("***");
UltipaClientDriver driver = null;
try {
driver = new UltipaClientDriver(configuration);
Connection conn = driver.getConnection();
String reply = conn.sayHello("Hi");
System.out.println(reply);
RequestConfig requestConfig = new RequestConfig();
requestConfig.setGraphName("amz");
requestConfig.setUseMaster(true);
Response res = conn.uql("find().nodes() as nodes return nodes{*} limit 10", requestConfig);
List<Node> nodeList = res.alias("nodes").asNodes();
for(int i = 0; i < nodeList.size(); i ++){
System.out.println("node " + i + " is: " + nodeList.get(i).toJson());
}
} finally {
if (driver != null) {
driver.close();
}
}
}
}
InsertRequestConfig
InsertRequestConfig
defines the information needed when sending insert type of requests to an Ultipa graph database.
Item | Type | Default Value | Description |
---|---|---|---|
graphName | String | name of graphset to use, or use defaultGraph configured when establishing server connection if not set |
|
timeout | int | 15 | timeout seconds for the request, or use timeout configured when establishing server connection if not set |
host | String | send the request to a designated host, or sent to a random host if not set | |
useMaster | boolean | False | if send the request to the leader to guarantee Consistency Read |
insertType | Ultipa.InsertType | NORMAL | insert mode (NORMAL, UPSERT, OVERWRITE) |
createNodeIfNotExist | boolean | false | if create start/end nodes of edge when the end nodes do not exist in the graphset |
Example: Create a server connection using graphset 'default', and insert nodes into graphset 'test' under overwrite mode
public class Main {
public static void main(String[] args) {
UltipaConfiguration configuration = UltipaConfiguration.config()
.hosts("192.168.1.85:60061,192.168.1.86:60061,192.168.1.87:60061")
.username("***")
.password("***");
UltipaClientDriver driver = null;
Connection conn;
try {
driver = new UltipaClientDriver(configuration);
conn = driver.getConnection();
String reply = conn.sayHello("Hi");
System.out.println(reply);
InsertRequestConfig insertRequestConfig = new InsertRequestConfig();
insertRequestConfig.setGraphName("test");
insertRequestConfig.setInsertType(Ultipa.InsertType.OVERWRITE);
List<Node> nodeList = new ArrayList<>();
Node node1 = new Node();
node1.setSchema("client");
node1.setID("CLIENT00001");
nodeList.add(node1);
Node node2 = new Node();
node2.setSchema("card");
node2.setID("CARD00004");
nodeList.add(node2);
conn.insertNodesBatchAuto(nodeList, insertRequestConfig);
} finally {
if (driver != null) {
driver.close();
}
}
}
}