Uploading Objects

upload Method

For better maintainability and code simplicity, Java API uses a Map object to store multiple key-value pairs and pass the Map object through variables, allowing for more efficient management and operation of multiple data entities.

public void upload(final Map<String, Entity> variableObjectMap)
  • The key of the Map represents the name of the object to be uploaded. The variable name can contain letters, digits and underscores, and the first character must be a letter.
  • The value of the Map represents the object to be uploaded.

For example:

@Test
public void testUpload() throws IOException {
    DBConnection dbConnection = new DBConnection();
    dbConnection.connect("192.168.0.68", 8848);

    Entity dict = dbConnection.run("dict(1 2 3,`IBM`MSFT`GOOG)");
    Map<String, Entity> map = new HashMap<String, Entity>();
    map.put("dict", dict);
    dbConnection.upload(map);
    Entity dict1 = dbConnection.run("dict");
    System.out.println(dict1.getString());
}

Execution result:

Connect to 192.168.0.68:8848.
{1,2,3}->{IBM,MSFT,GOOG}

tryUpload Method

Similar to the tryRun method mentioned in Executing Scripts, the upload method uses the same lock and the tryUpload method is provided. Note that tryUpload throws an IOException immediately if the lock is held by other threads, while tryRun returns a null value.

For example:

@Test
public void test_tryUpload() throws IOException{
    DBConnection dbConnection = new DBConnection();
    dbConnection.connect("192.168.0.68", 8848);

    BasicTable tb = (BasicTable) dbConnection.run("table(1..100 as id,take(`aaa,100) as name)");
    Map<String, Entity> upObj = new HashMap<>();
    upObj.put("table_uploaded",tb);
    dbConnection.tryUpload(upObj);
    Entity entity = dbConnection.run("table_uploaded");
    System.out.println(entity.getString());
}

Execution result:

Connect to 192.168.0.68:8848.
id name
-- ----
1  aaa 
2  aaa 
3  aaa 
4  aaa 
5  aaa 
6  aaa 
7  aaa 
8  aaa 
9  aaa 
10 aaa 
...