0 votes

I'm using openLCA core maven module to make impact calculations.

My problem is: I want to create the MatrixCache once, because it is long (30 seconds). This MatrixCache has a IDatabase property. I want to close the connection to this database when the cache is created, and get a new connection when I want to run the calculations :

IDatabase db = new DerbyDatabase(new File(path));
MatrixCache mCache = MatrixCache.createEager(db);
// Do other stuff
// Run calculations
ProductSystem system = ...
CalculationSetup setup = ...
SystemCalculator calc = new SystemCalculator(mCache, new DenseSolver());
SimpleResult r = calc.calculateContributions(setup);

This won't work because the database was closed. So how to "re-open" the MatrixCache database before using it ?

Thank you very much in advance,
Best regards,

in openLCA by (690 points)
edited by

1 Answer

0 votes
by (12k points)
selected by
Best answer

The idea of the matrix cache is to reuse data between different product system builds and calculations of a database. The use case of closing the database between these actions is not considered (why do you want to do this?). Thus, there is currently no API for resetting the database or reopening it in a matrix cache. However, you could always use the reflection API to swap the database instance of the matrix cache but this is of course a hacky solution and could result in other problems:

var matrixCache MatrixCache.createEager(db);
// replace the database in the cache
var dbField matrixCache.getClass().getDeclaredField("database");
dbField.set(matrixCache, freshDB);

by (690 points)
Thank you for your answer !

I wanted to do this so as not to let open the MatrixCache's database while I don't need it. But I understand now why you didn't provide an API for this.