Semplice implementazione di un Data Service Client che si basa su una tabella di un RDBMS
- Aggiungere dipendenza :
<dependency>
<groupId>io.github.caffetteria</groupId>
<artifactId>data-service-db-simple</artifactId>
<version>${data-service-db-simple-version}</version>
</dependency>
- Create database schema
CREATE TABLE data_service_db_simple (
id BIGINT,
content BLOB,
primary key (ID)
);
CREATE SEQUENCE data_service_db_simple_seq START WITH 1 INCREMENT BY 1;
- Configuration reference
parametero | obbligatorio | default | note |
---|---|---|---|
db_mode | false | Possible values are : postgres, mysql, oracle, if not set will try to get from database metadata | |
table_id | true | data_service_db_simple | Table id, with schema, catalog and so (ex. my_catalog.my_schema.my_table) |
field_id | true | id | Field to be used as id in the chosen table. Should be BIGINT |
field_content | true | content | Field to be used as content in the chosen table. Should be BLOB |
sequence_id | true | data_service_db_simple_seq | Name of the sequence to be used for id generation. |
Sample configuration :
db_mode=oracle
table_id=data_service_db_simple
field_id=id
field_content=content
- Setup data service
ConnectionFactory cf = ...
Properties dsProps = ...
ConfigParams config = new ConfigParamsDefault( dsProps );
DbSimpleDataServiceFacade facade = new DbSimpleDataServiceFacade( cf, config );
DataService dataService = DbSimpleDataService.newDataService( facade );
String testData = "testData";
try (InputStream input = new ByteArrayInputStream(testData.getBytes())) {
String id = dataService.save( input );
String readData = StreamIO.readString( dataService.load( id ) );
}