Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HSQLDB and in-memory files

Is it possible to setup HSQLDB in a way, so that the files with the db information are written into memory instead of using actual files? I want to use hsqldb to export some data structures together with hibernate mappings. Is is, however, not possible to write temporary files, so that I need to generate the files in-memory and return a stream with their contents as a response.

Setting hsqldb to use nio seems not to be a solution, because there is no way to get hold of those files before they get written onto the filesystem.

What I'm thinking of is a protocol handler for hsqldb, but I didn't find a suitable solution yet.

Just to describe in other words: A hack solution would be to pass hsqldb a stream or several streams. It would then during its operation write data into those streams. After all data is written, the user of the db could then use those streams to send it back over the network.

like image 760
paweloque Avatar asked Dec 04 '25 19:12

paweloque


1 Answers

Yes, of course, we use it all the time for integration testing.

use as url : jdbc:hsqldb:mem:aname

see here for more details

DbUnit offers a handy database dump method as part of their package :

    // database connection
    Class driverClass = Class.forName("org.hsqldb.jdbcDriver");
    Connection jdbcConnection = DriverManager.getConnection(
            "jdbc:hsqldb:sample", "sa", "");
    IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);

    // full database export
    IDataSet fullDataSet = connection.createDataSet();
    FlatXmlDataSet.write(fullDataSet, new FileOutputStream("full.xml"));

see DbUnit FAQ for more details. Of course there are routines to restore the data, as that is actually the puropose of the package : prepare a test database for integration testing. Usually we do this with an annotation, but you'll have to use tha API for that.

like image 65
Peter Tillemans Avatar answered Dec 06 '25 12:12

Peter Tillemans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!