Skip to main content
Version: 0.23.0

Persisting Models

Local database

The SDK provides the ability to save your model to a local SQLite database. This may be handy for situations such as saving a model in a specific state / configuration, or it may be quicker to persist the model to a local database and reload than it is rebuilding your model from a source data system every time you want to build it.

void saveToDb(String dbFile,
NetworkService networkService,
DiagramService diagramService,
CustomerService customerService) {
// All service are saved to the given dbFile file
MetadataCollection metadata = new MetadataCollection();
metadata.add(new DataSource("Name of source (e.g. GisExtractor)", "0.1", Instant.now()));
new DatabaseWriter(dbFile).save(metadata, Arrays.asList(networkService, diagramService, customerService));
}

void readFromDb(String dbFile,
MetadataCollection metadata,
NetworkService networkService,
DiagramService diagramService,
CustomerService customerService) {
// All the services will be loaded with their respective objects from dbFile
new DatabaseReader(dbFile).load(metadata, networkService, diagramService, customerService)
}

Evolve data service

danger

The API for persisting data to a remote server is currently in alpha and very likely to experience breaking changes in the future. Please provide any feedback about this API to Zepben.

The SDK provides a client to send models to a remote data server via gRPC. The service and proto definitions for this API can be found here. An implementation of the server for the services is provided with the Evolve platform data services.

Here is an example of how to connect to and send a model to the evolve data server:

NetworkService networkService = new NetworkService();
CustomerService customerService = new CustomerService();
DiagramService diagramService = new DiagramService();
populateNetworkObjects(networkService)

try (GrpcChannel channel = GrpcChannelFactory.create(new ConnectionConfig(host, port))) {
new NetworkProducerClient(channel).send(networkService);
new CustomerProducerClient(channel).send(customerService);
new DiagramProducerClient(channel).send(diagramService);
}

Caveats

This section covers things to keep in mind when attempting to save the model:

  • TODO