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.
- Java
- Kotlin
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)
}
fun saveToDb(
dbFile: String,
networkService: NetworkService,
diagramService: DiagramService,
customerService: CustomerService
) {
// The metadata and all service are saved to the given dbFile file
val metadata = MetadataCollection().apply { add(DataSource("Name of source (e.g. GisExtractor)", version = "0.1")) }
DatabaseWriter(dbFile).save(metadata, listOf(networkService, diagramService, customerService))
}
fun readFromDb(
dbFile: String,
metadata: MetadataCollection,
networkService: NetworkService,
diagramService: DiagramService,
customerService: CustomerService
) {
// The metadata and all the services will be loaded with their respective objects from dbFile
DatabaseReader(dbFile).load(metadata, networkService, diagramService, customerService)
}
Evolve data service
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:
- Java
- Kotlin
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);
}
val networkService = NetworkService()
val customerService = CustomerService()
val diagramService = DiagramService()
populateNetworkObjects(networkService)
GrpcChannelFactory.create(ConnectionConfig(host, port)).use {
NetworkProducerClient(it).send(networkService)
CustomerProducerClient(it).send(customerService)
DiagramProducerClient(it).send(diagramService)
}
Caveats
This section covers things to keep in mind when attempting to save the model:
- TODO