UltipaConfiguration
UltipaConfiguration
defines the information of the server needed when connecting to Ultipa Graph.
Item |
Type |
Default |
Description |
---|---|---|---|
hosts | String | IP addresses of cluster servers (comma-separated) or host URL (excluding "https://" or "http://") | |
username | String | Username of server | |
password | String | Password of server | |
passwordEncrypt | String | MD5 | Encryption method for password ; supports "MD5" and "LDAP"; set to "NOTHING" for no encryption; "NOTHING" is used when the configration content is blank |
timeout | Integer | 15 | Timeout threshold (in seconds) for requests |
connectTimeout | Integer | 2000 | Timeout threshold for connection (in milliseconds); each host will be attempted 3 times by default |
consistency | Boolean | false | Whether to use the leader host to guarantee Consistency Read |
crt | String | Set to the local certificate file path, then SSL will be used for connection, and overrideAuthority must be appropriately configured. Alternatively, set to "https" if the host URL uses the HTTPS protocol, in which case a public certificate will be used. When crt is ignored or empty, non-SSL connection will be used. |
|
keepAlive | Integer | 120 | The maximum period (in seconds) of inactivity before the client will send a keep-alive probe to the server to ensure the connection remains open and responsive; keep-alives can increase the load on services |
keepAliveWithoutCalls | Boolean | false | Whether the keep-alive mechanism is activated even when the connection is inactive |
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 |
Connect to a Cluster
Example: Connect to a cluster, 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();
}
}
}
}
Connect to Ultipa Cloud
Example: Connect to an instance on Ultipa Cloud, 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("mqj4zouys.us-east-1.cloud.ultipa.com:60010")
.username("***")
.password("***")
.crt("https");
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 | true | if test connections when return |
testWhileIdle | boolean | true | 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 the 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'.
The value of each configuration item is preferentially determined by the UltipaConfiguration
, followed by the ultipa.properties
file. If the item is not found in either configuration, the default value is used.
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.hosts=mqj4zouys.us-east-1.cloud.ultipa.com:60010
ultipa.username=root
ultipa.password=root
ultipa.passwordEncrypt=NOTHING
ultipa.defaultGraph=amz
# ultipa.crt=F:\\ultipa.crt
# ultipa.overrideAuthority=ultipa
# ultipa.crt=https
# ultipa.crt=
ultipa.keepAlive=180
ultipa.keepAliveWithoutCalls=true
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();
}
}
}
}