0 votes
941 views
Hi,

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);
db.close();
// 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,

Clement
in openLCA by (700 points)
edited by

1 Answer

0 votes
by (14.0k 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.setAccessible(true);
dbField.set(matrixCache, freshDB);

by (700 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.
ask.openLCA is a question-and-answer (Q&A) website on Life Cycle Assessment (LCA).

It is also the public support platform for openLCA, openLCA Nexus, data.openLCA and the LCA Collaboration Server.

Before asking questions please also consult our online manuals for openLCA and the LCA Collaboration Server.

Receive guaranteed and prioritised professional support via GreenDelta's help desk.

ask.openLCA is run by GreenDelta, the creators of openLCA.

openLCA

LCA Collaboration Server
...