1. Ultipa Database Address
Multiple addresses of the servers of a cluster should be separated with comma ',' before being configured as the Ultipa Database Address.
2. Account and Password
Default account and password of the Ultipa Database are both 'root'
3. Configuration
Configuration class UltipaConfiguration
suports settings such as connetion timeout, consistency level, etc. In the case of ssl connetection type, crt
and overrideAuthority
should be set.
Item | Range | Description |
---|---|---|
username | / | The account username |
password | / | The account password |
hosts | / | The server address, either the address of a stand-alone server, or multiple addresses of all servers of a cluster separated with comma ',' |
timeout | >0 | The UQL operation timeout |
consistency | true , false |
The consistency level |
crt | / | File path of CA certificate |
overrideAuthority | ultipa |
Over-ride the 'hostname' to match the cert the server uses |
heartbeat | >0, int | the seconds of heartbeat to all instances, 10 by default, and 0 means turn off heartbeat |
maxRecvSize | >0, int | max byte when receive data, 410241024 byte by default (4M) |
defaultGraph | str | graphset name when establishing connection with database, or 'default' graphset if not set |
4. Instantiation of UltipaClientDriver
UltipaConfiguration configuration = UltipaConfiguration.config()
.username("root")
.password("root")
.hosts("192.168.1.1:60061");
UltipaClientDriver driver = new UltipaClientDriver(configuration);
Connection client = new DefaultConnection(driver, "default");
String reply = client.sayHello("Ultipa");
System.out.println(reply);
5. Configuration File
The Ultipa Server can also be connected via a configuration file named 'ultipa.properties', which will be read automatically when creating UltipaClientDriver
and thus no need for UltipaConfiguration
.
Create file 'ultipa.properties' under classpath
of the database project, and fill below configurations:
ultipa.username=root
ultipa.password=root
ultipa.hosts=192.168.1.1:60061,192.168.1.2:60061,192.168.1.3:60061
ultipa.timeout=15
ultipa.consistency=false
ultipa.crt=F:\\ultipa.crt
ultipa.overrideAuthority=ultipa
ultipa.defaultGraph=default
Instantiate the UltipaClientDriver
with configuration file:
UltipaClientDriver driver = new UltipaClientDriver();
Connection client = new DefaultConnection(driver);
String reply = client.sayHello("Ultipa");
System.out.println(reply);
6. Connection Pool
UltipaClientDriver
uses connection pool by default. The underlying implementation uses Apache Common-Pool, connection pool information can be configured when creating UltipaClientDriver
(which will be overwritten by the configuration in the ultipa.properties
under classpath if there is any):
UltipaConfiguration configuration = UltipaConfiguration.config()
.username("root")
.password("root")
.hosts("192.168.1.1:60061");
PoolConfig poolConfig
= configuration.getPoolConfig();
poolConfig.setMaxIdle(50);
poolConfig.setMinIdle(2);
poolConfig.setMaxTotal(200);
poolConfig.setMaxWaitMillis(-1);
UltipaClientDriver driver = new UltipaClientDriver(configuration);
Connection client = new DefaultConnection(driver, "default");
String reply = client.sayHello("Ultipa");
System.out.println(reply);
The connection pool information can be alternatively included in the configuration file 'ultipa.properties':
# Maximum number of idle connections
ultipa.pool.maxIdle=50
# Minimum number of idle connections
ultipa.pool.minIdle=20
# Maximum number of total connections
ultipa.pool.maxTotal=2000
# Minimum idle time of an evictable connection, defalut is 1800000 ms (30 min)
ultipa.pool.minEvictableIdleTimeMillis=1800000
# Test interval for evictable connections (ms), default is -1 (do not scan)
ultipa.pool.timeBetweenEvictionRunsMillis=3600000
# Test connections when borrow, default is fasle
ultipa.pool.testOnBorrow=true
# Test connections when return, default is fasle
ultipa.pool.testOnReturn=false
# Test connections when idle, default is fasle
ultipa.pool.testWhileIdle=false
# Maximum wait time, default is -1 (infinite wait)
ultipa.pool.maxWaitMillis=-1
# Last in first out, default is true
ultipa.pool.lifo=true
# Block new request when connections are exhausted, default is true (block until timeout), false will popup error
ultipa.pool.blockWhenExhausted=true
# Number of connections to test each time, default is 3
ultipa.pool.numTestsPerEvictionRun=3
7. Create DataSource
When creating datasource the configuration in ultipa.properties
under classpath will be ingored:
UltipaConfiguration configuration = UltipaConfiguration.config()
.username("root")
.password("root")
.hosts("192.168.1.1:60061");
PoolConfig poolConfig
= configuration.getPoolConfig();
poolConfig.setMaxIdle(50);
poolConfig.setMinIdle(2);
poolConfig.setMaxTotal(200);
poolConfig.setMaxWaitMillis(-1);
DataSource dataSource = new DataSource();
dataSource.setUltipaConfiguration(configuration);
UltipaClientDriver driver = new UltipaClientDriver(dataSource);
Connection client = new DefaultConnection(driver, "default");
String reply = client.sayHello("Ultipa");
System.out.println(reply);