Hi everybody,
I’m currently trying to use ConJobs stored in the database. These job are triggering methods which use arguments. I have a problem with these arguments.
When looking at the BatchProcessor presentation of Servoy you just see that the method addCronJob requires an Array as argument for the method arguments (method called by the job), but you don’t see how it is stored in the database.
Currently I have a database column called fld_method_arguments of type text which is apparently the Array datatype of PostgreSQL for Strings.
And I store my arguments in this column that way:
fld_method_arguments = new Array(v_arguments); //v_arguments is a String
When I try to save I get the follwing error:
save failed for 1 or more records
com.servoy.j2db.dataprocessing.DataException: Cannot cast an instance of java.lang.String to type Types.ARRAY
What is the correct syntax to use to store the array? Is it the right way to do to make your cronjob work with arguments?
Hi Foobrother,
I wouldn’t suggest to use a database array type to store Java(Script) arrays. Instead use a text column and store the JSON object.
ROCLASI:
Hi Foobrother,
I wouldn’t suggest to use a database array type to store Java(Script) arrays. Instead use a text column and store the JSON object.
But when I set the column to datatype character varying(1000) and store the Array object, it puts [Ljava.lang.Object;@6df971 in the database
And when I try AddCronJob I get the following error (fld_method_arguments is the last argument):
Can’t find method com.servoy.extensions.plugins.scheduler.SchedulerProvider.js_addCronJob(string,string,function,java.util.Date,java.util.Date,string).
In Servoy presention, in the screenshots of the database table content, you can see “12|someText” in the fld_method_arguments column. I only get that in PostgreSQL if I actually store a String “12|someText”. But a String is not accepted by AddCronJob ![Sad :(]()
Foobrother:
ROCLASI:
Hi Foobrother,
I wouldn’t suggest to use a database array type to store Java(Script) arrays. Instead use a text column and store the JSON object.
But when I set the column to datatype character varying(1000) and store the Array object, it puts [Ljava.lang.Object;@6df971 in the database
Correct, that’s why you have to convert it into a JSON object using the serialize plugin (see plugins node in the solution explorer).
This plugin has 2 functions, toJSON and fromJSON. toJSON will return a string representation of the JavaScript object. And fromJSON it will take this string representation and turn it into a JavaScript object again.
Foobrother:
In Servoy presention, in the screenshots of the database table content, you can see “12|someText” in the fld_method_arguments column. I only get that in PostgreSQL if I actually store a String “12|someText”. But a String is not accepted by AddCronJob ![Sad :(]()
I guess what they do is reading the string and using the split() function to turn it back into an array.
var args = dbValue.split("|"); // returns an array
And to store the array back you use:
dbValue = args.join("|");// returns a string
Hope this helps.
I understand now how to do!
I have changed my code to use the serialize plugin functions and now it loads the jobs properly ![Very Happy :D]()
I actually get this kind of string when I use toJSON():
{“javaClass”:“java.util.ArrayList”,“list”:[4,3,“This Week”]}
Thank you for your help! ![Very Happy :D]()