Is there a way to hit the "Additional data stores" in report queries?

I am trying to move the reports I’ve generated from our development environment to a testing environment by exporting the reports and sending those files to the testers, who will then import them. The database names are different, though, so the SQL statements throughout the report must be altered once for testing, and then again when moved into full production. Is there a way to query the “Additional data stores” (found in Project Properties -> Advanced) instead of a local database with SQL?

additionalDataStoresField

reportExport

Hi,

You can pass the additional storename as parameter to persistence methods (createTransaction; getEntityManager).
For example the groovy script may look like this:


def persistence = AppBeans.get(Persistence.class)
def tx = persistence.createTransaction(/*storename*/)
try {
    def em = persistence.getEntityManager(/*storename*/)

    def queryString = 'select ... '
    def q = em.createNativeQuery(queryString)
     .........
	}
    tx.commit()
} finally {
    tx.end()
}

Thanks.
I’ve been toying with this throughout the day.

I keep getting:
No such property: AppBeans for class: Script1

Hi,

You have to import:


import com.haulmont.cuba.core.global.AppBeans
import com.haulmont.cuba.core.Persistence

Thank you, Tudor!

If you have an additional data store in the project, you can specify it for SQL and JPQL queries in the report editor. See the attached screenshot.

report_datastore