On 2010-11-06 12.52, Rickard Öberg wrote:
The past week I have battled with shuffling of data between sources,
such as doing restores of backups and similar. I came to realize that
there was a pattern behind how these things work, and created a simple
API that allows inputs and outputs to be encapsulated and easily used in
different scenarios. I've written a longish blogpost that outlines the
thinking, and potential usage:
http://www.jroller.com/rickard/entry/a_generic_input_output_api

If you this solution looks ok, I'd like to introduce it wherever it
makes sense in our API/SPI, to get a streamlined approach to data and
object shuffling.

To check it out, update qi4j-core 1.3-SNAPSHOT. It's in the
org.qi4j.api.io package, with tests.

I'm looking through the EntityStore SPI in particular for potential uses. I'd like to replace ImportSupport with an interface called BackupRestore, and which looks like this:
public interface BackupRestore
{
    /**
     * Input that allows data from the entity store to be backed up.
     * @return
     */
   Input<String, IOException> backup();

    /**
     * Output that allows data to be restored from a backup.
     */
   Output<String, IOException> restore();
}
---
To backup an EntityStore to a text file you would do:
EntityStore store = ...;
File backup = ...;
store.backup().transferTo(Outputs.text(backup));

A restore would be:
EntityStore store = ...;
File backup = ...;
Inputs.text(backup).transferTo(store.restore());

And that's pretty much it, error handling included (since it's done by the EntityStore and Outputs.text/Inputs.text respectively).

It would additionally be possible to add logic to text() methods to handle ".gz" file extensions automatically, so that zipping of data is done by simply calling the file "backup.json.gz".

Is it ok if I do this change?

/Rickard

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to