Data Type
Ultipa property types and Java data types are correlated as following pairs:
Ultipa | Java |
---|---|
string | String |
text | String |
float | float |
double | double |
int32 | int |
uint32 | long |
int64 | long |
uint64 | String |
datetime | java.util.Date |
timestamp | java.util.Date |
insertNodesBatchBySchema()
InsertNodesBatchBySchema()
will insert multiple nodes of a particular node schema. The properties carried in the values of nodes should be consistent with those declared in the schema structure.
Method and class:
Response insertNodesBatchBySchema(Schema schema, List<Node> nodes, InsertRequestConfig requestConfig)
class Schema {
String name;
String description;
List<Property> properties;
Ultipa.DBType dbType;
int total;
}
class Property {
String name;
String type;
Boolean lte;
String schema;
String description;
}
class Node {
Long uuid;
String id;
String schema;
Value values;
}
Example: Insert multiple nodes into schema 'customer' of graphset 'test', use normal insert mode
public class Main {
public static void main(String[] args) {
// omit code of establishing server connection 'conn' using graphset 'default'
InsertRequestConfig insertRequestConfig = new InsertRequestConfig();
insertRequestConfig.setInsertType(Ultipa.InsertType.NORMAL);
insertRequestConfig.setGraphName("test");
List<Property> propertyList = new ArrayList<>();
Property name = new Property();
name.setName("name");
name.setPropertyType(UltipaPropertyType.STRING);
Property age = new Property();
age.setName("age");
age.setPropertyType(UltipaPropertyType.INT32);
propertyList.add(name);
propertyList.add(age);
Schema schema = new Schema();
schema.setName("client");
schema.setDescription("bank client");
schema.setDbType(Ultipa.DBType.DBNODE);
schema.setProperties(propertyList);
List<Node> nodeList = new ArrayList<>();
Node node1 = new Node();
node1.setID("1");
Value value1 = new Value();
value1.put("name","Jason");
value1.put("age",35);
node1.setValues(value1);
nodeList.add(node1);
Node node2 = new Node();
node2.setID("2");
Value value2 = new Value();
value2.put("name","Alice");
value2.put("age",29);
node2.setValues(value2);
nodeList.add(node2);
Response res = conn.insertNodesBatchBySchema(schema, nodeList, insertRequestConfig);
}
}
insertNodesBatchAuto()
InsertNodesBatchAuto()
will insert multiple nodes of multiple node schemas. The nodes should carry schema, and the properties carried in the values of nodes should be consistent with those defined in the graphset.
Method and class:
BatchAutoInsertResponse insertNodesBatchAuto(List<Node> nodeList, InsertRequestConfig requestConfig)
class Node {
Long uuid;
String id;
String schema;
Value values;
}
Example: Insert multiple nodes into multiple schemas of graphset 'test', use upsert mode
public class Main {
public static void main(String[] args) {
// omit code of establishing server connection 'conn' using graphset 'default'
InsertRequestConfig insertRequestConfig = new InsertRequestConfig();
insertRequestConfig.setInsertType(Ultipa.InsertType.UPSERT);
insertRequestConfig.setGraphName("test");
List<Node> nodeList = new ArrayList<>();
Node node1 = new Node();
node1.setSchema("client");
node1.setID("1");
Value value1 = new Value();
value1.put("name","Jason");
value1.put("age",30);
node1.setValues(value1);
nodeList.add(node1);
Node node2 = new Node();
node2.setSchema("tag");
Value value2 = new Value();
value2.put("balance",3644.7f);
value2.put("value","VIP");
node2.setValues(value2);
nodeList.add(node2);
Response res = conn.insertNodesBatchAuto(nodeList, insertRequestConfig);
}
}
insertEdgesBatchBySchema()
InsertEdgesBatchBySchema()
will insert multiple edges of a particular edge schema. The properties carried in the values of edges should be consistent with those declared in the schema structure.
Method and class:
Response insertEdgesBatchBySchema(Schema schema, List<Edge> edges, InsertRequestConfig requestConfig)
class Schema {
String name;
String description;
List<Property> properties;
Ultipa.DBType dbType;
int total;
}
class Property {
String name;
String type;
Boolean lte;
String schema;
String description;
}
class Edge {
Long uuid;
Long fromUuid;
Long toUuid;
String from;
String to;
String schema;
Value values;
}
Example: Insert multiple edges into schema 'transfer' of graphset 'test', use normal insert mode, allowing start/end nodes to be created
public class Main {
public static void main(String[] args) {
// omit code of establishing server connection 'conn' using graphset 'default'
InsertRequestConfig insertRequestConfig = new InsertRequestConfig();
insertRequestConfig.setInsertType(Ultipa.InsertType.NORMAL);
insertRequestConfig.setGraphName("test");
insertRequestConfig.setCreateNodeIfNotExist(true);
List<Property> propertyList = new ArrayList<>();
Property amount = new Property();
amount.setName("amount");
amount.setPropertyType(UltipaPropertyType.DOUBLE);
Property time = new Property();
time.setName("time");
time.setPropertyType(UltipaPropertyType.TIMESTAMP);
propertyList.add(amount);
propertyList.add(time);
Schema schema = new Schema();
schema.setName("transfer");
schema.setDescription("bank card transfer");
schema.setDbType(Ultipa.DBType.DBEDGE);
schema.setProperties(propertyList);
List<Edge> edgeList = new ArrayList<>();
Edge edge1 = new Edge();
edge1.setFrom("CARD00002");
edge1.setTo("CARD00001");
Value value1 = new Value();
value1.put("amount",194.5d);
value1.put("time",Timestamp.valueOf("2022-02-13 9:34:14"));
edge1.setValues(value1);
edgeList.add(edge1);
Edge edge2 = new Edge();
edge2.setFrom("CARD00001");
edge2.setTo("CARD00002");
Value value2 = new Value();
value2.put("amount",400d);
value2.put("time", Timestamp.valueOf("2022-01-30 17:23:54"));
edge2.setValues(value2);
edgeList.add(edge2);
Response res = conn.insertEdgesBatchBySchema(schema, edgeList, insertRequestConfig);
}
}
insertEdgesBatchAuto()
InsertEdgesBatchAuto()
will insert multiple edges of multiple edge schemas. The edges should carry schema, and the properties carried in the values of edges should be consistent with those defined in the graphset.
Method and class:
BatchAutoInsertResponse insertEdgesBatchAuto(List<Edge> edgeList, InsertRequestConfig requestConfig)
class Edge {
Long uuid;
Long fromUuid;
Long toUuid;
String from;
String to;
String schema;
Value values;
}
Example: Insert multiple edges into multiple schemas of graphset 'test', use overwrite mode, allowing start/end nodes to be created
public class Main {
public static void main(String[] args) {
// omit code of establishing server connection 'conn' using graphset 'default'
InsertRequestConfig insertRequestConfig = new InsertRequestConfig();
insertRequestConfig.setInsertType(Ultipa.InsertType.OVERWRITE);
insertRequestConfig.setGraphName("test");
insertRequestConfig.setCreateNodeIfNotExist(true);
List<Edge> edgeList = new ArrayList<>();
Edge edge1 = new Edge();
edge1.setSchema("transfer");
edge1.setUUID(14L);
edge1.setFrom("CARD00002");
edge1.setTo("CARD00001");
Value value1 = new Value();
value1.put("amount",1254.5d);
value1.put("time",Timestamp.valueOf("2022-02-13 9:34:14"));
edge1.setValues(value1);
edgeList.add(edge1);
Edge edge2 = new Edge();
edge2.setSchema("own");
edge2.setFrom("CLIENT005");
edge2.setTo("CARD00002");
edgeList.add(edge2);
Response res = conn.insertEdgesBatchAuto(edgeList, insertRequestConfig);
}
}