MicroStream Reference Manual
MicroStream HomeAPI Docs
3.0
3.0
  • Preface
  • System Requirements
  • License
  • Changelog
  • Installation
  • Data-Store
    • Overview
    • Getting Started
    • Root Instances
    • Configuration
      • Properties
      • Storage Files and Directories
      • Using Channels
      • Housekeeping
      • Backup
      • Lock File
    • Storing Data
      • Convenience Methods and Explicit Storing (Transactions)
      • Lazy and Eager Storing
      • Transient Fields
      • Best Practice
    • Loading Data
      • Lazy Loading
        • Touched Timestamp, Null-Safe Variant
        • Clearing Lazy References
    • Deleting Data
    • Queries
    • Application Life-Cycle
    • Legacy Type Mapping
      • User Interaction
    • Backup Strategies
    • Import / Export
    • Housekeeping
    • Customizing
      • Custom Type Handler
      • Custom Legacy Type Handler
      • Custom Class Loader
      • Custom Storing Behavior
      • Optional Storage Manager Reference in Entities
    • REST Interface
      • Setup
      • REST API
      • Client GUI
    • FAQ
      • Data Model
      • Data Management
      • File Storage
      • Java Features
      • Miscellaneous
    • Addendum
      • Supported Java Features
      • Specialized Type Handlers
      • Examples and Demo Projects
  • Cache
    • Overview
    • Getting Started
    • Configuration
      • Properties
      • Storage
    • Use Cases
      • Hibernate Second Level Cache
      • Spring Cache
  • Basic Concepts
    • Layered Entities
      • Configuration
      • Defining Entities
      • Creating Entities
      • Updating Entities
      • Versioning
      • Logging
      • Multiple Layers
    • Wrapping
      • Configuration
      • Usage
Powered by GitBook
On this page
Export as PDF
  1. Data-Store

Import / Export

PreviousBackup StrategiesNextHousekeeping

Last updated 3 years ago

This is the manual for older MicroStream versions (Version < 5.0).

The new documentation (Version >= 5.0) is located at:

MicroStream provides an API to import and export persisted data of the storage. It is pretty much the same as writing and reading a backup.

The records in the storage are distributed in lots of files and folders, depending on channel count and other . To get order in the chaos the export produces one file per type. This files are used again by the import to read the data into the storage.

The created binary type data files contain only records of the according type, nevertheless they have the same format as the channel storage files.

Export
EmbeddedStorageManager            storage         = ...
Path                              targetDirectory = Paths.get("export-dir");
String                            fileSuffix      = "bin";
StorageConnection                 connection      = storage.createConnection();
StorageEntityTypeExportStatistics exportResult    = connection.exportTypes(
	new StorageEntityTypeExportFileProvider.Default(targetDirectory, fileSuffix),
	typeHandler -> true // export all, customize if necessary
);
XSequence<Path>                    exportFiles = CQL
	.from(exportResult.typeStatistics().values())
	.project(s -> Paths.get(s.file().identifier()))
	.execute()
;
Import
EmbeddedStorageManager storage    = ...
StorageConnection      connection = storage.createConnection();
connection.importFiles(X.Enum(
	Paths.get("type1.bin"),
	Paths.get("type2.bin")
));

Data Conversion

It is also possible to convert the exported binary files to a human readable format, namely CSV.

Why CSV?

Contrary to XML or JSON, CSV is perfectly suited to represent records with the least possible overhead. There are a lot of tools, like spreadsheet editors, which can read and modify CSV files. The file's size is at the possible minimum and the performance of the converter is significantly better than with the other formats.

Binary to CSV
EmbeddedStorageManager storage   = ...
Path                   csvDir    = Paths.get("csv-dir");
Path                   typeFile  = Paths.get("type1.bin");
StorageDataConverterTypeBinaryToCsv converter = 
    new StorageDataConverterTypeBinaryToCsv.UTF8(
		StorageDataConverterCsvConfiguration.defaultConfiguration(),
		new StorageEntityTypeConversionFileProvider.Default(csvDir, "csv"),
		storage.typeDictionary(),
		null, // no type name mapping
		4096, // read buffer size
		4096  // write buffer size
);
StorageLockedFile storageFile = StorageLockedFile.openLockedFile(typeFile);
try
{
	converter.convertDataFile(storageFile);
}
finally
{
	storageFile.close();
}
CSV to Binary
EmbeddedStorageManager storage = EmbeddedStorage.start();
Path                   binDir  = Paths.get("bin-dir");
Path                   csvFile = Paths.get("type1.csv");
StorageDataConverterTypeCsvToBinary<StorageFile> converter = 
	StorageDataConverterTypeCsvToBinary.New(
		StorageDataConverterCsvConfiguration.defaultConfiguration(),
		storage.typeDictionary(),
		new StorageEntityTypeConversionFileProvider.Default(binDir, "dat")
);
StorageLockedFile storageFile = StorageLockedFile.openLockedFile(csvFile);
try
{
	converter.convertCsv(storageFile);
}
finally
{
	storageFile.close();
}
https://docs.microstream.one/
settings