You can try to use a Script Unit in order to accomplish your task.
There are some useful articles in our WebRatio Wiki:
- Getting started with the Script unit
- Getting started with Groovy
- Script units accessing database
- Querying with Hibernate
Let's make a simple example on how you can write the Groovy script to perform your task.
Suppose you have an uploaded file and you want to save the content of this file inside one Entity of your Data Model.
In particular consider that each row of the uploaded file has a value and you want to save this value in the attribute "Value" of your Entity (i.e. "LogRecord").
So your script should perform these tasks:
1) Take as input the uploaded file
2) Read the uploaded file
3) Parse each row of the file
4) Save the content of each row in the entity LogRecord
First of all you have to define the input of the script (i.e. the uploaded file):
#input RTXBLOBData file
Then let's import some packages that you will use
The last import is the class which represents the JavaBean of the entity "LogRecord"
Now you have to recover the database session
/*Recover db session
Suppose that our database id is "db1"
def dbId = "db1"
def session = getDBSession(dbId)
At this point you have to create a File object from the input file, read it and save its content to the entity ""LogRecord""
/*Create temporary file to parse from RTXBLOBData*/
def tempFile=new File(file.getName());
InputStream inputStream= file.openFileInputStream()
OutputStream outStream=new FileOutputStream(tempFile);
def buf=new byte
Now you have the temporary File object that can be read row by row
/*Read temporary file row by row until !EoF*/
/*Parse your file row*/
In our case each row has only one value
//Create an instance of our entity
LogRecord log = new LogRecord()
//Use the setter method exposed by the JavaBean to set the value
//Save the data in the entity
//Close the InputStream and OutputStream instances in order to release any system resources associated with the streams
//Perform the commit of the database session in order to physically write the changes on the database