Use custom dataContext instance instead of dataManager for Data Import routine

Hi,

generic question here.

I am trying to import all data from a previous CUBA app. Have slight model changes so need to get around them pretty much manually. I proceed by creating a JMX class and calling @ManagedOperations through the interface.

My question is that currently when I run the import I use the following procedure:

a. read the source table such as “select * from tableA” corresponding tableA to the instances of entity A
b. traverse it via a java.sql.ResultSet
c. dataManager.create(newAInstance.class) and store it in a temp arraylist filled with the new entities
d. when I finish traversing the table I call dataManager.save(newEntitiesArray)

and that’s it

However it would save some job to use the following logic

a. read the source table such as “select * from tableA” corresponding tableA to the instances of entity A
b. traverse it via a java.sql.ResultSet
c. dataContext.create(newAInstance.class) (not using any array since instances are tracked by dataContext)
d. when I finish traversing the table I call dataContext.commit() and dataContext.clear()

and then go one with the next table…

In this latter way I wouldn’t need to manage the array holding the entities.

However I am not able to recreate the injected components in my JMX class. Is there any way to do so or would have to set up too many artifacts, being at the end a better approach to maintain the array of entities and then saving them via dataManager.

Hope my explanation was clear enough.

Thanks for any insights.

Regards,
Carlos.

Hi,

Sorry, but I didn’t understand what your problem is.

What components can’t be recreated? What do you mean by “recreated”?

What artifacts do you mean here?

Also, if you speak about a JMX method, then I don’t understand how DataContext is related to this topic? DataContext is only used in UI screens, not in JMX methods.

Could you please provide some code that explains what are you doing?

Just in case, there is a section in the documentation that explains ways to save multiple instances. Maybe you’ll be able to find something useful there.