Skip to content

Commit

Permalink
Merge pull request #2 from dartartem/master
Browse files Browse the repository at this point in the history
Fixed bean scopes
  • Loading branch information
cer authored Jan 19, 2021
2 parents c1367da + 25f99af commit c678dc5
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package io.eventuate.common.quarkus.id;

import io.eventuate.common.id.ApplicationIdGenerator;
import io.eventuate.common.id.IdGenerator;
import io.eventuate.common.id.DatabaseIdGenerator;
import io.eventuate.common.id.IdGenerator;
import org.eclipse.microprofile.config.inject.ConfigProperty;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Singleton;
import java.util.Optional;

@ApplicationScoped
@Singleton
public class IdGeneratorConfiguration {
@Produces
@Singleton
public IdGenerator idGenerator(@ConfigProperty(name = "eventuate.outbox.id") Optional<Long> id) {
return id
.map(DatabaseIdGenerator::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
import io.eventuate.common.inmemorydatabase.EventuateInMemoryDataSourceBuilder;

import javax.annotation.Priority;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Alternative;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Produces;
import javax.inject.Singleton;
import javax.sql.DataSource;
import java.util.stream.Collectors;

@ApplicationScoped
@Singleton
@Alternative
@Priority(0)
public class EventuateCommonInMemoryDatabaseConfiguration {
@Produces
@Singleton
public DataSource dataSource(Instance<EventuateDatabaseScriptSupplier> scripts) {
return new EventuateInMemoryDataSourceBuilder(scripts.stream().collect(Collectors.toList())).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.sql.DataSource;

@QuarkusTest
public class EventuateCommonInMemoryDatabaseTest {

@Inject
Instance<DataSource> dataSource;
DataSource dataSource;

@Test
public void testThatInMemoryDataSourceIsUsed() {
Assertions.assertTrue(dataSource.get().getClass().getName().contains("EmbeddedDataSource"));
Assertions.assertTrue(dataSource.getClass().getName().contains("EmbeddedDataSource"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
import org.eclipse.microprofile.config.inject.ConfigProperty;

import javax.annotation.Priority;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Alternative;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Produces;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.sql.DataSource;

@ApplicationScoped
@Singleton
@Alternative
@Priority(1)
public class DataSourceSelectorConfiguration {

@Produces
@Singleton
public DataSource defaultDatasource(@ConfigProperty(name = "eventuateDatabase") String db,
@Named("mysql") Instance<DataSource> mysql,
@Named("postgres") Instance<DataSource> postgres,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,25 @@
import io.eventuate.common.jdbc.EventuateSqlException;
import io.eventuate.common.jdbc.EventuateTransactionTemplate;
import io.eventuate.common.jdbc.sqldialect.SqlDialectSelector;
import io.quarkus.arc.DefaultBean;
import org.eclipse.microprofile.config.inject.ConfigProperty;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Produces;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Optional;

@ApplicationScoped
@Singleton
public class EventuateCommonJdbcOperationsConfiguration {

@Produces
@Singleton
public EventuateCommonJdbcOperations eventuateCommonJdbcOperations(EventuateJdbcStatementExecutor eventuateJdbcStatementExecutor,
SqlDialectSelector sqlDialectSelector,
@ConfigProperty(name = "eventuateDatabase") String dbName) {
return new EventuateCommonJdbcOperations(eventuateJdbcStatementExecutor, sqlDialectSelector.getDialect(dbName, Optional.empty()));
}

@Produces
@Singleton
public EventuateJdbcStatementExecutor eventuateJdbcStatementExecutor(Instance<DataSource> dataSource) {
return new EventuateCommonJdbcStatementExecutor(() -> {
try {
Expand All @@ -39,7 +35,7 @@ public EventuateJdbcStatementExecutor eventuateJdbcStatementExecutor(Instance<Da
});
}

@Produces
@Singleton
public EventuateTransactionTemplate eventuateTransactionTemplate(EventuateQuarkusTransactionTemplate eventuateQuarkusTransactionTemplate) {
return eventuateQuarkusTransactionTemplate::executeInTransaction;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.eventuate.common.quarkus.jdbc;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Singleton;
import javax.transaction.Transactional;
import java.util.function.Supplier;

@ApplicationScoped
@Singleton
public class EventuateQuarkusTransactionTemplate {

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import io.eventuate.common.jdbc.EventuateSchema;
import org.eclipse.microprofile.config.inject.ConfigProperty;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Singleton;
import java.util.Optional;

@ApplicationScoped
@Singleton
public class EventuateSchemaConfiguration {
@Produces
@Singleton
public EventuateSchema eventuateSchema(@ConfigProperty(name = "eventuate.database.schema") Optional<String> eventuateDatabaseSchema) {
return new EventuateSchema(eventuateDatabaseSchema.orElse(null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,36 @@
import io.eventuate.common.jdbc.sqldialect.SqlDialectSelector;
import org.eclipse.microprofile.config.inject.ConfigProperty;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Produces;
import javax.inject.Singleton;
import java.util.Optional;
import java.util.stream.Collectors;

@ApplicationScoped
@Singleton
public class SqlDialectConfiguration {

@Produces
@Singleton
public MySqlDialect mySqlDialect() {
return new MySqlDialect();
}

@Produces
@Singleton
public PostgresDialect postgreSQLDialect() {
return new PostgresDialect();
}

@Produces
@Singleton
public MsSqlDialect msSqlDialect() {
return new MsSqlDialect();
}

@Produces
@Singleton
public DefaultEventuateSqlDialect defaultSqlDialect(@ConfigProperty(name = "eventuate.current.time.in.milliseconds.sql")
Optional<String> customCurrentTimeInMillisecondsExpression) {
return new DefaultEventuateSqlDialect(customCurrentTimeInMillisecondsExpression.orElse(null));
}

@Produces
@Singleton
public SqlDialectSelector sqlDialectSelector(Instance<EventuateSqlDialect> dialects) {
return new SqlDialectSelector(dialects.stream().collect(Collectors.toList()));
}
Expand Down

0 comments on commit c678dc5

Please sign in to comment.