Şu satırı dahil ederiz
<dependency><groupId>expert.os.integration</groupId><artifactId>microstream-jakarta-data</artifactId><version>${microstream.data.version}</version></dependency><dependency><groupId>one.microstream</groupId><artifactId>microstream-afs-sql</artifactId><version>${microstream.version}</version></dependency><dependency><groupId>org.postgresql</groupId><artifactId>postgresql</artifactId><version>42.2.14</version></dependency>
Örnek
Şöyle yaparız
@ApplicationScoped class DataSourceSupplier implements Supplier<DataSource> { private static final String JDBC = "microstream.postgresql.jdbc"; private static final String USER = "microstream.postgresql.user"; private static final String PASSWORD = "microstream.postgresql.password"; @Override @Produces @ApplicationScoped public DataSource get() { Config config = ConfigProvider.getConfig(); PGSimpleDataSource dataSource = new PGSimpleDataSource(); dataSource.setUrl(config.getValue(JDBC, String.class)); dataSource.setUser(config.getValue(USER, String.class)); dataSource.setPassword(config.getValue(PASSWORD, String.class)); return dataSource; } } @Alternative @Priority(Interceptor.Priority.APPLICATION) @ApplicationScoped class SQLSupplier implements Supplier<StorageManager> { @Inject private DataSource dataSource; @Override @Produces @ApplicationScoped public StorageManager get() { SqlFileSystem fileSystem = SqlFileSystem.New( SqlConnector.Caching( SqlProviderPostgres.New(dataSource) ) ); return EmbeddedStorage.start(fileSystem.ensureDirectoryPath("microstream_storage")); } public void close(@Disposes StorageManager manager) { manager.close(); } }
Kullanmak için şöyle yaparız
@Repository public interface Airport extends CrudRepository<Airplane, String> { List<Airplane> findByModel(String model); } @Entity public class Airplane { @Id private String id; @Column("title") private String model; @Column("year") private Year year; @Column private String manufacturer; } try (SeContainer container = SeContainerInitializer.newInstance().initialize()) { Airplane airplane = ...; Airplane airplane2 = ...; Airplane airplane3 = ...; Airplane airplane4 = ...; Airplane airplane5 = ...; Airport airport = container.select(Airport.class).get(); airport.saveAll(List.of(airplane, airplane2, airplane3, airplane4, airplane5)); var boings = airport.findByModel(airplane.getModel()); var all = airport.findAll().toList(); System.out.println("The boings: " + boings); System.out.println("The boing models avialables: " + boings.size()); System.out.println("The airport total: " + all.size()); }
Hiç yorum yok:
Yorum Gönder